Created
June 23, 2020 06:37
-
-
Save federico-pepe/e91a7ddd842dc87ada24d14eea810bae 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 Oggetto { | |
int dimensione; | |
float xPosOg; | |
float yPosOg; | |
int direzione; | |
float velocita; | |
Oggetto(int d, float x, float y, int dir, float v) { | |
dimensione = d; | |
xPosOg = x; | |
yPosOg = y; | |
direzione = dir; | |
velocita = v; | |
} | |
void disegnaOggetto() { | |
fill(random(255), random(255), random(255)); | |
ellipse(xPosOg, yPosOg, dimensione, dimensione); | |
} | |
void movimento() { | |
yPosOg += velocita * direzione; //posizione y aumenta in base alla velocita | |
println("Direzione: " + direzione); | |
} | |
void respinto(Personaggio p) { | |
if(yPosOg >= p.yPosPers) { | |
if ( (xPosOg > p.xPosPers ) && (xPosOg < (p.xPosPers + 60) ) ) { | |
direzione *= -1; | |
println("Colpito"); | |
} | |
} | |
} | |
} |
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 Personaggio { //classe Personaggio | |
int larghezza; | |
int altezza; | |
int xPosPers; | |
int yPosPers; | |
color colorePersonaggio; | |
int velocita; | |
Personaggio(int l, int a, int x, int y, color c, int v) { | |
larghezza = l; | |
altezza = a; | |
xPosPers = x; | |
yPosPers = y; | |
colorePersonaggio = color(c); | |
velocita = v; | |
} | |
void disegnaPersonaggio() { | |
if (xPosPers > (width - 80)) xPosPers = width - 80; | |
{ | |
if (xPosPers < 0) xPosPers = 0; | |
rect(xPosPers, yPosPers, larghezza, altezza); | |
} | |
} | |
void muoviDestra() { //per utilizzare personaggio 1 cambiare con xPos ++; | |
xPosPers += velocita; | |
} | |
void muoviSinistra() { //per utilizzare personaggio 1 cambiare con xPos --; | |
xPosPers -= velocita; | |
} | |
} |
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 Oggetto { | |
int dimensione; | |
float xPosOg; | |
float yPosOg; | |
int direzione; | |
float velocita; | |
Oggetto(int d, float x, float y, int dir, float v) { | |
dimensione = d; | |
xPosOg = x; | |
yPosOg = y; | |
direzione = dir; | |
velocita = v; | |
} | |
void disegnaOggetto() { | |
fill(random(255), random(255), random(255)); | |
ellipse(xPosOg, yPosOg, dimensione, dimensione); | |
} | |
void movimento() { | |
yPosOg += velocita * direzione; //posizione y aumenta in base alla velocita | |
println("Direzione: " + direzione); | |
} | |
void respinto(Personaggio p) { | |
if(yPosOg >= p.yPosPers) { | |
if ( (xPosOg > p.xPosPers ) && (xPosOg < (p.xPosPers + 60) ) ) { | |
direzione *= -1; | |
println("Colpito"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment