• Home
  • Jobs
  • Courses
  • Questions
  • Teachers
  • For business
  • ES/EN

0

40
Views
How can I make different levels for a game? Would I have to make different classes?

I already have a sketch.js file with some gameStates.

var gameState = "wait";

I added conditional statements such as:

 if(gameState == "wait"){
    background(backgroundImg);
  textSize(50);
  fill("blue");
  text("Project42 Own",250,400);
  startButton.visible = true;
  gun.visible = false;
  backBoard.visible = false;
  }

Below is the code that has level 1, wait, play and end gameState:

function draw() {
  if(gameState == "wait"){
    background(backgroundImg);
  textSize(50);
  fill("blue");
  text("Project42 Own",250,400);
  startButton.visible = true;
  gun.visible = false;
  backBoard.visible = false;
  }
  if(mousePressedOver(startButton)&& gameState == "wait"){
    gunSound.play();
    gunSound.setVolume(0)
    gameState = "play";
  }
  if(gameState == "play"){
    background("#BDA297")
    fill("red");
    textSize(30);
  text("Score:" + score + " ",300,100);
  fill("green");
  text("Life:" + life + " ",800,100)
  gun.y=mouseY  
  startButton.visible = false;
  gun.visible = true;
  backBoard.visible = true;
 
 if(keyDown("SHIFT")){
   shootBullets();
 }
 if (frameCount % 80 === 0) {
  drawBlueBubble();
}

if (frameCount % 100 === 0) {
  drawRedBubble();
}

if(blueBubbleGroup.collide(bulletGroup)){
  handleBubbleCollision(blueBubbleGroup);
  score +=5;
}

if(redBubbleGroup.collide(bulletGroup)){
  handleBubbleCollision(redBubbleGroup);
  score += 10;
}
if (blueBubbleGroup.collide(backBoard)){
  handleGameover(blueBubbleGroup);
}

if (redBubbleGroup.collide(backBoard)) {
  handleGameover(redBubbleGroup);
}
  }
  if (life == 0) {
  gameState == "end"
}
if(gameState == "end"){
  background(gameOverImg)
  redBubbleGroup.hideEverything()
  blueBubbleGroup.hideEverything();
}
  drawSprites();
}

However, I now want to make level 2 in which there will be more obstacles. Also, I'm not a professional coder so please be clear in your answer.

about 1 month ago ·

Juan Pablo Isaza

Answer question
Find remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.