It is also the most preliminary simulation, which needs to be perfected. UFO speed problem is still hope that we adjust the speed of gamespeed.
The space is fired, the specific appearance of the launch I did not write.
#include <graphics.h>
#include <math.h>
#include <stdlib.h>
#include <dos.h>
#define KEY_ESC 0x01
#define KEY_SPACE 0x39
#define KEY_UP 0x48
#define KEY_LEFT 0x4b
#define Key_right 0x4d
#define Key_down 0x50
int gamespeed=1200; * * Change the speed of their game
int speed; /* Flying Saucer moving speed * *
int col; /* Center Coordinates * *
int score=0; /* Score * *
Char key_state[128],key_pressed[128]; /* Keyboard Operating variables/
void Init (); /* Initial * *
void Close (); /* Close * *
void PlayGame (); /* Game Process * *
void Prscore (); /* OUTPUT SCORE * *
void Drawm (int x,int y,int color); * * Draw sight/
void Win (); /* Output Final result * *
int getkey (int scancode); /* Here is the start of the key function * *
void interrupt Far (*oldint9handler) ();
void far interrupt NewInt9 ();
void Installkeyboard ();
void Shutdownkeyboard ();
Drawfly (int x,int y,int color); * * Painting flying saucer/
void Main (void)
void Prscore ()/* OUTPUT SCORE * *
{
Char s[10];
Setfillstyle (Solid_fill,black);
Bar (30,0,100,50);
SetColor (6);
Settextstyle (0,0,2);
sprintf (S, "%d", score);
Outtextxy (30,20,s);
}
void Drawm (int x,int y,int color)/* Draw sight/
void Win ()/* Output Final result * *
{
Settextstyle (0,0,4);
SetColor (RED);
if (score>18)
Outtextxy (200,200, "VERY good");
else if (score>10)
Outtextxy (250,200, "good");
Else
Outtextxy (250,200, "~@_@~");
}
void PlayGame ()/* Game Process * *
{
float X,y; * * The coordinates of the UFO * *
int mx,my;
int i,num=0;
for (I=40;I<640;I+=30)
Drawfly (I,65,white);
mx=my=300;
SetColor (15);
Line (0,80,640,80);
Randomize ();
while (NUM<20)
{
Prscore (); /* OUTPUT SCORE * *
Col=random (10); /* Center coordinates random *
col=col*20+200;
Speed=2+random (2); * * Flying Saucer speed random * *
for (x=-250;x<=250;x+=speed) * * Flying saucer Move WHOLE process * *
{
Y=pow ((X/10), 2) +200; /* Find y coordinate * *
Drawfly (X,y,white);
Drawm (Mx,my,yellow);
Delay (gamespeed); /* Interval * *
Drawm (Mx,my,black);
Drawfly (X,y,black);
if (Getkey (KEY_ESC))//End game * *
Break
if (Getkey (Key_left))
mx-=4;
if (Getkey (key_right))
mx+=4;
if (Getkey (Key_down))
my+=4;
if (Getkey (key_up) &&my>100)
my-=4;
if (Getkey (key_space))//* * rounds
{
if (((x+col+10) >= (mx-2) &&x<= (mx+2)) && (y>= (my-2) &&y<= (my+2))/* Here control accuracy * *
{
score++;
Drawfly (X,y,black);
Drawm (Mx,my,yellow);
Prscore ();
Drawm (Mx,my,black);
Break
}
}
if (y>490&&col+x>col)/* Automatically disappears * *
Break
}
if (y<490)
{
SetColor (RED);
Line (40+num*30-10,55,40+num*30+10,75);
Line (40+num*30-10,75,40+num*30+10,55);
}
num++;
if (Getkey (KEY_ESC))//End game * *
Break
}
Win ();
while (1)
}
void Init ()/* Initial * *
{int gd=detect,gm;
Initgraph (&GD,&GM, "C:\TC");
Cleardevice ();
Installkeyboard ();
}
void Close ()/* Shut down */
Drawfly (int x,int y,int color)/* Draw flying saucer * *
void far interrupt NewInt9 (void)
{
unsigned char scancode,temp;
SCANCODE=INPORTB (0x60);
TEMP=INPORTB (0x61);
OUTPORTB (0x61,temp 0x80);
OUTPORTB (0x61,temp & 0x7f);
if (scancode&0x80)
{
scancode&=0x7f;
key_state[scancode]=0;
}
Else
{
Key_state[scancode]=1;
Key_pressed[scancode]=1;
}
OUTPORTB (0x20,0x20);
}
void Installkeyboard (void)
{
int i;
for (i=0;i<128;i++)
key_state[i]=key_pressed[i]=0;
Oldint9handler=getvect (9); /* Interrupt Vector value * *
Setvect (9,NEWINT9); /* Interrupt program NEWINT9 address into the specified interrupt vector table int 09h*/
}
void Shutdownkeyboard (void)
int getkey (int scancode)
{
int res;
Res=key_state[scancode]key_pressed[scancode];
key_pressed[scancode]=0;
return res;
}