help with moving object
in
Programming Questions
•
2 years ago
hey im trying to move this object but its not going according to plan im trying to make this small square shoot off the page upwards and then making another 1 shoot when the first one is about half way...easiest way to think is when you shooting something i guess basically trying to make an animation of my box shooting...
these are my codes im still trying to figure it out but cant seem to get it so if any1 can help i appreciate it
color BG = color(32);
float angle;
float x = 0;
float y = 0;
float z = 0;
float w = 0;
float speed = 1;
void setup() {
size(500,500);
strokeWeight(5);
smooth();
rectMode(CENTER);
}
void draw() {
background(BG);
if (key =='1') {
translate(width/2, height-40);
rotate( angle );
rect(0,0, 60,60);
beginShape();
vertex(10, 10);
vertex(20, 25);
vertex(10, 20);
vertex(25, 20);
vertex(20, 20);
vertex(20, 25);
vertex(20, 10);
vertex(25, 20);
endShape(CLOSE);
angle = angle + PI/180;
}
else if (key == '2'){
move();
translate(width/2, height-40);
rect(x,y, 60,60);
beginShape();
vertex(x + 10, y + 10);
vertex(x + 20, y + 25);
vertex(x + 10, y + 20);
vertex(x + 25, y + 20);
vertex(x + 20, y + 20);
vertex(x + 20, y + 25);
vertex(x + 20, y + 10);
vertex(x + 25, y + 20);
endShape(CLOSE);
}
else if (key == '3'){
move();
shoot();
translate(width/2, height-40);
rect(0,0, 60, 60);
rect (z, w, 5, 5);
beginShape();
vertex(10, 10);
vertex(20, 25);
vertex(10, 20);
vertex(25, 20);
vertex(20, 20);
vertex(20, 25);
vertex(20, 10);
vertex(25, 20);
endShape(CLOSE);
}
}
void move() {
translate(x, 0);
x += speed;
if (x < -30 || x > 30) {
speed = -speed;
}
}
void shoot() {
translate(z, 0);
w = w + speed;
if (w > height) {
w = 0;
}
}
these are my codes im still trying to figure it out but cant seem to get it so if any1 can help i appreciate it
color BG = color(32);
float angle;
float x = 0;
float y = 0;
float z = 0;
float w = 0;
float speed = 1;
void setup() {
size(500,500);
strokeWeight(5);
smooth();
rectMode(CENTER);
}
void draw() {
background(BG);
if (key =='1') {
translate(width/2, height-40);
rotate( angle );
rect(0,0, 60,60);
beginShape();
vertex(10, 10);
vertex(20, 25);
vertex(10, 20);
vertex(25, 20);
vertex(20, 20);
vertex(20, 25);
vertex(20, 10);
vertex(25, 20);
endShape(CLOSE);
angle = angle + PI/180;
}
else if (key == '2'){
move();
translate(width/2, height-40);
rect(x,y, 60,60);
beginShape();
vertex(x + 10, y + 10);
vertex(x + 20, y + 25);
vertex(x + 10, y + 20);
vertex(x + 25, y + 20);
vertex(x + 20, y + 20);
vertex(x + 20, y + 25);
vertex(x + 20, y + 10);
vertex(x + 25, y + 20);
endShape(CLOSE);
}
else if (key == '3'){
move();
shoot();
translate(width/2, height-40);
rect(0,0, 60, 60);
rect (z, w, 5, 5);
beginShape();
vertex(10, 10);
vertex(20, 25);
vertex(10, 20);
vertex(25, 20);
vertex(20, 20);
vertex(20, 25);
vertex(20, 10);
vertex(25, 20);
endShape(CLOSE);
}
}
void move() {
translate(x, 0);
x += speed;
if (x < -30 || x > 30) {
speed = -speed;
}
}
void shoot() {
translate(z, 0);
w = w + speed;
if (w > height) {
w = 0;
}
}
1