Skip to content

Commit

Permalink
added counter for coins
Browse files Browse the repository at this point in the history
  • Loading branch information
loglot committed Aug 19, 2023
1 parent c90b4f2 commit 3147fa3
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions collectathon.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
var coin = 0
var collection = 0
var menu = 1
var growth_c = "yes"

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

draw_game()

document.addEventListener('keypress', (event) => {
var name = event.key;
var code = event.code;
key_man(name)
}, false);
key_man(code)
}, false);

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// library
Expand Down Expand Up @@ -144,31 +144,41 @@

function key_man(name) {
if (menu == 1) {
if (name == " ") {
if (name == "Space") {
menu++
spawn_coin(3000)
draw_game()
grow_circ(start)
}

if (name == "KeyT") {
if (growth_c == "yes") {
growth_c = "no"
} else {
growth_c = "yes"
}
draw_game()
}
}else{
// if (name == "-") (
// shrink_circ(20)
// )
// if (name == "=" || name == "+") {
// grow_circ(20)
// }
if (name == "w" || name == "ArrowUp") {
move_circ(0, -20)
if (name == "KeyW") {
move_circ(0, -20)
}
if (name == "s") {
if (name == "KeyS") {
move_circ(0, 20)
}
if (name == "a") {
move_circ(-20, 0)
}
if (name == "d") {
if (name == "KeyA") {
move_circ(-20, 0)
}
if (name == "KeyD") {
move_circ(20, 0)
}
}

}
};

Expand Down Expand Up @@ -208,14 +218,16 @@
ctx.font = '80px Sans-serif';
ctx.strokeStyle = 'black';
ctx.lineWidth = 8;
ctx.lineJoin="miter";
ctx.miterLimit=2;
ctx.strokeText(text, x, y);
ctx.fillStyle = 'white';
ctx.fillText(text, x, y);
}


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//circle drawing
//frame drawing
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function draw_game() {
Expand All @@ -224,21 +236,24 @@

draw_rect()


if (menu == 1) {
drawStroked("yet another collectathon", 250, 200)
drawStroked("press space to start", 260, 500)
drawStroked(`growth on coin: ${growth_c} (press t to flip)`, 260, 600)
} else{
coin_check()
draw_circ(r, "#afbfaf", x, y)
if (coin == 1) {
// console.log (coin)
draw_circ(coin_r, "yellow", coin_x, coin_y)
}
coin_check()
draw_circ(r, "#afbfaf", x, y)
if (coin == 1) {
// console.log (coin)
draw_circ(coin_r, "yellow", coin_x, coin_y)

}
drawStroked(`${collection}`, 50, 100)
}
}


function draw_circ(radius, color, x, y, shadow) {
inline = radius - 5

Expand Down

0 comments on commit 3147fa3

Please sign in to comment.