Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
d57c16ceea | |||
|
62bd1bd253 | ||
|
27d545326e | ||
|
5fb1308bd6 | ||
|
207fd7e7ca | ||
|
4e84473dff | ||
|
57111e5766 | ||
|
47ceeca0cd | ||
|
cbece676a6 | ||
|
63044ece48 | ||
|
6042fa2fac | ||
|
fe911b62bd | ||
|
63f2b48b96 | ||
|
b692082203 | ||
|
62e4655056 | ||
|
73182e90b9 | ||
|
b0b449cef0 | ||
|
b3f15d46e7 | ||
|
b70ebb007f | ||
eb547c65b7 | |||
|
deb66dd64e | ||
|
5c5efb40b4 |
16
README.md
16
README.md
@ -7,26 +7,24 @@ Willkommen im Trucksimulator-Repository! In diesem Spiel geht es darum, einen Tr
|
||||
Um das Spiel zu spielen, müssen Sie es zuerst herunterladen und auf Ihrem Computer installieren. Hier sind die Schritte:
|
||||
|
||||
1. Klonen Sie das Repository auf Ihren Computer mit dem Befehl
|
||||
`git clone https://git.braveslave.duckdns.org/Ihr Benutzername/LF08.git`.
|
||||
`git clone https://git.braveslave.duckdns.org/Yadciel/LF08.git`.
|
||||
Oder
|
||||
Ziehen sie sich die ".Exe" aus dem Pakete Tab.
|
||||
2. Stellen Sie sicher, dass Sie die neueste Version von Python und der pygame-Bibliothek installiert haben.
|
||||
3. Navigieren Sie zum Ordner `trucksimulator` und führen Sie das Spiel mit dem Befehl `python main.py` aus.
|
||||
3. Navigieren Sie zum Ordner `LF08` und führen Sie das Spiel mit dem Befehl `python main.py` aus.
|
||||
|
||||
## Spielanleitung
|
||||
|
||||
Das Ziel des Spiels ist es, eine Ladung von einer Mine abzuholen und zum Ziel zu bringen, ohne dabei von einem Helikopter erwischt zu werden. Hier sind die Schritte:
|
||||
|
||||
1. Starten Sie das Spiel, indem Sie die Datei `main.py` ausführen.
|
||||
1. Starten Sie das Spiel, indem Sie die Datei `main.py` ausführen oder die main.exe.
|
||||
(Wichtig! der resourcen Ordner muss im selben Ordner sein wie die main.py und oder main.exe)
|
||||
2. Fahren Sie den Truck zur Mine und laden Sie die Ladung auf.
|
||||
3. Bringen Sie die Ladung zum Ziel, indem Sie den Truck auf der Straße halten und Hindernissen ausweichen.
|
||||
3. Bringen Sie die Ladung zum Ziel, indem Sie den Truck auf der Straße halten und "Hindernissen" ausweichen.
|
||||
(Hindernisse folgen noch)
|
||||
4. Seien Sie vorsichtig und vermeiden Sie es, vom Helikopter erwischt zu werden, der Sie verfolgt. Wenn er zu nahe kommt, verlieren Sie das Spiel.
|
||||
5. Wenn Sie die Ladung erfolgreich zum Ziel gebracht haben, haben Sie das Spiel gewonnen!
|
||||
5. Wenn Sie erfolgreich 1000 Erz zum Ziel gebracht haben, haben Sie das Spiel gewonnen!
|
||||
|
||||
## Mitwirkende
|
||||
|
||||
Dieses Spiel wurde von Nico Schmidt entwickelt.
|
||||
|
||||
## Lizenz
|
||||
|
||||
Dieses Spiel steht unter der MIT-Lizenz. Siehe die Datei `LICENSE` für weitere Informationen.
|
||||
|
71
game.py
71
game.py
@ -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()
|
||||
|
||||
@ -24,7 +28,6 @@ def start():
|
||||
white = (255, 255, 255)
|
||||
blue = (0, 0, 255)
|
||||
|
||||
|
||||
while True:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
@ -33,20 +36,26 @@ 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.5
|
||||
|
||||
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:
|
||||
if player1.Erz > 0:
|
||||
player1.Erz -= 1
|
||||
|
||||
if GameOver == False:
|
||||
if player1.rect.colliderect(erzmine.rect):
|
||||
player1.Erz += 1
|
||||
|
||||
if player1.rect.colliderect(ziele.rect):
|
||||
if player1.Erz >= 1:
|
||||
player1.Erz -= 1
|
||||
ziel_erz += 1
|
||||
|
||||
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,15 +100,23 @@ def start():
|
||||
|
||||
# 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))
|
||||
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))
|
||||
|
||||
debug_selfrect = font.render('dest x: ' + str(player1.dest_x) + ' dest y: ' + str(player1.dest_y), True, white)
|
||||
win.blit(debug_selfrect, (20, 80))
|
||||
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)
|
||||
if gameover == 'win':
|
||||
w_screen.draw(win)
|
||||
pass
|
||||
if gameover == 'gameover':
|
||||
go_screen.draw(win)
|
||||
pass
|
||||
|
||||
pygame.display.update()
|
||||
|
@ -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)
|
||||
|
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.centerx = x
|
||||
self.rect.centery = y
|
||||
self.debug = False
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@ -27,9 +29,11 @@ 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):
|
||||
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)
|
||||
|
||||
|
||||
@ -43,9 +47,11 @@ 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):
|
||||
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)
|
||||
|
||||
|
||||
|
22
player.py
22
player.py
@ -1,11 +1,12 @@
|
||||
import pygame
|
||||
from fahrzeug import Fahrzeug
|
||||
|
||||
|
||||
class Player(Fahrzeug, pygame.sprite.Sprite):
|
||||
def __init__(self, x, y):
|
||||
super().__init__(x, y)
|
||||
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.centerx = x
|
||||
self.rect.centery = y
|
||||
@ -16,15 +17,17 @@ 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)
|
||||
rotated_rect = rotated_image.get_rect(center=self.rect.center)
|
||||
|
||||
#debug, nicht anrühren
|
||||
#self.angle += 1
|
||||
pygame.draw.rect(win, (255, 0, 0), rotated_rect)
|
||||
# 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
|
||||
|
48
win_screen.py
Normal file
48
win_screen.py
Normal file
@ -0,0 +1,48 @@
|
||||
import pygame
|
||||
import sys
|
||||
|
||||
|
||||
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