-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyProject.py
More file actions
70 lines (58 loc) · 1.66 KB
/
myProject.py
File metadata and controls
70 lines (58 loc) · 1.66 KB
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
import pygame
#set up code
pygame.init()
#setting up the pygame screen
WIDTH = 800
HEIGHT = 640
screen = pygame.display.set_mode([WIDTH,HEIGHT])
#set game title
pygame.display.set_caption("My Game Title")
#set up the pygame clock
clock = pygame.time.Clock()
fps = 60
#set up colors
white = [255,255,255]
black = [0,0,0]
yellow = [255,255,0]
#set up functions for game objects
#each game object should have 3 functions
#1. first function is the create function
#this should create a dictionary that defines the game object
#2. second function is the set function
#this should set the keys in the game object dictionary to values
#3. the third function is the update function
#This should tell pygame what the game object does each frame
#this is the player object
def createPlayer():
player = {
"x" : 0,
"y" : 0,
"width" : 0,
"height" : 0,
"rect" : pygame.Rect(0,0,0,0),
"color" : yellow
}
return player
def setPlayer(player):
player["x"] = WIDTH/2
player["y"] = HEIGHT/2
player["width"] = 50
player["height"] = 50
player["rect"].center = [player["x"],player["y"]]
player["rect"].width = player["width"]
player["rect"].height = player["height"]
def updatePlayer(player):
player["rect"].center = [player["x"],player["y"]]
pygame.draw.rect(screen,player["color"],player["rect"])
#creating player object from the player functions
player = createPlayer()
setPlayer(player)
#GameLoop
while True:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
pygame.quit()
screen.fill("white")
pygame.display.update()
clock.tick(fps)