Skip to content
Snippets Groups Projects
Commit 1513c96d authored by Robin VAN DE MERGHEL's avatar Robin VAN DE MERGHEL :computer:
Browse files

Adding VR course (android update)

parent b0600e30
No related branches found
No related tags found
No related merge requests found
// On va recréer paint pour android
// On va faire un jeu (comme le dinosore de chrome)
class Monstre {
color c = color(0, 255, 0);
private float x;
private float y;
color[] colors;
public Monstre(float x, float y) {
this.x = x;
this.y = y;
}
// On va créer 10 couleurs aléatoires
public void afficher() {
fill(0);
ellipse(x, y, 50, 50);
}
float getX() {
return x;
}
void setup() {
float getY() {
return y;
}
fullScreen(P2D);
}
ArrayList<Monstre> monstres = new ArrayList<Monstre>();
// On met comme fond blanc
background(255);
float g = 0.5; // gravité
float v = 0; // vitesse
float y = 0; // position
noStroke();
float speed;
colors = new color[10];
float ticks = 0;
float timeBeforeNextMonstre = 3;
for (int i = 0; i < colors.length; i++) {
boolean saut = false;
colors[i] = color(random(255), random(255), random(255));
int score = 0;
}
void setup() {
fullScreen(P2D);
y = height/2;
}
// Quand on touche l'écran, on dessine un cercle
void draw() {
background(255);
// On ajoute des touches pour changer la couleur
// On affiche 10 cercles avec les couleurs aléatoires
for (int i = 0; i < colors.length; i++) {
fill(colors[i]);
if (saut) {
v = -10;
saut = false;
}
ellipse(50 + i * 50, 50, 40, 40);
v += g;
y += v;
if (y > height/2) {
y = height/2;
v = 0;
}
// On rajoute un cercle noir pour effacer
fill(0);
ellipse(width/4, y, 50, 50);
ellipse(50 + 10 * 50, 50, 40, 40);
// On fait apparaître un monstre toutes les 3s
ticks += 1/frameRate;
if (ticks > timeBeforeNextMonstre) {
timeBeforeNextMonstre = random(0.2, 2);
monstres.add(new Monstre(width, height/2));
ticks = 0;
score += 1;
}
// Quand on presse l'écran, on relie le point précédent au point actuel
void mouseDragged() {
if (mouseY > 100) {
stroke(c);
strokeWeight(10);
line(mouseX, mouseY, pmouseX, pmouseY);
}
for (int i = 0; i < monstres.size(); i++) {
Monstre m = monstres.get(i);
m.afficher();
m.x -= speed;
if (score%3==0) {
speed += 0.4;
}
// Si on touche un cercle, on change la couleur
void mousePressed() {
for (int i = 0; i < colors.length; i++) {
if (dist(mouseX, mouseY, 50 + i * 50, 50) < 20) {
c = colors[i];
// Check collision
if (dist(m.getX(), m.getY(), width/4, y) < 50) {
// On perd
println("Perdu");
exit();
}
if (m.x == 0) {
// On supprime le monstre
monstres.remove(i);
}
// Si on touche le cercle noir, on efface
if (dist(mouseX, mouseY, 50 + 10 * 50, 50) < 20) {
}
background(255);
fill(0);
textSize(32);
text("Score : " + score, 10, 30);
}
void mousePressed() {
saut = true;
}
\ No newline at end of file
// On va recréer paint pour android
color c = color(0, 255, 0);
color[] colors;
// On va créer 10 couleurs aléatoires
void setup() {
fullScreen(P2D);
}
//On va créer un cube en 3D, le positionner et le faire tourner autour de lui-même
float zIndex = 0;
boolean shader = true;
boolean drawable = true;
// On créer un objet qui va contenir un cube, ses coordonnées, sa taille, sa couleur, etc.
class MonCube {
private float x, y, z;
private float size;
private int r, g, b;
MonCube(float x, float y, float z, float size, int r, int g, int b) {
this.x = x;
this.y = y;
this.z = z;
this.size = size;
this.r = r;
this.g = g;
this.b = b;
}
void display() {
pushMatrix();
translate(x, y, z);
fill(r, g, b);
box(size);
popMatrix();
}
void rotate(float angle) {
x = cos(angle) * x - sin(angle) * y;
y = sin(angle) * x + cos(angle) * y;
}
float getX() {
return x;
}
float getY() {
return y;
}
float getZ() {
return z;
}
float getSize() {
return size;
}
void setX(float x) {
this.x = x;
}
void setY(float y) {
this.y = y;
}
void setZ(float z) {
this.z = z;
}
void setRandomPosition() {
x = random( - width / 2, width / 2);
y = random( - height / 2, height / 2);
z = random( - 1000, 1000);
}
}
class ObjetComplexe {
private ArrayList<MonCube> cubes;
ObjetComplexe() {
cubes = new ArrayList<MonCube>();
}
void addCube(MonCube cube) {
cubes.add(cube);
}
void display() {
for (MonCube cube : cubes) {
cube.display();
}
}
// Si on fait une rotation, tout les cubes doivent bouger comme si une seule forme bougeait
// On doit calculer la position de chaque cube par rapport à la position du centre de l'objet
// Avec la trigonométrie dans l'espace, on peut calculer la position de chaque cube
void rotate(float angle) {
// On récupère la position du centre de l'objet
float centerX = 0;
float centerY = 0;
float centerZ = 0;
for (MonCube cube : cubes) {
centerX += cube.getX();
centerY += cube.getY();
centerZ += cube.getZ();
}
centerX /= cubes.size();
centerY /= cubes.size();
centerZ /= cubes.size();
// On calcule la position de chaque cube par rapport au centre de l'objet
for (MonCube cube : cubes) {
float x = cube.getX() - centerX;
float y = cube.getY() - centerY;
float z = cube.getZ() - centerZ;
// On fait une rotation de l'objet
cube.setX(cos(angle) * x - sin(angle) * y + centerX);
cube.setY(sin(angle) * x + cos(angle) * y + centerY);
cube.setZ(z + centerZ);
}
}
MonCube getCube(int index) {
return cubes.get(index);
}
ArrayList<MonCube> getCubes() {
return cubes;
}
}
ObjetComplexe objetComplexe = new ObjetComplexe();
void setup() {
fullScreen(P3D);
// On créer un objet complexe
// On en créer 5 autres
for (int i = 0; i < 5; i++) {
MonCube cube = new MonCube(0, 0, 0, 100, 255, 255, 255);
cube.setRandomPosition();
cube.rotate(random(0, TWO_PI));
objetComplexe.addCube(cube);
}
}
float angle = 0;
void draw() {
// On efface l'écran
background(0);
// On positionne le cube au centre de l'écran
translate(width/2, height/2, 0);
if (drawable) {
// On dessine tous les cubes
for (MonCube cube : objetComplexe.getCubes()) {
cube.display();
}
if (shader) {
// On fait une lumière à côté du premier cube
pointLight(255, 255, 255, objetComplexe.getCube(0).getX() + 100, objetComplexe.getCube(0).getY(), objetComplexe.getCube(0).getZ());
}
} else {
// On fait une rotation de l'objet
rotateZ(0.01 * frameCount);
}
// On rajoute un bouton bleu pour activer/désactiver le dessin
pushMatrix();
translate(-width / 2, -height / 2, 0);
fill(0, 0, 255);
rect(0, 0, 100, 50);
popMatrix();
}
// Si on appuye quelque part sur l'écran, on ajoute un cube à l'endroit de la souris
void mousePressed() {
if (mouseX < 100 && mouseY < 50) {
drawable = !drawable;
return;
}
MonCube cube = new MonCube(mouseX - width / 2, mouseY - height / 2, 0, 100, 255, 255, 255);
objetComplexe.addCube(cube);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment