Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Didattica > Corsi G - M > Laboratorio di multimedia I > Snake in Processing
Pages (2): [1] 2 »   Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
IsaMetallo
.illuminato.

User info:
Registered: Mar 2008
Posts: 179 (0.03 al dì)
Location: Treviglio
Corso: Comunicazione Digitale
Anno: Secondo
Time Online: 15:35:34 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
Snake in Processing

ciao a tutti... per smanettare un pò oggi mi sono messo ad implementare una versione semplice di snake (famoso gioco per cellulari) nella sua prima versione (quella cioè in cui si perdeva anche se si toccava il muro)...
sono ancora ad uno stadio iniziale, sto ancora lavorando sul movimento... ma la cosa stranissima è che solo le prime due parti del corpo del serpente si muovono correttamente, mentre le altre rimangono ferme, e non riesco a capire il perchè... se qualcuno mi dà una mano mi farebbe piacere...

SNAKEGAME

code:
Snake snake; int rate=1; int bodySize=20; //grandezza del corpo del serpente PVector direction=new PVector(0,bodySize); //direzione iniziale verso il basso (scelta a caso) static boolean running=true; //la variabile booleana fa vedere se il gioco è in corso o menp void setup(){ size(600,600); snake=new Snake(bodySize); frameRate(rate); smooth(); } void draw(){ if (running){ //il gioco in corso disegna il primo sfondo e fa muovere il serpente, il resto sarà gestito a parte background(loadImage("back.jpg")); snake.move(direction); } else //se no viene disegnata la schermata di perdita { background(loadImage("nelson.jpg")); textFont(loadFont("Arial-Black-48.vlw") , 40); fill(255); text("You Lose!",width-275,200); textFont(loadFont("Arial-Black-48.vlw"),20); text("Press n",width-200,height-100); text("for a new game", width-200,height-70); } } void keyPressed(){ //cambia direzione al serpente if (keyCode==UP) direction.set(0,-bodySize,0); if (keyCode==DOWN) direction.set(0,bodySize,0); if (keyCode==LEFT) direction.set(-bodySize,0,0); if (keyCode==RIGHT) direction.set(bodySize,0,0); if (key=='n') newGame(); } static void gameFinished(){ //se invocato ferma il gioco running=false; } void newGame(){ //ripristina lo stato iniziale snake=new Snake(bodySize); running=true; direction=new PVector(0,bodySize); }


SNAKE
code:
class Snake{ ArrayList snakeBody=new ArrayList(); Snake(int bodySize){ //crea un serpente con 5 pezzi int scala=0; for (int i=0; i<5; i++){ snakeBody.add(new SnakeBodyPart(new PVector(300-scala,10),bodySize)); scala+=bodySize; } } void move(PVector direction){ //la direzione influisce solo sul movimento della testa SnakeBodyPart head=(SnakeBodyPart)snakeBody.get(0); head.move(direction); head.display(); //il resto viene fatto in modo che un pezzo successivo prenda il posto del pezzo precedente int count=1; while(count<snakeBody.size()){ SnakeBodyPart part=(SnakeBodyPart)snakeBody.get(count); SnakeBodyPart previous=(SnakeBodyPart)snakeBody.get(count-1); part.setNewPos(previous.getOldPos()); part.display(); count=count+1; } } }


SNAKEBODYPART
code:
class SnakeBodyPart{ PVector pos,oldPos; int bodySize; float scala; SnakeBodyPart(PVector pos,int bodySize){ this.pos=pos.get(); this.oldPos=pos.get(); this.bodySize=bodySize; this.scala=bodySize/2; } void display(){ //disegna un rettangolo il cui centro viene letto dal vettore posizione rectMode(CENTER); fill(0,255,0); rect(pos.x,pos.y,bodySize,bodySize); } PVector getOldPos(){ return oldPos.get(); } PVector getPos(){ return pos.get(); } void setNewPos(PVector newPos){ pos.set(newPos.get()); } void move(PVector direction){ oldPos=pos.get(); pos.add(direction); //se la posizione esce dalla finestra si perde if (((pos.x-scala<0)||(pos.x+scala>width)) || ((pos.y-scala/2<0)||(pos.y+scala/2>height))) SnakeGame.gameFinished(); } }

__________________
"They Can't Stop Us Let Them Try...
for heavy metal we would die..."
(Manowar - Die For Metal)

http://www.jackassubs.com - Admin (in ricerca di traduttori!!!)

27-05-2009 18:32
Click Here to See the Profile for IsaMetallo Click here to Send IsaMetallo a Private Message Find more posts by IsaMetallo Add IsaMetallo to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
IsaMetallo
.illuminato.

User info:
Registered: Mar 2008
Posts: 179 (0.03 al dì)
Location: Treviglio
Corso: Comunicazione Digitale
Anno: Secondo
Time Online: 15:35:34 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

niente ho risolto :-)

__________________
"They Can't Stop Us Let Them Try...
for heavy metal we would die..."
(Manowar - Die For Metal)

http://www.jackassubs.com - Admin (in ricerca di traduttori!!!)

28-05-2009 11:49
Click Here to See the Profile for IsaMetallo Click here to Send IsaMetallo a Private Message Find more posts by IsaMetallo Add IsaMetallo to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Stetolo
.consigliere.

User info:
Registered: Oct 2007
Posts: 122 (0.02 al dì)
Location: Milano
Corso: Comunnicazione Digitale
Anno:
Time Online: 2 Days, 4:02:00: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

L'avevo fatto anch'io :) !

Attachment: snake_2.zip
This has been downloaded 14 time(s).

__________________
Stetolo

02-06-2009 06:29
Click Here to See the Profile for Stetolo Click here to Send Stetolo a Private Message Find more posts by Stetolo Add Stetolo to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
IsaMetallo
.illuminato.

User info:
Registered: Mar 2008
Posts: 179 (0.03 al dì)
Location: Treviglio
Corso: Comunicazione Digitale
Anno: Secondo
Time Online: 15:35:34 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

ehm... non funziona il tuo... nel senso, io passo col quadrato blu su quello giallo ma non si allunga il serpente... sbaglio qualcosa?

__________________
"They Can't Stop Us Let Them Try...
for heavy metal we would die..."
(Manowar - Die For Metal)

http://www.jackassubs.com - Admin (in ricerca di traduttori!!!)

02-06-2009 16:23
Click Here to See the Profile for IsaMetallo Click here to Send IsaMetallo a Private Message Find more posts by IsaMetallo Add IsaMetallo to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Stetolo
.consigliere.

User info:
Registered: Oct 2007
Posts: 122 (0.02 al dì)
Location: Milano
Corso: Comunnicazione Digitale
Anno:
Time Online: 2 Days, 4:02:00: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Sicuramente si..
Ti allego l'eseguibile per giocarci:

Attachment: application.windows.zip
This has been downloaded 18 time(s).

__________________
Stetolo

02-06-2009 16:44
Click Here to See the Profile for Stetolo Click here to Send Stetolo a Private Message Find more posts by Stetolo Add Stetolo to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
IsaMetallo
.illuminato.

User info:
Registered: Mar 2008
Posts: 179 (0.03 al dì)
Location: Treviglio
Corso: Comunicazione Digitale
Anno: Secondo
Time Online: 15:35:34 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

niente, io passo sopra con il quadrato blu su quello giallo e nn succede niente...

__________________
"They Can't Stop Us Let Them Try...
for heavy metal we would die..."
(Manowar - Die For Metal)

http://www.jackassubs.com - Admin (in ricerca di traduttori!!!)

02-06-2009 21:00
Click Here to See the Profile for IsaMetallo Click here to Send IsaMetallo a Private Message Find more posts by IsaMetallo Add IsaMetallo to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Stetolo
.consigliere.

User info:
Registered: Oct 2007
Posts: 122 (0.02 al dì)
Location: Milano
Corso: Comunnicazione Digitale
Anno:
Time Online: 2 Days, 4:02:00: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

L'ho riprovato ancora..
Su Windows..
You too?

__________________
Stetolo

02-06-2009 22:14
Click Here to See the Profile for Stetolo Click here to Send Stetolo a Private Message Find more posts by Stetolo Add Stetolo to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
IsaMetallo
.illuminato.

User info:
Registered: Mar 2008
Posts: 179 (0.03 al dì)
Location: Treviglio
Corso: Comunicazione Digitale
Anno: Secondo
Time Online: 15:35:34 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

si certo winodws xp... funziona uguale sia via processing che via applicazione...

__________________
"They Can't Stop Us Let Them Try...
for heavy metal we would die..."
(Manowar - Die For Metal)

http://www.jackassubs.com - Admin (in ricerca di traduttori!!!)

03-06-2009 08:50
Click Here to See the Profile for IsaMetallo Click here to Send IsaMetallo a Private Message Find more posts by IsaMetallo Add IsaMetallo to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Stetolo
.consigliere.

User info:
Registered: Oct 2007
Posts: 122 (0.02 al dì)
Location: Milano
Corso: Comunnicazione Digitale
Anno:
Time Online: 2 Days, 4:02:00: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Non so darti una spiegazione onestamente.. A me ed a varie altre persone a cui l'ho fatto provare funziona correttamente..

__________________
Stetolo

03-06-2009 12:45
Click Here to See the Profile for Stetolo Click here to Send Stetolo a Private Message Find more posts by Stetolo Add Stetolo to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
IsaMetallo
.illuminato.

User info:
Registered: Mar 2008
Posts: 179 (0.03 al dì)
Location: Treviglio
Corso: Comunicazione Digitale
Anno: Secondo
Time Online: 15:35:34 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

boh strano... pace... ma il modo in cui gioco è corretto giusto? controllo il quadrato blu e passo sopra quello giallo e basta..

__________________
"They Can't Stop Us Let Them Try...
for heavy metal we would die..."
(Manowar - Die For Metal)

http://www.jackassubs.com - Admin (in ricerca di traduttori!!!)

03-06-2009 13:06
Click Here to See the Profile for IsaMetallo Click here to Send IsaMetallo a Private Message Find more posts by IsaMetallo Add IsaMetallo to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Stetolo
.consigliere.

User info:
Registered: Oct 2007
Posts: 122 (0.02 al dì)
Location: Milano
Corso: Comunnicazione Digitale
Anno:
Time Online: 2 Days, 4:02:00: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Si, fai invio all'inizio per avviare, poi scegli la difficoltà, poi controlli lo snake con le frecce..

__________________
Stetolo

03-06-2009 13:43
Click Here to See the Profile for Stetolo Click here to Send Stetolo a Private Message Find more posts by Stetolo Add Stetolo to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
IsaMetallo
.illuminato.

User info:
Registered: Mar 2008
Posts: 179 (0.03 al dì)
Location: Treviglio
Corso: Comunicazione Digitale
Anno: Secondo
Time Online: 15:35:34 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
Talking

a chi interessasse, il mio finito... basta decommentare/commentare un pezzo di codice per farlo comportare come snake 1 o 2... il codice è commentato cmq, si capisce...

Attachment: snakegame.zip
This has been downloaded 34 time(s).

__________________
"They Can't Stop Us Let Them Try...
for heavy metal we would die..."
(Manowar - Die For Metal)

http://www.jackassubs.com - Admin (in ricerca di traduttori!!!)

05-06-2009 17:19
Click Here to See the Profile for IsaMetallo Click here to Send IsaMetallo a Private Message Find more posts by IsaMetallo Add IsaMetallo to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Supernick
.tritagranchi.

User info:
Registered: Jan 2008
Posts: 323 (0.05 al dì)
Location: Albairate (MI)
Corso: Comunicazione Digitale
Anno:
Time Online: 1 Day, 17:31:17 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Provato, ben fatto!
Ora si potrebbe mettere una stringa con il punteggio attuale, e magari migliorare la grafica del serpente e della frutta... e magari farlo in 3D, no beh non esageriamo :D

12-06-2009 17:25
Click Here to See the Profile for Supernick Click here to Send Supernick a Private Message Find more posts by Supernick Add Supernick to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
IsaMetallo
.illuminato.

User info:
Registered: Mar 2008
Posts: 179 (0.03 al dì)
Location: Treviglio
Corso: Comunicazione Digitale
Anno: Secondo
Time Online: 15:35:34 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

al 3d ci sto pensando da un pò... magari quando sono più tranquillo ci smanetto...

__________________
"They Can't Stop Us Let Them Try...
for heavy metal we would die..."
(Manowar - Die For Metal)

http://www.jackassubs.com - Admin (in ricerca di traduttori!!!)

13-06-2009 09:20
Click Here to See the Profile for IsaMetallo Click here to Send IsaMetallo a Private Message Find more posts by IsaMetallo Add IsaMetallo to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Supernick
.tritagranchi.

User info:
Registered: Jan 2008
Posts: 323 (0.05 al dì)
Location: Albairate (MI)
Corso: Comunicazione Digitale
Anno:
Time Online: 1 Day, 17:31:17 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Si in effetti ora non è proprio il momento :D

comunque ieri ho provato a fare due cazzatine con mobile processing e sul telefono mi andavano!!
Per chi non va ricordo che bisogna installare J2ME e il Wireless Toolkit

13-06-2009 11:06
Click Here to See the Profile for Supernick Click here to Send Supernick a Private Message Find more posts by Supernick Add Supernick to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 07:39.    Post New Thread    Post A Reply
Pages (2): [1] 2 »   Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.143 seconds (68.14% PHP - 31.86% MySQL) con 25 query.