2
* This file is part of the dis-Emi-A HaXe Library. Copyright (c) edA-qa mort-ora-y
3
* For full copyright and license information please refer to doc/license.txt.
9
import squix.CursorActor;
11
class PlayerCursor extends CorePanelObject
14
var speedFactor : Float;
15
var speedTime : Float;
17
public function new( game : Game )
21
new CursorActor( { marqueeSpeed: 2 } ),
22
game.global.cursorSize
26
place( Point2.at( game.surface.width /2, game.surface.height ) );
27
if( game.cursorStartOnEdge )
28
place( game.surface.findNearestEdge( sAt.roundDemote() ).promoteF() );
30
actor.actorSetSequence( CursorActor.seq.Create, ui.Action.bind( setAlive ) );
32
speed = game.global.cursorSpeed;
35
game.addEventListener( GameEvent.CursorDie, onCursorDie );
36
game.addEventListener( GameEvent.BonusCollected, onBonusCollected );
40
* Determines whether this cursor is in a "usable" state, that is, it
41
* is alive and can be regarded as a true cursor. Introduced so that
42
* the TraceSelector would not use a cursor which is being created
45
public function isUsable() : Bool
50
public function getSpeed() : Float
52
return speed * speedFactor;
55
override function onBonusCollected( ge : GameEvent )
60
speedFactor = game.global.cursorSpeedUpFactor;
61
speedTime = game.global.cursorSpeedRecoverTime;
62
actor.actorSetTrait1( CursorActor.trait.Marquee.Speed, 4 );
64
speedFactor = game.global.cursorSpeedDownFactor;
65
speedTime = game.global.cursorSpeedRecoverTime;
66
actor.actorSetTrait1( CursorActor.trait.Marquee.Speed, 0.5);
72
var invincibleTime : Float;
77
//check if near enemies...
78
if( game.isCursorNearEdgeKiller() )
80
invincibleTime = game.global.cursorInvincibleTime;
81
actor.actorSetTrait( CursorActor.trait.Invincible.On );
87
override function _stepTime( elapsed : Float )
89
//only move in normal sequence mode
93
//check for end of speedFactor
100
actor.actorSetTrait1( CursorActor.trait.Marquee.Speed, 2 );
104
//check for turning off invincible
105
if( invincibleTime > 0)
107
invincibleTime -= elapsed;
108
if( invincibleTime <= 0 )
109
actor.actorSetTrait( CursorActor.trait.Invincible.Off );
112
if( game.cursorPhase == CursorPhase.Edge )
113
actor.actorSetTrait( CursorActor.trait.Mode.Edge );
114
else if( game.cursorPhase == CursorPhase.Select )
115
actor.actorSetTrait( CursorActor.trait.Mode.Select );
117
if( game.cursorPhase != CursorPhase.Fill
118
&& (!game.lockCursorOnSelector || game.cursorPhase == CursorPhase.Edge ) )
119
moveCursor( elapsed );
122
function moveCursor( elapsed : Float )
124
//Same basic structure as in TraceSelector
125
var pos = targetCursorPos();
126
var dirs = game.surface.getCursorDirections( sAt );
127
var cdir = GridUtil.pointClosest( pos, dirs, game.allowCursorJitter ? null : sAt );
129
//if none then we'll just drift to where we need to be
133
//TODO: if dirs.length != 0, then check one more step to see which direction would lead us
134
//closed to the cursor (less sticky movement then (one-blocks don't halt the cursor then)
136
if( dirs.length !=0 ) //only if there was really *no* choice (as there might be two options, neither of which are closer to the mouse)
138
if( game.surface.isCovered( sAt.floorDemote() ) ) //only while in open area, should be locked when not... (shouldn't happen)
140
//snap to nearest intersection (to keep valid state)
141
place( sAt.round() ); //TODO: snap to x or y bound only!
145
//otherwise move towards destination (TODO: max move into new cell, use div 2 now to come close...)
146
//TODO: max the actual distance to mouse as well, otherwise jitters
147
cnext = sAt.unitVectorTo( pos ).div(2).add( sAt );
152
var step = GridUtil.excessStep( sAt, cnext, elapsed * getSpeed() );
153
//prevent off-surface wandering (Due here to actually have some elapsed movement -- see plan defect)
154
var next = step.next.constrain( Point2.at( 0, 0 ), Point2.at( game.surface.width, game.surface.height ) );
156
if( step.excess > 0 ) //perhaps should use !isZero
158
moveCursor( step.excess / getSpeed() );
163
override public function moveObject( smp : Point2 )
165
//assume location is valid.
169
function onCursorDie( ge : GameEvent )
172
actor.actorSetSequence( CursorActor.seq.Destroy, ui.Action.bind( destroy ) );
173
flashx.SoundManager.playSound( "playerDies" );
176
override function destroy()
181
game.removeEventListener( GameEvent.CursorDie, onCursorDie );
184
override function onLevelOver( ge : GameEvent )
186
game.numLives++; //we're returning to the player's lives remaining
187
super.onLevelOver( ge );
190
override public function getCorePanelCollisionObject( ) : flash.display.DisplayObject
192
if( !alive || invincibleTime > 0 )
195
return actor.getNative();