106 lines
3.5 KiB
Python
106 lines
3.5 KiB
Python
import pygame
|
|
import player
|
|
import helicopter
|
|
import object
|
|
import game_over
|
|
import tilemap
|
|
import sys
|
|
|
|
|
|
def start():
|
|
pygame.init()
|
|
win = pygame.display.set_mode((800, 800))
|
|
player1 = player.Player(500, 500)
|
|
enemy = helicopter.Helicopter(50, 50)
|
|
Erzmine = object.Erz(600, 40)
|
|
Tanken = object.Tank(200, 220)
|
|
Ziele = object.Ziel(600, 750)
|
|
GameOver = False
|
|
GO = game_over.GameOver()
|
|
|
|
tile_set = pygame.image.load("resources/roads2W.png").convert_alpha()
|
|
|
|
# Farben
|
|
white = (255, 255, 255)
|
|
blue = (0, 0, 255)
|
|
|
|
|
|
while True:
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
pygame.quit()
|
|
sys.exit()
|
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
|
player1.dest(pygame.mouse.get_pos())
|
|
|
|
if player1.rect.colliderect(Tanken.rect):
|
|
player1.Tank = 250
|
|
|
|
if player1.rect.colliderect(enemy.rect):
|
|
GameOver = True
|
|
|
|
if player1.rect.colliderect(Erzmine.rect):
|
|
player1.Erz += 1
|
|
|
|
if player1.rect.colliderect(Ziele.rect):
|
|
if player1.Erz >= 1:
|
|
player1.Erz -= 1
|
|
|
|
if GameOver == False:
|
|
# Hintergrundfarbe
|
|
win.fill(white)
|
|
tile = tilemap.tilemap()
|
|
# Tilemap
|
|
tile_size = tile.tilesize
|
|
# 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))
|
|
if tile.map_array[y][x] == 1:
|
|
win.blit(tile.road_senkrecht, (x * tile_size, y * tile_size))
|
|
if tile.map_array[y][x] == 2:
|
|
win.blit(tile.road_btr, (x * tile_size, y * tile_size))
|
|
if tile.map_array[y][x] == 3:
|
|
win.blit(tile.road_tbr, (x * tile_size, y * tile_size))
|
|
|
|
Erzmine.update()
|
|
Erzmine.draw(win)
|
|
|
|
Tanken.update()
|
|
Tanken.draw(win)
|
|
|
|
Ziele.update()
|
|
Ziele.draw(win)
|
|
|
|
player1.update()
|
|
player1.draw(win)
|
|
|
|
enemy.update(player1)
|
|
enemy.dest((player1.rect.centerx, player1.rect.centery))
|
|
enemy.draw(win)
|
|
|
|
# Game UI--------------------------------
|
|
font = pygame.font.SysFont(None, 24)
|
|
tank_label = font.render('Tank: ' + str(round(player1.Tank, 2)), True, white)
|
|
win.blit(tank_label, (20, 20))
|
|
font = pygame.font.SysFont(None, 24)
|
|
tank_label = font.render('Erz: ' + str(round(player1.Erz, 0)), True, white)
|
|
win.blit(tank_label, (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, 60))
|
|
|
|
debug_selfrect = font.render('dest x: ' + str(player1.dest_x) + ' dest y: ' + str(player1.dest_y), True, white)
|
|
win.blit(debug_selfrect, (20, 80))
|
|
# ---------------------------
|
|
# ----------------------------------------
|
|
else:
|
|
GO.draw(win)
|
|
pass
|
|
|
|
pygame.display.update()
|