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: RavensKrag/WireFu
base: 64c0301b50
...
head fork: RavensKrag/WireFu
compare: 30e922987e
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 28, 2012
@RavensKrag Last commit should say "walk and jump". New state transition private …
…method.
8fa824c
@RavensKrag Implement all animations and transitions except for wire kick.
Note: there is occasionally a dropped frame of animation, resulting in a flicker.
30e9229
View
43 collisions/PlayerEnvCollision.py
@@ -13,6 +13,10 @@ def begin(space, arbiter, jukebox):
player_shape, env_shape = arbiter.shapes
player_shape.gameobject.normal = arbiter.contacts[0].normal
+ #~ if arbiter.contacts[0].normal.y > 0:
+ #~ # If moving downwards from above
+ #~ player_shape.gameobject.ground_collision()
+
return True
@staticmethod
@@ -20,43 +24,6 @@ def pre_solve(space, arbiter, jukebox):
#~ a, b = arbiter.shapes
player_shape, env_shape = arbiter.shapes
- #~ print "==== Collision ===="
- #~ print player_shape.gameobject
- #~ print arbiter.contacts[0].normal
- #~ print "=========="
-
-
- #~ print "collide"
- #~ if(isinstance(a, Player) and isinstance(b, StaticObject)):
- #~ print "proper"
- #~ player_shape = a
- #~ env_shape = b
-
- #~ if(player_shape.body.velocity.y < 0 and env_shape.point_query(player_shape.body.position)):
-
-
- #~ print "===contacts"
- #~ for p in arbiter.contacts:
- #~ print p
-
-
- #~ print arbiter.contacts[0].normal
-
- # Orient the player in the direction of the normal
- #~ normal = arbiter.contacts[0].normal
- #~ if(normal.y < 0): # Insure y component is positive
- #~ normal.x *= -1
- #~ normal.y *= -1
- #~ angle = normal.get_angle()
- #~ if(angle < 0):
- #~ angle + math.pi
- #~ print "=="
- #~ print angle
- #~ player_shape.body.angle = angle
- #~ print player_shape.body.angle
- #~ player_shape.gameobject.rotate(player_shape.body.angle)
-
-
return True
@staticmethod
@@ -74,6 +41,4 @@ def post_solve(space, arbiter, jukebox):
def separate(space, arbiter, jukebox):
#~ player_shape, env_shape = arbiter.shapes
- #~ arbiter.shapes[0].body.angle = 0
-
return True
View
6 gameobjects/Player.py
@@ -100,9 +100,11 @@ def let_go(self, space):
def ground_collision(self):
#~ print "ground"
- self._animation.transition_to('walk_loop')
- self.in_air = False
+
+ if self.in_air:
+ self.in_air = False
+ self._animation.transition_to('stand')
self.jump_count = 0
View
127 utilities/Animation.py
@@ -50,22 +50,11 @@ def __init__(self):
def update(self, velocity=None):
# Set the image to the next frame, and update the rect as well
if self.next_state != self.state:
- self.state = self.next_state
- print "new state: {}".format(self.state)
- self._frame_count = 0
-
- # Transition to spritesheet for new state
- self.spritesheet = self.animations[self.state][0]
- self.frame_rects = self.animations[self.state][1]
-
- # Create new frame surface
- current_frame_rect = self.frame_rects[self._frame_count]
-
- self.current_frame = pygame.Surface((current_frame_rect[2], current_frame_rect[3]),
- pygame.SRCALPHA)
-
- self.current_frame.blit(self.spritesheet, (0,0), current_frame_rect)
+ self._transition_to_new_state()
else:
+ movement_threshold = 2
+ run_velocity = 350
+
#~ print "update"
#~ self._frame_count += 1
@@ -74,16 +63,32 @@ def update(self, velocity=None):
if velocity:
vx = velocity.x
- if vx < 0:
+ if vx > movement_threshold:
+ self.direction = 'right'
+ else:
vx *= -1
self.direction = 'left'
- else:
- self.direction = 'right'
+
self.tick += 1
- if self.state == 'walk_loop':
- if vx > 100:
+
+
+ if self.state == 'stand':
+ if vx > movement_threshold:
+ self.transition_to('walk_start')
+ elif self.state == 'walk_start':
+ # NOTE: This animation is a frame short of a full set
+ if self.tick >= 2:
+ self.tick = 0
+ self._frame_count += 1
+
+ if self._frame_count > 4:
+ self.transition_to('walk_loop')
+ elif self.state == 'walk_loop':
+ if vx > run_velocity:
+ self.transition_to('run')
+ elif vx > 100:
#~ print "high speed walking!!"
if self.tick >= 2:
self.tick = 0
@@ -94,20 +99,50 @@ def update(self, velocity=None):
self.tick = 0
self._frame_count += 1
else:
+ self.transition_to('stand')
+ elif self.state == 'walk_to_run':
+ if self.tick >= 1:
self.tick = 0
- self._frame_count = 0
+ self._frame_count += 1
+
+ if self.is_last_frame():
+ print "RUN!"
+ self.transition_to('run')
+
+ elif self.state == 'run':
+ if self.tick >= 3:
+ self.tick = 0
+ self._frame_count += 1
+
+ if vx < run_velocity:
+ self.transition_to('slide')
+ elif self.state == 'slide':
+ if self.tick >= 2:
+ self.tick = 0
+ self._frame_count += 1
+
+ if vx < movement_threshold:
+ self.transition_to('slide_to_stand')
+ elif self.state == 'slide_to_stand':
+ # NOTE: This animation is a frame short of a full set
+ if self.tick >= 2:
+ self.tick = 0
+ self._frame_count += 1
+
+ if self._frame_count > 5:
+ self.transition_to('stand')
elif self.state == 'jump':
- if self.tick >= 1:
+ if self.tick >= 2:
self.tick = 0
self._frame_count += 1
-
-
- if self.state == 'jump':
- if self._frame_count >= self.animations[self.state][2]:
+ if self.is_last_frame():
+ if self.state == 'jump' or self.state == 'slide':
+ # Stick on last frame
self._frame_count = self.animations[self.state][2]-1
- elif self._frame_count >= self.animations[self.state][2]:
- self._frame_count = 0
+ else:
+ # Loop animation
+ self._frame_count = 0
# Prep current frame
current_frame_rect = self.frame_rects[self._frame_count]
@@ -133,6 +168,9 @@ def get_width(self):
def get_height(self):
return self.current_frame.get_rect().height
+ def is_last_frame(self):
+ return self._frame_count >= self.animations[self.state][2]
+
def _load(self, name, frame_size):
fullname = os.path.join('sprites', name)
image = pygame.image.load(fullname)
@@ -141,24 +179,39 @@ def _load(self, name, frame_size):
frame_rects = []
- i = 0
- x = 0
+ frame_count = 0
+
y = 0
- #~ print "width: {} height: {}".format(image.get_width(), image.get_height())
- #~ print "frame size: {}x{}".format(frame_size[0], frame_size[1])
while y < image.get_height():
- #~ print "y cut"
x = 0
while x < image.get_width():
- i += 1
- #~ print "x cut"
- #~ print "new frame {}".format(name)
+ frame_count += 1
+
# Cut out sprite
frame_rects.append(pygame.Rect((x, y), frame_size))
x += frame_size[0]
y += frame_size[1]
- return image, frame_rects, i
+ return image, frame_rects, frame_count
+
+ def _transition_to_new_state(self):
+ self._frame_count = 0
+
+ self.state = self.next_state
+ print "new state: {}".format(self.state)
+
+
+ # Transition to spritesheet for new state
+ self.spritesheet = self.animations[self.state][0]
+ self.frame_rects = self.animations[self.state][1]
+
+ # Create new frame surface
+ current_frame_rect = self.frame_rects[self._frame_count]
+
+ self.current_frame = pygame.Surface((current_frame_rect[2], current_frame_rect[3]),
+ pygame.SRCALPHA)
+
+ self.current_frame.blit(self.spritesheet, (0,0), current_frame_rect)

No commit comments for this range

Something went wrong with that request. Please try again.