added speed upgrade
This commit is contained in:
@@ -4,15 +4,18 @@ let alive = true;
|
||||
let snakeDirection = 0;
|
||||
let AItype = "random";
|
||||
let gridSize = 20;
|
||||
let gridColumns = 20;
|
||||
let gridRows = 20;
|
||||
let gridColumns = 10;
|
||||
let gridRows = 10;
|
||||
let eatenApples = 0;
|
||||
let _textSize = 32;
|
||||
let appleAmount = 1;
|
||||
let gameSpeed = 10;
|
||||
let buttonAddColoums = null;
|
||||
let buttonAddRows = null;
|
||||
let buttonUpgradeAI = null;
|
||||
let buttonAddMoreApples = null;
|
||||
let buttonSpeedUpgrade = null;
|
||||
let SpeedUpgradePrice = 5;
|
||||
let AddMoreApplesPrice = 1;
|
||||
let AddColoumsPrice = 1;
|
||||
let AddRowsPrice = 1;
|
||||
@@ -23,6 +26,7 @@ function setup() {
|
||||
buttonAddRows = createButton("Add rows");
|
||||
buttonUpgradeAI = createButton("Upgrade AI");
|
||||
buttonAddMoreApples = createButton("Add more apples");
|
||||
buttonSpeedUpgrade = createButton("Increase speed");
|
||||
createCanvas(windowWidth, windowHeight);
|
||||
background(255, 255, 255);
|
||||
for (let i = 0; i < gridColumns; i++) {
|
||||
@@ -35,10 +39,28 @@ function setup() {
|
||||
buttonAddRows.mousePressed(buttonAddRowsPressed);
|
||||
buttonUpgradeAI.mousePressed(buttonUpgradeAIPressed);
|
||||
buttonAddMoreApples.mousePressed(buttonAddMoreApplesPressed);
|
||||
buttonSpeedUpgrade.mousePressed(buttonSpeedUpgradePressed);
|
||||
frameRate(gameSpeed);
|
||||
summonSnake();
|
||||
summonApple();
|
||||
drawGrid();
|
||||
}
|
||||
|
||||
function buttonSpeedUpgradePressed(){
|
||||
|
||||
if (eatenApples < SpeedUpgradePrice) {
|
||||
return;
|
||||
}
|
||||
|
||||
eatenApples -= SpeedUpgradePrice;
|
||||
|
||||
gameSpeed += 2;
|
||||
|
||||
frameRate(gameSpeed);
|
||||
|
||||
SpeedUpgradePrice += 5;
|
||||
}
|
||||
|
||||
function buttonAddColoumsPressed(){
|
||||
if (eatenApples < AddColoumsPrice) {
|
||||
return;
|
||||
@@ -78,8 +100,8 @@ function buttonAddMoreApplesPressed(){
|
||||
}
|
||||
|
||||
function summonApple(){
|
||||
let x = grid.length - floor(random(1, grid.length));
|
||||
let y = grid[0].length - floor(random(1, grid[0].length));
|
||||
let x = grid.length - floor(random(1, grid.length +1));
|
||||
let y = grid[0].length - floor(random(1, grid[0].length +1));
|
||||
if(grid[x][y] == 2 || grid[x][y] == 1){
|
||||
summonApple();//best practice coding right here
|
||||
return;
|
||||
@@ -215,13 +237,13 @@ function drawGrid() {
|
||||
}
|
||||
|
||||
function draw() {
|
||||
background(255);
|
||||
|
||||
if (alive == false){
|
||||
restartGame();
|
||||
return;
|
||||
}
|
||||
|
||||
background(255);
|
||||
|
||||
runSnake();
|
||||
drawGrid();
|
||||
|
||||
@@ -229,6 +251,7 @@ function draw() {
|
||||
textSize(_textSize);
|
||||
|
||||
text("₴ " + eatenApples, gridColumns * gridSize + gridSize + _textSize*3, _textSize * 1);
|
||||
|
||||
text("Apples: " + appleAmount, gridColumns * gridSize + gridSize, _textSize * 2);
|
||||
|
||||
buttonAddMoreApples.html("Add more apples ₴ " + AddMoreApplesPrice);
|
||||
@@ -248,6 +271,11 @@ function draw() {
|
||||
|
||||
buttonAddRows.html("Add rows ₴ " + AddRowsPrice);
|
||||
buttonAddRows.position(gridColumns * gridSize + gridSize + _textSize*6, _textSize * 4.5);
|
||||
|
||||
text("Speed: " + gameSpeed, gridColumns * gridSize + gridSize, _textSize * 6);
|
||||
|
||||
buttonSpeedUpgrade.html("Increase speed ₴ " + SpeedUpgradePrice);
|
||||
buttonSpeedUpgrade.position(gridColumns * gridSize + gridSize + _textSize*6, _textSize * 5.5);
|
||||
}
|
||||
|
||||
function mousePressed() {
|
||||
|
||||
Reference in New Issue
Block a user