Skip to content

Commit

Permalink
Added laser, greatly improved the networked emitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Ohmnivore committed Aug 21, 2014
1 parent 9d0d799 commit 764828d
Show file tree
Hide file tree
Showing 22 changed files with 558 additions and 58 deletions.
Binary file modified Client/export/windows/cpp/bin/SkullRush.exe
Binary file not shown.
74 changes: 69 additions & 5 deletions Client/source/SkullClient.hx
Original file line number Diff line number Diff line change
Expand Up @@ -588,18 +588,30 @@ class SkullClient extends Client
em.angleRange = cast arr[30];
em.distance = cast arr[31];
em.distanceRange = cast arr[32];

em.autoDestroy = cast arr[33];
}
}

if (MsgID == Msg.EmitterNew.ID)
{
var e:FlxEmitterAuto = cloneFromEmitter(NReg.emitters.get(Msg.EmitterNew.data.get("id")),
Msg.EmitterNew.data.get("x"), Msg.EmitterNew.data.get("y"));
e.makeParticles(Assets.images.get(Msg.EmitterNew.data.get("graphic")),
cast(Msg.EmitterNew.data.get("quantity"), Int), cast(Msg.EmitterNew.data.get("rotationFrames"), Int),
cast(Msg.EmitterNew.data.get("collide"), Float));
var quantity:Int = cast(Msg.EmitterNew.data.get("quantity"), Int);
if (quantity == 0)
{
e.makeParticles(Assets.images.get(Msg.EmitterNew.data.get("graphic")),
50, cast(Msg.EmitterNew.data.get("rotationFrames"), Int),
cast(Msg.EmitterNew.data.get("collide"), Float));
}
else
{
e.makeParticles(Assets.images.get(Msg.EmitterNew.data.get("graphic")),
quantity, cast(Msg.EmitterNew.data.get("rotationFrames"), Int),
cast(Msg.EmitterNew.data.get("collide"), Float));
}
e.start(Msg.EmitterNew.data.get("explode"), e.life.min, e.frequency,
Msg.EmitterNew.data.get("quantity"), e.life.max - e.life.min);
quantity, e.life.max - e.life.min);
Reg.state.emitters.add(e);

NReg.live_emitters.set(Msg.EmitterNew.data.get("id2"), e);
Expand All @@ -620,6 +632,56 @@ class SkullClient extends Client
}
}

if (MsgID == Msg.EmitterPause.ID)
{
var ID:Int = Msg.EmitterDelete.data.get("id");

var e:FlxEmitterAuto = NReg.live_emitters.get(ID);

if (e != null)
{
e.on = false;
}
}

if (MsgID == Msg.EmitterResume.ID)
{
var ID:Int = Msg.EmitterDelete.data.get("id");

var e:FlxEmitterAuto = NReg.live_emitters.get(ID);

if (e != null)
{
e.on = true;
}
}

if (MsgID == Msg.LineNew.ID)
{
var ID:Int = Msg.LineNew.data.get("id");

var line:FlxLaserLine = new FlxLaserLine(Msg.LineNew.data.get("x"),
Msg.LineNew.data.get("y"),
Msg.LineNew.data.get("length"),
Msg.LineNew.data.get("angle"));

Reg.state.background.add(line);

NReg.sprites.set(ID, line);
}

if (MsgID == Msg.LineToggle.ID)
{
var ID:Int = Msg.LineNew.data.get("id");

if (NReg.sprites.exists(ID))
{
var line:FlxLaserLine = cast NReg.sprites.get(ID);

line.visible = Msg.LineToggle.data.get("visible");
}
}

if (MsgID == Msg.AnnounceGuns.ID)
{
if (Reg.state.wepHUD != null)
Expand Down Expand Up @@ -702,7 +764,9 @@ class SkullClient extends Client
e.setYSpeed(E.yVelocity.min, E.yVelocity.max);
e.setAlpha(E.startAlpha.min, E.startAlpha.max, E.endAlpha.min, E.endAlpha.max);
e.setMotion(E.angle / 0.017453293, E.distance, E.life.min,
E.angleRange/0.017453293, E.distanceRange, E.life.max - E.life.min);
E.angleRange / 0.017453293, E.distanceRange, E.life.max - E.life.min);

e.autoDestroy = E.autoDestroy;

return e;
}
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ At the moment the client source code is a mess. I'll clean it up one day.
# TODO:

## Engine:
* Improve game feel
* Plugin reloading
* Scroll wheel weapon select
* Gadgets
* Secondary weapon fire
* Interactive triggers & events:
* Button trigger
* Area trigger
* Time trigger
* Lasers
* Teleporters


