





|
|
Source code
Here you have the full source code for Pic-Rogue v1.0
running on a P.I.P.E.R. Please take this is as a curiosity...
I am going to free the source but is forbidden any
commercial use of It. Feel free to modify or distribute, but just give
me some reports about what youre doing!
And here the code:
#define XMAX 21
#define YMAX 9
#define NMONSTER 7
#define NUMSPELL 11
#define L1 48
#define L2 58
//Definimos el keyboard
#define PROBSPEC 10
#define UP PIN_C1
#define DOWN PIN_C4
#define LEFT PIN_C2
#define RIGHT PIN_C3
#define PB1 PIN_A3
#define PB2 PIN_A4
#define PB3 PIN_A5
#define PB4 PIN_C0
#zero_ram
//Vamos a meter en la eprom los datos de l apantalla inicial
y la pantalla final
#rom 0x2100
={1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9 }
#define RUSTS 0b00000001
#define FREEZE 0b00000010
#define STING 0b00000100
#define DROPLEVEL 0b00001000
#define DRAINLIFE 0b00010000
#define CONFUSES 0b00100000
#define POISON 0b10000000
int selectedspell;
int1 seeall=0;
int dano;
int1 inicio=0;
int xtrap[3],ytrap[3];
int xsp,ysp;
int1 menuflag;
int1 chestflag;
//#define FAST_GLCD
//#define RAND_MAX 256
int1 FUP,FDOWN,FLEFT,FRIGHT;
int veneno;
typedef struct NPC{
int x,y;
int HP;
int AC;
int attack;
int damage;
int special;
int type;
int level;
int1 visible;
int1 dead;
int power;
int HPMAX;
int1 freezed;
int1 confused;
};
//En total 17 bytes
typedef struct entity{
char name[8];
int x,y;
int special;
};
const char monsters[26][8]={
"Player ",
"Goblin ",
"Orclord",
" Ogre ",
" Troll ",
" Human ",
" Elf ",
" Dwarf ",
" Gnome ",
"Skelet ",
" Zombi ",
" Ghoul ",
"Vampire",
"Wraith ",
"Centaur",
"Unicorn",
"Minos ",//14
"Hydra ",
"GelCube",
"Argoyle",//20
"Leprech",
"Sprite ",
" Nymph ",
" Golem ",
"Griffon",
"Dragon ",
};
const int ta_monsters[26][7]={
//EL primero es el jugador!!
//El esquema es
// HP AC hit dmg special id level
10, 1, 50, 5, 0, 0, 1,
2, 1, 30, 6, 0, 1, 1,
5, 2, 40, 8, 0, 2, 2,
12, 3, 40, 10, 0, 3, 3,
23, 5, 50, 14, CONFUSES, 4, 6,
5, 2, 40, 8, 0, 5, 2,
5, 1, 40, 4, 0, 6, 2,
7, 3, 50, 10, 0, 7, 3,
2, 0, 25, 3, 0, 8, 1,
5, 1, 30, 4, 0, 9, 2,
10, 2, 20, 4, POISON, 10, 3,
15, 2, 40, 5, DRAINLIFE, 11, 5,
22, 2, 20, 6, DRAINLIFE, 12, 5,
27, 2, 30, 6, DROPLEVEL, 13, 7,
16, 3, 40, 8, 0, 14, 4,
21, 3, 30, 10, FREEZE, 15, 5,
31, 5, 50, 12, 0, 16, 7,
21, 2, 70, 6, 0, 17, 6,
11, 0, 20, 3, FREEZE, 19, 1,
12, 2, 50, 8, FREEZE, 20, 2,
5, 4, 20, 0, STING, 21, 3,
11, 5, 30, 5, STING, 22, 4,
11, 5, 30, 6, RUSTS, 23, 5,
44, 4, 40, 10, CONFUSES, 24, 8,
25, 3, 50, 8, 0, 25, 6,
51, 5, 70, 12, CONFUSES, 18, 9,
};
const char spechit[7][9]={
"rusts! ",
"freeze! ",
"stings! ",
"amnesy! ",
"drains! ",
"stuns! ",
"poisons!",
};
const char deco[5][7]={
"armor ",
"attack",
"weapon",
"health",
"power ",
};
const char level1[5][8]={
"Mines",
"Cavern",
"Minion",
"Dungeon",
"Lair",
};
const char monstersL[26][2]={
"k",
"g",
"o",
"O",
"T",
"H",
"E",
"d",
"b",
"s",
"z",
"r",
"v",
"w",
"c",
"u",
"m",//14
"y",
"J",
"a",//20
"L",
"p",
"n",
"G",
"R",
"D",
};
const char spells[13][9]={
"Shield ",
"Rockskin",
"Cold ray",
"Heal ",
"Bless ",
"Seeall ",
"Fireball",
"Storm ",
"Teleport",
"Unfreeze",
"Seetraps",
"Paralyze",
"Unpoison",
};
const char mstart[20]={"Button1 for Start!"};
const char final1[9]={"You win!"};
const char nombre[18]={"By M.Lopez Coloma"};
//30 bytes
int act_level=1;//1b
int act_map[24];
//30b para un matriz de 20 x 10
char muro[] = "#";
char baldosa[] = ".";
char out[] = ">";
char trap[] = "%";
char chest[] = "+";
int exp=0;
int xout,yout;
int1 seetraps;
int AC,att;//buffer for spells
char stats[21];
struct NPC monster[7];//68
void init();
void pantallaintro();
void gen_level();
void blit();
void genmonsters();
int los(int x1, int y1, int x2, int y2, int1 color);
void newlevel();
void actualiza();
void traps();
void specat(int id);
void decoration();
void msg(L2);
int randi(int max)
{
return get_timer0()%max;
}
void cartel()
{
strcpy(stats, "#Pic Rogue#");
glcd_text57(1, 10, stats, 2, OFF);
}
void waitforinput()
{
while(1)
{
if(input(PB1))
{
while(input(PB1)){}
return;
}
}
}
void pantallaintro()
{
int i;
glcd_fillScreen(OFF);
cartel();
sprintf(stats, "Level %U",act_level);
glcd_text57(41, 30, stats, 1, OFF);
sprintf(stats, "%S %S ",monsters[act_level],level1[randi(5)]);
glcd_text57(18, 40, stats, 1, OFF);
strcpy(stats,mstart);
glcd_text57(10, L2, stats, 1, OFF);
waitforinput();
}
void pintabloque(int x,int y,int color)
{
//Aquí tenemos que buscar el byte que corresponde:
int byteobj,bitobj;
int xt,yt;
byteobj=(x+y*21)/8;
//y ahora a qué bit del byte:
bitobj = (x+y*21)%8;
if(color==1) bit_set(act_map[byteobj],bitobj);else
bit_clear(act_map[byteobj],bitobj);
}
int1 leebloque(int x,int y)//devuelve el color del bloque
{
//Aquí tenemos que buscar el byte que corresponde:
int byteobj,bitobj;
int xt,yt;
byteobj=(x+y*21)/8;
//y ahora a qué bit del byte:
bitobj = (x+y*21)%8;
return bit_test(act_map[byteobj],bitobj);
}
void borramapa()
{
int byteobj;
for(byteobj=0;byteobj<24;byteobj++)
{
act_map[byteobj]=0x00;
}
}
void blit()
{
//Esto vuelca act_map en la memoria del display.
//Vamos recorriendo el array byte a byte
//y en cada byte pintaremos f bits
int byteobj,bitobj,count;
int x,y,xt,yt;
int1 color;
glcd_fillScreen(OFF);
for(xt=0;xt<21;xt++)
{
for(yt=0;yt<9;yt++)
{
//if(leebloque(xt,yt)==1){glcd_text57(xt*6,yt*6, baldosa, 1,
0);}else {glcd_text57(xt*6,yt*6, muro, 1, 0);}
if(leebloque(xt,yt)==1){glcd_text57(xt*6,yt*6, baldosa, 1,
0);}
else if( leebloque(xt,yt)==0 && (leebloque(xt+1,yt)==1 ||
leebloque(xt-1,yt)==1 || leebloque(xt,yt+1)==1 ||
leebloque(xt,yt-1)==1)){glcd_text57(xt*6,yt*6, muro, 1, 0);}
// else{glcd_text57(xt*5,yt*5, baldosa, 1, 0);}
// if( leebloque(xt,yt)==1 && (leebloque(xt+1,yt) ==
leebloque(xt-1,yt)) && (leebloque(xt,yt+1)==
leebloque(xt,yt-1))&&(leebloque(xt+1,yt)==
leebloque(xt,yt-1))){glcd_text57(xt*5,yt*5, puerta, 1, 0);}
}
}
}
void borrabloque(int xt,int yt)
{
glcd_text57(xt*6,yt*6, baldosa, 1, 1);
}
void gen_level()
{
int x,y,xt,yt,width,height,z,count;
int xp[6];
int yp[6];
borramapa();
//Vamos a dividir aleatoriamente el mapa en secciones
//First we divide the 20x10 grid into 6 different pieces
evitando que se solapen los bloques
//y dejndo margen para un mínimo de tamaño de las
habitaciones.
//Pra hacer los pasadizos vamos a guardar un punto de cada
habitación
for(count=0;count<2;count++)//Para cada habitacion
{
for(z=0;z<3;z++)//Para cada habitacion
{
x=randi(2); //Las habitaciones empiezan entre 0 y 1
(relativo a divs)
y=randi(2)+count;//O entre 0 y 1 para Y.
width=randi(3)+3;//rango 3-5
// if(width+x+12>20)width=20-12-x;
height=randi(2)+2;//rango 3-4
//Tomamos un punto al azar de la habitación
//y hora tenemos que pintar en el mapa la habitacion que
hemos generado.
//Teneos que poner en alto un determindo bit del byte
correspondiente
for(xt=x+8*z;xt<x+8*z+width;xt++)
{
for(yt=y+4*count;yt<y+height+4*count;yt++)
{
pintabloque(xt,yt,1);
}
}
xp[z+3*count]=randi(width)+x+8*z;
yp[z+3*count]=randi(height)+y+4*count;
//pintabloque(xp[z+3],yp[z+3],0);
}
}
for(count=0;count<6;count++)//6 corredores
{
//Ahora vamos a unir al azar los nodos entre sí con 6
corredores:
//Elegimos el nodo inicial y el final
//Para cda habitcion la unimos a otra al azar
//width=randi()%6;
width=count;
repite:;
height=randi(6);
if(height==width){goto repite;}
//pintabloque(xp[width],yp[width],0);
//pintabloque(xp[height],yp[height],0);
//Podemos hacerlo de tres maneras:
//1.Igualar X
//2.Igualr Y
//3.Partido
//Partiendo del punto inicial
x=xp[width];
y=yp[width];
//Calculamos el "porcentaje de giro"
if(xp[height]>x){z=(xp[height]-x)/2;} else
{z=(x-xp[height])/2;}
do{
//Añadimos o restamos un valor a X hasta que la diferencia
entre ambos puntos sea cero
if(x>xp[height]){x--;}else{x++;}
pintabloque(x,y,1);
if(xp[height]>x){xt=xp[height]-x;} else {xt=x-xp[height];}
//blit();
}while(xt!=z);
//Ahora hacemos lo mismo pero con la y: modificamos la y
hasta que sea igual que la del objetivo
do{
//Añadimos o restamos un valor a X hasta que la diferencia
entre ambos puntos sea cero
if(y>yp[height]){y--;}else{y++;}
pintabloque(x,y,1);
if(yp[height]>y){yt=yp[height]-y;} else {yt=y-yp[height];}
//blit();
}while(yt!=0);
//Y terminamos igualando las X también
do{
//Añadimos o restamos un valor a X hasta que la diferencia
entre ambos puntos sea cero
if(x>xp[height]){x--;}else{x++;}
pintabloque(x,y,1);
if(xp[height]>x){xt=xp[height]-x;} else {xt=x-xp[height];}
//blit();
}while(xt!=0);
//blit(); //Volcamos el mapa a la memoria del LCD
}
//glcd_pixel(105,60,1);
}
void marco(){
glcd_line(1,58,127,58,1);
}
void place(int id)
{
repiteloc2:
monster[id].x=randi(21);
monster[id].y=randi(9);
if(leebloque(monster[id].x,monster[id].y)!=1) {goto
repiteloc2;}
}
void genmonsters()
{
int i,id,kx,ky;
//inicio==1 es que me lee la tabla del jugador, si es cero
no toca las stats
for(i=0;i<NMONSTER;i++)
{
//elegimos el monstruo según el nivel
//Esto hbrá que ponerlo luego
monstrep:
id=randi(act_level)+1;
if(i==1){id=act_level;}
if(i==0){id=0;}
//Cargamos el monstruo en la estructura
place(i);
sprintf(stats, "%U",i);
// glcd_text57(0,0, stats, 1, 1);
if(inicio==1 && i==0){goto nolees;}
monster[i].HP=ta_monsters[id][0];
monster[i].HPMAX=monster[i].HP;
monster[i].AC=ta_monsters[id][1];
monster[i].attack=ta_monsters[id][2];
monster[i].damage=ta_monsters[id][3];
monster[i].special=ta_monsters[id][4];
monster[i].type=id;
monster[i].dead=0;
monster[i].level=ta_monsters[id][6];
monster[i].freezed=0;
monster[i].confused=0;
nolees:;
if(i>0){
monster[i].visible=los(monster[0].x,monster[0].y,monster[i].x,monster[i].y,1);
}
else
{
monster[i].visible=0;
dano=monster[0].damage;
ac=monster[0].ac;
att=monster[0].attack;
}
}
}
void castspell(int id)
{
int i;
//0"-shield ",
//1"-rockskin",
//2"-cold ray",
//3"-heal ",
//4"-Bless ",
//5"-seeall ",
//6"-fireball",
//7"-Storm ",
//8"-teleport",
//9"-unfreeze",
//10"-traps ",
if(monster[0].power<id){return;}
monster[0].power-=id;
switch(id){
case 0: //Esto es shield, aumenta AC en +1
AC=monster[0].AC;
monster[0].AC++;
//actualiza();
break;
case 1: //Rockskin
AC=monster[0].AC;
monster[0].AC+=3;
//actualiza();
break;
case 2: //coldray hace un ataque 1d12
dano=monster[0].damage;
monster[0].damage=12;
break;
case 3: //heals completely the player
monster[0].HP= monster[0].HPMAX;
//actualiza();
break;
case 4: //Bless increases attack
att=monster[0].attack;
monster[0].attack+=1;
break;
case 5: //draw everybody
seeall=1;//will override los test in mueve()
actualiza();
break;
case 6: //Fireball damage 1d24...maybe zone damage if enough
rom?
dano=monster[0].damage;
monster[0].damage=24;
break;
case 7: //Storm will damage 1d36
dano=monster[0].damage;
monster[0].damage=36;
break;
case 8: //Teleport elsewhere randomly
borrabloque(monster[0].x,monster[0].y);
place(0);
strcpy(stats, monstersL[0]);
glcd_text57(monster[0].x*6,monster[0].y*6, stats, 1, 1);
break;
case 9: //unfreeze...cures freeze??
monster[0].freezed=0;
break;
case 10: //traps...paint traps
seetraps=1;
traps();
break;
case 11: //freeze...get freeze special
bit_set(monster[0].special,0);
break;
case 12: //unpoison
veneno=0;
break;
}
}
void specat(int id)
{
int i,spectipe,prob;
/*
"RUSTS",
"FREEZE",
"STING",
"DRAINXP",
"DRAINHP",
"CONFUSES",
"POISON",*/
i=monster[id].special;
if(i==0){return;}
//prob=randi(100);
if(randi(100)<PROBSPEC)
{
if(bit_test(i,0) ){monster[0].damage--;spectipe=0;}
if(bit_test(i,1) ){monster[0].freezed=1;spectipe=1;}
if(bit_test(i,2) ){monster[0].attack-=10;spectipe=2;}
if(bit_test(i,3) ){exp/=2;spectipe=3;}
if(bit_test(i,4)
){monster[0].HP/=2;monster[0].HPMAX/=2;spectipe=4;}
if(bit_test(i,5) ){monster[0].confused=1;spectipe=5;}
if(bit_test(i,6) ){veneno=1;spectipe=6;}
sprintf(stats,"Attack %S ",spechit[spectipe]);
// glcd_text57(1, L2, stats, 1, 1);
msg(L2);
}
}
void msg(int pos)
{
glcd_text57(1, pos, stats, 1, 1);
}
void menu()
{
if(menuflag==0)
{
// sprintf(stats, "Hp%U/%U Po%U %S",
monster[0].HP,monster[0].HPMAX,monster[0].power,spells[selectedspell]);
sprintf(stats, "HP%U/%U At%U Dm%U AC%U ",
monster[0].HP,monster[0].HPMAX,monster[0].attack,monster[0].damage,monster[0].AC);
// glcd_text57(1, L2, stats, 1, 1);
msg(L2);
}
else
{
// sprintf(stats, "Xp%U Lv%U Dm%U %S", exp,
monster[0].level,monster[0].damage,spells[selectedspell]);
// sprintf(stats, "Xp%U Lv%U At%U Dm%U", exp,
monster[0].level,monster[0].attack,monster[0].damage);
sprintf(stats, "Xp%U Lv%U Po%U %S", exp,
monster[0].level,monster[0].power,spells[selectedspell]);
msg(L2);
// glcd_text57(1, L2, stats, 1, 1);
}
}
//Devuelve 1 si hay LOS
int1 los(int x1, int y1, int x2, int y2, int1 color)
{
signed int x, y, addx, addy, dx, dy;
signed long P;
int i;
dx = abs((signed int)(x2 - x1));
dy = abs((signed int)(y2 - y1));
x = x1;
y = y1;
if(x1 > x2)
addx = -1;
else
addx = 1;
if(y1 > y2)
addy = -1;
else
addy = 1;
if(dx >= dy)
{
P = 2*dy - dx;
for(i=0; i<=dx; ++i)
{
//strcpy(stats,"+");
//glcd_text57(x*5,y*5, stats, 1, 1);
if(leebloque(x,y)==0){return 1;}
if(P < 0)
{
P += 2*dy;
x += addx;
}
else
{
P += 2*dy - 2*dx;
x += addx;
y += addy;
}
}
}
else
{
P = 2*dx - dy;
for(i=0; i<=dy; ++i)
{
//strcpy(stats,"+");
//glcd_text57(x*5,y*5, stats, 1, 1);
if(leebloque(x,y)==0){return 1;}
if(P < 0)
{
P += 2*dx;
y += addy;
}
else
{
P += 2*dx - 2*dy;
x += addx;
y += addy;
}
}
}
return 0;
}
int1 inrange(int xobj,int yobj, int xcenter, int ycenter)
{
}
void death()
{
sprintf(stats, "You have been killed!");
msg(L2);
waitforinput();
reset_cpu();
}
void attack(int fighter,int objective)
{
int dmg;
//Lo primero es mover el mensaje anterior arriba!!
//Tiramos 1d100
//glcd_text57(1, 55, stats, 1, ON);
if( (randi(100))<(monster[fighter].attack))
{//Entonces le hemos dado
//Tiramos 1-Dmg y le restamos la AC del personaje, menor
daño
dmg=randi(monster[fighter].damage);
if(dmg<monster[objective].AC){return;}
else {
dmg-=monster[objective].AC;
if(monster[objective].HP<dmg)
{
monster[objective].dead=1;
sprintf(stats, "Killed %S
",monsters[monster[objective].type]);
//strcpy(stats,"ataque con exito!");
msg(L2);
//glcd_text57(1, L2, stats, 1, ON);
delay_ms(500);
exp+=monster[objective].level;
if(objective==0)
{
death();
}
}
else
{
monster[objective].HP-=dmg;
specat(fighter);
delay_ms(500);
sprintf(stats, "%S does %U dmg!
",monsters[monster[fighter].type],dmg);
//strcpy(stats,"ataque con exito!");
msg(L2);
//glcd_text57(1, L2, stats, 1, ON);
delay_ms(500);
specat(fighter);
delay_ms(500);
}
}
}
else
{sprintf(stats, "%S fails
attack",monsters[monster[fighter].type]);
msg(L2);
//glcd_text57(1, L2, stats, 1, ON);
delay_ms(500);
}
if(fighter==0){monster[0].damage=dano;}
}
void confuse()
{
FLEFT=randi(2);
FRIGHT=randi(2);
FUP=randi(2);
FDOWN=randi(2);
}
int filtra(int *a,int max)
{
if(*a==(max)){*a=max-1;}
if(*a==255){*a=0;}
}
void mueve()
{
int xlocal,ylocal,i,z,id;
for(id=0;id<NMONSTER;id++)
{
if (monster[id].dead==1 || monster[id].freezed==1
){continue;}
//Vamos a hacer que si un mostruo es visible vaya directo
contra el jugador
//si no se quedara con movimientos al azar
//Esto hay que cambiarlo para los demás monstruos
if(id>0)
{
if(monster[id].visible==0)
{
//Aqui tienen que ir a por el jugador por el camino más
rápido.
//No hay problemas de chocar con paredes porque siempre se
verán!
//Vemos qué x es mayor
if(monster[id].x>monster[0].x){FLEFT=1;FRIGHT=0;goto
ya;}else{FRIGHT=1;FLEFT=0;goto ya;}
if(monster[id].y>monster[0].y){FUP=1;FDOWN=0;goto
ya;}else{FDOWN=1;FUP=0;goto ya;}
if(monster[id].x==monster[0].x){FLEFT=0;FRIGHT=0;}
if(monster[id].y==monster[0].y){FUP=0;FDOWN=0;}
}
}
else{if((monster[0].confused==1)){confuse();if((randi(100)<50)){monster[0].confused=0;}}}
ya:
xlocal=monster[id].x-FLEFT+FRIGHT;
ylocal=monster[id].y-FUP+FDOWN;
//si hay que moverse, comprueba que donde vas es muro, con
lo que deshaces el incremento
//entoces mueve y borra el caracter anterior
//0 es muro y 1 baldosa
filtra(&xlocal,21);
filtra(&ylocal,9);
if(leebloque(xlocal,ylocal)==1)//esto es que se puede mover
{
//si el movimiento te lleva a la casilla que ocupa el
jugador
//entonces haz la rutina de ataque y no te muevas!
//El jugador nunca se puede atacar por lo que me ahorro el
if
//Aqui hay que hacer una rutina para que te ataquen!!!???
//Si tienes al jugador pegado a ti ataca!!
for(z=0;z<NMONSTER;z++)
{
//Comprobamos si es el jugador el que ataca a cada mosntruo
if(xlocal==monster[z].x && ylocal==monster[z].y)
{
//pero que no se ataquen entre monstruos!!
if(monster[z].dead==0) //ataca solo si el monstruo esta vivo
{
if((z==0 || id==0)&&(z!=id)){attack(id,z);goto
nomuevas;}else{goto nomuevas;}
}
}
//hay que cambiar y separar el ataque
//si el monstruo esta muerto hay que hacer que pueda andar
por el!!!
}
borrabloque(monster[id].x,monster[id].y);
monster[id].x=xlocal;monster[id].y=ylocal;
nomuevas:;
if(id>0){monster[id].visible=los(monster[0].x,monster[0].y,monster[id].x,monster[id].y,1);}else{monster[id].visible=0;}
if(seeall==1){monster[id].visible=0;}
if(monster[id].visible==0 )
{
if(id>0){strcpy(stats,
monstersL[monster[id].type]);}else{strcpy(stats,
monstersL[0]);}
glcd_text57(monster[id].x*6,monster[id].y*6, stats, 1, 1);
}
}
if(randi(100)<50){monster[id].freezed=0;}
}
if(los(monster[0].x,monster[0].y,xout,yout,1)==0)
{
glcd_text57(xout*6,yout*6, out, 1, 1);
}
monster[0].HP-=veneno;
if(monster[0].HP==0){death();}
}
//Esto se puede optimizar par que sólo dibuje lo que quiero
void actualiza()
{
//Ahora los eventos de cambio de tiempo son solo al moverse
el jugador.
mueve();
traps();
decoration();
menu();
}
#separate
void placespecial(int *x,int *y)
{
repitefunc:
*x=randi(21);
*y=randi(9);
//glcd_text57(xout*5,yout*5, out, 1, 1);
delay_ms(50);
if(leebloque(*x,*y)!=1) {goto repitefunc;}
}
void init()
{
int i;
int *pt1,*pt2;
gen_level();
genmonsters();
blit();
placespecial(&xout,&yout);
// glcd_text57(xout*5,yout*5, out, 1, 1);
for(i=0;i<3;i++)
{
pt1=&xtrap[i];
pt2=&ytrap[i];
//Joder esto hay que sacarlo de aqui!!!
// placespecial(xtrap,ytrap);
// placespecial(xsp,ysp);
placespecial(pt1,pt2);
placespecial(&xsp,&ysp);
}
}
void decoration()
{
int i;
if(xsp==monster[0].x && ysp==monster[0].y && chestflag==0)
{
i=randi(6);
switch(i)
{
case 0: monster[0].AC+=1;
if (monster[0].AC>9){monster[0].AC=9;}
break;
case 1: monster[0].attack+=5;
break;
case 2: monster[0].damage+=1;
break;
case 3: monster[0].HPMAX+=2;
break;
case 4: monster[0].power+=2;
break;
}
sprintf(stats, "Improved %S ",deco[i]);
msg(L2);
//glcd_text57(1, L2, stats, 1, 1);
chestflag=1;
delay_ms(500);
}
if(los(monster[0].x,monster[0].y,xsp,ysp,1)==0)
{
strcpy(stats, chest);
glcd_text57(xsp*6, ysp*6, stats, 1, 1);
}
}
//OPT se puede quitar que los monstruos caigan en las
trampas 50 bytes
void traps()
{
int i;
for(i=0;i<3;i++)
{
if(xtrap[i]==monster[0].x && ytrap[i]==monster[0].y)
{
monster[0].HP/=2;
strcpy(stats, "Got Caught on a trap!");
msg(L2);
//glcd_text57(1, L2, stats, 1, 1);
delay_ms(500);
}
if(seetraps==1)
{
strcpy(stats, trap);
glcd_text57(xtrap[i]*6, ytrap[i]*6, stats, 1, 1);
}
}
}
void readkey(){
FUP=0;FDOWN=0;FLEFT=0;FRIGHT=0;
if(input(PB1))
{
newlevel();
return;
}
if(input(PB2))
{
delay_ms(10);
if(menuflag==1){menuflag=0;}else{menuflag=1;}
menu();
return;
}
if(input(PB3))
{
//blit();
//mueve();
castspell(selectedspell);
delay_ms(500);
return;
}
//0"-shield ",
//1"-rockskin",
//2"-cold ray",
//3"-heal ",
//4"-Bless ",
//5"-seeall ",
//6"-fireball",
//7"-Storm ",
//8"-teleport",
if(input(PB4))
{
delay_ms(10);
while(input(PB4)){}
if(selectedspell++>NUMSPELL){selectedspell=0;}
menu();
return;
}
if(input(UP))
{
FUP=1;
delay_ms(10);
actualiza();
return;
}
if(input(DOWN))
{
FDOWN=1;
delay_ms(10);
actualiza();
return;
}
if(input(LEFT))
{
FLEFT=1;
delay_ms(10);
actualiza();
return;
}
if(input(RIGHT))
{
FRIGHT=1;
delay_ms(10);
actualiza();
return;
}
if(xout==monster[0].x && yout==monster[0].y &&
chestflag==1){newlevel();}
}
void selectmenu()
{
while(!input(PB1))
{
if(input(UP))
{while(input(UP)){}sprintf(stats, "-");glcd_text57(59,
12+5*monster[0].y, stats, 1,
1);if(monster[0].y>0){monster[0].y--;}}
if(input(DOWN))
{while(input(DOWN)){}sprintf(stats, "-");glcd_text57(59,
12+5*monster[0].y, stats, 1,
1);if(monster[0].y<3){monster[0].y++;}}
sprintf(stats, "+");
glcd_text57(59, 12+5*monster[0].y, stats, 1, 1);
//sprintf(stats, "menu %U",player.y);
//glcd_text57(3, 59, stats, 1, 1);
}
}
void newlevel()
{
pantallaintro();
init();
actualiza();
if(act_level++>25)
{
glcd_fillScreen(OFF);
cartel();
strcpy(stats, final1);
glcd_text57(30, 30, stats, 1, 0);
strcpy(stats,nombre);
msg(58);//glcd_text57(1, 58, stats, 1, OFF);
waitforinput();
reset_cpu();
}
seeall=0;
seetraps=0;
monster[0].AC=AC;
monster[0].attack=att;
monster[0].freezed=0;
monster[0].confused=0;
bit_clear(monster[0].special,0);
chestflag=0;
}
void checkxp()
{
//el jugador sube de nivel cada 10 de xp
if(exp>10)
{
exp=0;
monster[0].level++;
//ahora aumentan todas sus caracteristicas
monster[0].HP+=1;
monster[0].AC+=1;
monster[0].attack+=1;
monster[0].damage+=1;
monster[0].HPMAX=monster[0].HP;
}
}
void main() {
int x;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
delay_ms(200);
set_tris_a(0b00111000);
glcd_init(ON);
delay_ms(200);
newlevel();
inicio=1;//esto indica que no modifique al personaje en los
nuevos gens!!
// marco();
// barralateral();
// menu();
while(1){
//read_EEPROM (0);
readkey();
checkxp();
}
// Draw the clock circle
delay_ms(200);
}
|
|