Last active
October 2, 2015 23:28
-
-
Save samsmo/2345572 to your computer and use it in GitHub Desktop.
Bat class for Imaginary Monsters prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com | |
{ | |
import flash.display.InteractiveObject; | |
import flash.geom.Point; | |
import org.flixel.*; | |
public class Bat extends Enemy | |
{ | |
[Embed(source = "../../data/bat.png")] private var ImgBat:Class; | |
private var _move_speed:int = 400; | |
private var _jump_power:int = 350; | |
private var _state:PlayState; | |
private var dontAttack:Boolean; | |
private var initializer:Boolean; | |
private var moveOver:Number | |
private var originalY:Number; | |
private var arc:Number; | |
public function Bat(state:PlayState,X:Number,Y:Number):void | |
{ | |
super(X, Y); | |
loadGraphic(ImgBat, true, true, 26,34); | |
_state = state; | |
maxVelocity.x = 200; | |
maxVelocity.y = 200; | |
//Set the player health | |
health = 10; | |
//Gravity | |
acceleration.y = -400; | |
//Friction | |
drag.x = 200; | |
width=26; | |
height=35; | |
originalY = this.y; | |
addAnimation("fly", [2,3], 7); | |
addAnimation("idle", [0], 7); | |
play("idle"); | |
dontAttack = false; | |
initializer = false; | |
exists = true; | |
controlMe = false; | |
} | |
override public function resetDefaults():void | |
{ | |
dontAttack = false; | |
initializer = false; | |
exists = true; | |
controlMe = false; | |
acceleration.y = -400; | |
} | |
override public function attack():void | |
{ | |
if(!initializer){ | |
initializer = true; | |
acceleration.y = 0; | |
} | |
if(_state.player.y <= this.y+35) | |
{ | |
if(!dontAttack){ | |
dontAttack = true; | |
moveOver = Math.random()*100; | |
//trace(moveOver); | |
} | |
if(_state.player.facing == RIGHT){ | |
acceleration.y = -400; | |
velocity.x -= moveOver; | |
}else if(_state.player.facing == LEFT){ | |
acceleration.y = -400; | |
velocity.x += moveOver; | |
} | |
}else{ | |
play("fly"); | |
velocity.y += _state.player.y* .005; | |
} | |
} | |
override public function getLikeMe():void { | |
if ( FlxG.keys.LEFT ) | |
{ | |
facing = LEFT; | |
velocity.x -= _move_speed * FlxG.elapsed; | |
} | |
else if (FlxG.keys.RIGHT ) | |
{ | |
facing = RIGHT; | |
velocity.x += _move_speed * FlxG.elapsed; | |
} | |
if (FlxG.keys.X) | |
{ | |
velocity.y = -200 | |
} | |
if (velocity.y < 0 &&!FlxG.keys.C) | |
{ | |
play("fly"); | |
} | |
else | |
{ | |
if ( velocity.y > 0 ) | |
{ | |
play("fly"); | |
} | |
else if (velocity.x == 0 && !FlxG.keys.C) | |
{ | |
play('idle'); | |
} | |
else | |
{ | |
if(!FlxG.keys.C){ | |
play("idle"); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment