-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.py
More file actions
100 lines (81 loc) · 2.55 KB
/
Copy pathGame.py
File metadata and controls
100 lines (81 loc) · 2.55 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
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
import pygame
import Player
import Ghost
STEP_SIZE = 15
WINDOW_WIDTH = 54 * STEP_SIZE
WINDOW_HEIGHT = 40 * STEP_SIZE
# Define some colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GHOST_COLOURS = ["ghost1.png", "ghost2.png", "ghost3.png"]
GREEN_GHOST = ["ghost2.png"]
PURPLE_GHOST = ["ghost3.png"]
pygame.init()
# Set the height and width of the screen
size = [WINDOW_WIDTH, WINDOW_HEIGHT]
screen = pygame.display.set_mode(size)
# Don't display the mouse pointer
pygame.mouse.set_visible(False)
# Loop until the user clicks the close button.
done = False
# Used to manage how fast the screen updates
clock = pygame.time.Clock()
# Sprite list
all_sprites_list = pygame.sprite.Group()
# Game characters
player = Player.Player()
annoying = Ghost.AnnoyingGhost() # Creates an AnnoyingGhost
annoying.setX(100)
annoying.setY(100)
shy = Ghost.ShyGhost() # Creates a ShyGhost
shy.setX(500)
shy.setY(100)
shy.setColours(GREEN_GHOST)
cultured = Ghost.CulturedGhost() # Creates a Culturedghost
cultured.setX(100)
cultured.setY(500)
cultured.setColours(PURPLE_GHOST)
robo = Ghost.RobotGhost() # Creates a RobotGhost
robo.setX(500)
robo.setY(500)
# Add the ball to the list of player-controlled objects
all_sprites_list.add(player)
# -------- Main Program Loop -----------
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
# Drawing to screen
all_sprites_list.update()
screen.fill(BLACK)
all_sprites_list.draw(screen)
# Game logic
print("ANNOYING GHOST:")
annoying.go_home(player.rect.x, player.rect.y)
annoying.be_flashy(GHOST_COLOURS)
annoying.draw(screen, annoying._ghost_surf)
annoying.boo()
annoying.move()
# annoying.lights_on() # Cannot be called since annoying ghost does not have the lightsOn method
print("SHY GHOST:")
shy.draw(screen, shy._ghost_surf)
shy.boo()
shy.lights_on()
shy.run(player.rect.x, player.rect.y)
shy.move()
print("CULTURED GHOST:")
cultured.draw(screen, cultured._ghost_surf)
cultured.boo()
cultured.go_home()
# cultured.lights_on() # Cannot be called since cultured ghost does not have the lightsOn method
print("ROBO GHOST:")
robo.draw(screen, robo._ghost_surf)
robo.boo()
robo.lights_on()
robo.run()
robo.be_flashy(GHOST_COLOURS)
robo.move()
clock.tick(35)
# Go ahead and update the screen with what we've drawn.
pygame.display.flip()
pygame.quit()