-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (44 loc) · 1.96 KB
/
main.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
import pygame as pg
from constants import WINDOW_WIDTH, WINDOW_HEIGHT
from models.player import Player
from engine.control import handle_key_up, handle_key_down
from models.space_ship import SpaceShip
from pygame import Rect
def main():
""" Set up the game and run the main game loop """
pg.init() # Prepare the pygame module for use
surface_height = WINDOW_WIDTH # Desired physical surface size, in pixels.
surface_width = WINDOW_HEIGHT # Desired physical surface size, in pixels.
clock = pg.time.Clock()
# Create surface of (width, height), and its window.
main_surface = pg.display.set_mode((surface_height, surface_width))
some_color = (0, 0, 255) # A color is a mix of (Red, Green, Blue)
some_other_color = (255, 255, 255)
# Set up some data to describe a small rectangle and its color
space_ship = SpaceShip(50,30, (255,0,0))
player = Player(space_ship)
while True:
clock.tick(60)
ev = pg.event.poll() # Look for any event
keys=pg.key.get_pressed()
if ev.type == pg.QUIT: # Window close button clicked?
break # . .. leave game loop
elif ev.type == pg.KEYDOWN:
handle_key_down(ev)
elif ev.type == pg.KEYUP:
handle_key_up(ev)
if keys[pg.K_LEFT]:
player.change_direction(-0.1)
elif keys[pg.K_RIGHT]:
player.change_direction(0.1)
# Update your game objects and data structures here...
# We draw everything from scratch on each frame.
# So first fill everything with the background color
main_surface.fill(some_color)
player.draw()
# main_surface.fill(some_other_color, small_box)
# Overpaint a smaller rectangle on the main surface
# Now the surface is ready, tell pygame to display it!
pg.display.flip()
pg.quit() # Once we leave the loop, close the window.
main()