introduce tiles layer
This commit is contained in:
parent
ffec6dd74a
commit
04efd8876a
@ -1,13 +1,9 @@
|
||||
import os
|
||||
|
||||
import pygame
|
||||
from pygame.rect import Rect
|
||||
|
||||
from survival.player import Player
|
||||
from survival.quad_tree import QuadTree
|
||||
from survival.stone import Stone
|
||||
from survival.textureatlas import TextureAtlas
|
||||
from survival.tile import Tile
|
||||
from survival.tile_layer import TileLayer
|
||||
|
||||
|
||||
class GameMap:
|
||||
@ -18,15 +14,12 @@ class GameMap:
|
||||
self.game_objects = []
|
||||
self.player = Player()
|
||||
self.game_objects.append(self.player)
|
||||
self.tiles = [[Tile() for x in range(width)] for y in range(height)]
|
||||
self.atlas = TextureAtlas(os.path.join('..', 'assets', 'atlas.png'))
|
||||
self.tiles_layer = TileLayer(width, height)
|
||||
self.game_objects.append(Stone([100, 200]))
|
||||
self.quad_tree = QuadTree(0, Rect(0, 0, width * 32, height * 32))
|
||||
|
||||
def draw(self, window):
|
||||
for y in range(self.height):
|
||||
for x in range(self.width):
|
||||
window.blit(self.atlas.image_at(self.tiles[y][x].origin, (32, 32)), (x*32, y*32))
|
||||
self.tiles_layer.draw(window)
|
||||
|
||||
for game_object in self.game_objects:
|
||||
game_object.draw(window)
|
||||
|
@ -1,7 +1,3 @@
|
||||
import pygame
|
||||
from random import randrange
|
||||
|
||||
|
||||
class Tile:
|
||||
def __init__(self):
|
||||
self.origin = (0, 0)
|
||||
|
17
survival/tile_layer.py
Normal file
17
survival/tile_layer.py
Normal file
@ -0,0 +1,17 @@
|
||||
import os
|
||||
|
||||
from survival.textureatlas import TextureAtlas
|
||||
from survival.tile import Tile
|
||||
|
||||
|
||||
class TileLayer:
|
||||
def __init__(self, width, height):
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.tiles = [[Tile() for x in range(self.width)] for y in range(self.height)]
|
||||
self.atlas = TextureAtlas(os.path.join('..', 'assets', 'atlas.png'))
|
||||
|
||||
def draw(self, window):
|
||||
for y in range(self.height):
|
||||
for x in range(self.width):
|
||||
window.blit(self.atlas.image_at(self.tiles[y][x].origin, (32, 32)), (x * 32, y * 32))
|
Loading…
Reference in New Issue
Block a user