Skip to content

Commit

Permalink
Scoreboard now is ordered and fixed scoreboard rendering bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Ohmnivore committed Jun 8, 2014
1 parent bb830a0 commit 131d40a
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 79 deletions.
Binary file modified Client/export/windows/cpp/bin/SkullRush.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion Client/export/windows/cpp/bin/config.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=0.2.2
version=0.2.3
name=Ohmnivore
team=1
ip=
Expand Down
5 changes: 3 additions & 2 deletions Client/source/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,12 @@ class PlayState extends FlxState
{
for (i in NReg.HUDS.keys())
{
trace("Delete ", i);
//trace("Delete ", i);
var h:FlxText = NReg.HUDS.get(i);
hud.remove(h, true);
//h.kill();
NReg.HUDS.remove(i);
if (NReg.HUDS.exists(i))
NReg.HUDS.remove(i);
//h.destroy();
}
for (k in NReg.sprites.keys())
Expand Down
1 change: 0 additions & 1 deletion Client/source/Player.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Player extends PlayerBase
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
Expand Down
4 changes: 2 additions & 2 deletions Client/source/SkullClient.hx
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ class SkullClient extends Client
p.setGun(1);
}

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

Expand Down
4 changes: 2 additions & 2 deletions Client/source/WeaponBar.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ 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);
super(X, 0, FlxBar.FILL_TOP_TO_BOTTOM, 10, Height, null, "", 0, 2000, true);

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

centerY();
}
Expand Down
4 changes: 2 additions & 2 deletions Client/source/WeaponHUD.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import flixel.util.FlxSpriteUtil;
*/
class WeaponHUD extends FlxSpriteGroup
{
static public inline var PADDING:Int = 3;
static public inline var PADDING:Int = 2;

private var icons:Map<Int, FlxSprite>;
private var hiders:Map<Int, FlxSprite>;
Expand Down Expand Up @@ -61,7 +61,7 @@ class WeaponHUD extends FlxSpriteGroup
icons.set(Slot, icon);
hiders.set(Slot, hider);

background.makeGraphic(Std.int(width), Std.int(height - PADDING), 0x99000000);
background.makeGraphic(Std.int(width), Std.int(height - PADDING * 2), 0x99000000);
FlxSpriteUtil.screenCenter(this, false, true);
}

Expand Down
23 changes: 15 additions & 8 deletions Client/source/networkobj/NScoreboard.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ class NScoreboard
public var group:FlxSpriteGroup;
private var t_group:FlxSpriteGroup;
private var texts:Map<Int, Dynamic>;
public var sortBy:Int;

public var back:FlxSprite;
public var ID:Int;

public function new(id:Int, Title:String, Headers:Array<String>, Color:Int = 0xff000000)
public function new(id:Int, Title:String, Headers:Array<String>,
SortBy:Int = 0, Color:Int = 0xffffffff)
{
title = Title;
headers = Headers;
//headers.unshift("Player");
color = Color;
sortBy = SortBy;

scores = new Map<Int, Dynamic>();
texts = new Map<Int, Dynamic>();
Expand Down Expand Up @@ -124,12 +127,12 @@ class NScoreboard
{
var arr:Array<Dynamic> = cast Unserializer.run(S);

//for (t in t_group.members)
//{
//t_group.remove(t, true);
//t.kill();
for (t in t_group.members)
{
t_group.remove(t, true);
t.kill();
//t.destroy();
//}
}

Y = X_BORDER + 2 * Y_SPACING;

Expand Down Expand Up @@ -176,13 +179,17 @@ class NScoreboard
X = X_BORDER;
Y = X_BORDER;

group.add(new FlxText(X, Y, FlxG.width, title));
var tt:FlxText = new FlxText(X, Y, FlxG.width, title);
tt.setBorderStyle(FlxText.BORDER_OUTLINE, 0xff000000);
group.add(tt);

Y += Y_SPACING;

for (h in headers)
{
group.add(new FlxText(X, Y, FlxG.width, Std.string(h)));
var ht:FlxText = new FlxText(X, Y, FlxG.width, Std.string(h));
ht.setBorderStyle(FlxText.BORDER_OUTLINE, 0xff000000);
group.add(ht);
X += X_SPACING;
}

Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ At the moment the source code is a mess. I'll take a couple of weeks to clean al
# TODO:

## Engine:
* Order scoreboard by score
* Plugins
* Spectate
* Interactive events:
Expand All @@ -49,13 +48,12 @@ At the moment the source code is a mess. I'll take a couple of weeks to clean al

## Gameplay:
* New maps
* footstool jumping
* rework splasher
* custom tiles


## Bugs:
* Fix annoying LAN server discovery bug
* Fix client-side crashes on map change


## Assets:
Expand Down
Binary file modified Server/export/windows/cpp/bin/SkullRushServer.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions Server/export/windows/cpp/bin/config.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=0.2.2
version=0.2.3

############################

Expand All @@ -9,7 +9,7 @@ crashdump=true
manifesturl=null
#https://dl.dropboxusercontent.com/u/229424261/skullrush/manifest.json

maps=CrateWorld, CaptureHell, TwinCapture, Test
maps=Test, CrateWorld, CaptureHell, TwinCapture

masterserver=http://skullrush.elementfx.com/laravel/public/

Expand Down
4 changes: 2 additions & 2 deletions Server/source/InitState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class InitState extends FlxState

//Make trace also write to flixel's debugger's log
old_trace = Log.trace;
Log.trace = new_trace;
//Log.trace = new_trace;

//Setup networking
Reg.maps = Reg.parseMaps();
Expand All @@ -87,7 +87,7 @@ class InitState extends FlxState

private static function new_trace(v:Dynamic, ?inf:haxe.PosInfos)
{
old_trace(v);
old_trace(v, inf);
FlxG.log.add(v);
}

Expand Down
35 changes: 27 additions & 8 deletions Server/source/gamemodes/DefaultHooks.hx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class DefaultHooks
static public function playerCollide(P:Player, P2:Player):Void
{
var iskill:Bool = false;
var isjump:Bool = false;
var winner:Player = P;
var loser:Player = P2;

Expand All @@ -135,13 +136,19 @@ class DefaultHooks
winner = P;
loser = P2;

//P2.health = 0;

//announceSquish(winner, loser);

iskill = true;
}
}
else
{
if (P.y < P2.y)
{
winner = P;
loser = P2;

isjump = true;
}
}

if (P2.dashing_down)
{
Expand All @@ -150,13 +157,19 @@ class DefaultHooks
winner = P2;
loser = P;

//P.health = 0;

//announceSquish(winner, loser);

iskill = true;
}
}
else
{
if (P2.y < P.y)
{
winner = P2;
loser = P;

isjump = true;
}
}