Expand Down
1 change: 0 additions & 1 deletion Server/assets/maps/TwinCapture.oel
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@
<Platform id="13" x="2048" y="832" Speed="50" Mode="YOYO">
<node x="2048" y="576" />
</Platform>
<Laser id="14" x="192" y="464" angle="0" />
<JumpPad id="15" x="528" y="752" angle="0" />
<JumpPad id="16" x="1072" y="656" angle="0" />
<JumpPad id="17" x="1616" y="736" angle="0" />
Expand Down
Binary file modified Server/export/windows/cpp/bin/SkullRushServer.exe
Binary file not shown.
4 changes: 4 additions & 0 deletions Server/export/windows/cpp/bin/assets/maps/TwinCapture.oel
Original file line number Diff line number Diff line change
Expand Up @@ -344,5 +344,9 @@
<JumpPad id="17" x="1616" y="736" angle="0" />
<JumpPad id="18" x="1504" y="624" angle="180" />
<JumpPad id="19" x="640" y="624" angle="180" />
<Laser id="20" x="192" y="944" angle="270" />
<Laser id="21" x="448" y="688" angle="180" />
<Laser id="22" x="384" y="608" angle="90" />
<Laser id="23" x="672" y="704" angle="315" />
</Entities>
</level>
11 changes: 11 additions & 0 deletions Server/source/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import flash.display.BitmapData;
import flash.display.StageQuality;
import flixel.addons.tile.FlxRayCastTilemap;
import flixel.addons.weapon.FlxBullet;
import flixel.effects.particles.FlxEmitter;
import flixel.effects.particles.FlxEmitterExt;
import flixel.FlxG;
import flixel.FlxObject;
Expand Down Expand Up @@ -75,6 +76,8 @@ class PlayState extends FlxState

public var spawns:Array<Spawn>;

public var drawArea:DrawArea;

/**
* Function that is called up when to state is created to set it up.
*/
Expand Down Expand Up @@ -116,6 +119,10 @@ class PlayState extends FlxState
hud = new FlxGroup();
add(hud);

drawArea = new DrawArea();
drawArea.alpha = 0.8;
//ent.add(drawArea);

Reg.chatbox = new ChatBox();
hud.add(Reg.chatbox);
Reg.chatbox.callback = Reg.server.sendChatMsg;
Expand All @@ -134,6 +141,10 @@ class PlayState extends FlxState

Insomnia.preventSleep();
Insomnia.setProcessPriority(Insomnia.P_HIGH_PRIORITY_CLASS);

//var testEmitter:FlxEmitter = new FlxEmitter(500, 500);
//testEmitter.makeParticles("assets/images/explosionparticle.png");
//testEmitter.start(false, 1.5, 0.1, 0,
}

public function loadMap(Name:String):Void
Expand Down
160 changes: 153 additions & 7 deletions Server/source/entities/Laser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import entities.JumpPad.JumpPadSprite;
import entities.Platform.PlatformSprite;
import flixel.FlxG;
import flixel.FlxObject;
import flixel.FlxSprite;
import flixel.util.FlxAngle;
import flixel.util.FlxMath;
import flixel.util.FlxPath;
import flixel.util.FlxPoint;
import flixel.util.FlxSpriteUtil;
import networkobj.NEmitter;
import networkobj.NFlxEmitterAuto;
import networkobj.NFlxLine;
import networkobj.NSprite;
import networkobj.NTemplate;
import networkobj.NFlxSprite;
Expand All @@ -28,10 +33,45 @@ import gamemodes.DefaultHooks;
class Laser extends NSprite
{
static public var TEMPL:NTemplate;
static public var LASER:String = "laser";
static public var BURN:Int;

public function new(X:Float, Y:Float)
public var angle:Int;
public var working(get, set):Bool;
private var _working:Bool;

public function get_working():Bool
{
return _working;
}

public function set_working(Value:Bool):Bool
{
_working = Value;

var sprite:LaserSprite = cast s;
if (_working)
{
//if (!sprite.emitter.on)
NEmitter.resumeEmitter(sprite.emitter, true, 0);
sprite.beam.setVisible(true, 0);
}
else
{
//if (sprite.emitter.on)
NEmitter.pauseEmitter(sprite.emitter, true, 0);
sprite.beam.setVisible(false, 0);
}

return _working;
}

public function new(X:Float, Y:Float, Angle:Int = 0)
{
angle = Angle;
super(X, Y, TEMPL, LaserSprite);

working = true;
}

override public function announce(PlayerID:Int):Void
Expand All @@ -40,41 +80,147 @@ class Laser extends NSprite

setFields(0, ["health"], [0]);
setFields(0, ["immovable"], [true]);
setFields(0, ["angle"], [s.angle]);

var sprite:LaserSprite = cast s;
sprite.beam.announce(PlayerID);
sprite.beam.setVisible(sprite.beam.visible, PlayerID, false);
}

static public function makeFromXML(D:Fast):Laser
{
return new Laser(Std.parseInt(D.att.x), Std.parseInt(D.att.y));
return new Laser(Std.parseInt(D.att.x), Std.parseInt(D.att.y), Std.parseInt(D.att.angle));
}

