Laser blaster effect?
Answered
- Need more info
- Answered
- Working on it
in
Programming Questions
•
3 years ago
Okay, I'm toying with drawing a blaster turrent as an learning project. This one is meant to be an Object and doing a sort of Star Wars laser vice Star Trek Phaser effect. A short line that keeps moving on the screen.
When I run the code below it just draws the lines once. I'm trying to use the ideas from the 2 car tutorial but it's not working yet. Thoughts?
Leam
When I run the code below it just draws the lines once. I'm trying to use the ideas from the 2 car tutorial but it's not working yet. Thoughts?
Leam
- Turrent myTurrent;
int bg = 255;
void setup() {
size(250,400);
background(bg);
myTurrent = new Turrent(125,200);
}
void draw() {
myTurrent.display();
myTurrent.fire();
}
class Turrent {
float xpos;
float ypos;
Turrent(float tmpXpos, float tmpYpos) {
xpos = tmpXpos;
ypos = tmpYpos;
}
void display() {
stroke(0);
fill(150);
ellipseMode(CENTER);
ellipse(xpos, ypos, 30,40);
fill(0);
rect(xpos - 6, ypos - 30, 3, 20);
rect(xpos + 3, ypos - 30, 3, 20);
}
void fire() {
float laserXpos = xpos;
float laserYpos = ypos;
stroke(255,0,0);
line(xpos - 5, laserYpos - 50, xpos - 5, laserYpos - 100);
line(xpos + 3, laserYpos - 50, xpos + 3, laserYpos - 100);
laserYpos = laserYpos - 10 ;
}
}
1