77import pygame
88from ui import ui
99from joystick import joystick
10+ from popUp import popUp
1011from pygame .sprite import Sprite
1112
1213#sys.stdout = os.devnull
@@ -56,6 +57,7 @@ def __init__(self):
5657 self .screen = None
5758 self .playerBox = None
5859 self .ui = None
60+ self .popUp = None
5961
6062
6163 def move (self , direction ):
@@ -164,11 +166,20 @@ def gameSpeedUp(self):
164166 self .gameSpeedFactor += 1
165167 if self .gameSpeedFactor >= len (self .gameSpeedFactors ):
166168 self .gameSpeedFactor -= 1
169+ self .speedChanged ()
167170
168171 def gameSpeedDown (self ):
169172 self .gameSpeedFactor -= 1
170173 if self .gameSpeedFactor < 0 :
171174 self .gameSpeedFactor = 0
175+ self .speedChanged ()
176+
177+ def speedChanged (self ):
178+ oneBased = self .gameSpeedFactor + 1
179+ txt = "|" * oneBased
180+ txt = "[" + txt .ljust (len (self .gameSpeedFactors )) + "]"
181+
182+ self .popUp .singlePopUp (txt )
172183
173184 def run_game (self ):
174185 # Game parameters
@@ -196,6 +207,7 @@ def run_game(self):
196207
197208 # init the menu, add stuff later
198209 self .iUi = ui (self .screen )
210+ self .popUp = popUp (self .screen )
199211
200212 pygame .joystick .init ()
201213 self .joystickInteract = joystick ()
@@ -222,19 +234,22 @@ def run_game(self):
222234 worldChanged = False
223235
224236 if self .joystickInteract .joystickAvailable ():
225- if self .joystickInteract .haveAction () == "move" :
237+ joyAction = self .joystickInteract .getAction ()
238+ if joyAction == "move" :
226239 doMove = self .joystickInteract .getMoveAction ()
227- elif self . joystickInteract . haveAction () == "speedUp" :
240+ elif joyAction == "speedUp" :
228241 self .gameSpeedUp ()
229- elif self . joystickInteract . haveAction () == "speedDown" :
242+ elif joyAction == "speedDown" :
230243 self .gameSpeedDown ()
231- elif self . joystickInteract . haveAction () == "restart" :
244+ elif joyAction == "restart" :
232245 self .resetGame ()
246+ gameOver = False
247+ elif joyAction == 'quit' :
248+ self .exit_game ()
233249
234250 for event in pygame .event .get ():
235251 if event .type == pygame .QUIT :
236252 self .exit_game ()
237-
238253 elif event .type == pygame .KEYDOWN :
239254 if event .key in keymap :
240255 doMove = keymap [event .key ]
@@ -270,7 +285,7 @@ def run_game(self):
270285 for elem in reversed (self .elements ):
271286 elem .update ()
272287
273- # add elements BEVORE blit is called and they change direction!
288+ # add elements BEFORE blit is called and they change direction!
274289 # WEIRD stuff would happen otherwise!!!1!!!!!!!!
275290 if len (self .haveToAdd ) > 0 :
276291 for i in range (len (self .haveToAdd )):
@@ -283,23 +298,27 @@ def run_game(self):
283298 self .haveToAdd .pop (i )
284299 break
285300 else :
286- # if theres NOTHING to add to the Snake, add a new snak, if needed
301+ # if there is NOTHING to add to the Snake, add a new snak, if needed
287302 # preventing from spawning a snack inside the "new" tail of the snake and shit
288303 self .addSnack (self .elements )
289304
290305 # update elements
291306 for elem in reversed (self .elements ):
292307 elem .blit ()
293308
294- # if a snak has been eaten, add it to the to add list
309+ # draw pop ups
310+ self .popUp .drawPopUps ()
311+
312+ # if a snack has been eaten, add it to the to add list
295313 snackEaten = self .eatSnack (self .elements )
296314 if snackEaten != None :
297315 self .haveToAdd .append (snackEaten )
316+ self .popUp .singlePopUp (str (self .getBodyLen ()))
298317
299318 # collision!
300319 if self .headDied (self .elements ) == True :
301320 gameOver = True
302-
321+
303322 pygame .display .flip ()
304323
305324
0 commit comments