Hey guys, this is my first post so I hope I hope I’m doing this correctly. I am trying to create a code where each time an object hits the bottom of the screen a new circle is on the screen, starting in the top left screen. Each time the objects hits the ground the next circle is drawn to the right of the previous circle and so on, if it moves out of room it would move to the next line. My only problem is that once the first circle is drawn the previous circle gets deleted and is no longer on the screen. The drawing of the circles is in loop inside a function which is called once the hammer reaches the bottom of the screen.
Homework
only problem is that once the first circle is drawn the previous circle gets deleted and is no longer on the screen
store number of circles / coins you have. For loop i up to that number. Draw the coins insides this loop.
Call this loop not when the hammer falls but in your draw()
And please share what code you have already written!
This is everything I have so far relevant to my question (didn’t copy all of it so its easier to read) also to the first person telling me to the for loop, thank you for your advice, the only problem is that i want each circle to appear as the hammer reaches the bottom not every circle to be drawn, thank you for your help though
int HammerSide1 = int(random(2, 8)); //HAMMER SIDE TO SIDE
int HammerDown1 = 0; // HAMMER DOWN
int circlesize = 30;
int count = 570;
float x = -560;
int A = -40;
int B = 40;
int circle = 0;
int circledraw = 35;
void setup() {
size(512, 318); //DISPLAY WINDOW
frameRate(60); //FRAME RATE
HammerSide1 = HammerSide1 * 64;
DoorClosed = (int)random(180, 480);
DoorOpen = (int)random(180, 480);
}
void draw() {
background(135, 206, 255);
strokeWeight(1);
fill(120, 72, 0);
rect(0, 300, 512, 20);
//HAMMER FALLING CODE ------>
fill(0, 255, 0);
if (HammerDown1 < -25) {
HammerSide1 = int(random(2, 8));
HammerSide1 = HammerSide1 * 64;
}
if (HammerDown1 < 275);
{
HammerDown1 = HammerDown1 + 2;
}
if (HammerDown1 >= 275) {
HammerDown1 = -75;
A = A + 80;
//circledraw = circledraw - 1;
}
circles();
/*if (circledraw == 1){
circles();
} */
// HAMMER FALLING CODE <-----
//HAMMER DESING ---->
fill(165, 45, 45);
rect(HammerSide1, HammerDown1, 35, 10);
rect(HammerSide1-10, HammerDown1, 10, 10);
fill(169);
stroke(169);
rect(HammerSide1, HammerDown1 -10, 10, 10);
rect(HammerSide1, HammerDown1, 10, 20);
//HAMMER DESING <----
void circles(){
while (count > 0) {
noStroke();
fill(0);
ellipse(A, B, circlesize, circlesize);
count = -5;
circlesize = -10;
}
count = 570;
circlesize = 30;
if (A > 570) {
A = 40;
B = B + 80;
}
if (A > 570) {
if (B > 260) {
A = 40;
B = 40;
count = 570;
}
}
}
Not sure if you got me there.
When the hammer falls, you increase the number of circles you want to display. 0, then 1,then 2…
Displaying is then in the for loop
Thank you for your reply again @Chrisir
I understand what your saying now however I’m struggling to implement it, can you tell me what i have done wrong? full code below
//VARIABLES ---->
int i = 0;
int HammerSide1 = int(random(2, 8)); //HAMMER SIDE TO SIDE
int HammerDown1 = 0; // HAMMER DOWN
int circlesize = 30;
int count = 570;
float x = -560;
int A = 40;
int B = 40;
// VATRIABLES <-------
void setup() {
size(512, 318); //DISPLAY WINDOW
frameRate(60); //FRAME RATE
HammerSide1 = HammerSide1 * 64;
}
void draw() {
background(135, 206, 255);
strokeWeight(1);
fill(120, 72, 0);
rect(0, 300, 512, 20);
//HAMMER FALLING CODE ------>
fill(0, 255, 0);
if (HammerDown1 < -25) {
HammerSide1 = int(random(2, 8));
HammerSide1 = HammerSide1 * 64;
}
if (HammerDown1 < 275);
{
HammerDown1 = HammerDown1 + 2;
}
if (HammerDown1 >= 275) {
HammerDown1 = -75;
i = i ++;
//circledraw = circledraw - 1;
}
circles();
/*if (circledraw == 1){
circles();
} */
// HAMMER FALLING CODE <-----
//HAMMER DESING ---->
fill(165, 45, 45);
rect(HammerSide1, HammerDown1, 35, 10);
rect(HammerSide1-10, HammerDown1, 10, 10);
fill(169);
stroke(169);
rect(HammerSide1, HammerDown1 -10, 10, 10);
rect(HammerSide1, HammerDown1, 10, 20);
//HAMMER DESING <----
}
void circles() {
for ( i = 0; i > 32; ) {
noStroke();
fill(0);
ellipse(A, B, circlesize, circlesize);
/*
if (A > 570) {
A = 40;
B = B + 80;
}
if (A > 570) {
if (B > 260) {
A = 40;
B = 40;
}
}*/
}
}
//GAME CODE <<<<<<<<
for ( i = 0; i > numberOfCircles; i++) {
i++ is missing
numberOfCircles: make it a global Variable of type int; increase every time hammer hits
Call circles from draw
@Chrisir Thank you so much for your help ill let you know how i progress
Ok then, excellent
Actually it should be
for (int i = 0; i < numberOfCircles; i++) {
otherwise the program will get stuck in an infinite loop
ah, thanks! my bad…