Created
May 2, 2019 20:51
-
-
Save ybakos/f8a88da3cf382ba707c20277aa38ef71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Rocket { | |
| PVector position; | |
| PVector velocity; | |
| PVector acceleration; | |
| float size; | |
| Rocket(PVector location) { | |
| acceleration = new PVector(); | |
| velocity = new PVector(); | |
| position = location.get(); | |
| size = 4; | |
| } | |
| void applyForce(PVector f) { | |
| acceleration.add(f); | |
| } | |
| void update() { | |
| velocity.add(acceleration); | |
| position.add(velocity); | |
| acceleration.mult(0); | |
| } | |
| void display() { | |
| float theta = velocity.heading2D() + PI/2; | |
| fill(200, 100); | |
| stroke(0); | |
| pushMatrix(); | |
| translate(position.x, position.y); | |
| rotate(theta); | |
| // Thrusters | |
| rectMode(CENTER); | |
| fill(0); | |
| rect(-size/2, size*2, size/2, size); | |
| rect(size/2, size*2, size/2, size); | |
| // Fuselage | |
| fill(175); | |
| beginShape(TRIANGLES); | |
| vertex(0, -size*2); | |
| vertex(-size, size*2); | |
| vertex(size, size*2); | |
| endShape(); | |
| popMatrix(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment