Skip to content

Commit

Permalink
Finished weapon HUD
Browse files Browse the repository at this point in the history
  • Loading branch information
Ohmnivore committed Jun 8, 2014
1 parent f5ef500 commit bb830a0
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 6 deletions.
Binary file modified Client/export/windows/cpp/bin/SkullRush.exe
Binary file not shown.
5 changes: 4 additions & 1 deletion Client/source/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class PlayState extends FlxState
public var m:Mutex;

public var wepHUD:WeaponHUD;
public var wepBar:WeaponBar;

/**
* Function that is called up when to state is created to set it up.
Expand Down Expand Up @@ -123,7 +124,9 @@ class PlayState extends FlxState
}

wepHUD = new WeaponHUD(2);
add(wepHUD);
hud.add(wepHUD);
//wepBar = new WeaponBar(2);
//hud.add(wepBar);

Assets.initAssets();
Thread.create(thread);
Expand Down
13 changes: 11 additions & 2 deletions Client/source/Player.hx
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package ;
import flixel.util.FlxSpriteUtil;
import ext.FlxWeaponExt;
import flixel.util.FlxTimer;

/**
* ...
* @author Ohmnivore
*/
class Player extends PlayerBase
{
//public var requestShoot:Bool = false;

public function new(Id:Int, Name:String, X:Int, Y:Int)
{
super(Id, Name, X, Y);
setGun(1);
}

override public function fire():Void
{
super.fire();

var reload:FlxTimer = new FlxTimer(last_shot.mock_fireRate / 1000);
Reg.state.wepBar.setRange(0, 1);
Reg.state.wepBar.setParent(reload, "progress", false);
trace(last_shot.mock_fireRate);
}

override public function setGun(GunID:Int, Force:Bool = false):Void
{
if (Std.is(GunID, Int))
Expand Down
5 changes: 5 additions & 0 deletions Client/source/SkullClient.hx
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,11 @@ class SkullClient extends Client
NWeapon.setUpWeapons(p);
p.setGun(1);
}

Reg.state.wepBar = new WeaponBar(0, Std.int(Reg.state.wepHUD.height - WeaponHUD.PADDING));
Reg.state.hud.add(Reg.state.wepBar);
Reg.state.wepBar.y = Reg.state.wepHUD.y - 1;
Reg.state.wepBar.x = Reg.state.wepHUD.x + Reg.state.wepHUD.width;
}

if (MsgID == Msg.GrantGun.ID)
Expand Down
27 changes: 27 additions & 0 deletions Client/source/WeaponBar.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ;
import flixel.ui.FlxBar;
import flixel.util.FlxSpriteUtil;

/**
* ...
* @author Ohmnivore
*/
class WeaponBar extends FlxBar
{

public function new(X:Float = 0, Height:Int = 100)
{
super(X, 0, FlxBar.FILL_VERTICAL_INSIDE_OUT, 10, Height, null, "", 0, 2000, true);

scrollFactor.set();
createFilledBar(0xff005100, 0xff00F400, true, 0xff000000);

centerY();
}

public function centerY():Void
{
FlxSpriteUtil.screenCenter(this, false, true);
}

}
4 changes: 2 additions & 2 deletions Client/source/WeaponHUD.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import flixel.FlxSprite;
import flixel.group.FlxGroup;
import flixel.group.FlxSpriteGroup;
import flixel.text.FlxText;
import flixel.ui.FlxBar;
import flixel.util.FlxSpriteUtil;

/**
Expand All @@ -19,7 +20,7 @@ class WeaponHUD extends FlxSpriteGroup

private var selector:FlxSprite;

public function new(X:Float)
public function new(X:Float = 0)
{
super(X, 0);
scrollFactor.set();
Expand Down Expand Up @@ -61,7 +62,6 @@ class WeaponHUD extends FlxSpriteGroup
hiders.set(Slot, hider);

background.makeGraphic(Std.int(width), Std.int(height - PADDING), 0x99000000);

FlxSpriteUtil.screenCenter(this, false, true);
}

Expand Down
4 changes: 3 additions & 1 deletion Client/source/networkobj/NWeapon.hx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class NWeapon
public var shotsToFire:Int = 1;
public var spread:Int = 0;
public var ignoreCollisions:Bool = false;
public var mock_fireRate:Int = 0;

public var TRAIL_EMITTER:Int;
public var TRAIL_EMITTER_GRAPHIC:String;
Expand All @@ -46,7 +47,7 @@ class NWeapon
bulletLifeSpan = Arr[1];
bulletSpeed = Arr[2];
fireRate = Std.int(Arr[3] / 2);
//trace(fireRate);
mock_fireRate = Arr[3];
name = Arr[4];
bulletGraphic = Arr[5];
gunGraphic = Arr[6];
Expand Down Expand Up @@ -109,6 +110,7 @@ class NWeapon
w.shotsToFire = shotsToFire;
w.spread = spread;
w.setFireRate(fireRate);
w.mock_fireRate = mock_fireRate;

w.makeImageBullet(10, Assets.images.get(bulletGraphic),
Std.int(bulletOffset.x), Std.int(bulletOffset.y), false, 180);
Expand Down
2 changes: 2 additions & 0 deletions Shared/code/ext/FlxWeaponExt.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class FlxWeaponExt extends FlxWeapon

public var inheritance:FlxPoint;

public var mock_fireRate:Int;

public function new(Name:String, ?ParentRef:FlxSprite, ?BulletType:Class<FlxBullet>, ?BulletID:Int = 0)
{
super(Name, ParentRef, BulletType, BulletID);
Expand Down

0 comments on commit bb830a0

Please sign in to comment.