win game,pre-release, alpha

This commit is contained in:
Yadciel 2023-05-08 22:11:59 +02:00
parent eb547c65b7
commit b70ebb007f
5 changed files with 112 additions and 32 deletions

50
game.py
View File

@ -3,6 +3,7 @@ import player
import helicopter
import object
import game_over
import win_screen
import tilemap
import sys
@ -12,11 +13,14 @@ def start():
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()
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
tile_set = pygame.image.load("resources/roads2W.png").convert_alpha()
@ -33,20 +37,25 @@ def start():
if event.type == pygame.MOUSEBUTTONDOWN:
player1.dest(pygame.mouse.get_pos())
if player1.rect.colliderect(Tanken.rect):
player1.Tank = 250
if player1.rect.colliderect(tanken.rect):
if player1.Tank < 250:
player1.Tank += 0.1
if player1.rect.colliderect(enemy.rect):
GameOver = True
gameover = 'gameover'
if player1.rect.colliderect(Erzmine.rect):
if player1.rect.colliderect(erzmine.rect):
player1.Erz += 1
if player1.rect.colliderect(Ziele.rect):
if player1.rect.colliderect(ziele.rect):
if player1.Erz >= 1:
player1.Erz -= 1
ziel_erz += 1
if GameOver == False:
if ziel_erz >= 1000:
gameover = 'win'
if not gameover:
# Hintergrundfarbe
win.fill(white)
tile = tilemap.tilemap()
@ -65,14 +74,14 @@ def start():
if tile.map_array[y][x] == 3:
win.blit(tile.road_tbr, (x * tile_size, y * tile_size))
Erzmine.update()
Erzmine.draw(win)
erzmine.update()
erzmine.draw(win)
Tanken.update()
Tanken.draw(win)
tanken.update()
tanken.draw(win)
Ziele.update()
Ziele.draw(win)
ziele.update()
ziele.draw(win)
player1.update()
player1.draw(win)
@ -91,6 +100,7 @@ def start():
# debug ausgabe
# ---------------------------
if debug:
debug_selfrect = font.render('self centerx: ' + str(player1.rect.centerx) + ' self centery: ' + str(player1.rect.centery), True, white)
win.blit(debug_selfrect, (20, 60))
@ -99,7 +109,11 @@ def start():
# ---------------------------
# ----------------------------------------
else:
GO.draw(win)
if gameover == 'win':
w_screen.draw(win)
pass
if gameover == 'gameover':
go_screen.draw(win)
pass
pygame.display.update()

View File

@ -22,6 +22,7 @@ class Helicopter(Fahrzeug, pygame.sprite.Sprite):
self.speed = 1
self.duration_speed = 0.02
self.start_time = time.time()
self.debug = False
def update(self, player):
keys = pygame.key.get_pressed()
@ -67,8 +68,8 @@ class Helicopter(Fahrzeug, pygame.sprite.Sprite):
# debug nicht anrühren
# self.angle += 1
pygame.draw.rect(win, (255, 0, 0), rotated_rect)
if self.debug:
pygame.draw.rect(win, (0, 255, 0), self.rect)
win.blit(rotated_image, rotated_rect)
self.rotor.draw(win)

View File

@ -12,8 +12,10 @@ class Erz(pygame.sprite.Sprite):
self.rect = self.scaled_image.get_rect(center=(x, y))
self.rect.centerx = x
self.rect.centery = y
self.debug = False
def draw(self, win):
if self.debug:
pygame.draw.rect(win, (255, 0, 0), self.rect)
win.blit(self.scaled_image, self.rect)
@ -27,8 +29,10 @@ class Tank(pygame.sprite.Sprite):
self.rect = self.scaled_image.get_rect(center=(x, y))
self.rect.centerx = x
self.rect.centery = y
self.debug = False
def draw(self, win):
if self.debug:
pygame.draw.rect(win, (255, 0, 0), self.rect)
win.blit(self.scaled_image, self.rect)
@ -43,8 +47,10 @@ class Ziel(pygame.sprite.Sprite):
self.rect = self.scaled_image.get_rect(center=(x, y))
self.rect.centerx = x
self.rect.centery = y
self.debug = False
def draw(self, win):
if self.debug:
pygame.draw.rect(win, (255, 0, 0), self.rect)
win.blit(self.scaled_image, self.rect)

View File

@ -1,6 +1,7 @@
import pygame
from fahrzeug import Fahrzeug
class Player(Fahrzeug, pygame.sprite.Sprite):
def __init__(self, x, y):
super().__init__(x, y)
@ -16,7 +17,8 @@ class Player(Fahrzeug, pygame.sprite.Sprite):
self.angle = 0
self.Tank = 250
self.Erz = 0
self.debug = False
self.b_move = False
def draw(self, win):
rotated_image = pygame.transform.rotate(self.image, self.angle)
@ -24,6 +26,7 @@ class Player(Fahrzeug, pygame.sprite.Sprite):
# debug, nicht anrühren
# self.angle += 1
if self.debug:
pygame.draw.rect(win, (255, 0, 0), rotated_rect)
win.blit(rotated_image, rotated_rect)
@ -39,23 +42,32 @@ class Player(Fahrzeug, pygame.sprite.Sprite):
if self.rect.centery > self.dest_y:
self.rect.centery -= self.speed
#bug wenn beide methoden zeitgleich benutzt werden
self.b_move = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
self.rect.centerx -= self.speed
self.dest_x -= self.speed
self.angle = 90
self.b_move = True
if keys[pygame.K_RIGHT]:
self.rect.centerx += self.speed
self.dest_x += self.speed
self.angle = 270
self.b_move = True
if keys[pygame.K_UP]:
self.rect.centery -= self.speed
self.dest_y -= self.speed
self.angle = 0
self.b_move = True
if keys[pygame.K_DOWN]:
self.rect.centery += self.speed
self.dest_y += self.speed
self.angle = 180
self.b_move = True
if self.b_move:
self.Tank -= 0.1
def dest(self, pos):
self.dest_x, self.dest_y = pos

47
win_screen.py Normal file
View File

@ -0,0 +1,47 @@
import pygame
class WinScreen(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.label = pygame.font.SysFont("Arial", 50).render("Win", True, (255, 0, 0))
self.rect = self.label.get_rect(center=(400, 300))
def draw(self, win):
win.fill((0, 0, 0)) # Black
win.blit(self.label, self.rect)
self.start_quit(win)
@staticmethod
def start_quit(win):
# Rechtecke
start_button = pygame.Rect(200, 400, 100, 50)
quit_button = pygame.Rect(500, 400, 120, 50)
# Schriftart
font = pygame.font.Font(None, 32)
# Text
start_text = font.render("Start", True, (0, 0, 0))
quit_text = font.render("Beenden", True, (0, 0, 0))
# Buttons zeichnen
pygame.draw.rect(win, (100, 100, 100), start_button)
win.blit(start_text, (start_button.x + 25, start_button.y + 10))
pygame.draw.rect(win, (100, 100, 100), quit_button)
win.blit(quit_text, (quit_button.x + 10, quit_button.y + 10))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_pos = event.pos
# Start-Button
if start_button.collidepoint(mouse_pos) or \
start_text.get_rect(center=(start_button.x + 50, start_button.y + 25)).collidepoint(mouse_pos):
game.start()
# Beenden-Button
if quit_button.collidepoint(mouse_pos) or \
quit_text.get_rect(center=(quit_button.x + 60, quit_button.y + 25)).collidepoint(mouse_pos):
pygame.quit()
sys.exit()