Skip to content

Commit

Permalink
added settings!
Browse files Browse the repository at this point in the history
  • Loading branch information
loglot committed Sep 7, 2024
1 parent fa690a0 commit 7b9909c
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 52 deletions.
64 changes: 43 additions & 21 deletions lib/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,51 @@ export class Draw {
this.Rect()

if (this.game.MainMenu) {
// if (this.game.player.currentSpeedOption == this.game.player.snailSpeedOption) {
// var speed_option_eng = "snail";
// } else if (this.game.player.currentSpeedOption == this.game.player.slowSpeedOption) {
// var speed_option_eng = "slow";
// } else if (this.game.player.currentSpeedOption == this.game.player.mediumSpeedOption) {
// var speed_option_eng = "medium"
// } else if (this.game.player.currentSpeedOption == this.game.player.fastSpeedOption) {
// var speed_option_eng = "fast"
// } else if (this.game.player.currentSpeedOption == this.game.player.unstableSpeedOption) {
// var speed_option_eng = "unstable"
// }
this.DrawStroked("Yet Another Collectathon", 250, 200)
this.DrawStroked("Press W To Start", 260, 350)
console.log("menu")

if(this.game.MenuState == "main"){

this.DrawStroked("Yet Another Collectathon", 250, 200)
this.DrawStroked("Press W To Start", 260, 350)
this.DrawStroked("Press S For Settings", 260, 450)

} else if(this.game.MenuState == "settings") {
if (this.game.SpeedSelect == this.game.player.snailSpeedOption) {
var speed_option_eng = "snail";
} else if (this.game.SpeedSelect == this.game.player.slowSpeedOption) {
var speed_option_eng = "slow";
} else if (this.game.SpeedSelect == this.game.player.mediumSpeedOption) {
var speed_option_eng = "medium"
} else if (this.game.SpeedSelect == this.game.player.fastSpeedOption) {
var speed_option_eng = "fast"
} else if (this.game.SpeedSelect == this.game.player.unstableSpeedOption) {
var speed_option_eng = "unstable"
}


this.DrawStroked(`New Style : ${this.game.Style}`, 260, 250)

this.DrawStroked(`Coin Collect Growth? : ${this.game.Grow}`, 260, 350)
this.DrawStroked("==> <==", 110, 250 + (100*this.game.SettingSelect))
this.DrawStroked(`Speed : ${speed_option_eng}`, 260, 450)


this.DrawStroked("S to go back to menu", 260, 750)
}
// this.DrawStroked(`growth on coin: ${this.game.player.GrowOnCoinOption ? "yes" : "no"} (press 1 to flip)`, 260, 500)
// this.DrawStroked(`speed : ${speed_option_eng} (press 2 to flip)`, 260, 600)
// this.DrawStroked(" ==> to move", 756, 767)
} else {
this.Circ(this.game.player.R, "#afbfaf", this.game.player.X, this.game.player.Y, true)
console.log(this.game.player.coins)
for(let i = 0; i < this.game.player.coins.length; i++){
this.Circ(this.game.player.coins[i].R, "yellow", this.game.player.coins[i].X, this.game.player.coins[i].Y, true)
}
if(this.game.Style){
this.Circ(this.game.player.R, "#afbfaf", this.game.player.X, this.game.player.Y, true, "#33363f")
for(let i = 0; i < this.game.player.coins.length; i++){
this.Circ(this.game.player.coins[i].R, "#dfdf8d", this.game.player.coins[i].X, this.game.player.coins[i].Y, true, "#33363f")
}
} else {
this.Circ(this.game.player.R, "#afbfaf", this.game.player.X, this.game.player.Y, true)
for(let i = 0; i < this.game.player.coins.length; i++){
this.Circ(this.game.player.coins[i].R, "yellow", this.game.player.coins[i].X, this.game.player.coins[i].Y, true)
}
}

this.DrawStroked(`${this.game.Collected}`, 50, 100)
}
Expand Down Expand Up @@ -71,14 +93,14 @@ export class Draw {
ctx.closePath();
}

Circ(radius, color, x, y, shadow) {
Circ(radius, color, x, y, shadow, OLColor = "black") {
let inline = radius - 5

//outline

ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI * 2, false);
ctx.fillStyle = "black";
ctx.fillStyle = OLColor;
ctx.fill();
ctx.closePath();

Expand Down
11 changes: 10 additions & 1 deletion lib/imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@ export class Game{
this.keyMan = new KeyManager(this)
this.player = new Player(this)
this.display = new Draw(this)

}

MainMenu = true
MenuState = "main"
SettingSelect = 0

Style = true
Grow = false
SpeedSelect = 2




MainMenu = true
Collected = 0

sleep(ms) {
Expand Down
51 changes: 23 additions & 28 deletions lib/player/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export class Player {
fastSpeedOption = 3
unstableSpeedOption =4

currentSpeedOption = 2
GrowOnCoinOption = false

snailSpeed = 1
slowSpeed = 5
Expand Down Expand Up @@ -62,13 +60,34 @@ export class Player {
for(let i = 0; i < this.coins.length; i++){
this.checkCoinCollision(i)
}

if (this.X < this.R + 20) {
this.X = this.R + 20
this.velX = 0
}

if (this.X > -this.R + 1656) {
this.X = -this.R + 1656
this.velX = 0
}

if (this.Y < this.R + 20) {
this.Y = this.R + 20
this.velY = 0
}

if (this.Y > -this.R + 898) {
this.Y = -this.R + 898
this.velY = 0
}
this.changeSpeedBasedOnOption()
}

checkCoinCollision(i) {
if (Math.hypot(this.X - this.coins[i].X, this.Y - this.coins[i].Y) <= this.R + this.coins[i].R) {
this.game.Collected++
this.coins.splice(i, 1)
if (this.GrowOnCoinOption) {
if (this.game.Grow) {
this.grow(10)
}
}
Expand All @@ -84,22 +103,6 @@ export class Player {
this.R = this.MaxR
}

if (this.X < this.R + 5) {
this.X = this.R + 5
}

if (this.X > -this.R + 1670) {
this.X = -this.R + 1670
}

if (this.Y < this.R + 8) {
this.Y = this.R + 8
}

if (this.Y > -this.R + 910) {
this.Y = -this.R + 910
}

}

}
Expand Down Expand Up @@ -160,18 +163,10 @@ export class Player {
}
}

cycleSpeedOption() {
this.currentSpeedOption++;

if (this.currentSpeedOption == this.unstableSpeedOption+1) {
this.currentSpeedOption = this.snailSpeedOption;
}

this.changeSpeedBasedOnOption();
}

changeSpeedBasedOnOption() {
switch (this.currentSpeedOption) {
switch (this.game.SpeedSelect) {
case this.snailSpeedOption:
this.currentSpeed = this.snailSpeed;
break;
Expand Down
42 changes: 40 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,49 @@ var game = new Game()
function gameLoop() {
game.keyMan.update()
game.display.Game()
game.player.update()
if(game.keyMan.wasKeyJustPressed("KeyW") && game.MainMenu){
if(!game.MainMenu){
game.player.update()
}
if(game.keyMan.wasKeyJustPressed("KeyW") && game.MainMenu && game.MenuState == "main"){
game.MainMenu = false
game.player.grow(70)
}else if(game.keyMan.wasKeyJustPressed("KeyS") && game.MainMenu && game.MenuState == "main"){
game.MenuState = "settings"
}else if(game.keyMan.wasKeyJustPressed("KeyS") && game.MainMenu && game.MenuState == "settings"){
game.MenuState = "main"
}else if(game.keyMan.wasKeyJustPressed("ArrowUp") && game.MainMenu && game.MenuState == "settings"){
game.SettingSelect -= 1
}else if(game.keyMan.wasKeyJustPressed("ArrowDown") && game.MainMenu && game.MenuState == "settings"){
game.SettingSelect += 1
}else if(game.keyMan.wasKeyJustPressed("ArrowLeft") && game.MainMenu && game.MenuState == "settings"){
if(game.SettingSelect == 0){
game.Style = !game.Style
}
if(game.SettingSelect == 1){
game.Grow = !game.Grow
}
if(game.SettingSelect == 2){
game.SpeedSelect--
if(game.SpeedSelect < 0){
game.SpeedSelect = 4
}
}
}else if(game.keyMan.wasKeyJustPressed("ArrowRight") && game.MainMenu && game.MenuState == "settings"){
if(game.SettingSelect == 0){
game.Style = !game.Style
}
if(game.SettingSelect == 1){
game.Grow = !game.Grow
}
if(game.SettingSelect == 2){
game.SpeedSelect++
if(game.SpeedSelect > 4){
game.SpeedSelect = 0
}
}

}
console.log(game.MenuState)
requestAnimationFrame(gameLoop)
}
requestAnimationFrame(gameLoop)
Expand Down

0 comments on commit 7b9909c

Please sign in to comment.