From 7b9909cf7677c104804b8e0977f754de08e8caad Mon Sep 17 00:00:00 2001 From: LogLot Date: Fri, 6 Sep 2024 21:48:03 -0500 Subject: [PATCH] added settings! --- lib/display/display.js | 64 ++++++++++++++++++++++++++++-------------- lib/imports.js | 11 +++++++- lib/player/player.js | 51 +++++++++++++++------------------ main.js | 42 +++++++++++++++++++++++++-- 4 files changed, 116 insertions(+), 52 deletions(-) diff --git a/lib/display/display.js b/lib/display/display.js index 2392d19..da09649 100644 --- a/lib/display/display.js +++ b/lib/display/display.js @@ -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) } @@ -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(); diff --git a/lib/imports.js b/lib/imports.js index c307509..1f8eacb 100644 --- a/lib/imports.js +++ b/lib/imports.js @@ -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) { diff --git a/lib/player/player.js b/lib/player/player.js index 88ddd39..fe95ba1 100644 --- a/lib/player/player.js +++ b/lib/player/player.js @@ -25,8 +25,6 @@ export class Player { fastSpeedOption = 3 unstableSpeedOption =4 - currentSpeedOption = 2 - GrowOnCoinOption = false snailSpeed = 1 slowSpeed = 5 @@ -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) } } @@ -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 - } - } } @@ -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; diff --git a/main.js b/main.js index d2860b2..3f18fbe 100644 --- a/main.js +++ b/main.js @@ -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)