Please advise me on my cannon simulation code!

int angle=0,a=1;

void setup(){
size(1500,750);

fill(26,185,53);
rectMode(CORNER);
rect(0,600,1500,150);
fill(75,78,75);
rect(0,610,1500,20);
fill(233,243,255);
rect(0,0,1500,600);
stroke(247,251,0);
line(0,620,100,620);
line(120,620,220,620);
line(240,620,340,620);
line(360,620,460,620);
line(480,620,580,620);
line(600,620,700,620);
line(720,620,820,620);
line(840,620,940,620);  
line(960,620,1060,620);
line(1080,620,1180,620);
line(1200,620,1300,620);
line(1320,620,1420,620);
line(1440,620,1540,620);
line(1560,620,1660,620);
line(1680,620,1780,620);
noStroke();
ellipseMode(CENTER);
fill(0,0,0);
ellipse(250,620,30,30);

}

void draw(){
while(a==1){keyPressed();}
}
 
void keyPressed(){
if (keyCode == UP)angle++;
else if(keyCode == DOWN)angle--;
else if(key == 'w'){fire();}
}
void fire(){
  
}

I’ve worked it out here, but…

According to my code, is the value of the angle variable increased/decreased when the arrow key was pressed?

Also, how do cannons vary the angle of launch depending on the value of the angle variable?

the first velocity of a cannonball : Entered by the user

please delete this in draw():

while (a==1) {
keyPressed();
}

a while loop would block your entire draw()

keyPressed() gets called automatically.

Do all the drawing in draw, not in setup

Start draw() with background(0);

post the entire code again, formatted as code.

Chrisir

1 Like

Read the first three textual tutorials

Read the examples about animation and motion

You can’t ask for every little step here please

Do some research and learning on your own please