Skip to content

Commit

Permalink
Added moving platforms and zero gravity plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Ohmnivore committed Aug 19, 2014
1 parent 74eeb2b commit eb296de
Show file tree
Hide file tree
Showing 16 changed files with 265 additions and 9 deletions.
Binary file modified Client/export/windows/cpp/bin/SkullRush.exe
Binary file not shown.
12 changes: 12 additions & 0 deletions Client/source/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ class PlayState extends FlxState
FlxG.collide(tocollide, maps); //collidemap
FlxG.collide(bullets, maps, bulletCollide); //collidemap
FlxG.overlap(bullets, players, bulletCollidePl);
FlxG.overlap(bullets, ent, bulletCollideEnt);
FlxG.collide(emitters, maps); //collidemap

if (player != null)
Expand Down Expand Up @@ -720,6 +721,17 @@ class PlayState extends FlxState
Bullet.kill();
}

private function bulletCollideEnt(Bullet:FlxBullet, Ent:FlxSprite):Void
{
if (Ent.health != 1)
{
var wep_ext:FlxWeaponExt = cast Bullet._weapon;

if (!wep_ext.template.ignoreCollisions)
Bullet.kill();
}
}

private function bulletCollidePl(Bullet:FlxBullet, Pl:Player):Void
{
var wep_ext:FlxWeaponExt = cast Bullet._weapon;
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ At the moment the client source code is a mess. I'll clean it up one day.
* Button trigger
* Area trigger
* Time trigger
* Platform
* Meteorite strike
* Lasers


Expand Down
10 changes: 6 additions & 4 deletions Server/Server.hxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@
<!-- Other classes to be compiled into your SWF -->
<classpaths>
<class path="C:\HaxeToolkit\haxe\lib\crashdumper\git" />
<class path="C:\HaxeToolkit\haxe\lib\lime\1,0,0" />
<class path="C:\HaxeToolkit\haxe\lib\flixel-addons\git" />
<class path="C:\HaxeToolkit\haxe\lib\openfl\2,0,0" />
<class path="C:\HaxeToolkit\haxe\lib\openfl\2,0,1" />
<class path="C:\HaxeToolkit\haxe\lib\flixel\3,3,4" />
<class path="C:\HaxeToolkit\haxe\lib\lime\1,0,0" />
<class path="C:\HaxeToolkit\haxe\lib\lime\1,0,1" />
<class path="source" />
<class path="..\Shared\code" />
<class path="C:\HaxeToolkit\haxe\lib\openfl\2,0,0\backends\native" />
<class path="C:\HaxeToolkit\haxe\lib\openfl\2,0,1\backends\native" />
<class path="export\windows\cpp\haxe" />
</classpaths>
<!-- Build options -->
<build>
<option directives="crashdumper=&#xA;flixel-addons=1.1.0&#xA;openfl=2.0.0&#xA;flixel=3.3.4&#xA;lime=1.0.0&#xA;FLX_NO_GAMEPAD&#xA;SERVER&#xA;native&#xA;openfl-native&#xA;FLX_NO_FOCUS_LOST_SCREEN&#xA;tools=1.5.4&#xA;HXCPP_CHECK_POINTER&#xA;HXCPP_STACK_TRACE&#xA;lime_native&#xA;no-compilation&#xA;HXCPP_STACK_LINE&#xA;HXCPP_DEBUG_LINK&#xA;FLX_NO_TOUCH&#xA;safeMode&#xA;display&#xA;FLX_RENDER_TILE&#xA;windows&#xA;desktop" />
<option directives="crashdumper=&#xA;flixel-addons=1.1.0&#xA;openfl=2.0.1&#xA;flixel=3.3.4&#xA;lime=1.0.1&#xA;FLX_NO_GAMEPAD&#xA;SERVER&#xA;native&#xA;openfl-native&#xA;FLX_NO_FOCUS_LOST_SCREEN&#xA;tools=1.5.4&#xA;HXCPP_CHECK_POINTER&#xA;HXCPP_STACK_TRACE&#xA;lime_native&#xA;no-compilation&#xA;HXCPP_STACK_LINE&#xA;HXCPP_DEBUG_LINK&#xA;FLX_NO_TOUCH&#xA;safeMode&#xA;display&#xA;FLX_RENDER_TILE&#xA;windows&#xA;desktop" />
<option flashStrict="False" />
<option noInlineOnDebug="False" />
<option mainClass="ApplicationMain" />
<option enabledebug="False" />
<option additional="--no-output&#xA;--remap flash:openfl&#xA;--macro keep(&quot;Main&quot;)" />
<option additional="--no-output&#xA;--remap flash:openfl&#xA;#--macro keep(&quot;Main&quot;)" />
</build>
<!-- haxelib libraries -->
<haxelib>
Expand Down
10 changes: 9 additions & 1 deletion Server/assets/maps/ProjectDef.oep
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,15 @@
<ImageDefinition DrawMode="Image" ImagePath="..\..\..\Shared\assets\images\platform.png" Tiled="false">
<RectColor A="255" R="255" G="0" B="0" />
</ImageDefinition>
<ValueDefinitions />
<ValueDefinitions>
<ValueDefinition xsi:type="IntValueDefinition" Name="Speed" Default="100" Min="0" Max="300" ShowSlider="true" />
<ValueDefinition xsi:type="EnumValueDefinition" Name="Mode">
<Elements>
<string>LOOPING</string>
<string>YOYO</string>
</Elements>
</ValueDefinition>
</ValueDefinitions>
<NodesDefinition Enabled="true" Limit="-1" DrawMode="Path" Ghost="true" />
</EntityDefinition>
<EntityDefinition Name="Trigger" Limit="-1" ResizableX="false" ResizableY="false" Rotatable="false" RotateIncrement="15">
Expand Down
3 changes: 3 additions & 0 deletions Server/assets/maps/TwinCapture.oel
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,8 @@
<Spawn id="11" x="1872" y="544" Teams="0100" />
<Flag id="6" x="1984" y="720" team="1" graphic="assets/images/flag_y.png" />
<Flag id="0" x="208" y="736" team="0" graphic="assets/images/flag_b.png" />
<Platform id="12" x="96" y="848" Speed="50" Mode="YOYO">
<node x="96" y="576" />
</Platform>
</Entities>
</level>
Binary file modified Server/export/windows/cpp/bin/SkullRushServer.exe
Binary file not shown.
10 changes: 9 additions & 1 deletion Server/export/windows/cpp/bin/assets/maps/ProjectDef.oep
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,15 @@
<ImageDefinition DrawMode="Image" ImagePath="..\..\..\Shared\assets\images\platform.png" Tiled="false">
<RectColor A="255" R="255" G="0" B="0" />
</ImageDefinition>
<ValueDefinitions />
<ValueDefinitions>
<ValueDefinition xsi:type="IntValueDefinition" Name="Speed" Default="100" Min="0" Max="300" ShowSlider="true" />
<ValueDefinition xsi:type="EnumValueDefinition" Name="Mode">
<Elements>
<string>LOOPING</string>
<string>YOYO</string>
</Elements>
</ValueDefinition>
</ValueDefinitions>
<NodesDefinition Enabled="true" Limit="-1" DrawMode="Path" Ghost="true" />
</EntityDefinition>
<EntityDefinition Name="Trigger" Limit="-1" ResizableX="false" ResizableY="false" Rotatable="false" RotateIncrement="15">
Expand Down
3 changes: 3 additions & 0 deletions Server/export/windows/cpp/bin/assets/maps/TwinCapture.oel
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,8 @@
<Spawn id="11" x="1872" y="544" Teams="0100" />
<Flag id="6" x="1984" y="720" team="1" graphic="assets/images/flag_y.png" />
<Flag id="0" x="208" y="736" team="0" graphic="assets/images/flag_b.png" />
<Platform id="12" x="96" y="848" Speed="50" Mode="YOYO">
<node x="96" y="576" />
</Platform>
</Entities>
</level>
8 changes: 8 additions & 0 deletions Server/source/Admin.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import gevents.ConfigEvent;
import networkobj.NReg;
import networkobj.NTimer;
import plugins.SysMeteor;
import plugins.SysGravity;

/**
* ...
Expand All @@ -30,6 +31,7 @@ class Admin
FlxG.console.registerFunction("stopTimers", stopTimers);
FlxG.console.registerFunction("startTimers", startTimers);
FlxG.console.registerFunction("rain", rainHell);
FlxG.console.registerFunction("stopgrav", stopGrav);

FlxG.console.addCommand(["setmap"], setMap, "Set map, ex: setmap Test", "", 1, -1);
}
Expand All @@ -40,6 +42,12 @@ class Admin
sysm.rainHell();
}

static public function stopGrav():Void
{
var sysg:SysGravity = cast Reg.plugins.get("SysGravity");
sysg.ruinPhysics();
}

static public function stopTimers():Void
{
for (t in NReg.timers.iterator())
Expand Down
4 changes: 3 additions & 1 deletion Server/source/Lvls.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import gamemodes.FFA;
import gamemodes.KOTH;

import plugins.SysMeteor;
import plugins.SysGravity;
import plugins.Welcomer;

import sys.io.File;
Expand All @@ -28,8 +29,9 @@ class Lvls

//Write plugins here so that their reference is picked up by the compiler.
//Otherwise plugins won't be compiled.
Welcomer;
SysMeteor;
SysGravity;
Welcomer;

return File.getContent("assets/maps/" + Name + ".oel");
}
Expand Down
105 changes: 105 additions & 0 deletions Server/source/entities/Platform.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package entities;

import entities.Platform.PlatformSprite;
import flixel.FlxG;
import flixel.FlxObject;
import flixel.util.FlxMath;
import flixel.util.FlxPath;
import flixel.util.FlxPoint;
import networkobj.NEmitter;
import networkobj.NSprite;
import networkobj.NTemplate;
import networkobj.NFlxSprite;
import networkobj.NReg;
import ext.FlxEmitterAuto;
import flixel.tile.FlxTilemap;
import gevents.HurtInfo;
import gevents.HurtEvent;
import gamemodes.BaseGamemode;
import haxe.xml.Fast;
import gamemodes.DefaultHooks;

/**
* ...
* @author ...
*/

class Platform extends NSprite
{
static public var TEMPL:NTemplate;

public var speed:Int;
public var nodes:Array<FlxPoint>;
public var mode:Int;

public function new(X:Float, Y:Float, Nodes:Array<FlxPoint>, Mode:Int, Speed:Int = 100)
{
nodes = Nodes;
mode = Mode;
speed = Speed;

super(X, Y, TEMPL, PlatformSprite);
}

override public function announce(PlayerID:Int):Void
{
super.announce(PlayerID);

setFields(0, ["health"], [0]);
}

static public function makeFromXML(D:Fast):Platform
{
var speed:Int = Std.parseInt(D.att.Speed);
var mode:String = D.att.Mode;
var realmode:Int = FlxPath.LOOP_FORWARD;
if (mode == "YOYO")
realmode = FlxPath.YOYO;
var nodes:Array<FlxPoint> = [];
nodes.push(new FlxPoint(Std.parseInt(D.att.x), Std.parseInt(D.att.y)));

for (n in D.elements)
{
if (n.name == "node")
{
nodes.push(new FlxPoint(Std.parseInt(n.att.x), Std.parseInt(n.att.y)));
}
}

return new Platform(Std.parseInt(D.att.x), Std.parseInt(D.att.y), nodes, realmode, speed);
}

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

class PlatformSprite extends NFlxSprite
{
public var platform:Platform;

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

platform = Parent;

var path:FlxPath = new FlxPath(this, platform.nodes, platform.speed, platform.mode);
}

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

super.update();
}

private function collisionHandler(Platf:PlatformSprite, Pl:Player):Void
{
Pl.velocity.y = Platf.velocity.y;
Pl.velocity.x = Platf.velocity.x;
}
}
3 changes: 3 additions & 0 deletions Server/source/gamemodes/BaseGamemode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import gevents.SetTeamEvent;
import insomnia.Insomnia;
import networkobj.NScoreManager;
import plugins.BasePlugin;
import plugins.SysGravity;
import plugins.SysMeteor;

class BaseGamemode extends Sprite
Expand Down Expand Up @@ -60,6 +61,8 @@ class BaseGamemode extends Sprite
//System plugins
var sysm:SysMeteor = new SysMeteor();
Reg.plugins.set(sysm.pluginName, sysm);
var sysg:SysGravity = new SysGravity();
Reg.plugins.set(sysg.pluginName, sysg);

//Third-party plugins
var raw:String = Assets.config.get("plugins");
Expand Down
101 changes: 101 additions & 0 deletions Server/source/plugins/SysGravity.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package plugins;

import entities.MeteoriteStrike.Meteor;
import flixel.util.FlxPoint;
import flixel.util.FlxRandom;
import flixel.util.FlxTimer;
import gamemodes.BaseGamemode;
import gevents.GenEvent;
import networkobj.NLabel;
import gamemodes.DefaultHooks;
import ext.FlxMarkup;
import gevents.RespawnEvent;

/**
* ...
* @author ...
*/
class SysGravity extends BasePlugin
{
public var gravityWorking:Bool = true;

private var msg:NLabel;

public function new()
{
pluginName = "SysGravity";
version = "0.0.1";

super();
}

override public function hookEvents(Gm:BaseGamemode):Void
{
super.hookEvents(Gm);

Gm.addEventListener(RespawnEvent.RESPAWN_EVENT, onSpawn, false, 10);
}

override public function onSpawn(E:GenEvent):Void
{
super.onSpawn(E);

var p:Player = cast E.info;

if (gravityWorking)
{
p.acceleration.y = 440;
}
else
{
p.acceleration.y = 0;
}
}

public function ruinPhysics(Timer:FlxTimer = null):Void
{
announceRuin();
new FlxTimer(6, ruinGravity);
new FlxTimer(16, undo);
}

private function ruinGravity(Timer:FlxTimer = null):Void
{
gravityWorking = false;

for (p in Reg.server.playermap.iterator())
{
p.acceleration.y = 50;
}
}

private function fixGravity(Timer:FlxTimer = null):Void
{
gravityWorking = true;

for (p in Reg.server.playermap.iterator())
{
p.acceleration.y = 440;
}
}

private function announceRuin():Void
{
msg = new NLabel(180, 100, 0xffffffff, 0, true);
msg.setLabel("Losing artificial gravity!");
new FlxTimer(6, deleteAnnounce);
}

private function undo(Timer:FlxTimer = null):Void
{
msg = new NLabel(140, 100, 0xffffffff, 0, true);
msg.setLabel("Reestablishing artificial gravity. Get to solid ground!");
new FlxTimer(6, fixGravity);
new FlxTimer(6, deleteAnnounce);
}

private function deleteAnnounce(T:FlxTimer):Void
{
msg.delete();
}
}
Loading

0 comments on commit eb296de

Please sign in to comment.