Hier mein Sourcecode!
Wer Verbesserungsvorschläge hat, einfach melden!
int ballx, bally,richtung,player=1,com=0,zeit=2300,tick,punkt,treffx,treffy,dif,finish;
int ziel,adockbreite=40,ageschwindigkeit=60,dockbreite,geschwindigkeit,lastTouch;
int punkte[3];
int dock[3];
bool score,treffen;
void Ton() {
PlayTone(1000, 2);
}
void showdock(int p,int y) {
int x;
x=dock[p]+dockbreite;
LineOut(dock[p],y,x,y);
}
void Countdown(string txt,int fr) {
TextOut(50,30,"Ready?");
TextOut(Random(80),Random(20),txt);
Wait(200);
ClearScreen();
PlayTone(1000,fr);
}
void RandomX() {
switch (Random(6)) {
case 1: richtung=270; break;
case 2: richtung=280; break;
case 3: richtung=260; break;
case 4: richtung=90; break;
case 5: richtung=100; break;
case 0: richtung=80; break;
}
}
void neu() {
ballx=1750;
bally=1000;
geschwindigkeit=ageschwindigkeit+100;
dockbreite=adockbreite;
RandomX();
punkt=0;
ClearScreen();
Countdown("1",70);
Countdown("2",70);
Countdown("3",70);
Countdown("GO!",200);
tick=CurrentTick();
}
int Anfang(int max, int min, string text1, string text2,string text3,string text4,int player,int waitt) {
while (!ButtonPressed(BTN4, true)){
if (ButtonPressed(BTN2 ,true)) {
player++;
Ton();
}
if (ButtonPressed(BTN3 ,true)) {
player--;
Ton();
}
if (player<min) {player=min; }
if (player>max) {player=max; }
NumOut(10,30,player);
TextOut(0,60,text1);
TextOut(0,50,text2);
TextOut(0,10,text3);
TextOut(0,0,text4);
Wait(waitt);
ClearScreen();
}
Ton();
while (ButtonPressed(BTN4, true)) {}
return player;
}
bool boolFrage(string t1,string t2, string t3, string t4) {
if (Anfang(2,1,t1,t2,t3,t4,1,130)==1) { return true;}
else {return false;}
}
void menue() {
score=true; ziel=3;
player=Anfang(2,1,"Wie viele","Spieler spielen mit?","max. 2","",1,130);
if (player==1) { com=Anfang(4,0,"Willst du","gegen einen Com","spielen? 0=Nein","hoch -> stark",2,130);dock[0]=30;}
treffen=boolFrage("(2)Willst du auf","Fehler spielen?","oder Punkte","treffen(1)");
if (!treffen) {
ziel=Anfang(200,1,"Auf wie viele","Fehler spielen?","","",3,130);
finish=ziel;
ArrayInit(punkte,0,3);
} else {
ziel=Anfang(200,1,"Wie viele","Treffer","werden fuer den","Sieg benoetigt?",3,130);
ArrayInit(punkte,ziel,3);
finish=0;
}
if (!boolFrage("Standardspiel","spielen?","1 -> Ja","2 -> Nein")) {
adockbreite=Anfang(70,10,"Wie gross soll","das Dock sein?"," "," ",40,40);
ageschwindigkeit=Anfang(80,20,"Wie schnell soll","der Ball sein?","Fast <--> Slow","",60,40);
zeit=Anfang(100,3,"Wie schnell soll","es schwieriger","werden?","Fast <--> Slow",23,40);
zeit*=100;
score=boolFrage("Score","aktivieren?","moeglichst lange","1 = >Ja");
}
if (treffen) {
treffx=Random(1750);
treffy=Random(1000);
}
}
void show() {
int x=ballx/35,y=bally/35;
CircleOut(x,y,2);
CircleOut(x,y,1);
}
void explo(int r) {
Wait(20);
CircleOut(treffx/35,treffy/35,r);
}
void Fertig() {
if (boolFrage("GAME OVER","Willst du ein","neues Spiel mit","gleichen Einst. starten?")) {
neu();
if (!treffen) {
ArrayInit(punkte,0,3);
} else {
ArrayInit(punkte,ziel,3);
}
} else {
StopAllTasks();
}
}
void prall(int p) {
int x=ballx/35;
int x2=dock[p]+dockbreite;
x2+=4;
int mitte=(x2+dock[p]-4)/2;
if (x>dock[p]-4&&x<x2) {
richtung=360-richtung;
Ton();
if (p==1) {
if (x>mitte) {
richtung=richtung-x+mitte;
} else {
richtung=richtung+mitte-x;
}
bally+=80;
} else {
if (x>mitte) {
richtung=richtung+x-mitte;
} else {
richtung=richtung-mitte+x;
}
bally-=80;
}
lastTouch=p;
} else {
PlayTone(3000, 3);
Wait(100);
PlayTone(2000, 3);
Wait(100);
PlayTone(1500, 2);
Wait(100);
Ton();
Wait(100);
PlayTone(500,5);
CircleOut(ballx/35,bally/35,6);
Wait(2000);
ResetRotationCount(OUT_A);
if (player>1) {ResetRotationCount(OUT_B);}
neu();
punkte[p]++;
}
}
void zeig(int r) {
CircleOut(ballx/35,bally/35,r);
}
void Treffer() {
punkte[lastTouch]--;
explo(3);
PlayTone(500,5);
explo(4);
Ton();
explo(5);
PlayTone(1500, 2);
explo(6);
PlayTone(2000, 3);
explo(7);
PlayTone(3000, 3);
explo(8);
treffx=Random(3500);
treffy=Random(2000);
}
task main() {
menue();
neu();
while (true) {
Wait(geschwindigkeit);
ClearScreen();
///////////////////////////////////////////////////////////////////
showdock(1,0);
show();
if (player<3) {NumOut(0,20,punkte[1]);}
if (score) {NumOut(0,40,punkt); punkt++;}
///////////////////////////////////////////////////////////////////
dock[1]=MotorRotationCount(OUT_A)/3+30;
if (bally<100) {
prall(1);
}
if (player==1&&com==0) {
if (bally>2100) {
richtung=360-richtung;
Ton(); bally-=60;
}
}
if (ballx<100||ballx>3400) {richtung=180-richtung; Ton();}
ballx+=Cos(richtung);
bally+=Sin(richtung);
///////////////////////////////////////////////////////////////////
if (player>1&&com==0) {
dock[2]=MotorRotationCount(OUT_B)/3+30;
showdock(2,63);
if (bally>2200) {
prall(2);
}
if (player<3) {NumOut(85,40,punkte[2]);}
}
///////////////////////////////////////////////////////////////////
if (treffen) {
CircleOut(treffx/35,treffy/35,3);
if (treffy<bally+150&&treffy>bally-150&&treffx<ballx+150&&treffx>ballx-150) {
Treffer();
}
}
if (punkte[1]==finish) {Fertig();}
if (punkte[2]==finish&&player>1) {Fertig();}
if (punkte[0]==finish&&com>0) {Fertig();}
///////////////////////////////////////////////////////////////////
if (com>0) {
if (ballx/35>dock[0]+10){ dock[0]+=com;}
if (ballx/35<dock[0]+10){ dock[0]-=com;}
showdock(0,63);
if (bally>2200) {
prall(0);
}
NumOut(85,40,punkte[0]);
}
///////////////////////////////////////////////////////////////////
dif=CurrentTick()-tick;
if (dif>zeit) {
if (geschwindigkeit<30&&geschwindigkeit>10) {geschwindigkeit--;}
if (geschwindigkeit>ageschwindigkeit) { geschwindigkeit-=100; zeig(5); PlayTone(1500, 3); Wait(100); zeig(6);zeig(7);PlayTone(3000, 3);Wait(100);zeig(8);PlayTone(500, 3);}
else if (geschwindigkeit>29) {geschwindigkeit=geschwindigkeit-7;}
if(dockbreite>3) {dockbreite--;}
tick=CurrentTick();
}
}
}