// C Source File
// Created 19/09/2001; 17:47:51
#define OPTIMIZE_ROM_CALLS // Use ROM Call Optimization
#define SAVE_SCREEN // Save/Restore LCD Contents
#include <all.h> // Include Header Files
short _ti89; // Produce .89Z File
INT_HANDLER save_int_1; // global variables
int x, y, pause, add, count;
int speed, hard, delay;
int nbwall, wallposition[9], wallheight[9];
int top[6]={0,0,-2,-5,-4,1};
int options[4]={0,0,0,0};
unsigned int score;
unsigned int hiscore[10]={20000,15000,10000,8000,6000,4000,2000,1000,500,100};
char hiname[10][4]={"jpf","jpf","jpf","jpf","jpf","jpf","jpf","jpf","jpf","jpf"};
unsigned char ball[8]={0x3C,0x7E,0xFF,0xFF,0xFF,0xFF,0x7E,0x3C};
unsigned char ok[8]={0x4,0x8,0x50,0x20,0x0,0x0,0x0,0x0};
unsigned short wall[8]={0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
unsigned short nowall[8]={0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};
unsigned short line[1]={0xFFFF};
void wait(long time) // to slow the game
{
long n;
for (n=0; n<time; n++) ;
}
void titlescreen(void) // titlescreen drawing
{
DrawStr(2, 2, "1. Play", A_NORMAL);
DrawStr(2, 12, "2. Options", A_NORMAL);
DrawStr(2, 22, "3. High Scores", A_NORMAL);
DrawStr(2, 32, "4. About", A_NORMAL);
DrawStr(2, 42, "5. Quit", A_NORMAL);
wait(100000);
}
void select(void) // select speed and difficulty
{
char n[1];
speed=0, hard=0;
ClrScr();
DrawStr(2,2,"Select speed (1-9)",A_NORMAL);
wait(100000);
while (speed==0)
{
if ((_rowread(0xEF) & 0x2) || (_rowread(0xDF) & 0x80)) speed=1;
if ((_rowread(0xF7) & 0x2) || (_rowread(0xEF) & 0x80)) speed=2;
if ((_rowread(0xFB) & 0x2) || (_rowread(0xF7) & 0x80)) speed=3;
if ((_rowread(0xEF) & 0x4) || (_rowread(0xFB) & 0x80)) speed=4;
if ((_rowread(0xF7) & 0x4) || (_rowread(0xFD) & 0x80)) speed=5;
if (_rowread(0xFB) & 0x4) speed=6;
if (_rowread(0xEF) & 0x8) speed=7;
if (_rowread(0xF7) & 0x8) speed=8;
if (_rowread(0xFB) & 0x8) speed=9;
}
delay=10-speed;
delay*=750;
sprintf(n, "%d", speed);
DrawStr(2,12,n,A_NORMAL);
wait(100000);
DrawStr(2,22,"Select difficulty (1-3)",A_NORMAL);
while (hard==0)
{
if ((_rowread(0xEF) & 0x2) || (_rowread(0xDF) & 0x80)) hard=1;
if ((_rowread(0xF7) & 0x2) || (_rowread(0xEF) & 0x80)) hard=2;
if ((_rowread(0xFB) & 0x2) || (_rowread(0xF7) & 0x80)) hard=3;
}
sprintf(n, "%d", hard);
DrawStr(2,32,n,A_NORMAL);
wait(200000);
ClrScr();
}
void newwall(int position, int nb) // draws a new wall
{
int n;
for(n=0; n<10; n++)
{
if (random(2*hard+1)!=0)
Sprite16(16*n, position, wallheight[nb], wall, LCD_MEM, SPRT_XOR);
}
Sprite16(16*random(9), position, wallheight[nb], nowall, LCD_MEM, SPRT_AND);
}
void startgame(void) // initializes vars and draws first walls
{
y=0, x=75;
pause=8;
score=0;
add=0;
nbwall=4;
wallheight[0]=8;
wallheight[1]=8;
wallheight[2]=8;
wallheight[3]=8;
wallheight[4]=7;
wallheight[5]=6;
wallheight[6]=5;
wallheight[7]=4;
wallheight[8]=3;
wallposition[0]=24;
wallposition[1]=49;
wallposition[2]=74;
wallposition[3]=99;
randomize();
newwall(74,2);
newwall(99,3);
Sprite8(x, y, 8, ball, LCD_MEM, SPRT_XOR);
}
void movewall(void) // moves the walls
{
int n, m;
for (n=0; n<nbwall; n++)
{
if (wallposition[n]==top[nbwall-4])
{
for (m=0; m<10; m++)
{
if (GetPix(16*m, top[nbwall-4]+wallheight[n]-1) && GetPix(16*m+15, top[nbwall-4]+wallheight[n]-1))
Sprite16(16*m, top[nbwall-4], wallheight[n], wall, LCD_MEM, SPRT_XOR);
}
if (add!=2)
{
wallposition[n]=99;
newwall(99,n);
}
else
{
wallposition[n]=200;
wallheight[n]=wallheight[nbwall-1];
}
}
else
{
for (m=0; m<10; m++)
{
if ((wallposition[n]>-1 && GetPix(16*m, wallposition[n]) && GetPix(16*m+15, wallposition[n])) || (wallposition[n]<0 && GetPix(16*m, wallposition[n]+wallheight[n]-1) && GetPix(16*m+15, wallposition[n]+wallheight[n]-1)))
{
Sprite16(16*m, wallposition[n]-1, 1, line, LCD_MEM, SPRT_XOR);
Sprite16(16*m, wallposition[n]+wallheight[n]-1, 1, line, LCD_MEM, SPRT_XOR);
}
}
wallposition[n]--;
}
}
}
void moveball(void) // moves the ball
{
int n, m, t;
t=0;
for (n=0; n<2; n++)
{
for (m=0; m<8; m++)
t+=GetPix(x+m, y+8);
if (t==0)
{
if (y<90)
{
Sprite8(x, y, 8, ball, LCD_MEM, SPRT_XOR);
y+=2;
Sprite8(x, y, 8, ball, LCD_MEM, SPRT_XOR);
}
}
else
{
Sprite8(x, y, 8, ball, LCD_MEM, SPRT_XOR);
y--;
Sprite8(x, y, 8, ball, LCD_MEM, SPRT_XOR);
}
}
if ((_rowread(0xFE) & 0x2) && x>1)
{
t=0;
for (n=0; n<8; n++)
t+=GetPix(x-2, y+n);
if (t==0)
{
Sprite8(x, y, 8, ball, LCD_MEM, SPRT_XOR);
x-=2;
Sprite8(x, y, 8, ball, LCD_MEM, SPRT_XOR);
}
}
if ((_rowread(0xFE) & 0x8) && x<150)
{
t=0;
for (n=0; n<8; n++)
t+=GetPix(x+9, y+n);
if (t==0)
{
Sprite8(x, y, 8, ball, LCD_MEM, SPRT_XOR);
x+=2;
Sprite8(x, y, 8, ball, LCD_MEM, SPRT_XOR);
}
}
}
void testwall(void) // tests wall position
{
int n=0,t=0;
while (n<nbwall && t==0)
{
t+=(wallposition[n]==99-(100-top[nbwall-4])/nbwall);
n++;
}
if (t==1)
{
if (n==nbwall)
n=0;
wallposition[n]=99;
newwall(99,n);
count++;
}
if (count==nbwall-1)
add=0;
}
int game(void) // game function
{
movewall();
moveball();
score++;
if (options[0]==1 && (score==score/3*3))
delay--;
if (!(*(volatile char*)0x60001A & 0x2))
off();
if (y<0 || (_rowread(0xBF) & 0x1))
return 0;
wait(delay);
if (pause==8 && (_rowread(0xDF) & 0x1))
{
wait(100000);
while(!(_rowread(0xDF) & 0x1))
{
idle();
if (!(*(volatile char*)0x60001A & 0x2)) off();
}
pause=0;
}
if (!(_rowread(0xDF) & 0x1) && pause<8)
pause++;
if (options[1]==1 && score!=0 && score==score/500*500)
add=1;
if (add==2) // quand cest execute = BUG!!!!!!!!!!!!!!!!!!!!!!
testwall();
if (add==1 && wallposition[nbwall-1]==99-(100-top[nbwall-3])/(nbwall+1))
{
count=0;
add=2;
nbwall++;
wallposition[nbwall-1]=99;
newwall(99,nbwall-1);
}
return 1;
}
void newhiscore(int nb) // enters new hiscore
{
int n;
void *kbq = kbd_queue ();
unsigned short key;
nb--;
for (n=9; n>nb; n--)
{
hiscore[n]=hiscore[n-1];
strcpy(hiname[n],hiname[n-1]);
}
hiscore[nb]=score;
DrawStr(2, 2, "New High Score !", A_NORMAL);
DrawStr(2, 12, "Please Enter Your Name",A_NORMAL);
wait(70000);
SetIntVec (AUTO_INT_1, save_int_1);
for (n=0; n<4; n++)
{
if (!OSdequeue (&key, kbq))
{
if (key==257)
{
if (n!=0)
{
DrawChar(-4+6*n, 22, hiname[nb][n-1], A_XOR);
n-=2;
}
else
n--;
}
else
{
if (n!=3)
{
DrawChar(2+6*n, 22, key, A_NORMAL);
hiname[nb][n]=key;
}
}
}
else
n--;
}
SetIntVec (AUTO_INT_1, DUMMY_HANDLER);
DrawStr(2, 32, "Press Enter", A_NORMAL);
wait(70000);
while(!((_rowread(0xFD) & 0x1) || (_rowread(0xBF) & 0x1)));
ClrScr();
}
void end(void) // game over
{
char scorestr[20];
int n, m;
float s=1, t=1, fhard=hard;
ClrScr();
if (options[0]==1)
s=1.5;
if (options[1]==1)
t=1.5;
DrawStr(2, 2, "Base Score :", A_NORMAL);
sprintf(scorestr, "%d", score);
DrawStr(46, 2, scorestr, A_NORMAL);
DrawStr(2, 12, "Speed Bonus :", A_NORMAL);
sprintf(scorestr, "* %f", sqrt(speed));
DrawStr(50, 12, scorestr, A_NORMAL);
DrawStr(2, 22, "Difficulty Bonus :", A_NORMAL);
sprintf(scorestr, "* %f", sqrt(fhard/2));
DrawStr(62, 22, scorestr, A_NORMAL);
DrawStr(2, 32, "Acceleration Bonus :", A_NORMAL);
sprintf(scorestr, "* %f", s);
DrawStr(74, 32, scorestr, A_NORMAL);
DrawStr(2, 42, "Wall Bonus :", A_NORMAL);
sprintf(scorestr, "* %f", t);
DrawStr(46, 42, scorestr, A_NORMAL);
score=score*sqrt(speed*fhard/2)*s*t;
DrawStr(2, 52, "Your Score Is :", A_NORMAL);
sprintf(scorestr, "%d", score);
DrawStr(55, 52, scorestr, A_NORMAL);
DrawStr(2, 62, "Press Enter", A_NORMAL);
m=11;
for (n=0; n<10; n++)
m-=(score>hiscore[n]);
wait(70000);
while(!((_rowread(0xFD) & 0x1) || (_rowread(0xBF) & 0x1)));
ClrScr();
if (score>20000)
options[2]=1;
if (m<11)
newhiscore(m);
}
void option(void) // options screen
{
int n, t[4];
ClrScr();
DrawStr(2, 2, "1. Acceleration :", A_NORMAL);
if (options[0]==1)
Sprite8(60, 2, 4, ok, LCD_MEM, SPRT_XOR);
DrawStr(2, 12, "2. Add walls :", A_NORMAL);
if (options[1]==1)
Sprite8(49, 12, 4, ok, LCD_MEM, SPRT_XOR);
if (options[2]==1)
{
DrawStr(2, 22, "3. Reverse mode :", A_NORMAL);
if (options[3]==1)
Sprite8(63, 22, 4, ok, LCD_MEM, SPRT_XOR);
}
DrawStr(2, 32, "Press Enter to exit and save changes", A_NORMAL);
DrawStr(2, 42, "Press Escape to exit without saving changes", A_NORMAL);
for(n=0; n<4; n++)
t[n]=options[n];
while (!(_rowread(0xBF) & 0x1))
{
wait(100000);
if ((_rowread(0xEF) & 0x2) || (_rowread(0xDF) & 0x80))
{
t[0]=(t[0]==0);
Sprite8(60, 2, 4, ok, LCD_MEM, SPRT_XOR);
}
if ((_rowread(0xF7) & 0x2) || (_rowread(0xEF) & 0x80))
{
t[1]=(t[1]==0);
Sprite8(49, 12, 4, ok, LCD_MEM, SPRT_XOR);
}
if (t[2]==1 && ((_rowread(0xFB) & 0x2) || (_rowread(0xF7) & 0x80)))
{
t[3]=(t[3]==0);
Sprite8(63, 22, 4, ok, LCD_MEM, SPRT_XOR);
}
if (_rowread(0xFD) & 0x1)
{
for (n=0; n<4; n++)
options[n]=t[n];
break;
}
}
ClrScr();
}
void showhiscore(void) // hiscores screen
{
int n;
char scorestr[5], nstr[3];
ClrScr();
for (n=0; n<10; n++)
{
sprintf(nstr, "%d.", n+1);
DrawStr(2,2+7*n,nstr,A_NORMAL);
DrawStr(17,2+7*n,hiname[n],A_NORMAL);
sprintf(scorestr, "%d", hiscore[n]);
DrawStr(37,2+7*n,scorestr,A_NORMAL);
}
DrawStr(2,80,"Press Enter",A_NORMAL);
while(!((_rowread(0xFD) & 0x1) || (_rowread(0xBF) & 0x1)));
ClrScr();
}
void about(void) // about screen
{
ClrScr();
DrawStr(2,2,"This game was made by jp !!!!!!!!",A_NORMAL);
DrawStr(2,15,"Here are the keys :",A_NORMAL);
DrawStr(7,25,"Left & Right : Move the ball",A_NORMAL);
DrawStr(7,35,"Apps : Pauses the game",A_NORMAL);
DrawStr(7,45,"Esc : Exits the game",A_NORMAL);
DrawStr(2,58,"Tips :",A_NORMAL);
DrawStr(7,68,"Modify parameters in options menu",A_NORMAL);
DrawStr(7,78,"Beat the first high score...",A_NORMAL);
DrawStr(2,91,"Press Enter",A_NORMAL);
while(!((_rowread(0xFD) & 0x1) || (_rowread(0xBF) & 0x1)));
ClrScr();
}
void _main(void) // Main Function
{
save_int_1 = GetIntVec (AUTO_INT_1);
SetIntVec (AUTO_INT_1, DUMMY_HANDLER); // redirect auto-int 1 to "nothing"
FontSetSys(F_4x6);
ClrScr();
titlescreen();
while (!((_rowread(0xBF) & 0x1) || (_rowread(0xF7) & 0x4) || (_rowread(0xFD) & 0x80)))
{
idle();
if (!(*(volatile char*)0x60001A & 0x2))
off();
if ((_rowread(0xEF) & 0x2) || (_rowread(0xDF) & 0x80))
{
select();
startgame();
while (game());
end();
titlescreen();
}
if ((_rowread(0xF7) & 0x2) || (_rowread(0xEF) & 0x80))
{
option();
titlescreen();
}
if ((_rowread(0xFB) & 0x2) || (_rowread(0xF7) & 0x80))
{
showhiscore();
titlescreen();
}
if ((_rowread(0xEF) & 0x4) || (_rowread(0xFB) & 0x80))
{
about();
titlescreen();
}
}
wait(100000);
SetIntVec (AUTO_INT_1, save_int_1); // restore auto-int 1
}
[edit]Edité par jpflori le 02-10-2001 à 20:36:43[/edit]
Y a deux fesses qui sont sur la plage et l'une dit à l'autre :
"Qu'est ce qu'on fait maintenant ?"
Et l'autre lui répond :
"Ben PROUT !!!"