Help With My New Game

Hello. I’m am extremely new to coding in general. I do not know anything about libraries and functions or any of that vocabulary of coding because I started about one month ago and I taught myself to code using Youtube videos. I’m making a game that has a rectangle (which represents your character) and a bunch of small balls (which are toxic and you want to avoid them). I’m having trouble with many things. For instance, I want to make it so that if your character goes off the border of your canvas, you die, or if you get hit with a toxic ball you also die (I want to make more than one ball btw and I don’t know how to make multiple balls quicker than making like 20 ellipses). I also want to make a starting page where you have the “instructions button” and the “play button”. Thanks, and here is my code (which has a lot of errors and unnecessary floats and integers).

int youX = 400;
int youY = 300;
int OX = 405;
int OY = 25;

int OX2 = 350;
int OY2 = 375;

int xSpeed = 5;
int ySpeed = 5;
void setup() {
  size(800, 600);
 
}

void draw() {
  background(0);
  rect(youX, youY, 25, 25);
  if (youX > width || youX < 0) {
    background(0);
    text("GAMEOVER :( the ball got ya! (please restart)", 100, 100);
    textSize(25);
    
    
    if(youX > height || youX < 0) {
       background(0);
    text("GAMEOVER :( the ball got ya!", 100, 100);
    textSize(25);
    }
  }
  
  if(keyPressed == true && key == 'w') {
    youY = youY - 6;
  }
    
  if(keyPressed == true && key == 's') {
    youY = youY + 6;
  }
  
  if(keyPressed == true && key == 'a') {
    youX = youX - 6;
  }
  
  if(keyPressed == true && key == 'd') {
    youX = youX + 6;
    
  }
  
   ellipse(OX, OY, 20, 20);
   OY = OY + ySpeed;
   if(OY > height || OY < 0) {
     ySpeed = ySpeed * -1;
   }
   
   OX = OX + xSpeed;
   if(OX > width || OX < 0) {
     xSpeed = xSpeed * -1;
   }
   
}

Divide and conquer. You have many tasks. Just focus in one at the time. For a better learning experience, build small sketches that demonstrates the concept before you merge them into your game.

First do the different windows: Start/intro, running your game, end/final/conclusion. For this, check previous posts working with a concept called states.

Second, work with your player. Can you move it inside the sketch? Can it detect when it reaces the border?

Third, generate a random number of toxic balls

Fourth, design your code so the player can interact with the toxic balls.

You can always start by exploring the examples in the Processing foundation’s webpage. They are self contained and explain basic core concepts that you can easily use in your code. Have the reference handy to check the documentation of the different commands. Never guess or assume functionality. Always check it in the reference if in doubt. Also ask in the forum if something is not clear.

Related to your code above, what is the problem? What does it do? Any issues? What would you like it to do instead?

****EDIT: Also format your post. You can edit your previous post, select your code and hit the </> button. Save the changes.

Kf

4 Likes

If you don’t already know, this is something that would be easier to undertake with objects/classes. This means that you can basically have a way of storing lots of information about one object all in one place–like a super-large variable with variables inside. This means that you can store things like the positions, colors, speeds and so on of all the ellipses in one place in the code where only information about the ellipses is stored. Also, this “object” can be used to create multiple ellipses that all have positions, colors, speeds, etc., even if the values different.

Here are a few links that explain Object Oriented Programming better than me and give some examples:

Daniel Shiffman (Youtube Playlist)

Daniel Shiffman (processing.org)

codingforart.com

processing.org example 1

processing.org example 2

java website

-The Wizard Bear

2 Likes

Thank you so much for helping!