Red de conocimiento informático - Espacio del host - Libro de diseño y programación de juegos móviles

Libro de diseño y programación de juegos móviles

El lenguaje C se puede usar para compilar juegos móviles. Puedes decirle que muera, pero tengo el código de Snake. Puedes echarle un vistazo (debes pasarlo compilando con TC)

#include lt;stdlib.hgt;

#include lt;graphics.hgt;

#include lt;bios.hgt; incluir lt;dos.hgt ;

#include lt;conio.hgt

#define Ingresar 7181

#define ESC 283

#define ARRIBA 18432

#define ABAJO 20480

#define IZQUIERDA 19200

#define DERECHA 19712

#ifdef __cplusplus

# define __CPPARGS...

#else

#define __CPPARGS

#endif

interrupción nula (* oldhandler)(__CPPARGS);

interrupción nula newhandler(__CPPARGS)

void SetTimer(interrupción nula (*IntProc)(__CPPARGS)); (void);

p>

void Initgra(void);

void TheFirstBlock(void); p>

void Initsnake(void);

void Initfood(void);

void Snake_Headmv(void);

void Flag(int, int); , int, int);

void GameOver(void);

void Snake_Bodymv(void);

void Snake_Bodyadd(void); p>void PrntScore(void);

void Timer(void);

void Win(void);

void TheSecondBlock(void); >

void Food(void);

void Dsnkorfd(int, int, int);

void Delay(int); /p>

{int x; int y;int color;}Snk[12];

struct Food

{int x;int y;int color;}Fd

int bandera1= 1, bandera2=0, bandera3=0, bandera4=0, bandera5=0, bandera6=0,

checkx, checky, num, clave=0, Tiempos, Puntuación, Hscore, Snkspeed, TimerCo

unter, TureorFalse;

char Sco[2], Tiempo[6]

void main()

