win game,pre-release, alpha
This commit is contained in:
parent
eb547c65b7
commit
b70ebb007f
58
game.py
58
game.py
@ -3,6 +3,7 @@ import player
|
|||||||
import helicopter
|
import helicopter
|
||||||
import object
|
import object
|
||||||
import game_over
|
import game_over
|
||||||
|
import win_screen
|
||||||
import tilemap
|
import tilemap
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -12,11 +13,14 @@ def start():
|
|||||||
win = pygame.display.set_mode((800, 800))
|
win = pygame.display.set_mode((800, 800))
|
||||||
player1 = player.Player(500, 500)
|
player1 = player.Player(500, 500)
|
||||||
enemy = helicopter.Helicopter(50, 50)
|
enemy = helicopter.Helicopter(50, 50)
|
||||||
Erzmine = object.Erz(600, 40)
|
erzmine = object.Erz(600, 40)
|
||||||
Tanken = object.Tank(200, 220)
|
tanken = object.Tank(200, 220)
|
||||||
Ziele = object.Ziel(600, 750)
|
ziele = object.Ziel(600, 750)
|
||||||
GameOver = False
|
gameover = ''
|
||||||
GO = game_over.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()
|
tile_set = pygame.image.load("resources/roads2W.png").convert_alpha()
|
||||||
|
|
||||||
@ -33,20 +37,25 @@ def start():
|
|||||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
player1.dest(pygame.mouse.get_pos())
|
player1.dest(pygame.mouse.get_pos())
|
||||||
|
|
||||||
if player1.rect.colliderect(Tanken.rect):
|
if player1.rect.colliderect(tanken.rect):
|
||||||
player1.Tank = 250
|
if player1.Tank < 250:
|
||||||
|
player1.Tank += 0.1
|
||||||
|
|
||||||
if player1.rect.colliderect(enemy.rect):
|
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
|
player1.Erz += 1
|
||||||
|
|
||||||
if player1.rect.colliderect(Ziele.rect):
|
if player1.rect.colliderect(ziele.rect):
|
||||||
if player1.Erz >= 1:
|
if player1.Erz >= 1:
|
||||||
player1.Erz -= 1
|
player1.Erz -= 1
|
||||||
|
ziel_erz += 1
|
||||||
|
|
||||||
if GameOver == False:
|
if ziel_erz >= 1000:
|
||||||
|
gameover = 'win'
|
||||||
|
|
||||||
|
if not gameover:
|
||||||
# Hintergrundfarbe
|
# Hintergrundfarbe
|
||||||
win.fill(white)
|
win.fill(white)
|
||||||
tile = tilemap.tilemap()
|
tile = tilemap.tilemap()
|
||||||
@ -65,14 +74,14 @@ def start():
|
|||||||
if tile.map_array[y][x] == 3:
|
if tile.map_array[y][x] == 3:
|
||||||
win.blit(tile.road_tbr, (x * tile_size, y * tile_size))
|
win.blit(tile.road_tbr, (x * tile_size, y * tile_size))
|
||||||
|
|
||||||
Erzmine.update()
|
erzmine.update()
|
||||||
Erzmine.draw(win)
|
erzmine.draw(win)
|
||||||
|
|
||||||
Tanken.update()
|
tanken.update()
|
||||||
Tanken.draw(win)
|
tanken.draw(win)
|
||||||
|
|
||||||
Ziele.update()
|
ziele.update()
|
||||||
Ziele.draw(win)
|
ziele.draw(win)
|
||||||
|
|
||||||
player1.update()
|
player1.update()
|
||||||
player1.draw(win)
|
player1.draw(win)
|
||||||
@ -91,15 +100,20 @@ def start():
|
|||||||
|
|
||||||
# debug ausgabe
|
# debug ausgabe
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
debug_selfrect = font.render('self centerx: ' + str(player1.rect.centerx) + ' self centery: ' + str(player1.rect.centery), True, white)
|
if debug:
|
||||||
win.blit(debug_selfrect, (20, 60))
|
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)
|
debug_selfrect = font.render('dest x: ' + str(player1.dest_x) + ' dest y: ' + str(player1.dest_y), True, white)
|
||||||
win.blit(debug_selfrect, (20, 80))
|
win.blit(debug_selfrect, (20, 80))
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
else:
|
else:
|
||||||
GO.draw(win)
|
if gameover == 'win':
|
||||||
|
w_screen.draw(win)
|
||||||
|
pass
|
||||||
|
if gameover == 'gameover':
|
||||||
|
go_screen.draw(win)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
@ -22,6 +22,7 @@ class Helicopter(Fahrzeug, pygame.sprite.Sprite):
|
|||||||
self.speed = 1
|
self.speed = 1
|
||||||
self.duration_speed = 0.02
|
self.duration_speed = 0.02
|
||||||
self.start_time = time.time()
|
self.start_time = time.time()
|
||||||
|
self.debug = False
|
||||||
|
|
||||||
def update(self, player):
|
def update(self, player):
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
@ -67,8 +68,8 @@ class Helicopter(Fahrzeug, pygame.sprite.Sprite):
|
|||||||
|
|
||||||
# debug nicht anrühren
|
# debug nicht anrühren
|
||||||
# self.angle += 1
|
# 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)
|
win.blit(rotated_image, rotated_rect)
|
||||||
|
|
||||||
self.rotor.draw(win)
|
self.rotor.draw(win)
|
||||||
|
12
object.py
12
object.py
@ -12,9 +12,11 @@ class Erz(pygame.sprite.Sprite):
|
|||||||
self.rect = self.scaled_image.get_rect(center=(x, y))
|
self.rect = self.scaled_image.get_rect(center=(x, y))
|
||||||
self.rect.centerx = x
|
self.rect.centerx = x
|
||||||
self.rect.centery = y
|
self.rect.centery = y
|
||||||
|
self.debug = False
|
||||||
|
|
||||||
def draw(self, win):
|
def draw(self, win):
|
||||||
pygame.draw.rect(win, (255, 0, 0), self.rect)
|
if self.debug:
|
||||||
|
pygame.draw.rect(win, (255, 0, 0), self.rect)
|
||||||
win.blit(self.scaled_image, self.rect)
|
win.blit(self.scaled_image, self.rect)
|
||||||
|
|
||||||
|
|
||||||
@ -27,9 +29,11 @@ class Tank(pygame.sprite.Sprite):
|
|||||||
self.rect = self.scaled_image.get_rect(center=(x, y))
|
self.rect = self.scaled_image.get_rect(center=(x, y))
|
||||||
self.rect.centerx = x
|
self.rect.centerx = x
|
||||||
self.rect.centery = y
|
self.rect.centery = y
|
||||||
|
self.debug = False
|
||||||
|
|
||||||
def draw(self, win):
|
def draw(self, win):
|
||||||
pygame.draw.rect(win, (255, 0, 0), self.rect)
|
if self.debug:
|
||||||
|
pygame.draw.rect(win, (255, 0, 0), self.rect)
|
||||||
win.blit(self.scaled_image, self.rect)
|
win.blit(self.scaled_image, self.rect)
|
||||||
|
|
||||||
|
|
||||||
@ -43,9 +47,11 @@ class Ziel(pygame.sprite.Sprite):
|
|||||||
self.rect = self.scaled_image.get_rect(center=(x, y))
|
self.rect = self.scaled_image.get_rect(center=(x, y))
|
||||||
self.rect.centerx = x
|
self.rect.centerx = x
|
||||||
self.rect.centery = y
|
self.rect.centery = y
|
||||||
|
self.debug = False
|
||||||
|
|
||||||
def draw(self, win):
|
def draw(self, win):
|
||||||
pygame.draw.rect(win, (255, 0, 0), self.rect)
|
if self.debug:
|
||||||
|
pygame.draw.rect(win, (255, 0, 0), self.rect)
|
||||||
win.blit(self.scaled_image, self.rect)
|
win.blit(self.scaled_image, self.rect)
|
||||||
|
|
||||||
|
|
||||||
|
22
player.py
22
player.py
@ -1,11 +1,12 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from fahrzeug import Fahrzeug
|
from fahrzeug import Fahrzeug
|
||||||
|
|
||||||
|
|
||||||
class Player(Fahrzeug, pygame.sprite.Sprite):
|
class Player(Fahrzeug, pygame.sprite.Sprite):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
super().__init__(x, y)
|
super().__init__(x, y)
|
||||||
self.image = pygame.image.load("resources/player.png").convert_alpha()
|
self.image = pygame.image.load("resources/player.png").convert_alpha()
|
||||||
self.image = pygame.transform.scale(self.image, (self.image.get_width()/1.2, self.image.get_height()/1.2))
|
self.image = pygame.transform.scale(self.image, (self.image.get_width() / 1.2, self.image.get_height() / 1.2))
|
||||||
self.rect = self.image.get_rect(center=(x, y))
|
self.rect = self.image.get_rect(center=(x, y))
|
||||||
self.rect.centerx = x
|
self.rect.centerx = x
|
||||||
self.rect.centery = y
|
self.rect.centery = y
|
||||||
@ -16,15 +17,17 @@ class Player(Fahrzeug, pygame.sprite.Sprite):
|
|||||||
self.angle = 0
|
self.angle = 0
|
||||||
self.Tank = 250
|
self.Tank = 250
|
||||||
self.Erz = 0
|
self.Erz = 0
|
||||||
|
self.debug = False
|
||||||
|
self.b_move = False
|
||||||
|
|
||||||
def draw(self, win):
|
def draw(self, win):
|
||||||
rotated_image = pygame.transform.rotate(self.image, self.angle)
|
rotated_image = pygame.transform.rotate(self.image, self.angle)
|
||||||
rotated_rect = rotated_image.get_rect(center=self.rect.center)
|
rotated_rect = rotated_image.get_rect(center=self.rect.center)
|
||||||
|
|
||||||
#debug, nicht anrühren
|
# debug, nicht anrühren
|
||||||
#self.angle += 1
|
# self.angle += 1
|
||||||
pygame.draw.rect(win, (255, 0, 0), rotated_rect)
|
if self.debug:
|
||||||
|
pygame.draw.rect(win, (255, 0, 0), rotated_rect)
|
||||||
|
|
||||||
win.blit(rotated_image, 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:
|
if self.rect.centery > self.dest_y:
|
||||||
self.rect.centery -= self.speed
|
self.rect.centery -= self.speed
|
||||||
|
|
||||||
|
#bug wenn beide methoden zeitgleich benutzt werden
|
||||||
|
|
||||||
|
self.b_move = False
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
if keys[pygame.K_LEFT]:
|
if keys[pygame.K_LEFT]:
|
||||||
self.rect.centerx -= self.speed
|
self.rect.centerx -= self.speed
|
||||||
self.dest_x -= self.speed
|
self.dest_x -= self.speed
|
||||||
self.angle = 90
|
self.angle = 90
|
||||||
|
self.b_move = True
|
||||||
if keys[pygame.K_RIGHT]:
|
if keys[pygame.K_RIGHT]:
|
||||||
self.rect.centerx += self.speed
|
self.rect.centerx += self.speed
|
||||||
self.dest_x += self.speed
|
self.dest_x += self.speed
|
||||||
self.angle = 270
|
self.angle = 270
|
||||||
|
self.b_move = True
|
||||||
if keys[pygame.K_UP]:
|
if keys[pygame.K_UP]:
|
||||||
self.rect.centery -= self.speed
|
self.rect.centery -= self.speed
|
||||||
self.dest_y -= self.speed
|
self.dest_y -= self.speed
|
||||||
self.angle = 0
|
self.angle = 0
|
||||||
|
self.b_move = True
|
||||||
if keys[pygame.K_DOWN]:
|
if keys[pygame.K_DOWN]:
|
||||||
self.rect.centery += self.speed
|
self.rect.centery += self.speed
|
||||||
self.dest_y += self.speed
|
self.dest_y += self.speed
|
||||||
self.angle = 180
|
self.angle = 180
|
||||||
|
self.b_move = True
|
||||||
|
if self.b_move:
|
||||||
|
self.Tank -= 0.1
|
||||||
|
|
||||||
def dest(self, pos):
|
def dest(self, pos):
|
||||||
self.dest_x, self.dest_y = pos
|
self.dest_x, self.dest_y = pos
|
||||||
|
47
win_screen.py
Normal file
47
win_screen.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user