-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
173 lines (148 loc) · 7.84 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import pygame
from GUI.display import display_surface
from GUI.tiles import Tile
from GUI.decorations import Decoration
from GUI.player import Player
from GUI.ruby import RubyMaker
from GUI.portal import Portal
from GUI.background import Background
from game import Game
vector = pygame.math.Vector2
pygame.init()
# Set FPS and clock
FPS = 60
clock = pygame.time.Clock()
# Create sprite groups
my_background_group = pygame.sprite.Group()
my_main_tile_group = pygame.sprite.Group()
my_platform_group = pygame.sprite.Group()
my_player_group = pygame.sprite.Group()
my_bullet_group = pygame.sprite.Group()
my_zombie_group = pygame.sprite.Group()
my_portal_group = pygame.sprite.Group()
my_ruby_group = pygame.sprite.Group()
# CREATE THE TILE MAP
# 0 -> no tile, 1 -> dirt, 2-5 -> platforms, 6 -> ruby maker, 7-8 -> portal, 9 -> player, 10 -> background
tile_map = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0],
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
]
# Generate Tile objects from the tile map
# Loop through the 23 lists(rows) in the tile map
for i in range(len(tile_map)):
# Loop through the 40 elements in a given list(cols)
for j in range(len(tile_map[i])):
# Background
if tile_map[i][j] == 10:
Background(j * 32, i * 32, my_background_group)
# Dirt
elif tile_map[i][j] == 1:
Tile(j * 32, i * 32, 1, my_main_tile_group)
# Platform
elif tile_map[i][j] == 2:
Tile(j * 32, i * 32, 2, my_main_tile_group, my_platform_group)
elif tile_map[i][j] == 3:
Tile(j * 32, i * 32, 3, my_main_tile_group, my_platform_group)
elif tile_map[i][j] == 4:
Tile(j * 32, i * 32, 4, my_main_tile_group, my_platform_group)
elif tile_map[i][j] == 5:
Tile(j * 32, i * 32, 5, my_main_tile_group, my_platform_group)
# Ruby maker
elif tile_map[i][j] == 6:
RubyMaker(j * 32, i * 32, my_main_tile_group)
# Portals
elif tile_map[i][j] == 7:
Portal(j * 32, i * 32, "green", my_portal_group)
elif tile_map[i][j] == 8:
Portal(j * 32, i * 32, "purple", my_portal_group)
# Player
elif tile_map[i][j] == 9:
my_player = Player(j * 32 - 32, i * 32 + 32, my_platform_group, my_portal_group, my_bullet_group)
my_player_group.add(my_player)
elif tile_map[i][j] == 11:
Decoration(j * 32, i * 32, 11, my_main_tile_group)
elif tile_map[i][j] == 12:
Decoration(j * 32, i * 32, 12, my_main_tile_group)
elif tile_map[i][j] == 13:
Decoration(j * 32, i * 32, 13, my_main_tile_group)
elif tile_map[i][j] == 14:
Decoration(j * 32, i * 32, 14, my_main_tile_group)
elif tile_map[i][j] == 15:
Decoration(j * 32, i * 32, 15, my_main_tile_group)
elif tile_map[i][j] == 16:
Decoration(j * 32, i * 32, 16, my_main_tile_group)
elif tile_map[i][j] == 17:
Decoration(j * 32, i * 32, 17, my_main_tile_group)
elif tile_map[i][j] == 18:
Decoration(j * 32, i * 32, 18, my_main_tile_group)
elif tile_map[i][j] == 19:
Decoration(j * 32, i * 32, 19, my_main_tile_group)
elif tile_map[i][j] == 20:
Decoration(j * 32, i * 32, 20, my_main_tile_group)
elif tile_map[i][j] == 21:
Decoration(j * 32, i * 32, 21, my_main_tile_group)
# Create a game
my_game = Game(my_player, my_zombie_group, my_platform_group, my_portal_group, my_bullet_group, my_ruby_group, my_background_group)
my_game.pause_game("The Last Blade", "Press 'Enter' to begin")
pygame.mixer.music.play(-1, 0.0)
# The main game loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
# Player wants to jump
if event.key == pygame.K_SPACE:
my_player.jump()
# Player wants to fire
if event.key == pygame.K_UP:
my_player.fire()
# Fill the background
display_surface.fill((0, 0, 0))
# Update and draw background
my_background_group.update()
my_background_group.draw(display_surface)
# Draw tiles and update ruby maker
my_main_tile_group.update()
my_main_tile_group.draw(display_surface)
# Update and draw sprite groups
my_portal_group.update()
my_portal_group.draw(display_surface)
my_player_group.update()
my_player_group.draw(display_surface)
my_bullet_group.update()
my_bullet_group.draw(display_surface)
my_zombie_group.update()
my_zombie_group.draw(display_surface)
my_ruby_group.update()
my_ruby_group.draw(display_surface)
# Update and draw the game
my_game.update()
my_game.draw()
# Update the display and tick the clock
pygame.display.update()
clock.tick(FPS)
pygame.quit()