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:
|
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
|
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
|
Oder
|
||||||
Ziehen sie sich die ".Exe" aus dem Pakete Tab.
|
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.
|
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
|
## 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:
|
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.
|
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.
|
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
|
## Mitwirkende
|
||||||
|
|
||||||
Dieses Spiel wurde von Nico Schmidt entwickelt.
|
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 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()
|
||||||
|
|
||||||
@ -24,7 +28,6 @@ def start():
|
|||||||
white = (255, 255, 255)
|
white = (255, 255, 255)
|
||||||
blue = (0, 0, 255)
|
blue = (0, 0, 255)
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
@ -33,20 +36,26 @@ 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.5
|
||||||
|
|
||||||
if player1.rect.colliderect(enemy.rect):
|
if player1.rect.colliderect(enemy.rect):
|
||||||
GameOver = True
|
if player1.Erz > 0:
|
||||||
|
|
||||||
if player1.rect.colliderect(Erzmine.rect):
|
|
||||||
player1.Erz += 1
|
|
||||||
|
|
||||||
if player1.rect.colliderect(Ziele.rect):
|
|
||||||
if player1.Erz >= 1:
|
|
||||||
player1.Erz -= 1
|
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
|
# 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,23 @@ 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,
|
||||||
win.blit(debug_selfrect, (20, 80))
|
white)
|
||||||
|
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
|
||||||
|
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