camera can adjust to map size now, added test map generator
This commit is contained in:
parent
e51a2aed3a
commit
924e7b46ca
8
main.py
8
main.py
@ -39,6 +39,7 @@ class Game():
|
|||||||
def new(self):
|
def new(self):
|
||||||
# initialize all variables and do all the setup for a new game
|
# initialize all variables and do all the setup for a new game
|
||||||
|
|
||||||
|
# sprite groups
|
||||||
self.roadTiles, self.wallTiles = map_new.getTiles()
|
self.roadTiles, self.wallTiles = map_new.getTiles()
|
||||||
|
|
||||||
self.all_sprites = pg.sprite.Group()
|
self.all_sprites = pg.sprite.Group()
|
||||||
@ -50,7 +51,7 @@ class Game():
|
|||||||
if tile_object.name == 'wall':
|
if tile_object.name == 'wall':
|
||||||
Obstacle(self, tile_object.x, tile_object.y, tile_object.width, tile_object.height)
|
Obstacle(self, tile_object.x, tile_object.y, tile_object.width, tile_object.height)
|
||||||
|
|
||||||
self.camera = Camera(self.map.width, self.map.height)
|
self.camera = Camera(MAP_WIDTH_PX, MAP_HEIGHT_PX)
|
||||||
self.draw_debug = False
|
self.draw_debug = False
|
||||||
|
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ class Game():
|
|||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
pg.display.set_caption("{:.2f}".format(self.clock.get_fps()))
|
pg.display.set_caption("{:.2f}".format(self.clock.get_fps()))
|
||||||
# self.screen.blit(self.new_surface, self.camera.apply_rect(self.map_rect))
|
|
||||||
map_new.renderTiles(self.roadTiles, self.screen, self.camera)
|
map_new.renderTiles(self.roadTiles, self.screen, self.camera)
|
||||||
map_new.renderTiles(self.wallTiles, self.screen, self.camera, self.draw_debug)
|
map_new.renderTiles(self.wallTiles, self.screen, self.camera, self.draw_debug)
|
||||||
|
|
||||||
@ -89,9 +90,6 @@ class Game():
|
|||||||
self.screen.blit(sprite.image, self.camera.apply(sprite))
|
self.screen.blit(sprite.image, self.camera.apply(sprite))
|
||||||
if self.draw_debug:
|
if self.draw_debug:
|
||||||
pg.draw.rect(self.screen, CYAN, self.camera.apply_rect(sprite.hit_rect), 1)
|
pg.draw.rect(self.screen, CYAN, self.camera.apply_rect(sprite.hit_rect), 1)
|
||||||
# if self.draw_debug:
|
|
||||||
# for wall in self.walls:
|
|
||||||
# pg.draw.rect(self.screen, CYAN, self.camera.apply_rect(wall.rect), 1)
|
|
||||||
|
|
||||||
pg.display.flip()
|
pg.display.flip()
|
||||||
|
|
||||||
|
@ -3,14 +3,8 @@ from map_new import map_pattern
|
|||||||
import pygame as pg
|
import pygame as pg
|
||||||
from settings import *
|
from settings import *
|
||||||
|
|
||||||
# def getMap():
|
|
||||||
# array = map_utils.getBlankMapArray()
|
|
||||||
# pattern = map_pattern.getPattern()
|
|
||||||
# surface = map_utils.makeSurfaceMap(array, pattern)
|
|
||||||
# return surface
|
|
||||||
|
|
||||||
def getTiles():
|
def getTiles():
|
||||||
array = map_utils.getBlankMapArray()
|
array = map_utils.generateMap()
|
||||||
pattern = map_pattern.getPattern()
|
pattern = map_pattern.getPattern()
|
||||||
tiles = map_utils.getSprites(array, pattern)
|
tiles = map_utils.getSprites(array, pattern)
|
||||||
return tiles
|
return tiles
|
||||||
|
@ -1,36 +1,28 @@
|
|||||||
|
import random
|
||||||
import pygame as pg
|
import pygame as pg
|
||||||
|
from settings import *
|
||||||
from map_new.tile import Tile
|
from map_new.tile import Tile
|
||||||
|
|
||||||
MAP_WIDTH = 5
|
|
||||||
MAP_HEIGHT = 5
|
|
||||||
|
|
||||||
TILE_SIZE_PX = 64
|
|
||||||
|
|
||||||
# tworzenie pustego arraya o podanych wymiarach
|
# tworzenie pustego arraya o podanych wymiarach
|
||||||
def getBlankMapArray():
|
def getBlankMapArray():
|
||||||
map = [[0 for x in range(0,MAP_WIDTH)] for y in range (0,MAP_HEIGHT)]
|
map = [[0 for x in range(0,MAP_WIDTH)] for y in range (0,MAP_HEIGHT)]
|
||||||
|
|
||||||
map[0][1] = 1
|
|
||||||
map[0][2] = 1
|
|
||||||
|
|
||||||
return map
|
return map
|
||||||
|
|
||||||
# tworzenie surface poprzed czytanie arraya i wedle niego wypelnianie konkretnymi tile'ami
|
# generowanie obiektow na mapie
|
||||||
# def makeSurfaceMap(map, pattern):
|
def generateMap():
|
||||||
# surface = pg.Surface((MAP_WIDTH * TILE_SIZE_PX, MAP_HEIGHT * TILE_SIZE_PX))
|
map = getBlankMapArray()
|
||||||
|
for i in range(0, 20):
|
||||||
# for i in range(len(map)):
|
x = random.randint(0, MAP_WIDTH-1)
|
||||||
# offsetY = i * TILE_SIZE_PX
|
y = random.randint(0, MAP_HEIGHT-1)
|
||||||
# for j in range(len(map[i])):
|
map[y][x] = 1
|
||||||
# offsetX = j * TILE_SIZE_PX
|
return map
|
||||||
# surface.blit(pattern[map[i][j]], (offsetX, offsetY))
|
|
||||||
# return surface
|
|
||||||
|
|
||||||
# tworzenie grup sprite'ow
|
# tworzenie grup sprite'ow
|
||||||
def getSprites(map, pattern):
|
def getSprites(map, pattern):
|
||||||
roadTiles = pg.sprite.Group()
|
roadTiles = pg.sprite.Group()
|
||||||
wallTiles = pg.sprite.Group()
|
wallTiles = pg.sprite.Group()
|
||||||
|
|
||||||
|
#objechanie tablicy i generowanie tile'a na danych kordach
|
||||||
for i in range(len(map)):
|
for i in range(len(map)):
|
||||||
offsetY = i * TILE_SIZE_PX
|
offsetY = i * TILE_SIZE_PX
|
||||||
for j in range(len(map[i])):
|
for j in range(len(map[i])):
|
||||||
@ -41,6 +33,7 @@ def getSprites(map, pattern):
|
|||||||
roadTiles.add(tile)
|
roadTiles.add(tile)
|
||||||
else:
|
else:
|
||||||
wallTiles.add(tile)
|
wallTiles.add(tile)
|
||||||
|
|
||||||
return roadTiles, wallTiles
|
return roadTiles, wallTiles
|
||||||
|
|
||||||
|
|
||||||
@ -49,3 +42,4 @@ def getSprites(map, pattern):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
10
settings.py
10
settings.py
@ -26,4 +26,12 @@ PLAYER_ROT_SPEED = 200
|
|||||||
PLAYER_IMG = 'garbagetruck/trashmaster_v2.png'
|
PLAYER_IMG = 'garbagetruck/trashmaster_v2.png'
|
||||||
PLAYER_HIT_RECT = pg.Rect(0, 0, 50, 50)
|
PLAYER_HIT_RECT = pg.Rect(0, 0, 50, 50)
|
||||||
PLAYER_WIDTH = 64
|
PLAYER_WIDTH = 64
|
||||||
PLAYER_HEIGHT = 32
|
PLAYER_HEIGHT = 32
|
||||||
|
|
||||||
|
#map settings
|
||||||
|
MAP_WIDTH = 20
|
||||||
|
MAP_HEIGHT = 20
|
||||||
|
|
||||||
|
TILE_SIZE_PX = 64
|
||||||
|
MAP_WIDTH_PX = MAP_WIDTH * TILE_SIZE_PX
|
||||||
|
MAP_HEIGHT_PX = MAP_HEIGHT * TILE_SIZE_PX
|
Loading…
Reference in New Issue
Block a user