Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Dudev <emildudev@gmail.com>2013-12-20 22:41:36 (GMT)
committer Emil Dudev <emildudev@gmail.com>2013-12-20 22:41:36 (GMT)
commitf6093a3537d4bf751464a78ce5d54c9b1626e64a (patch)
tree9d9ea49770af2e0df82ee803b04ffa152e71fc16
parentdf6a4f4da10eebd32c31d9667ded270cecbcc147 (diff)
Mazes with holes
Added animation when falling Improved the hole generation algorithm The hole count is now dependant on the maze's difficulty Fixes #3495
-rw-r--r--game.py12
-rw-r--r--maze.py17
-rw-r--r--player.py28
3 files changed, 44 insertions, 13 deletions
diff --git a/game.py b/game.py
index e0cca7c..cdb37c5 100644
--- a/game.py
+++ b/game.py
@@ -519,11 +519,11 @@ class MazeGame:
for player in self.allplayers:
oldposition = player.position
- newposition = player.animate(self.maze)
- if oldposition != newposition:
+ update, newposition = player.animate(self.maze)
+ if update:
self.markPointDirty(oldposition)
self.markPointDirty(newposition)
- if player in self.localplayers:
+ if oldposition != newposition and player in self.localplayers:
self.maze.map[player.previous[0]][player.previous[1]] = \
self.maze.SEEN
if self.maze.map[newposition[0]][newposition[1]] == \
@@ -531,7 +531,7 @@ class MazeGame:
self.finish(player)
elif self.maze.map[newposition[0]][newposition[1]] == \
self.maze.HOLE:
- self.reset()
+ player.fallThroughHole()
finish_delay = min(2 * len(self.allplayers), 6)
if self.finish_time is not None and \
@@ -577,7 +577,7 @@ class MazeGame:
pygame.draw.ellipse(self.screen, self.TRAIL_COLOR, dot, 0)
elif tile == self.maze.HOLE:
pygame.draw.rect(self.screen, self.EMPTY_COLOR, rect, 0)
- dot = rect.inflate(-self.outline * 2, -self.outline * 2)
+ dot = rect.inflate(-self.outline, -self.outline)
pygame.draw.ellipse(self.screen, self.HOLE_COLOR, dot, 0)
elif tile == self.maze.GOAL:
pygame.draw.rect(self.screen, self.GOAL_COLOR, rect, 0)
@@ -604,7 +604,7 @@ class MazeGame:
# draw all players
for player in self.allplayers:
if not player.hidden:
- player.draw(self.screen, self.bounds, self.tileSize)
+ player.draw(self.screen, self.bounds, self.tileSize, self.HOLE_COLOR)
# draw the elapsed time for each player that has finished
finishedPlayers = filter(lambda p: p.elapsed is not None,
diff --git a/maze.py b/maze.py
index daa9704..5d66135 100644
--- a/maze.py
+++ b/maze.py
@@ -57,8 +57,15 @@ class Maze:
return self.bounds.collidepoint(x,y) and self.map[x][y]==self.SOLID
def validHole(self, x, y):
- return x > 1 and y > 1 and x < self.width - 2 and y < self.height - 2\
- and self.map[x][y] == self.SOLID
+ if x > 1 and y > 1 and x < self.width - 2 and y < self.height - 2\
+ and self.map[x][y] == self.SOLID:
+ left = (self.map[x-1][y] == self.SOLID)
+ right = (self.map[x+1][y] == self.SOLID)
+ up = (self.map[x][y-1] == self.SOLID)
+ down = (self.map[x][y+1] == self.SOLID)
+ return (left and right and not (up or down)) or \
+ (up and down and not (left or right))
+ return False
def validDigDirections(self, x, y):
directions = []
@@ -100,7 +107,11 @@ class Maze:
else:
stack.pop()
- max_holes = 1
+ if self.width < 10:
+ max_holes = 0
+ else:
+ max_holes = int(self.width / 5)
+
holes = 0
while holes != max_holes:
x = self.generator.randrange(1, self.width, 1)
diff --git a/player.py b/player.py
index f9a3452..05c506b 100644
--- a/player.py
+++ b/player.py
@@ -46,14 +46,25 @@ class Player:
self.colors = map(string2Color, colors)
self.shape = shape
self.hidden = False
+ self.falling = 0.0
self.bonusplayers = None
self.reset()
- def draw(self, screen, bounds, size):
+ def draw(self, screen, bounds, size, holeColor):
+ if self.falling > 0.0:
+ self.falling -= 0.2
+ if self.falling <= 0.0:
+ self.falling = 0.0
+ self.reset()
+
rect = pygame.Rect(bounds.x + self.position[0] * size, bounds.y + self.position[1] * size, size, size)
+ fg, bg = self.colors
+ if self.falling > 0.0:
+ fg = holeColor
+ size *= 2.0 - self.falling
border = size / 10.
center = rect.inflate(-border * 2, - border * 2)
- fg, bg = self.colors
+
if self.shape == 'circle':
pygame.draw.ellipse(screen, fg, rect, 0)
pygame.draw.ellipse(screen, bg, center, 0)
@@ -77,16 +88,22 @@ class Player:
def animate(self, maze):
# if the player finished the maze, then don't move
+ update = False
if maze.map[self.position[0]][self.position[1]] == maze.GOAL:
self.direction = (0, 0)
+ elif maze.map[self.position[0]][self.position[1]] == maze.HOLE:
+ update = True
+ self.direction = (0, 0)
if self.direction == (0, 0):
- return self.position
+ return (update, self.position)
+
if self.canGo(self.direction, maze):
+ update = True
self.move(self.direction, maze)
self.keepGoing(self.direction, maze)
else:
self.direction = (0, 0)
- return self.position
+ return (update, self.position)
def move(self, direction, maze):
"""Move the player in a given direction (deltax,deltay)"""
@@ -94,6 +111,9 @@ class Player:
self.previous = self.position
self.position = newposition
+ def fallThroughHole(self):
+ self.falling = 2.0
+
def canGo(self, direction, maze):
"""Can the player go in this direction without bumping into somethi ng?"""
newposition = (self.position[0] + direction[0], self.position[1] + direction[1])