LF08/game.py

123 lines
4.0 KiB
Python
Raw Normal View History

2023-03-27 08:58:12 +02:00
import pygame
import player
import helicopter
2023-04-25 08:30:43 +02:00
import object
2023-04-27 13:21:11 +02:00
import game_over
2023-05-08 22:11:59 +02:00
import win_screen
2023-04-19 10:59:13 +02:00
import tilemap
2023-03-27 08:58:12 +02:00
import sys
2023-04-25 08:30:43 +02:00
2023-03-27 08:58:12 +02:00
def start():
pygame.init()
win = pygame.display.set_mode((800, 800))
2023-04-27 13:21:11 +02:00
player1 = player.Player(500, 500)
enemy = helicopter.Helicopter(50, 50)
2023-05-08 22:11:59 +02:00
erzmine = object.Erz(600, 40)
tanken = object.Tank(200, 220)
ziele = object.Ziel(600, 750)
gameover = ''
go_screen = game_over.GameOver()
w_screen = win_screen.WinScreen()
debug = False
ziel_erz = 0
2023-03-27 08:58:12 +02:00
2023-04-22 12:45:53 +02:00
tile_set = pygame.image.load("resources/roads2W.png").convert_alpha()
2023-04-19 10:59:13 +02:00
2023-03-27 08:58:12 +02:00
# 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())
2023-05-08 22:11:59 +02:00
if player1.rect.colliderect(tanken.rect):
if player1.Tank < 250:
2023-05-12 12:09:57 +02:00
player1.Tank += 0.5
2023-04-25 08:30:43 +02:00
2023-04-27 13:21:11 +02:00
if player1.rect.colliderect(enemy.rect):
2023-05-12 12:09:57 +02:00
if player1.Erz > 0:
player1.Erz -= 1
2023-04-27 13:21:11 +02:00
2023-05-08 22:11:59 +02:00
if player1.rect.colliderect(erzmine.rect):
2023-04-28 10:30:51 +02:00
player1.Erz += 1
2023-05-08 22:11:59 +02:00
if player1.rect.colliderect(ziele.rect):
2023-04-28 10:30:51 +02:00
if player1.Erz >= 1:
player1.Erz -= 1
2023-05-08 22:11:59 +02:00
ziel_erz += 1
2023-04-28 10:30:51 +02:00
2023-05-08 22:11:59 +02:00
if ziel_erz >= 1000:
gameover = 'win'
if not gameover:
2023-04-27 13:21:11 +02:00
# 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))
2023-05-08 22:11:59 +02:00
erzmine.update()
erzmine.draw(win)
2023-04-27 13:21:11 +02:00
2023-05-08 22:11:59 +02:00
tanken.update()
tanken.draw(win)
2023-04-27 13:21:11 +02:00
2023-05-08 22:11:59 +02:00
ziele.update()
ziele.draw(win)
2023-04-27 13:21:11 +02:00
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
# ---------------------------
2023-05-08 22:11:59 +02:00
if debug:
2023-05-11 17:35:29 +02:00
debug_selfrect = font.render(
'self centerx: ' + str(player1.rect.centerx) + ' self centery: ' + str(player1.rect.centery), True,
white)
2023-05-08 22:11:59 +02:00
win.blit(debug_selfrect, (20, 60))
2023-04-27 13:21:11 +02:00
2023-05-11 17:35:29 +02:00
debug_selfrect = font.render('dest x: ' + str(player1.dest_x) + ' dest y: ' + str(player1.dest_y), True,
white)
2023-05-08 22:11:59 +02:00
win.blit(debug_selfrect, (20, 80))
2023-04-27 13:21:11 +02:00
# ---------------------------
# ----------------------------------------
else:
2023-05-08 22:11:59 +02:00
if gameover == 'win':
w_screen.draw(win)
pass
if gameover == 'gameover':
go_screen.draw(win)
2023-04-27 13:21:11 +02:00
pass
2023-04-19 10:59:13 +02:00
pygame.display.update()