summaryrefslogtreecommitdiffstats
path: root/Jumper-main/Day 6/jumper-main.py
blob: 39393eda40db28a17be8ea91edf64f0129d52cc1 (plain)
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
from setup import *
from colors import COLOR_WHITE
from jumper import Jumper
from splash import Splash

is_running = True

dimensions = (SCREEN_WIDTH, SCREEN_HEIGHT)
screen = pygame.display.set_mode(dimensions)

# Set the window title to Jumper
pygame.display.set_caption("Jumper")

current_scene = Splash()

previous_time = pygame.time.get_ticks()

# Main game loop
while is_running:
	# Find the change in time (delta_time) since the previous frame
	current_time = pygame.time.get_ticks()
	delta_time = current_time - previous_time
	previous_time = current_time

	# Draw white background
	screen.fill(COLOR_WHITE)

	# Update logic and draw
	# Store the status of the current scene (return value of update)
	status = current_scene.update(delta_time)
	current_scene.draw(screen)  

	# If current scene requests to exit, end the game loop
	if status == COMMAND_EXIT:
		is_running = False
	# If the current scene requests to start (or restart) the game, set the current scene to a new
	# instance of Jumper
	elif status == COMMAND_START:
		current_scene = Jumper()

	# Update the display with the latest frame...
	# This is used so that everything is displayed to the user in one step, after all instructions 
	# are completed. Pygame does not immediately display drawn objects, as otherwise the user would
	# see them flicker out (as the screen is filled) and in (as the object is drawn). This update
	# will replace the previous frame.
	pygame.display.update()

pygame.quit()