static public function init():Void
{
TEMPL = new NTemplate("assets/images/laser_base.png", 0, 0, 400);
NReg.registerTemplate(TEMPL);

var t_emit:NFlxEmitterAuto = new NFlxEmitterAuto(Reg.state.emitters);
t_emit.setRotation(0, 0);
t_emit.setMotion(0, 17, 0.9, 360, 25, 0);
t_emit.setAlpha(1, 1, 0, 0);
t_emit.setColor(0xffE80000, 0xffF54242);
t_emit.setXSpeed(150, 150);
t_emit.setYSpeed(150, 150);
t_emit.bounce = 0.5;
t_emit.autoDestroy = false;

BURN = NEmitter.registerEmitter(t_emit);
}
}

class LaserSprite extends NFlxSprite
{
public var laser:Laser;
public var stop:FlxPoint;
public var emitter:Int;
public var beam:NFlxLine;

public function new(X:Float, Y:Float, GraphicString:String, Parent:Laser)
{
super(X, Y, GraphicString, Parent);

laser = Parent;
angle = laser.angle;

var endPoint:FlxPoint = FlxAngle.rotatePoint(400, 0, 0, 0, angle);
endPoint.x += x + width / 2;
endPoint.y += y + height / 2;

var finalPoint:FlxPoint = new FlxPoint();
finalPoint.copyFrom(endPoint);

for (m in Reg.state.maps.members)
{
var map:FlxTilemap = cast m;

var res:FlxPoint = new FlxPoint();

if (!map.ray(getMidpoint(), finalPoint, res))
{
finalPoint.copyFrom(res);
}
}

stop = new FlxPoint();
stop.copyFrom(finalPoint);
beam = new NFlxLine(x + width / 2, y + height / 2,
Std.int(FlxMath.distanceToPoint(this, finalPoint)), angle);
Reg.state.background.add(beam);
emitter = NEmitter.playEmitter(Laser.BURN, true, Std.int(finalPoint.x), Std.int(finalPoint.y),
"assets/images/explosionparticle.png", 0, 0, false, 0);
}

override public function update():Void
{
//FlxG.collide(this, Reg.state.players, collisionHandler);
//FlxG.overlap(Reg.state.bullets, this, DefaultHooks.bulletCollide);

super.update();

FlxG.collide(this, Reg.state.players);
FlxG.overlap(Reg.state.bullets, this, DefaultHooks.bulletCollide);

for (p in Reg.server.playermap.iterator())
{
if (rayBoxIntersect2(getMidpoint(), stop, new FlxPoint(p.x, p.y),
new FlxPoint(p.x + width, p.y + height)).length > 0)
{
var info:HurtInfo = new HurtInfo();
info.attacker = 0;
info.victim = p.ID;
info.dmg = 15;
info.dmgsource = stop;
info.weapon = null;
info.type = Laser.LASER;
info.message = " promptly combusted.";

Reg.gm.dispatchEvent(new HurtEvent(HurtEvent.HURT_EVENT, info));
}
}
}

private static function rayBoxIntersect2(r1:FlxPoint, r2:FlxPoint,
box1:FlxPoint, box2:FlxPoint):Array<FlxPoint>
{
var arr:Array<FlxPoint> = [];
var intersection:FlxPoint;

intersection = rayRayIntersect(r1, r2, box1, new FlxPoint(box2.x, box1.y));
if (intersection != null) arr.push(intersection);

intersection = rayRayIntersect(r1, r2, box1, new FlxPoint(box1.x, box2.y));
if (intersection != null) arr.push(intersection);

intersection = rayRayIntersect(r1, r2, box2, new FlxPoint(box2.x, box1.y));
if (intersection != null) arr.push(intersection);

intersection = rayRayIntersect(r1, r2, box2, new FlxPoint(box1.x, box2.y));
if (intersection != null) arr.push(intersection);

return arr;
}

private function collisionHandler(Platf:JumpPadSprite, Pl:Player):Void
private static function rayRayIntersect(p1:FlxPoint, p2:FlxPoint, p3:FlxPoint, p4:FlxPoint):FlxPoint
{
Pl.velocity.y -= 550;
var denom:Float = ((p4.y - p3.y)*(p2.x - p1.x)) - ((p4.x - p3.x)*(p2.y - p1.y));
var nume_a:Float = ((p4.x - p3.x)*(p1.y - p3.y)) - ((p4.y - p3.y)*(p1.x - p3.x));
var nume_b:Float = ((p2.x - p1.x)*(p1.y - p3.y)) - ((p2.y - p1.y)*(p1.x - p3.x));

if(denom == 0.0) {
if(nume_a == 0.0 && nume_b == 0.0) {
return null; //COINCIDENT;
}
return null; //PARALLEL;
}

var ua:Float = nume_a / denom;
var ub:Float = nume_b / denom;

if(ua >= 0.0 && ua <= 1.0 && ub >= 0.0 && ub <= 1.0) { //INTERSECTING
// Get the intersection point.
return new FlxPoint(p1.x + ua*(p2.x - p1.x), p1.y + ua*(p2.y - p1.y));
}

return null;
}
}
Loading

0 comments on commit 764828d

Please sign in to comment.