# I need help is to make an easy game but i have some problem now

my basic idea is to draw a small planet (ellipse code) and then make it move. But I want to minimize where it can go.
like I will make a boolean ( kinda hitbox) wich smaller than my planet, if the hitbox touches the rear of the canvas it only moves the other direction, not the direction go out of the canvas.

``````float x,y;

void setup()
{
size(1000, 1000);
x=width/2;
y=height/5*(4.5);

}
void draw()
{
draw_planet(x,y,width/50);
}
void draw_planet(float x, float y, float diam) {

fill(0, 100, 0);
ellipse(x,y,diam,diam);

}
void Planet_move(float x_flight, float y_flight){
y=y+y_flight;
x=x+x_flight;
}
void keyPressed()
{
if (key=='w' ||key =='i')
{
Planet_move(0,-10);
}
else if (key == 's'|| key =='k')
{
Planet_move(0, 10);

} else if (key == 'd' | key == 'l')
{
Planet_move(10, 0);

} else if (key == 'a' | key=='j')
{
Planet_move(-10, 0);
}
}
void Planet_move_in_the_canvas_or_not()
{

}

``````

I want to use boolean but I cant type`boolean planet(float x, float y, float z)=true`

i understand that you think you need a boolean function,
more inside code and some clean up i hope you like.

``````// https://discourse.processing.org/t/i-need-help-is-to-make-an-easy-game-but-i-have-some-problem-now/5803
/*
when you want do like:

if ( hungry() ) eat();

// need function
void eat(){ }
// and boolean function
boolean hungry(){
if ( eatlastTime > 5min ) return true;
return false;
}

*/

int   my_width = 500, my_height = my_width;     // window
float x = my_width/2, y = 45, w = my_width/50, step = 10;                                  // object position
float fence_x = 20, fence_y = 20, fence_w = my_width-2*fence_x;  //

void settings() {
size(my_width, my_height);
}

void setup() {
println("use key [w][s][d][a]");
}

void draw() {
noFill();
stroke(0,0,200);
planet_draw(x, y, w);
}

void planet_draw(float x, float y, float diam) {
fill(0, 100, 0);
noStroke();
ellipse(x, y, diam, diam);
}

void planet_move(float x_flight, float y_flight) {
y=y+y_flight;
x=x+x_flight;
if (planet_check_fence(x,y,w)) { println("what do now?"); }
}

boolean planet_check_fence(float x, float y, float diam) {
// if x y at fence return true; ??
return false;
}

void keyPressed() {
if      ( key == 'w' || key == 'i')  planet_move(0, -step);
else if ( key == 's' || key == 'k')  planet_move(0,  step);
else if ( key == 'd' || key == 'l')  planet_move( step, 0);
else if ( key == 'a' || key == 'j')  planet_move(-step, 0);
}

``````

Look for “bounce” examples in the PDE examples folder and in Processing.org examples. Also look for “collision detection” – these are the ways to describe related problems, and you will find lots of example code, tutorials, and resources. Coding Train and Happy Coding also have tutorials on collision detection with bouncing.