This repository has been archived by the owner on Jul 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameplay.py
143 lines (116 loc) · 4.75 KB
/
gameplay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import pygame
import colors
import fileUtils
from countdown import CountDown
from gameOverScreen import GameOverScreen, GameOverState
from gameState import GameState
from menu.pauseMenu import PauseScreen
from player import Player
from pumptrackWayPoints import way_points_pump_track
from rider import Rider
from timeCounter import TimeCounter
def game_play(screen, screen_rect):
playing = True
game_state = GameState.STARTING
number_of_laps = 2
# Load images, assign to sprite classes
img = fileUtils.load_image('rider1-placeholder.png')
Player.images = [img, pygame.transform.flip(img, 1, 0)]
# decorate the game window
# icon = pygame.transform.scale(Rider.images[0], (32, 32))
# pygame.display.set_icon(icon)
# pygame.display.set_caption('Pygame Aliens')
# pygame.mouse.set_visible(0)
# create the background, tile the bgd image
background = fileUtils.load_image('pumptrack.png')
background_rect = background.get_rect()
screen.blit(background, background_rect)
pygame.display.flip()
background_in_alpha = pygame.Surface((screen_rect.size[0], screen_rect.size[1]))
background_in_alpha.set_alpha(128)
background_in_alpha.fill(colors.black)
# load the sound effects
# shoot_sound = load_sound('car_door.wav')
"""if pygame.mixer:
music = os.path.join(main_dir, 'data', 'house_lo.wav')
pygame.mixer.music.load(music)
pygame.mixer.music.play(-1)"""
# fileUtils.load_music("Lame_Drivers_-_01_-_Frozen_Egg.mp3")
# pygame.mixer.music.play(-1)
# Initialize Game Groups
aliens = pygame.sprite.Group()
all = pygame.sprite.RenderUpdates()
lastalien = pygame.sprite.GroupSingle()
# assign default groups to each sprite class
Player.containers = all
Rider.containers = aliens, all, lastalien
TimeCounter.containers = all
# Create Some Starting Values
clock = pygame.time.Clock()
# initialize our starting sprites
player = Player(screen_rect, way_points_pump_track, True)
time_counter = TimeCounter()
time_countdown = CountDown()
game_over = GameOverScreen()
pause_menu = PauseScreen()
if pygame.font:
all.add(time_counter)
button_down = False
while playing:
# get input
for event in pygame.event.get():
game_over_state = game_over.update_input(event)
if game_over_state == GameOverState.RESTART:
game_state = GameState.RESTART
elif game_over_state == GameOverState.QUIT:
return
quit_game = pause_menu.update_input(event)
if quit_game:
return
if event.type == pygame.QUIT \
or (event.type == pygame.KEYDOWN
and event.key == pygame.K_ESCAPE
and game_state == GameState.PLAYING):
game_state = GameState.PAUSED
if event.type == pygame.KEYDOWN \
and event.key == pygame.K_SPACE \
and button_down is False \
and game_state == GameState.PLAYING:
button_down = True
all.clear(screen, background)
all.update()
# player.update_state(game_state)
time_counter.set_state(game_state)
time_countdown.set_state(game_state)
game_over.set_state(game_state)
time_countdown.update()
if time_countdown.countdown <= 0 and game_state == GameState.STARTING:
game_state = GameState.PLAYING
screen.blit(background, background_rect)
pygame.display.flip()
if game_state == GameState.PLAYING:
player.pump()
if button_down is True:
player.add_pump()
button_down = False
if player.lap >= number_of_laps:
game_state = GameState.GAME_OVER
game_over.set_final_time(time_counter.time_in_millis)
if game_state == GameState.STARTING:
time_countdown.draw(screen, screen_rect, background, background_in_alpha)
pygame.display.update()
if game_state == GameState.PAUSED:
pause_menu.draw(screen, screen_rect, background, background_in_alpha)
pygame.display.update()
if game_state == GameState.GAME_OVER:
game_over.draw(screen, screen_rect, background, background_in_alpha)
pygame.display.update()
if game_state == GameState.RESTART:
clock = pygame.time.Clock()
player = Player(screen_rect, way_points_pump_track, True)
time_counter = TimeCounter()
time_countdown = CountDown()
game_state = GameState.STARTING
dirty = all.draw(screen)
pygame.display.update(dirty)
clock.tick(30)