Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ATTENTION: this code is written in PROCESSING
- //ATTENTION: THIS IS JUST THE SOURCE CODE AND IT WON'T WORK WITHOUT THE RELEVANT FILES.
- // FOR THE FULL, PLAYABLE GAME PLEASE DOWNLOAD:
- // http://www.mediafire.com/?50byk9d04yblqfg
- //For more games and updates follow us on twitter: @d_codes_
- int window_x=700, window_y=500;
- int linelaenge=30, lineabstand=15;
- int liney;
- //Schiffe...
- int schiff1_h=90, schiff2_h=90, schiff1_b=15, schiff2_b=15;
- int xPos1=15, yPos1;
- int xPos2=window_x-xPos1-schiff2_b, yPos2;
- int seitenabstand=5;
- int geschw2; //ycheat;
- //instead of mouseY
- int keypos1=window_y/2;
- int keypos2=window_y/2;
- boolean[] keys;
- //Ball
- int r=10;
- int x=window_x/2, y=window_y/2;
- float yRichtung;
- float xRichtung;
- //Punkte
- int points1=0, points2=0;
- int errPunkte;
- boolean zehner;
- void randomx()
- {
- float xspeed=random(-1,1);
- if (xspeed<=0)
- xRichtung=-1;
- else if (xspeed>0)
- xRichtung=1;
- }
- void randomy()
- {
- float yspeed=random(-1,1);
- if (yspeed<=0)
- yRichtung=-1;
- else if (yspeed>0)
- yRichtung=1;
- }
- PFont texts;
- void setup()
- {
- texts=loadFont("schriftart.vlw");
- size(window_x, window_y);
- smooth();
- //noStroke();
- yPos1=((window_y/2)-(schiff1_h/2));
- yPos2=((window_y/2)-(schiff2_h/2));
- errPunkte=0;
- zehner=false;
- //to move both ships at the same time
- keys=new boolean[4];
- keys[0]=false;
- keys[1]=false;
- keys[2]=false;
- keys[3]=false;
- //ask();
- randomx();
- randomy();
- /*float ystartpos=random(window_y-r,r);
- y=int(ystartpos);*/
- }
- void draw()
- {
- background(40);
- //Mittellinie...
- //fill(255,0,0);
- text(points1 +" : "+ points2, 339, 20, 10);
- for(liney=30; liney <= window_y; liney+=linelaenge+lineabstand){
- line((window_x/2), liney, (window_x/2), liney+linelaenge);
- }
- //Schiff Spieler...
- if (keypos1>=seitenabstand+(schiff1_h/2) && keypos1<=(window_y-seitenabstand-schiff1_h/2))
- yPos1=keypos1-(schiff1_h/2);
- fill(255);
- rect(xPos1, yPos1, schiff1_b, schiff1_h);
- if (keys[0])
- keypos1=keypos1-5;
- else if (keys[1])
- keypos1=keypos1+5;
- //Schiff Computer...
- if (keypos2>=seitenabstand+(schiff1_h/2) && keypos2<=(window_y-seitenabstand-schiff1_h/2))
- yPos2=keypos2-(schiff1_h/2);
- fill(255);
- rect(xPos2, yPos2, schiff2_b, schiff2_h);
- if (keys[2])
- keypos2=keypos2-5;
- else if (keys[3])
- keypos2=keypos2+5;
- //println(yPos2);
- //Ball...
- //Bewegung Ball:
- x+=xRichtung;
- y+=yRichtung;
- //Zeichnung
- fill(240);
- ellipse(x, y, r*2, r*2);
- //Kollision erkennen...
- //oben & unten
- if (y<=r || y>=(window_y-r))
- {
- yRichtung*=-1;
- if (yRichtung<0 && yRichtung>=-6)
- {
- yRichtung-=0.1;
- }
- else if (yRichtung>=0 && yRichtung<=6)
- {
- yRichtung+=0.1;
- }
- }
- //Kollision mit Schiff1
- if (x<=xPos1+schiff1_b+r && y>=yPos1-r/2 && y<=yPos1+schiff1_h+r/2) // Kollision an rechter Seite
- {
- xRichtung*=-1;
- if (xRichtung<=6)
- xRichtung+=0.3;
- }
- if ((y+r)>=yPos1-1 && (y+r)<=yPos1+1 && x>=xPos1-r && x<=(xPos1+schiff1_b+r/2)) //Kollision am oberen Rand
- yRichtung*=-1;
- //Kollision mit Schiff2
- if (x>=xPos2-r && y>=yPos2 && y<=yPos2+schiff1_h)
- {
- xRichtung*=-1;
- if (xRichtung>=-6)
- xRichtung-=0.1;
- }
- /*if (upspeed<=5)
- xRichtung++;
- else if (upspeed*/
- //links
- if (x<-r)
- {
- points2++;
- delay(1000);
- //Nur vorläufig:
- //danach mit start bei gewinner
- x=window_x/2;
- y=window_y/2;
- randomx();
- randomy();
- }
- //rechts
- if (x >= (window_x+r))
- {
- points1++;
- delay(1000);
- //Nur vorläufig:
- //danach mit start bei gewinner
- x=window_x/2;
- y=window_y/2;
- randomx();
- randomy();
- }
- println("speedx: " + xRichtung + " speedy: " + yRichtung);
- }
- void keyPressed()
- {
- //TEST
- /*switch(key)
- {
- case 'q': y=r+1;
- break;
- case 'a': y=window_y-r-1;
- break;
- //Anzahl punkte
- case '0':
- //errPunkte;
- break;
- case 't': yRichtung=1;
- xRichtung=-1;
- x=80; y=40;
- break;
- }*/
- //to move both ships at the same time
- if (key=='w')
- keys[0]=true;
- if (key=='s')
- keys[1]=true;
- if (key=='o')
- keys[2]=true;
- if (key=='l')
- keys[3]=true;
- }
- //to move both ships at the same time
- void keyReleased()
- {
- if (key=='w')
- keys[0]=false;
- if (key=='s')
- keys[1]=false;
- if (key=='o')
- keys[2]=false;
- if (key=='l')
- keys[3]=false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement