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