Advertisement
Guest User

Untitled

a guest
May 30th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. # coding: utf-8
  2. from scene import *
  3.  
  4. class Alien (SpriteNode):
  5. def __init__(self, start, **kwargs):
  6. SpriteNode.__init__(self, 'plf:AlienGreen_front',position=start, **kwargs)
  7. self.default_sprite = Texture('plf:AlienGreen_front')
  8. self.stand_sprite = Texture('plf:AlienGreen_stand')
  9. self.walk_sprites = Texture('plf:AlienGreen_walk1'), Texture('plf:AlienGreen_walk2')
  10. self.climb_sprites = Texture('plf:AlienGreen_climb1'), Texture('plf:AlienGreen_climb2')
  11. self.crouch_sprite = Texture('plf:AlienGreen_duck')
  12. self.jump_sprite = Texture('plf:AlienGreen_jump')
  13. self.swim_sprites = Texture('plf:AlienGreen_swim1'), Texture('plf:AlienGreen_swim2')
  14. self.hit_sprite = Texture('plf:AlienGreen_hit')
  15. self.frames_until_animation = 0
  16. self.frame_index = False
  17. self.facing_right = False
  18. self.anchor_point = .5, 0
  19. self.gravity = 1 #for y-coordinate only
  20. #State can be standing, swimming, hurt, crouching, walking, climbing, in air
  21. self.current_action_state = 'in air'
  22. self.velocity = Vector2(0, 0)
  23. self.bound = Rect(self.position.x - 25, self.position.y -25, 50, 100)
  24. self.landed = False
  25. self.z_position = 1
  26.  
  27. def above_collided_object(self, item):
  28. self.landed = False
  29. if int(self.position.y) in range(int(item.bound.max_y - 2), int(item.bound.max_y - self.velocity.y)):
  30. self.landed = True
  31. self.position = (self.position.x, item.bound.max_y - self.velocity.y)
  32.  
  33. def walk(self):
  34. self.frames_until_animation -= self.velocity.x
  35. if self.frames_until_animation < 1:
  36. self.frame_index = True if not self.frame_index else False
  37. self.frames_until_animation = 60
  38.  
  39. def update_position(self):
  40. self.position += self.velocity
  41. self.change_facing_position()
  42. self.bound = Rect(self.position.x - 25, self.position.y -25, 50, 100)
  43. if self.landed:
  44. self.velocity = Vector2(0, .05)
  45. else:
  46. self.velocity -= (0, .05)
  47.  
  48. def change_facing_position(self):
  49. #changes y scale
  50. if self.gravity < 0 and self.y_scale > 0:
  51. self.y_scale = -self.y_scale
  52. elif self.gravity > 0 and self.y_scale < 0:
  53. self.y_scale = abs(self.y_scale)
  54. #changes x scale
  55. if self.facing_right and self.x_scale < 0:
  56. self.x_scale = abs(self.x_scale)
  57. elif not self.facing_right and self.x_scale > 0:
  58. self.x_scale = -self.x_scale
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement