diff --git a/Assets/IceTileset.tsx b/Assets/IceTileset.tsx
new file mode 100644
index 0000000..29b28d9
--- /dev/null
+++ b/Assets/IceTileset.tsx
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/Assets/Player2.png b/Assets/Player.png
similarity index 100%
rename from Assets/Player2.png
rename to Assets/Player.png
diff --git a/Assets/RPG Nature Tileset Autumn.tsx b/Assets/RPG Nature Tileset Autumn.tsx
new file mode 100644
index 0000000..665acf2
--- /dev/null
+++ b/Assets/RPG Nature Tileset Autumn.tsx
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/Assets/RPG Nature Tileset.tsx b/Assets/RPG Nature Tileset.tsx
new file mode 100644
index 0000000..a726d98
--- /dev/null
+++ b/Assets/RPG Nature Tileset.tsx
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/game.py b/game.py
index 28df354..1b4ccb2 100644
--- a/game.py
+++ b/game.py
@@ -2,18 +2,59 @@
import pygame
+import pytmx
+
+import pyscroll
+
+from src.Player import Player
+
class Game:
def __init__(self):
super().__init__()
- self.screen = pygame.display.set_mode((1080,720))
+ self.screen = pygame.display.set_mode((1080, 720))
pygame.display.set_caption("Desert-island-adventure")
+ # Map data
+ tmx_data = pytmx.util_pygame.load_pygame('main_map.tmx')
+ map_data = pyscroll.data.TiledMapData(tmx_data)
+ self.map_layer = pyscroll.orthographic.BufferedRenderer(map_data, self.screen.get_size())
+ self.map_layer.zoom = 1.8
+
+ # Player spawn
+ self.player_spawn = tmx_data.get_object_by_name("spawn")
+
+ # Player instence
+ self.player = Player(self.player_spawn.x, self.player_spawn.y)
+ # group with map
+ self.group = pyscroll.PyscrollGroup(map_layer=self.map_layer, default_layer=4)
+ self.group.add(self.player)
+
+ def handle(self):
+ keys = pygame.key.get_pressed()
+
+ if keys[pygame.K_UP]:
+ self.player.move_up()
+ self.player.change_image('up')
+ elif keys[pygame.K_DOWN]:
+ self.player.move_down()
+ self.player.change_image('down')
+ elif keys[pygame.K_LEFT]:
+ self.player.move_left()
+ self.player.change_image('left')
+ elif keys[pygame.K_RIGHT]:
+ self.player.move_right()
+ self.player.change_image('right')
+
def run(self):
running = True
+ clock = pygame.time.Clock()
while running:
-
+ self.handle()
+ self.group.update()
+ self.group.draw(self.screen)
+ self.group.center(self.player.rect.center)
# Refresh window
pygame.display.flip()
@@ -24,3 +65,5 @@ def run(self):
print("✅ - Window closes")
sys.exit(0)
running = False
+
+ clock.tick(60)
\ No newline at end of file
diff --git a/main_map.tmx b/main_map.tmx
new file mode 100644
index 0000000..e7332b3
--- /dev/null
+++ b/main_map.tmx
@@ -0,0 +1,209 @@
+
+
diff --git a/src/Player.py b/src/Player.py
new file mode 100644
index 0000000..7b39d16
--- /dev/null
+++ b/src/Player.py
@@ -0,0 +1,41 @@
+import pygame
+
+
+class Player(pygame.sprite.Sprite):
+ def __init__(self, x, y):
+ super().__init__()
+ self.sprite_sheet = pygame.image.load("Assets/Player.png")
+ self.image = self.get_image(0, 0)
+ self.rect = self.image.get_rect()
+ self.position = [x, y]
+ self.speed = 2
+ self.images = {
+ 'down': self.get_image(0, 0),
+ 'up': self.get_image(0, 96),
+ 'left': self.get_image(0, 32),
+ 'right': self.get_image(0, 64)
+ }
+
+ def update(self):
+ self.rect.topleft = self.position
+
+ def get_image(self, x, y):
+ image = pygame.Surface([32, 32])
+ image.blit(self.sprite_sheet, (0, 0), (x, y, 32, 32))
+ image.set_colorkey([0, 0, 0])
+ return image
+
+ def change_image(self, name):
+ self.image = self.images[name]
+
+ def move_up(self):
+ self.position[1] -= self.speed
+
+ def move_down(self):
+ self.position[1] += self.speed
+
+ def move_left(self):
+ self.position[0] -= self.speed
+
+ def move_right(self):
+ self.position[0] += self.speed