if (iskill)
{
Expand All @@ -175,6 +188,12 @@ class DefaultHooks

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

if (isjump)
{
winner.velocity.y -= 280;
loser.velocity.y += 100;
}
}

public static function handleDamage(info:HurtInfo, useTeams:Bool = false):Void
Expand Down
62 changes: 59 additions & 3 deletions Server/source/networkobj/NScoreboard.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import flixel.group.FlxSpriteGroup;
import flixel.text.FlxText;
import flixel.util.FlxSpriteUtil;
import gamemodes.BaseGamemode;
import haxe.ds.ArraySort;
import haxe.Serializer;

/**
Expand All @@ -31,18 +32,21 @@ class NScoreboard
public var group:FlxSpriteGroup;
private var texts:Map<Int, Dynamic>;

public var sortBy:Int;

public var back:FlxSprite;

public var ID:Int;

public function new(Title:String, Headers:Array<String>, DefaultHeaders:Array<String>,
Color:Int = 0xff000000)
SortBy:Int = 0, Color:Int = 0xffffffff)
{
title = Title;
headers = Headers;
headers.unshift("Player");
default_headers = DefaultHeaders;
color = Color;
sortBy = SortBy;

scores = new Map<Int, Dynamic>();
texts = new Map<Int, Dynamic>();
Expand Down Expand Up @@ -106,6 +110,7 @@ class NScoreboard
{
var arr:Array<FlxText> = cast texts.get(P.ID);
var i:Int = 0;
var old_check:Float = Std.parseFloat(arr[sortBy + 2].text);
for (t in arr)
{
if (i > 0)
Expand All @@ -115,6 +120,36 @@ class NScoreboard
}
i++;
}
var new_check:Float = Std.parseFloat(arr[sortBy + 2].text);
if (new_check > old_check)
{
for (ID in texts.keys())
{
if (ID != P.ID)
{
var arr2:Array<FlxText> = cast texts.get(ID);
if (Std.parseFloat(arr[sortBy + 2].text) > Std.parseFloat(arr2[sortBy + 2].text))
{
var oldpos:Float = arr[0].y;
var newpos:Float = arr2[0].y;

if (newpos < oldpos)
{
for (t1 in arr)
{
t1.y = newpos;
t1.update();
}
for (t2 in arr2)
{
t2.y = oldpos;
t2.update();
}
}
}
}
}
}
}

public function removePlayer(P:Player):Void
Expand Down Expand Up @@ -178,9 +213,26 @@ class NScoreboard
arr.push(arr2);
}

arr.sort(compareDatas);
arr.reverse();

return Serializer.run(arr);
}

private function compareDatas(T1:Array<String>, T2:Array<String>):Int
{
var toCompare1:Float = Std.parseFloat(T1[sortBy + 2]);
var toCompare2:Float = Std.parseFloat(T2[sortBy + 2]);

if (toCompare1 == toCompare2)
return 0;
if (toCompare1 > toCompare2)
return 1;
if (toCompare1 < toCompare2)
return -1;
return 0;
}

public function destroy():Void
{
BaseGamemode.scores.removeBoard(this);
Expand All @@ -203,13 +255,17 @@ class NScoreboard
X = X_BORDER;
Y = X_BORDER;

group.add(new FlxText(X, Y, FlxG.width, title));
var tt:FlxText = new FlxText(X, Y, FlxG.width, title);
tt.setBorderStyle(FlxText.BORDER_OUTLINE, 0xff000000);
group.add(tt);

Y += Y_SPACING;

for (h in headers)
{
group.add(new FlxText(X, Y, FlxG.width, Std.string(h)));
var ht:FlxText = new FlxText(X, Y, FlxG.width, Std.string(h));
ht.setBorderStyle(FlxText.BORDER_OUTLINE, 0xff000000);
group.add(ht);
X += X_SPACING;
}

Expand Down
Loading

0 comments on commit 131d40a

Please sign in to comment.