Skip to content

Commit

Permalink
Add scoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ybs1164 committed Jun 28, 2020
1 parent 7f6c53a commit ef8f700
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 19 deletions.
6 changes: 3 additions & 3 deletions dist/js/core.js

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions lib/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ type Score struct {
}

// Scoreboard is
type Scoreboard [11]Score
type Scoreboard [10]Score

// Scoreboard Push
func (sc *Scoreboard) Push(value Score) {
var index = 0
for ; value.Score < sc[index+1].Score && index < 9; index++ {
var index int = 0
for ; value.Score < sc[index].Score && index < 9; index++ {
}
for j := 9; j >= index; j-- {
if index == 9 {
return
}
for j := 8; j >= index; j-- {
sc[j+1] = sc[j]
}
sc[index] = value
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func scoreBoard(ticker time.Ticker) {
}
}

var sendData []byte = make([]byte, 5)
var sendData []byte = make([]byte, 1)

sendData[0] = 3

Expand Down
4 changes: 2 additions & 2 deletions src/js/data/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ export const Obj = function(id) {
let a = -((Math.cos(data.dir)*Math.cos(this.dir)) + (Math.sin(data.dir)*Math.sin(this.dir))-1) * Math.PI / 2;

if (ccw > 0) {
this.dir -= a * 0.8;
this.dir -= a * 0.5;
} else if (ccw < 0) {
this.dir += a * 0.8;
this.dir += a * 0.5;
}
} else {
this.dir = data.dir;
Expand Down
18 changes: 14 additions & 4 deletions src/js/data/ui/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ export default class DefaultUI {
this.my = my || "mid"; // "up" "mid" "down"
this.color = c;
this.childs = [];
this.isEnable = true;
}

addChild(obj) {
this.childs.push(obj);
return this;
}

setEnable(isEnable) {
this.isEnable = isEnable;
}

setPosition(x, y, w, h, z) {
let pos = {
sx: 0,
Expand Down Expand Up @@ -54,12 +59,14 @@ export default class DefaultUI {
}

draw(ctx, x, y, w, h, z) {
if (!this.isEnable) return;

let {sx, sy} = this.setPosition(x, y, w, h, z);

this.drawThis(ctx, sx, sy, z);

this.childs.forEach((o) => {
o.draw(ctx, sx, sy, this.w, this.h, z);
o.draw(ctx, sx, sy, this.w * z, this.h * z, z);
});
}
}
Expand All @@ -71,8 +78,8 @@ export class Bar extends DefaultUI {
}

drawThis(ctx, sx, sy, z) {
z *= 3;
drawBar(ctx, sx / z, sy / z + this.h / 2, this.h / 6, this.w / 3, z, 1, this.per, this.color);
if (!this.isEnable) return;
drawBar(ctx, sx / (z * 3), sy / (z * 3) + this.h / 6, this.h / 6, this.w / 3, z * 3, 1, this.per, this.color);
}
}

Expand All @@ -85,7 +92,8 @@ export class Text extends DefaultUI {
}

drawThis(ctx, sx, sy, z) {
drawText(ctx, sx / z, sy / z, z, 1, new RGB("#ffffff"), this.text, this.size, this.dir);
if (!this.isEnable) return;
drawText(ctx, sx / z, sy / z + this.h / 2, z, 1, new RGB("#ffffff"), this.text, this.size, this.dir);
}
}

Expand All @@ -103,6 +111,8 @@ export class List extends DefaultUI {
}

draw(ctx, x, y, w, h, z) {
if (!this.isEnable) return;

let {sx, sy} = this.setPosition(x, y, w, h, z);

this.childs.forEach((o) => {
Expand Down
49 changes: 44 additions & 5 deletions src/js/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ export default class System {

this.gameui = new UISystem(); // set gameUI

let scoreboardui = [];

this.scoreboardui = [];
for (let i = 0; i < 10; i ++) {
scoreboardui.push(new ui.Bar(0, 0, 166, 35, "left", "up", new RGB("#00F46C")).setPer(1));
this.scoreboardui.push(new ui.Bar(0, 0, 166, 35, "left", "up", new RGB("#00F46C")).setPer(1).addChild(new ui.Text(0, 0, 0, 28, "mid", "down", new RGB("#000000"))));
}

this.gameui.addUI(new ui.Text(0, 0, 0, 50, "mid", "down", new RGB("#000000")).setText("Test",20));
this.gameui.addUI(new ui.List(-25, 2, 166, 500, "right", "up").setList(scoreboardui).setPadding(-15));
this.gameui.addUI(new ui.Text(0, 0, 0, 50, "mid", "down", new RGB("#000000")).setText("Test", 20));
this.gameui.addUI(new ui.List(-25, 2, 166, 500, "right", "up").setList(this.scoreboardui).setPadding(-15));

this.textinputcontainer = document.getElementById("textInputContainer"); // name input
this.textinput = document.getElementById("textInput");
Expand Down Expand Up @@ -307,7 +308,6 @@ export default class System {
i++;

let u = new Uint8Array(msg.data.slice(i,i+len))

obj.team = String.fromCharCode.apply(null, u);
i+=len;

Expand All @@ -317,6 +317,7 @@ export default class System {
u = new Uint8Array(msg.data.slice(i,i+len));
obj.type = new TextDecoder().decode(u);
i += len;

len = view.getUint8(i);
i++;

Expand Down Expand Up @@ -360,6 +361,44 @@ export default class System {
return;
}
case 3: { // scoreboard
let i = 1;
let j = 0;

let maxScore = view.getUint32(i);

while (i < msg.data.byteLength) {

let score = view.getUint32(i);
this.scoreboardui[j].setEnable(true);
this.scoreboardui[j].setPer(score / maxScore);
i+=4;

let len = view.getUint8(i);
i++;

let u = new Uint8Array(msg.data.slice(i,i+len))
//let team = String.fromCharCode.apply(null, u);
i+=len;

len = view.getUint8(i);
i++;

u = new Uint8Array(msg.data.slice(i,i+len));
let type = new TextDecoder().decode(u);
if (!type) this.scoreboardui[j].setEnable(false);
i += len;

len = view.getUint8(i);
i++;

u = new Uint8Array(msg.data.slice(i,i+len));
let name = new TextDecoder().decode(u);
i += len;

this.scoreboardui[j].childs[0].setText(name + "-" + score, 13);

j++;
}

return;
}
Expand Down

0 comments on commit ef8f700

Please sign in to comment.