-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nick B
committed
Aug 29, 2023
1 parent
e6b422d
commit 6f0bb87
Showing
5 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
abstract class GraphicObject { | ||
PVector location; | ||
PVector velocity; | ||
PVector acceleration; | ||
|
||
color fillColor = color (255); | ||
color strokeColor = color (255); | ||
float strokeWeight = 1; | ||
|
||
abstract void update(int time); | ||
|
||
abstract void display(); | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
class Thing extends GraphicObject { | ||
public boolean isAlive = true; | ||
int w = 40; | ||
int h = 60; | ||
int mass = 1; | ||
int lastTime = 0; | ||
|
||
PImage drop; | ||
|
||
Thing() { | ||
init(); | ||
|
||
location.x = width / 2; | ||
} | ||
|
||
void init() { | ||
drop = loadImage("drop.png"); | ||
location = new PVector(0, -w); | ||
velocity = new PVector(); | ||
acceleration = new PVector(); | ||
} | ||
|
||
void update (int time) { | ||
if (!isAlive) return; | ||
|
||
velocity.add(acceleration); | ||
|
||
// Cette opération permet de toujours avoir la même vitesse | ||
// peu importe le frameRate | ||
var fraction = PVector.mult(velocity, ((time - lastTime) / 1000f)); | ||
location.add(fraction); | ||
|
||
acceleration.mult(0); | ||
|
||
if (location.y - h > height || location.y + h < 0 || | ||
location.x - w > width || location.x + w < 0) { | ||
isAlive = false; | ||
} | ||
|
||
lastTime = time; | ||
} | ||
|
||
|
||
void display() { | ||
if (!isAlive) return; | ||
|
||
pushMatrix(); | ||
translate (location.x, location.y); | ||
|
||
image(drop, 0, 0, w, h); | ||
//ellipse(0, 0, size, size); | ||
|
||
popMatrix(); | ||
} | ||
|
||
public void applyForce (PVector _force) { | ||
PVector force = PVector.div(_force, mass); | ||
acceleration.add(force); | ||
} | ||
|
||
public void respawn() { | ||
location.x = random(0, width); | ||
location.y = -h; | ||
isAlive = true; | ||
velocity.y = 0; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
int currentTime; | ||
|
||
int spawnInterval = 2500; | ||
int spawnPrevious = 0; | ||
|
||
Thing theThing; | ||
PVector gravity = new PVector(0, 10); | ||
|
||
void setup() { | ||
size (800, 600); | ||
|
||
theThing = new Thing(); | ||
} | ||
|
||
void draw() { | ||
currentTime = millis(); | ||
|
||
update(currentTime); | ||
display(); | ||
} | ||
|
||
void update(int time) { | ||
if (theThing.isAlive) { | ||
theThing.applyForce(gravity); | ||
|
||
theThing.update(time); | ||
spawnPrevious = time; | ||
} else { | ||
if (currentTime - spawnPrevious > spawnInterval) { | ||
theThing.respawn(); | ||
} | ||
} | ||
} | ||
|
||
void display() { | ||
background(0); | ||
theThing.display(); | ||
} |