{ Initgra(); p>SetTimer(newhandler);

TheFirstBlock();

mientras(1)

{DrawMap();

Snake_Headmv(

GameOver();

Snake_Bodymv();

Snake_Bodyadd()

PrntScore();

Temporizador();

Ganar();

if(clave==ESC)

romper

si( clave==Entrar)

{cleardevice();

ElPrimerBloque();

}

ElSegundoBloque(); >

Comida();

Retraso(Snkspeed);

}

closegraph()

KillTimer();

}

interrupción nula newhandler(__CPPARGS)

{

TimerCounter

oldhandler(); /p>

}

void SetTimer(interrupción nula (*IntProc)(__CPPARGS))

{

oldhandler=getvect(0x1c); /p>

deshabilitar();

setvect(0x1c, IntProc

habilitar()

}

void KillTimer()

{

disable();

setvect(0x1c, oldhandler); p>

p>

}

void Initgra()

{int gd=DETECT,gm

initgraph(amp;gd, amp;gm," d:\\tc");

}

void TheFirstBlock()

{setcolor(11); p>settextstyle(0, 0, 4);

outtextxy(100, 220, "El primer bloque");

bucle: key=bioskey(0); >

if (clave==Entrar)

{cleardevice();

Initsnake()

Initfood(); p>Puntuación=0 ;

Hpuntuación=1;

Snkspeed=10;

num=2;

clave=0;

TureorFalse=1

T;

imerCounter=0;

Tiempo[0]='0'; Tiempo[1]='0'; Tiempo[2]=':'; ]='0'; Tiempo[5]='\0';

}

else if(key==ESC) cleardevice(); else ir al bucle

}

void DrawMap()

{line(10, 10, 470, 10); (470, 10, 470, 470);

línea(470, 470, 10, 470);

línea(10, 470, 10, 10);

línea(480, 20, 620, 20);

línea(620, 20, 620, 460);

línea(620, 460, 480, 460);

line(480, 460, 480, 20);

}

void Initsnake()

{randomize(); /p>

num=2;

Snk[0].x=random(440

Snk[0].x=Snk[0].x-; Snk[0].x20 50;

Snk[0].y=random(440);

Snk[0].y=Snk[0].y-Snk[); 0].y20 50;

Snk[0].color=4

Snk[1].x=Snk[0].x; Snk[1].y=Snk[0].y 20

Snk[1].color=4

}

void Initfood();

{randomize();

Fd.x=random(440

Fd.x=Fd.x-Fd.x20

Fd.x=Fd.x-Fd.x20

p>

p>

Fd.y=random(440);

Fd.y=Fd.y-Fd.y20

Fd.color= aleatorio(14) 1 ;

}

void Snake_Headmv()

{if(bioskey(1))

{key= bioskey(0);

interruptor(tecla)

{caso ARRIBA: Bandera(1, 0, 0, 0); Bandera(0, 1, 0, 0);

caso IZQUIERDA: Bandera (0, 0, 1, 0);

caso DERECHA: Bandera (0, 0); 0, 0, 1 ); romper;

predeterminado: romper

}

}

if(bandera1)

{ checkx=Snk[0].x;

checky=Snk[0].y

Dsnkorfd(Snk[0].x, Snk[0] .y, 0) ;

Snk[0].y-=20

Dsnkorfd(Snk[0].x, Snk[0].y, Snk[0] .color);

}

if(flag2)

{checkx=Snk[0].x

checky=Snk[0].y; >Dsnkorfd(Snk[0].x, Snk[0].y, 0);

Snk[0].y =20

Dsnkorfd(Snk[0]. x, Snk[0].y, Snk[0].color

}

if(flag3)

{checkx=Snk[0] .x;

checky=Snk[0].y;

Dsnkorfd(Snk[0].x, Snk[0].y,

<); p>Snk[0].x-=20;

Dsnkorfd(Snk[0].x, Snk[0].y, Snk[0].color

); }

if(flag4)

{checkx=Snk[0].x

checky=Snk[0].y; p>Dsnkorfd(Snk[0].x, Snk[0].y, 0

Snk[0].x =20

Dsnkorfd(Snk[0]); .x, Snk[0].y, Snk[0].color);

}

}

void Flag(int a, int b, int c, int d)

{flag1=a; bandera2=b; bandera3=c; bandera4=d;}

void GameOver()

{ int i;

if(Snk[0].xlt; 20||Snk[0].xgt; 460||Snk[0].ylt; 20||Snk[0].ygt; 460 )

{cleardevice();

setcolor(11);

settextstyle(0, 0, 4); 160, 220, "Juego terminado");

loop1: key=bioskey(0);

if(key==Enter)

{cleardevice(

ElPrimerBloque();

}

else

if(key==ESC)

cleardevice();

else

ir a loop1;

}

for(i=3; ilt; num; i )

{if(Snk[0].x==Snk[i].xamp;amp;Snk[0].y==Snk[i].y)

{cleardevice ();

setcolor(11);

settextstyle(0, 0, 4);

outtextxy(160, 220, "Juego terminado");

loop2:key=bioskey(0);

if(key==Enter)

{cleardevice();

TheFirstBlock; ();

}

si no

if(clave==ESC)

cleardevice();

else ir a bucle2

}

}

}

void Snake_Bodymv()

{int i, s, t

for(i=1; ilt; num; i)

{Dsnkorfd (checkx, checky, Snk[i].color

Dsnkorfd(Snk[i].x, Snk[i].y,

s=Snk[); i].x;

t=Snk[i].y;

Snk[i].x=checkx

Snk[i].y; =checky;

checkx=s;

checky=t;

}

}

void Comida ()

{if(flag5)

{randomize();

Fd.x=random(440); .x=Fd.x-Fd.x20 30;

Fd.y=aleatorio(440);

Fd.y=Fd.y-Fd.y20

p>

Fd.y=random(440);

p>

Fd.color=random(14)

flag5=0; >

}

Dsnkorfd(Fd.x, Fd.y, Fd.color

}

void Snake_Bodyadd()

;

{if(Snk[0].x==Fd.xamp;amp;Snk [0].y==Fd.y)

{if(Snk[num-1].xgt ; Snk[num-2].x)

{num;

Snk[num-1].x=Snk[num-2].x 20;

Snk[num-1].y=Snk[num-2].y

Snk[num-1].color=Fd.color

}

else

if(Snk[num-1 ].xlt;Snk[num-2].x)

{num

Snk[num-1].x=Snk[num-2].x-20

Snk[num-1].y=Snk[num-2].y

;

Snk[num-1].color=Fd.color;

}

else

if(Snk[num-1].ygt; Snk[num-2].y)

{num

p>

Snk[num-1].x=Snk[num-2].x;

Snk[num-1].y=Snk[num-2].y 20;

Snk[num-1].color=Fd.color

}

else

if(Snk[num-1] .ylt;Snk[num-2].y)

{num

<; p>Snk[num-1].x=Snk[num-2].x;

Snk[num-1].y=Snk[num-2].y-20; >

Snk[núm-1].color

=Fd.color;

}

flag5=1;

Puntuación

}

}

void PrntScore()

{if(Hscore!=Puntuación)

{setcolor(11

settextstyle(0, 0); , 3);

outtextxy(490, 100, "PUNTUACIÓN");

setcolor(2);

setfillstyle(1, 0); p>

setcolor(2);

setfillstyle(1,0);

p>

rectángulo(520, 140, 580, 180); >

inundación(530, 145, 2);

Sco[0]=(char)(Puntuación 48 );

Sco[1]='\0';

Hscore=Puntuación;

setcolor(4);

settextstyle (0, 0, 3); 150, Sco);

}

}

Temporizador vacío( )

{if(TimerCountergt; 18)

{Tiempo[4]=(char)(Tiempo[4]-1

if(Tiempo [4]lt; '0')

{Tiempo[); 4]='9';

Tiempo[3]=(char)(Tiempo[3]-1

}

if(Tiempo[); 3]lt;'0')

{Tiempo[3]='5';

Tiempo[1]=(char)(Tiempo[1]-1); /p>

}

if(TureorFalse)

{setcolor(11);

settextstyle(0, 0, 3); >

outtextxy(490, 240, "TIMER");

setcolor(2);

setfillstyle(1, 0); 490, 280, 610, 320);

inundación(530, 300, 2);

setcolor(11); 3);

outtextxy(495, 290, Hora);

TureorFalse=0;

}

if(Tiempo[1); ]=='0'amp; Tiempo[3]=='0'amp; Tiempo[4]=='0 ')

{setcolor(11);

settextstyle(0, 0, 4);

outtextxy(160, 220, "Juego terminado");

bucle:key=bioskey(0); >

if(clave==Entrar)

{cleardevice();

ElPrimerBloque (); if(key==ESC) cleardevice();

else ir al bucle;

}

TimerCounter=0

TureorFalse=1

}

}

void Win()

{if(Puntuación==3)

Veces

if(Veces==2)

{cleardevice();

setcolor(11);

settextstyle(0, 0, 4);

outtextxy(160, 220, "Tú Win");

bucle: key=bioskey(0);

if(key==Enter)

{cleardevice();

ElPrimerBloque();

clave=0;

}

else if(clave==ESC) cleardevice(); p>de lo contrario ir al bucle

}

}

void TheSecondBlock()

{if(Score==3) p>

{cleardevice();

setcolor(11);

settextstyle(0, 0, 4); , 220 , "El segundo bloque");

bucle: key=bioskey(0);

if(key==Enter)

{cleardevice(

Initsnake();

Initfood();

Puntuación=0

Hscore=1;

Snkspeed=8;

num=2

clave=0

}

si no(clave==; ESC) cleardevice();

else ir al bucle

}

}

void Dsnkorfd(int x, int y, int color)

{setcolor(color);

setfillstyle(1, color

círculo(x, y, 10); p> inundación(x, y, color);

}

retraso vacío(int veces)

{int i; for( i=1; ilt; = veces; i )

retraso(15000

}