Skip to content

Commit 6a6e757

Browse files
committed
added a score also you can die now. score is technically saved but not shown yet
1 parent 7b345fc commit 6a6e757

5 files changed

Lines changed: 60 additions & 2 deletions

File tree

UI/Button.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ class UIButton extends UIElement
44
bgcolor="#FF9000";
55
constructor(rekt)
66
{
7-
super();
8-
this.hitbox= new Rectangle(rekt.x,rekt.y,rekt.width,rekt.height);
7+
super(rekt);
98

109
}
1110
draw(ctx)

UI/DisplayLabel.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class DisplayLabel extends UIElement
2+
{
3+
text = "";
4+
constructor(rekt,text)
5+
{
6+
super(rekt);
7+
this.text=text;
8+
}
9+
draw(ctx)
10+
{
11+
super.draw(ctx);
12+
UIRenderer.drawScreenBox(ctx,this.hitbox.x, this.hitbox.y,this.hitbox.width,this.hitbox.height, this.text);
13+
}
14+
click()
15+
{
16+
17+
}
18+
}

UI/Renderer.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,30 @@ class UIRenderer
116116
ctx.stroke();
117117

118118
}
119+
120+
static drawScreenBox(ctx,x,y,w,h,text)
121+
{
122+
let main = "16 16 16";
123+
let outline = "40 40 40";
124+
let outline2 ="128 128 128";
125+
let fontcolour ="0 192 16";
126+
ctx.beginPath();
127+
ctx.roundRect(x+0.5,y+0.5,w,h,7);
128+
ctx.fillStyle=this.rgb(main);
129+
ctx.fill();
130+
ctx.strokeStyle=this.rgb(outline);
131+
ctx.lineWidth=9;
132+
ctx.stroke();
133+
ctx.strokeStyle=this.rgb(outline2);
134+
ctx.lineWidth=5;
135+
ctx.stroke();
136+
ctx.font = "small-caps bold 42px monospace";
137+
ctx.textAlign="center";
138+
ctx.textBaseline="middle";
139+
//ctx.strokeStyle=this.rgb(outline);
140+
ctx.fillStyle=this.rgb(fontcolour);
141+
ctx.fillText(text,x+w/2,y+h/2);
142+
}
119143
static drawButton(ctx,x,y,w,h,text)
120144
{
121145
let main ="255 64 0";

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<script src="UI/UIElement.js"></script>
1212
<script src="UI/Button.js"></script>
1313
<script src="UI/AbilitySlot.js"></script>
14+
<script src="UI/DisplayLabel.js"></script>
1415
<script src="GameObject.js"></script>
1516
<script src="Animation.js"></script>
1617
<script src="gameObjects/Ability.js"></script>

scenes/Dash.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class GameSceneDash extends GameScene
77
normalSpeedSpot = 100;
88
movingship = false;
99
uimgr;
10+
scoredisplay;
11+
score=0;
1012
constructor()
1113
{
1214
super();
@@ -30,6 +32,9 @@ class GameSceneDash extends GameScene
3032
this.player.abilities.push(lazor);
3133
const bt = new AbilitySlot(new Rectangle(10,this.longSide-100,70,72),lazor);
3234
this.uimgr.components.push(bt);
35+
const scoredspl= new DisplayLabel(new Rectangle(this.shortSide-220,10,170,45),"000000");
36+
this.scoredisplay=scoredspl;
37+
this.uimgr.components.push(scoredspl);
3338
}
3439
addObject(obj)
3540
{
@@ -114,6 +119,15 @@ class GameSceneDash extends GameScene
114119
});
115120
});
116121
this.doSpeedStuff(dT);
122+
this.scoredisplay.text= String(this.score).padStart(6,'0');
123+
124+
baddies.forEach((enemy)=>{
125+
if(enemy.hitbox.testRect(this.player.hitbox))
126+
{
127+
localStorage.setItem("bestScore", this.score);
128+
window.gameManager.currentScene = new GameSceneDash();
129+
}
130+
});
117131
//console.log(living.length);
118132
//console.log(living);
119133
//this.gameObjects=living;
@@ -140,6 +154,8 @@ class GameSceneDash extends GameScene
140154
enemy.targetX=this.player.x;
141155
enemy.targetY=this.player.y;
142156
this.addObject(enemy);
157+
enemy.onDeath=()=>{
158+
this.score++;};
143159
//console.log(enemy);
144160
}
145161
}

0 commit comments

Comments
 (0)