Skip to content

Commit 63850cf

Browse files
committed
code cleaning
1 parent 28f8d87 commit 63850cf

6 files changed

Lines changed: 141 additions & 85 deletions

File tree

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
pySnake
2-
=======
1+
# pySnake
2+
33

44
tiny snake in Python pygame
5+
6+
7+
## FEATURES
8+
9+
* Joystick and GamePad support
10+
* fullscreen and window mode
11+
* fully customizable

conf.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# screen settings
2+
#SCREEN_WIDTH = 1024
3+
#SCREEN_HEIGHT = 600
4+
SCREEN_WIDTH = 1152
5+
SCREEN_HEIGHT = 864
6+
FULLSCREEN = False
7+
8+
# window settings
9+
WINDOW_POSITION_X = 0
10+
WINDOW_POSITION_Y = 0
11+
WINDOW_BORDER = False
12+
13+
# game settings
14+
BLOCKSIZE = 25
15+
SNACKS = 10
16+
SNACK_COLOR = (99, 255, 99) # 'green'
17+
SNAKE_COLOR = (245, 101, 44) # ORANGE
18+
BG_COLOR = (55, 55, 55) # GRAY

joystick.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pygame
22

3+
34
class joystick(object):
45
def __init__(self):
56
self.joystick_names = []
@@ -12,22 +13,23 @@ def __init__(self):
1213
self.joystick_names.append(pygame.joystick.Joystick(i).get_name())
1314

1415
# By default, load the first available joystick.
15-
if (len(self.joystick_names) > 0):
16+
if len(self.joystick_names) > 0:
1617
self.myJoystick = pygame.joystick.Joystick(0)
1718
self.myJoystick.init()
1819

1920
def joystickAvailable(self):
20-
if self.myJoystick != None:
21+
if self.myJoystick is not None:
2122
return True
2223
else:
2324
return False
2425

2526
def getAction(self):
2627
action = ""
27-
if self.myJoystick != None:
28+
if self.myJoystick is not None:
2829
try:
2930
xAx = 0
3031
yAx = 0
32+
3133
# sometimes 2 axis, sometimes 6, wtf?!
3234
if self.myJoystick.get_numaxes() == 2:
3335
xAx = 0
@@ -39,25 +41,25 @@ def getAction(self):
3941
self.doMove = 2
4042
elif self.myJoystick.get_axis(xAx) < 0:
4143
self.doMove = 4
42-
elif self.myJoystick.get_axis(yAx) > 0:
44+
elif self.myJoystick.get_axis(yAx) > 0:
4345
self.doMove = 3
44-
elif self.myJoystick.get_axis(yAx) < 0:
46+
elif self.myJoystick.get_axis(yAx) < 0:
4547
self.doMove = 1
4648

47-
if self.myJoystick.get_button(0) and self.joyButtonDown == False: # speed up
49+
if self.myJoystick.get_button(0) and self.joyButtonDown is False: # speed up
4850
action = "speedUp"
49-
elif self.myJoystick.get_button(1) and self.joyButtonDown == False: # speed down
51+
elif self.myJoystick.get_button(1) and self.joyButtonDown is False: # speed down
5052
action = "speedDown"
51-
elif (self.myJoystick.get_button(9) and self.joyButtonDown == False)\
52-
or (self.myJoystick.get_button(3) and self.joyButtonDown == False): # (re)start
53+
elif (self.myJoystick.get_button(9) and self.joyButtonDown is False)\
54+
or (self.myJoystick.get_button(3) and self.joyButtonDown is False): # (re)start
5355
action = "restart"
54-
elif (self.myJoystick.get_button(8) and self.joyButtonDown == False):
56+
elif self.myJoystick.get_button(8) and self.joyButtonDown is False:
5557
action = 'quit'
5658
#else:
5759
# make sure NO button is down for reset
5860
someJoyButtonDown = False
5961
for i in range(0, self.myJoystick.get_numbuttons()):
60-
if (self.myJoystick.get_button(i)):
62+
if self.myJoystick.get_button(i) is True:
6163
someJoyButtonDown = True
6264
self.joyButtonDown = someJoyButtonDown
6365

popUp.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
import pygame
22
import time
3+
4+
35
class popUp(object):
46
def __init__(self, screen):
57
self._screen = screen
6-
self.fnt = pygame.font.SysFont("MS Comic Sans" , 30)
8+
self.fnt = pygame.font.SysFont("MS Comic Sans", 30)
79
self.color = (245, 101, 44) # orange ;)
810
self.popUps = []
911
self.defaultDuration = 3
1012

11-
1213
def singlePopUp(self, txt, duration=0):
1314
if duration == 0:
1415
duration = self.defaultDuration
1516
self.popUps = []
16-
self.popUps.append({"txt":txt, "start":time.time(), "duration":duration})
17+
self.popUps.append({"txt": txt, "start": time.time(), "duration": duration})
1718

1819
def addPopUp(self, txt, duration=0):
1920
if duration == 0:
2021
duration = self.defaultDuration
21-
self.popUps.append({"txt":txt, "start":time.time(), "duration":duration})
22+
self.popUps.append({"txt": txt, "start": time.time(), "duration": duration})
2223

2324
def drawPopUps(self):
2425
if len(self.popUps) == 0:
@@ -37,6 +38,6 @@ def drawPopUps(self):
3738
# http://stackoverflow.com/questions/2770886/pygames-message-multiple-lines
3839
if fullText != "":
3940
xPos = (self._screen.get_width() / 2)
40-
self._screen.blit(self.fnt.render(fullText, 1, self.color), ( xPos - (self.fnt.size(fullText)[0] / 2), 5))
41+
self._screen.blit(self.fnt.render(fullText, 1, self.color), (xPos - (self.fnt.size(fullText)[0] / 2), 5))
4142

4243
return True

0 commit comments

Comments
 (0)