map, tilemap
This commit is contained in:
parent
15b3fd2046
commit
d964caf807
25
game.py
25
game.py
@ -1,6 +1,7 @@
|
||||
import pygame
|
||||
import fahrzeug
|
||||
import background
|
||||
import tilemap
|
||||
import sys
|
||||
|
||||
def start():
|
||||
@ -11,19 +12,14 @@ def start():
|
||||
Tanken = background.Tank()
|
||||
Ziele = background.Ziel()
|
||||
|
||||
tile_set = pygame.image.load("roads2W.png").convert_alpha()
|
||||
|
||||
# Farben
|
||||
white = (255, 255, 255)
|
||||
blue = (0, 0, 255)
|
||||
|
||||
# Tilemap
|
||||
tile_size = 16
|
||||
map_width = 200
|
||||
map_height = 200
|
||||
tilemap = [[0 for y in range(map_height)] for x in range(map_width)]
|
||||
|
||||
for x in range(map_width):
|
||||
for y in range(map_height):
|
||||
tilemap[x][y] = 1
|
||||
tile_size = 64
|
||||
|
||||
while True:
|
||||
for event in pygame.event.get():
|
||||
@ -35,12 +31,13 @@ def start():
|
||||
|
||||
# Hintergrundfarbe
|
||||
win.fill(white)
|
||||
|
||||
# Tilemap zeichnen
|
||||
for x in range(map_width):
|
||||
for y in range(map_height):
|
||||
if tilemap[x][y] == 1:
|
||||
pygame.draw.rect(win, blue, (x * tile_size, y * tile_size, tile_size, tile_size))
|
||||
tile = tilemap.tilemap()
|
||||
# Schleife durch das Tilemap-Array
|
||||
for y in range(len(tile.map_array)):
|
||||
for x in range(len(tile.map_array[y])):
|
||||
# Überprüfen, ob der Wert in der aktuellen Zelle gleich 0 ist
|
||||
if tile.map_array[y][x] == 0:
|
||||
win.blit(tile.road_quer, (x * tile_size, y * tile_size))
|
||||
|
||||
font = pygame.font.SysFont(None, 24)
|
||||
tank_label = font.render('Tank: ' + str(round(player1.Tank, 2)), True, white)
|
||||
|
BIN
roads2W.png
Normal file
BIN
roads2W.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.0 KiB |
13
tilemap.py
Normal file
13
tilemap.py
Normal file
@ -0,0 +1,13 @@
|
||||
import pygame
|
||||
class tilemap(pygame.sprite.Sprite):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.image =pygame.image.load("roads2w.png").convert_alpha()
|
||||
self.rect = self.image.get_rect()
|
||||
self.rect = 0, 0
|
||||
self.road_quer = self.image.subsurface(64*2, 0, 64, 64)
|
||||
self.map_array = [[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0]]
|
Loading…
Reference in New Issue
Block a user