229 lines
6.7 KiB
ActionScript
229 lines
6.7 KiB
ActionScript
package com.arc.dh.objects
|
|
{
|
|
import com.arc.dh.Color;
|
|
import com.arc.dh.state.HorizontalMode;
|
|
import com.arc.dh.state.TadpoleMode;
|
|
import com.arc.dh.util.Config;
|
|
import com.arc.dh.util.Data;
|
|
import com.arc.flixel.ArcSprite;
|
|
import com.arc.flixel.ArcU;
|
|
import org.flixel.FlxG;
|
|
import org.flixel.FlxPoint;
|
|
import org.flixel.FlxU;
|
|
|
|
public class Diamond extends ArcSprite
|
|
{
|
|
|
|
private static const sprite:Class = Diamond_sprite;
|
|
|
|
private static const PULL_DISTANCE:int = 25;
|
|
|
|
private static const PULL_SPEED:int = 240;
|
|
|
|
public var value:int = 1;
|
|
|
|
public var pullDelay:Number = 0;
|
|
|
|
public var diamondColor:int = 0;
|
|
|
|
private var _pulled:Boolean = false;
|
|
|
|
private var _magnet:Boolean = false;
|
|
|
|
private var _hidden:Boolean = false;
|
|
|
|
private var _thisPoint:FlxPoint = new FlxPoint();
|
|
|
|
private var _otherPoint:FlxPoint = new FlxPoint();
|
|
|
|
private var outsideFunction:Function;
|
|
|
|
private var _c:int = -1;
|
|
|
|
private var _r:int = -1;
|
|
|
|
public function Diamond(param1:Number, param2:Number, param3:int = 1, param4:Boolean = false, param5:int = -1, param6:int = -1)
|
|
{
|
|
var _loc7_:int = 0;
|
|
super(param1,param2);
|
|
loadGraphic(sprite,true,false,10,10);
|
|
this._hidden = param4;
|
|
this._c = param5;
|
|
this._r = param6;
|
|
solid = false;
|
|
this.value = param3;
|
|
switch(param3)
|
|
{
|
|
case 1:
|
|
_loc7_ = 0;
|
|
this.diamondColor = Color.YELLOW;
|
|
break;
|
|
case 2:
|
|
_loc7_ = 1;
|
|
this.diamondColor = Color.GREEN;
|
|
break;
|
|
case 3:
|
|
_loc7_ = 2;
|
|
this.diamondColor = Color.CYAN;
|
|
break;
|
|
case 4:
|
|
_loc7_ = 3;
|
|
this.diamondColor = Color.BLUE;
|
|
break;
|
|
case 5:
|
|
_loc7_ = 4;
|
|
this.diamondColor = Color.PURPLE;
|
|
break;
|
|
case 6:
|
|
_loc7_ = 5;
|
|
this.diamondColor = Color.WHITE;
|
|
break;
|
|
case 10:
|
|
_loc7_ = 6;
|
|
this.diamondColor = Color.BLACK;
|
|
break;
|
|
default:
|
|
_loc7_ = 0;
|
|
this.diamondColor = Color.GREEN;
|
|
}
|
|
var _loc8_:int = _loc7_ * 6;
|
|
addAnimation("glow",[_loc8_ + 0,_loc8_ + 1,_loc8_ + 2,_loc8_ + 3,_loc8_ + 4,_loc8_ + 5,_loc8_ + 4,_loc8_ + 3,_loc8_ + 2,_loc8_ + 1],ArcU.rand(5,12),true);
|
|
play("glow");
|
|
if(Data.state is HorizontalMode)
|
|
{
|
|
this.outsideFunction = this.runmodeOutside;
|
|
}
|
|
else
|
|
{
|
|
this.outsideFunction = this.playmodeOutside;
|
|
}
|
|
}
|
|
|
|
public static function valueFromLevel(param1:int) : int
|
|
{
|
|
var _loc2_:int = 0;
|
|
if(param1 < 9)
|
|
{
|
|
_loc2_ = 1;
|
|
}
|
|
else if(param1 < 20)
|
|
{
|
|
_loc2_ = 2;
|
|
}
|
|
else if(param1 < 31)
|
|
{
|
|
_loc2_ = 3;
|
|
}
|
|
else if(param1 < 42)
|
|
{
|
|
_loc2_ = 4;
|
|
}
|
|
else if(param1 < 53)
|
|
{
|
|
_loc2_ = 5;
|
|
}
|
|
else if(param1 < 61)
|
|
{
|
|
_loc2_ = 6;
|
|
}
|
|
else
|
|
{
|
|
_loc2_ = 10;
|
|
}
|
|
return _loc2_;
|
|
}
|
|
|
|
private function runmodeOutside() : Boolean
|
|
{
|
|
var _loc1_:int = x / Config.BLOCK_SIZE;
|
|
if(_loc1_ <= Data.state.despawnTop - 2)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private function playmodeOutside() : Boolean
|
|
{
|
|
var _loc1_:int = y / Config.BLOCK_SIZE;
|
|
if(_loc1_ >= Data.state.despawnBottom + 2 || _loc1_ <= Data.state.despawnTop - 2)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function get pullDistance() : int
|
|
{
|
|
if(Data.state is TadpoleMode)
|
|
{
|
|
return 50;
|
|
}
|
|
return PULL_DISTANCE + Data.attract * 7;
|
|
}
|
|
|
|
override public function update() : void
|
|
{
|
|
var _loc2_:Number = NaN;
|
|
var _loc3_:Number = NaN;
|
|
var _loc4_:Number = NaN;
|
|
if(this.outsideFunction())
|
|
{
|
|
kill();
|
|
}
|
|
this.pullDelay -= FlxG.elapsed;
|
|
var _loc1_:Boolean = !this._hidden || Data.state.player.inHidden > 0;
|
|
if(_loc1_ && (this.pullDelay <= 0 || this._magnet))
|
|
{
|
|
this._thisPoint.x = x + 2;
|
|
this._thisPoint.y = y + 2;
|
|
this._otherPoint.x = Data.state.player.x + Data.state.player.width / 2;
|
|
this._otherPoint.y = Data.state.player.y + Data.state.player.height / 2;
|
|
_loc2_ = FlxU.getDistance(this._thisPoint,this._otherPoint);
|
|
if(_loc2_ < this.pullDistance && Data.state.tilemap.ray(this._thisPoint,this._otherPoint) || this._magnet)
|
|
{
|
|
_loc3_ = FlxU.getAngle(this._thisPoint,this._otherPoint) - 90;
|
|
_loc4_ = Math.PI / 180 * _loc3_;
|
|
this._pulled = true;
|
|
velocity.x = (PULL_SPEED + (this._magnet ? 150 : 0)) * Math.cos(_loc4_) + (Data.state is HorizontalMode ? (Data.state as HorizontalMode).camera.velocity.x : 0);
|
|
velocity.y = (PULL_SPEED + (this._magnet ? 150 : 0)) * Math.sin(_loc4_);
|
|
if(!this._magnet)
|
|
{
|
|
solid = true;
|
|
}
|
|
}
|
|
else if(this._pulled)
|
|
{
|
|
velocity.x = velocity.y = 0;
|
|
}
|
|
if(_loc2_ < 4)
|
|
{
|
|
solid = true;
|
|
}
|
|
}
|
|
super.update();
|
|
}
|
|
|
|
public function set magnet(param1:Boolean) : void
|
|
{
|
|
var _loc2_:int = getScreenXY().x;
|
|
var _loc3_:int = getScreenXY().y;
|
|
var _loc4_:Boolean = !this._hidden || Data.state.player.inHidden > 0;
|
|
if(_loc2_ >= -width && _loc2_ < FlxG.width && _loc3_ >= -height && _loc3_ < FlxG.height && _loc4_)
|
|
{
|
|
this._magnet = true;
|
|
solid = false;
|
|
}
|
|
}
|
|
|
|
public function despawn() : void
|
|
{
|
|
if(this._c != -1 && this._r != -1)
|
|
{
|
|
Data.state.despawn(this._c,this._r);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|