Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- from scene import *
- class Alien (SpriteNode):
- def __init__(self, start, **kwargs):
- SpriteNode.__init__(self, 'plf:AlienGreen_front',position=start, **kwargs)
- self.default_sprite = Texture('plf:AlienGreen_front')
- self.stand_sprite = Texture('plf:AlienGreen_stand')
- self.walk_sprites = Texture('plf:AlienGreen_walk1'), Texture('plf:AlienGreen_walk2')
- self.climb_sprites = Texture('plf:AlienGreen_climb1'), Texture('plf:AlienGreen_climb2')
- self.crouch_sprite = Texture('plf:AlienGreen_duck')
- self.jump_sprite = Texture('plf:AlienGreen_jump')
- self.swim_sprites = Texture('plf:AlienGreen_swim1'), Texture('plf:AlienGreen_swim2')
- self.hit_sprite = Texture('plf:AlienGreen_hit')
- self.frames_until_animation = 0
- self.frame_index = False
- self.facing_right = False
- self.anchor_point = .5, 0
- self.gravity = 1 #for y-coordinate only
- #State can be standing, swimming, hurt, crouching, walking, climbing, in air
- self.current_action_state = 'in air'
- self.velocity = Vector2(0, 0)
- self.bound = Rect(self.position.x - 25, self.position.y -25, 50, 100)
- self.landed = False
- self.z_position = 1
- def above_collided_object(self, item):
- self.landed = False
- if int(self.position.y) in range(int(item.bound.max_y - 2), int(item.bound.max_y - self.velocity.y)):
- self.landed = True
- self.position = (self.position.x, item.bound.max_y - self.velocity.y)
- def walk(self):
- self.frames_until_animation -= self.velocity.x
- if self.frames_until_animation < 1:
- self.frame_index = True if not self.frame_index else False
- self.frames_until_animation = 60
- def update_position(self):
- self.position += self.velocity
- self.change_facing_position()
- self.bound = Rect(self.position.x - 25, self.position.y -25, 50, 100)
- if self.landed:
- self.velocity = Vector2(0, .05)
- else:
- self.velocity -= (0, .05)
- def change_facing_position(self):
- #changes y scale
- if self.gravity < 0 and self.y_scale > 0:
- self.y_scale = -self.y_scale
- elif self.gravity > 0 and self.y_scale < 0:
- self.y_scale = abs(self.y_scale)
- #changes x scale
- if self.facing_right and self.x_scale < 0:
- self.x_scale = abs(self.x_scale)
- elif not self.facing_right and self.x_scale > 0:
- self.x_scale = -self.x_scale
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement