map, tilemap

This commit is contained in:
Yadciel 2023-04-19 10:59:13 +02:00
parent 15b3fd2046
commit d964caf807
3 changed files with 33 additions and 23 deletions

43
game.py
View File

@ -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,25 +31,26 @@ 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)
tank_label = font.render('Tank: ' + str(round(player1.Tank, 2)), True, white)
win.blit(tank_label, (20, 20))
#debug ausgabe
#---------------------------
#debug_selfrect = font.render('self centerx: ' + str(player1.rect.centerx) + ' self centery: ' + str(player1.rect.centery), True, white)
#win.blit(debug_selfrect, (20, 40))
# debug ausgabe
# ---------------------------
# debug_selfrect = font.render('self centerx: ' + str(player1.rect.centerx) + ' self centery: ' + str(player1.rect.centery), True, white)
# win.blit(debug_selfrect, (20, 40))
#debug_selfrect = font.render('dest x: ' + str(player1.dest_x) + ' dest y: ' + str(player1.dest_y), True, white)
#win.blit(debug_selfrect, (20, 60))
#---------------------------
# debug_selfrect = font.render('dest x: ' + str(player1.dest_x) + ' dest y: ' + str(player1.dest_y), True, white)
# win.blit(debug_selfrect, (20, 60))
# ---------------------------
Erzmine.update()
Erzmine.draw(win)
@ -67,4 +64,4 @@ def start():
player1.update()
player1.draw(win)
pygame.display.update()
pygame.display.update()

BIN
roads2W.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

13
tilemap.py Normal file
View 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]]