Skip to content

Commit

Permalink
Ajout de la goutte d'eau
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick B committed Aug 29, 2023
1 parent e6b422d commit 6f0bb87
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
Binary file modified s01c_perlin_terrain/temp.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions xtra/spawning/GraphicObject.pde
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();

}
67 changes: 67 additions & 0 deletions xtra/spawning/Thing.pde
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;
}
}
Binary file added xtra/spawning/data/drop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions xtra/spawning/spawning.pde
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();
}

0 comments on commit 6f0bb87

Please sign in to comment.