Hey there, i’m new to processing and programming in general, so go easy on me
Well, i was writing this simple game for processing 3, and found myself into some difficulties.
I Made 2 tabs, one for the main coding, and other for classes (maybe you could give some tips for organization as well )
so here’s my code
Main code tab:
ball myBall;
int score;
int deaths;
void setup() {
size ( 640, 480);
noStroke();
myBall = new ball();
}
void draw() {
background(126);
myBall.display();
fill (255);
ellipse(mouseX, mouseY, 33, 33);
fill (0);
text ("Score: " + score, 10, 460);
text ("Deaths: " + deaths, 570, 460);
if (mouseX == myBall.xposb + 33 || mouseY == myBall.yposb + 33 || mouseX == myBall.xposb - 33 || mouseY == myBall.yposb - 33){
die();
}
}
void die(){
deaths++;
score = 0;
}
classes tab:
class ball {
color c;
float xposb;
float yposb;
float xspeed;
ball(){
c = color (0);
xposb = width/2;
yposb = height/2;
xspeed = 0;
}
void display(){
rectMode(CENTER);
fill(c);
rect(xposb, yposb, 33, 33);
}
}
so, is there any easiest or clearer way to reference the rect hitbox instead of - ?
if (mouseX == myBall.xposb + 33 || mouseY == myBall.yposb + 33 || mouseX == myBall.xposb - 33 || mouseY == myBall.yposb - 33){
die();
}
and when i put the “if” outside the “draw()” function it says “expecting EOF, found if” but when i put it inside “draw()” function, the “die()” function runs every frame, which is very bad cause i don’t want it to happen, since it have to “die” once every time it hit the hitbox