forked from KevinFrazier/CitrusHack2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.py
364 lines (317 loc) · 16.2 KB
/
Game.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
import pygame
from GameSequence import GameSequence
from Player import Player
from Tile import Tile
from MapGrid import MapGrid
from Character import Character
import sys
import itertools
'''
Task List:
-heroes
make the class
design -> (circles)
appropriately put it in map grid
then graphics
Map ->
make grid
design (2D grid of 45 degrees, skewed squared)
scaling
cosmetics
put into graphics
'''
'''
characters
variables: hp, atk, mp, abilities (array), weakness, movement, range,
other variables: sprite, animation
'''
'''
MapGrid
variables: length, width
functions:
moveObject(position):
'''
def startGame():
# colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
# graphics
'''
1. make grid
2. put objects in grid
3. manipulating objects in grid
'''
GameMap = MapGrid(10, 10, 100)
grid = GameMap.grid
clock = pygame.time.Clock()
totalUnits = 0
character1 = Character('IronOcto.png', 100, 10, 1, 1, 1, 3,totalUnits) #image, hp, atk, mp, abilities, movement, range
totalUnits += 1
character2 = Character('NinjaOcto.png', 100, 10, 1, 1, 1, 3,totalUnits)
totalUnits += 1
character3 = Character('MegaOcto.png',100, 10, 1, 1, 1, 3,totalUnits)
#player1 init
player1 = grid[1][2]
player1.changeCharacter(character1)
player1.isfilled = True
# player2 init
player2 = grid[2][3]
player2.changeCharacter(character2)
player2.isfilled = True
player3 = grid[5][4]
player3.changeCharacter(character3)
player3.isfilled = True
P1 = Player(1)
P2 = Player(2)
P1.addMember(player1.character)
P1.addMember(player3.character)
P2.addMember(player2.character)
print("P1: ")
print(P1.getTeam())
print("P2: ")
print(P2.getTeam())
theGame= GameSequence((P1, P2))
theGame.startGame()
#should be P1's turn
theGame.startTurn()
# Initialize pygame
pygame.init()
# Set the HEIGHT and WIDTH of the screen
WINDOW_SIZE = [GameMap.tileWidth * GameMap.gridWidth,
GameMap.tileHeight * GameMap.gridHeight]
screen = pygame.display.set_mode(WINDOW_SIZE)
# Set title of screen
pygame.display.set_caption("Array Backed Grid")
# Loop until the user clicks the close button.
done = False
# -------- Main Program Loop -----------
printPlayer = False
while not done:
currentPlayer = theGame.getCurrentPlayer()
if(not printPlayer):
print(currentPlayer.player)
print("TEAM: ")
print(currentPlayer.getTeam)
printPlayer = True
# print("WHOS TURN: ")
# print(currentPlayer.player)
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop
elif event.type is pygame.KEYDOWN:
if event.key is pygame.K_x: #MOVE
if currentPlayer.getChosenTile() is not None:
theGame.changeMode(0)
if event.key is pygame.K_z: #ATTACK
if currentPlayer.getChosenTile() is not None:
theGame.changeMode(1)
if event.key is pygame.K_c: #END TURN
print("ENDING TURN")
theGame.changeTurn()
theGame.startTurn()
if event.key is pygame.K_q:
printPlayer = False
elif event.type == pygame.MOUSEBUTTONDOWN:
# User clicks the mouse. Get the position
pos = pygame.mouse.get_pos()
# Change the x/y screen coordinates to grid coordinates
column = pos[0] // GameMap.tileWidth
row = pos[1] // GameMap.tileHeight
clickedTile = grid[row][column]
#if trying to attack
if theGame.currentMode is 1:
if currentPlayer.getChosenTile() is not None:
if clickedTile.isfilled is True and currentPlayer.isInTeam(clickedTile.character) is False:
print("Attacking")
result = GameMap.attackCharacter(clickedTile, currentPlayer.getChosenTile())
if result:
theGame.changeMode(2)
else:
theGame.changeMode(2)
currentPlayer.getChosenTile().changeHighlighted(False)
currentPlayer.highlightedTile = None
else:
theGame.changeMode(2)
currentPlayer.getChosenTile().changeHighlighted(False)
currentPlayer.highlightedTile = None
#trying to move
elif theGame.currentMode is 0:
if currentPlayer.getChosenTile() is not None:
if grid[row][column].isfilled is False:
print("Moving")
result = GameMap.moveCharacter(currentPlayer.getChosenTile(), currentPlayer.getChosenTile().posX,
currentPlayer.getChosenTile().posY, column, row)
print(result)
if result:
theGame.changeMode(2)
else:
theGame.changeMode(2)
currentPlayer.getChosenTile().changeHighlighted(False)
currentPlayer.highlightedTile = None
else:
theGame.changeMode(2)
currentPlayer.getChosenTile().changeHighlighted(False)
currentPlayer.highlightedTile = None
elif theGame.currentMode is 2:
print("IS FILLED")
#hes trying to click on a unit
currentTile = grid[row][column]
print("player's team: ")
print(currentPlayer.getTeam())
if currentPlayer.getChosenTile() is not None:
theGame.changeMode(2)
currentPlayer.getChosenTile().changeHighlighted(False)
currentPlayer.highlightedTile = None
elif currentPlayer.isInTeam(currentTile.character):
theGame.changeMode(2)
if currentPlayer.getChosenTile() is not None:
currentPlayer.getChosenTile().changeHighlighted(False)
currentPlayer.highlightedTile = None
currentTile.changeHighlighted(True)
currentPlayer.lookAtTile(currentTile)
theGame.changeMode(2)
elif clickedTile.isfilled is False:
print("did nothing")
else:
print("======================EDGE CASE==============================")
theGame.changeMode(2)
if(currentPlayer.getChosenTile() is not None):
currentPlayer.getChosenTile().changeHighlighted(False)
currentPlayer.highlightedTile = None
else:
print("WTF")
# else:
# if theGame.currentMode is not 2:
# if currentPlayer.getChosenTile() is not None:
# theGame.changeMode(2)
# currentPlayer.getChosenTile().changeHighlighted(False)
# currentPlayer.highlightedTile = None
# if GameMap.attackCharacter(player2, player1) is False:
# print("Not in range")
# else:
# GameMap.moveCharacter(player1.posX, player1.posY, column, row)
# player1 = grid[row][column]
print("Click ", pos, "Grid coordinates: ", row, column)
# Set the screen background
screen.fill((255,255,255))
#drawing!
# Draw the grid
for row in range(GameMap.gridHeight):
for column in range(GameMap.gridWidth):
temp = grid[row][column]
#Attack
'''
highlight the tiles within the attack range
'''
#Move
if temp.isHighlighted() is True:
# print("HIGHLIGHTED")
temp.changeBackground('green.jpg')
screen.blit(temp.background,
[GameMap.tileWidth * column, GameMap.tileHeight * row, GameMap.tileWidth,
GameMap.tileHeight])
temp.changeBackground('Square with outline.png')
else:
screen.blit(temp.background, ((column * GameMap.tileWidth), (row * GameMap.tileHeight)) )
#pygame.draw.rect(screen,(255,255,255),[GameMap.tileWidth * column,GameMap.tileHeight * row,GameMap.tileWidth,GameMap.tileHeight])
if temp.isFilled() is True:
if(currentPlayer.isInTeam(temp.character)):
if(currentPlayer.player is 1):
temp.changeBackground('blue.png')
else:
temp.changeBackground('red.jpg')
screen.blit(temp.background, ((column * GameMap.tileWidth), (row * GameMap.tileHeight)))
screen.blit(temp.character.image, ((column * GameMap.tileWidth), (row * GameMap.tileHeight)))
temp.changeBackground('Square with outline.png')
currentTile = currentPlayer.getChosenTile()
if(currentTile is not None):
if theGame.currentMode is 0:
# print("in here")
currentTile.changeBackground('blue.png')
position = currentPlayer.getChosenTile().getPosition()
# print("movement:")
# print(currentPlayer.getChosenTile().character.movement)
for i in range(currentTile.character.movement):
screen.blit(currentTile.background,
[GameMap.tileWidth * (position[0] - i-1), GameMap.tileHeight * position[1],
GameMap.tileWidth, GameMap.tileHeight])
screen.blit(currentTile.background,
[GameMap.tileWidth * (position[0] + i+1), GameMap.tileHeight * position[1],
GameMap.tileWidth, GameMap.tileHeight])
screen.blit(currentTile.background,
[GameMap.tileWidth * position[0], GameMap.tileHeight * (position[1] - i -1),
GameMap.tileWidth, GameMap.tileHeight])
screen.blit(currentTile.background,
[GameMap.tileWidth * position[0], GameMap.tileHeight * (position[1] + i +1),
GameMap.tileWidth, GameMap.tileHeight])
for i in range(currentTile.character.movement - 1):
screen.blit(currentTile.background,
[GameMap.tileWidth * (position[0] + i+1), GameMap.tileHeight * (position[1] - i -1),
GameMap.tileWidth, GameMap.tileHeight])
screen.blit(currentTile.background,
[GameMap.tileWidth * (position[0] + i+1), GameMap.tileHeight * (position[1] + i+1) ,
GameMap.tileWidth, GameMap.tileHeight])
screen.blit(currentTile.background,
[GameMap.tileWidth * (position[0] - i-1), GameMap.tileHeight * (position[1] + i+1),
GameMap.tileWidth, GameMap.tileHeight])
screen.blit(currentTile.background,
[GameMap.tileWidth * (position[0] - i-1), GameMap.tileHeight * (position[1] - i-1),
GameMap.tileWidth, GameMap.tileHeight])
currentTile.changeBackground('green.jpg')
screen.blit(currentTile.background,
[GameMap.tileWidth * position[0], GameMap.tileHeight * position[1], GameMap.tileWidth,
GameMap.tileHeight])
screen.blit(currentTile.character.image,
((position[0] * GameMap.tileWidth), (position[1] * GameMap.tileHeight)))
currentTile.changeBackground('Square with outline.png')
if theGame.currentMode is 1:
# print("in here")
currentTile.changeBackground('red.jpg')
position = currentPlayer.getChosenTile().getPosition()
# print("range:")
# print(currentPlayer.getChosenTile().character.range)
for i in range(currentTile.character.range):
screen.blit(currentTile.background,
[GameMap.tileWidth * (position[0] - i -1), GameMap.tileHeight * position[1],
GameMap.tileWidth, GameMap.tileHeight])
screen.blit(currentTile.background,
[GameMap.tileWidth * (position[0] + i +1), GameMap.tileHeight * position[1],
GameMap.tileWidth, GameMap.tileHeight])
screen.blit(currentTile.background,
[GameMap.tileWidth * position[0], GameMap.tileHeight * (position[1] - i-1),
GameMap.tileWidth, GameMap.tileHeight])
screen.blit(currentTile.background,
[GameMap.tileWidth * position[0], GameMap.tileHeight * (position[1] + i+1),
GameMap.tileWidth, GameMap.tileHeight])
for i in range(currentTile.character.range - 1):
screen.blit(currentTile.background,
[GameMap.tileWidth * (position[0] + i+1), GameMap.tileHeight * (position[1] - i-1),
GameMap.tileWidth, GameMap.tileHeight])
screen.blit(currentTile.background,
[GameMap.tileWidth * (position[0] + i+1), GameMap.tileHeight * (position[1] + i+1),
GameMap.tileWidth, GameMap.tileHeight])
screen.blit(currentTile.background,
[GameMap.tileWidth * (position[0] - i-1), GameMap.tileHeight * (position[1] + i+1),
GameMap.tileWidth, GameMap.tileHeight])
screen.blit(currentTile.background,
[GameMap.tileWidth * (position[0] - i-1), GameMap.tileHeight * (position[1] - i -1),
GameMap.tileWidth, GameMap.tileHeight])
currentTile.changeBackground('green.jpg')
screen.blit(currentTile.background,
[GameMap.tileWidth * position[0], GameMap.tileHeight * position[1], GameMap.tileWidth,
GameMap.tileHeight])
screen.blit(currentTile.character.image,
((position[0] * GameMap.tileWidth), (position[1] * GameMap.tileHeight)))
currentTile.changeBackground('Square with outline.png')
# Limit to 60 frames per second
clock.tick(60)
# Go ahead and update the screen with what we've drawn.
pygame.display.flip()
# Be IDLE friendly. If you forget this line, the program will 'hang'
# on exit.
pygame.quit()
def main():
startGame()
if __name__ == "__main__":
main()