Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: donno/RollyTheSnake
base: eec836f811
...
head fork: donno/RollyTheSnake
compare: 94f5672dcc
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
BIN  assets/eater.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
20 engine/drawablesnake.py
@@ -1,5 +1,4 @@
import pygame
-
import os.path
def path(*args):
@@ -11,6 +10,7 @@ class DrawableSnake:
def __init__(self):
self.headImage = pygame.image.load(path('head.png'))
self.middleImage = pygame.image.load(path('middle.png'))
+ self.eaterImage = pygame.image.load(path('eater.png'))
self.headImages = {}
for degree in xrange(0, 360, 4):
@@ -21,6 +21,15 @@ def __init__(self):
image = pygame.transform.flip(self.headImages[degree], True, False)
self.headImages[degree] = pygame.transform.rotate(image, degree )
+ self.eaterImages = {}
+ for degree in xrange(0, 360, 4):
+ self.eaterImages[degree] = pygame.transform.rotate(self.eaterImage, degree )
+ if degree < 90 or degree < 270:
+ self.eaterImages[degree] = pygame.transform.flip(self.eaterImages[degree], True, False)
+ elif degree > 270:
+ image = pygame.transform.flip(self.eaterImages[degree], True, False)
+ self.eaterImages[degree] = pygame.transform.rotate(image, degree )
+
self.middleImages = {}
for degree in xrange(0, 360, 4):
@@ -31,11 +40,14 @@ def __init__(self):
self.middleImages[degree] = pygame.transform.flip(self.middleImages[degree], False, True)
- def drawHead(self, screen, position, rotation):
+ def drawHead(self, screen, position, rotation, isEating):
rotation = int(rotation) - int(rotation) % 4
- image = self.headImages[rotation % 360]
-
+ if isEating:
+ image = self.eaterImages[rotation % 360]
+ else:
+ image = self.headImages[rotation % 360]
+
imageRect = image.get_rect()
x, y = position
dest = pygame.Rect(x - imageRect.center[0], y - imageRect.center[1],
View
2  engine/mouse.py
@@ -35,7 +35,7 @@ class Mouse:
@property
def rect(self):
- size = 20
+ size = self.image.get_rect().width - 3 # 3 for the transparency
return pygame.Rect(self.x - size, self.y - size/2, size, size)
def __init__(self, x, y):
View
8 engine/snake.py
@@ -40,7 +40,7 @@ def drawSnake(screen, snake):
x = head.x% screenRect.width
y = head.y% screenRect.height
- snake.drawSnake.drawHead(screen, (x% screenRect.width, y% screenRect.height), head.rotation)
+ snake.drawSnake.drawHead(screen, (x% screenRect.width, y% screenRect.height), head.rotation, snake.mouthOpen)
# Disable this circle
#pygame.draw.circle(screen, (255, 0,0), (x%screenRect.width, y%screenRect.width), 10, 0)
@@ -78,6 +78,8 @@ def __init__(self, position):
# The score the snake has.
self.score = 0
+ self.mouthOpen = False
+
def new_segment(self):
self.all_joints.append(Joint(self.x, self.y, Snake.SegmentDistance))
@@ -89,9 +91,13 @@ def remove_segment(self):
def eat_mouse(self, safeToEat):
if safeToEat:
+ # You can't eat a mouse if your mouth is not open.
+ if not self.mouthOpen: return
self.new_segment()
self.score += 5
else:
+ # You still get damanged by zombie mouse reguardless if you had
+ # your mouth open or not.
self.remove_segment()
self.score -= 2
View
10 game.py
@@ -77,6 +77,11 @@ def onEvent(self, event):
if event.key == pygame.K_s:
# Spawn a mouse
self.spawnMouse()
+ if event.key == pygame.K_SPACE:
+ # Open the snakes mouth.
+ if not self.player.mouthOpen:
+ self.player.mouthOpen = True
+ self.mouthTimeOut = 20
elif event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
self.leftPressed = False
@@ -99,6 +104,11 @@ def onUpdate(self):
self.check_mice()
+ if self.player.mouthOpen:
+ self.mouthTimeOut -= 1
+ if self.mouthTimeOut == 0:
+ self.player.mouthOpen = False
+
def onRender(self, screen):
# Clear the whole screen
screen.fill((0,0,0))

No commit comments for this range

Something went wrong with that request. Please try again.