map, tilemap
This commit is contained in:
parent
15b3fd2046
commit
d964caf807
25
game.py
25
game.py
@ -1,6 +1,7 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import fahrzeug
|
import fahrzeug
|
||||||
import background
|
import background
|
||||||
|
import tilemap
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
@ -11,19 +12,14 @@ def start():
|
|||||||
Tanken = background.Tank()
|
Tanken = background.Tank()
|
||||||
Ziele = background.Ziel()
|
Ziele = background.Ziel()
|
||||||
|
|
||||||
|
tile_set = pygame.image.load("roads2W.png").convert_alpha()
|
||||||
|
|
||||||
# Farben
|
# Farben
|
||||||
white = (255, 255, 255)
|
white = (255, 255, 255)
|
||||||
blue = (0, 0, 255)
|
blue = (0, 0, 255)
|
||||||
|
|
||||||
# Tilemap
|
# Tilemap
|
||||||
tile_size = 16
|
tile_size = 64
|
||||||
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
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
@ -35,12 +31,13 @@ def start():
|
|||||||
|
|
||||||
# Hintergrundfarbe
|
# Hintergrundfarbe
|
||||||
win.fill(white)
|
win.fill(white)
|
||||||
|
tile = tilemap.tilemap()
|
||||||
# Tilemap zeichnen
|
# Schleife durch das Tilemap-Array
|
||||||
for x in range(map_width):
|
for y in range(len(tile.map_array)):
|
||||||
for y in range(map_height):
|
for x in range(len(tile.map_array[y])):
|
||||||
if tilemap[x][y] == 1:
|
# Überprüfen, ob der Wert in der aktuellen Zelle gleich 0 ist
|
||||||
pygame.draw.rect(win, blue, (x * tile_size, y * tile_size, tile_size, tile_size))
|
if tile.map_array[y][x] == 0:
|
||||||
|
win.blit(tile.road_quer, (x * tile_size, y * tile_size))
|
||||||
|
|
||||||
font = pygame.font.SysFont(None, 24)
|
font = pygame.font.SysFont(None, 24)
|
||||||
tank_label = font.render('Tank: ' + str(round(player1.Tank, 2)), True, white)
|
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