#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<time.h>
int xp=39,yp=23,xt=1,yt=1,xb=1,yb,yh,hp=3,stg=1,i,cnt=0;
int input,tekan;
void delay(int n) {
int i;
for(i=0; i<n*n*n*5; i++);
}
void loading(int cnt) {
_setcursortype(_NOCURSOR);
clrscr();
textcolor(LIGHTBLUE);
gotoxy(34,8); cprintf(“NOW LOADING”);
textcolor(BROWN);
gotoxy(25,18); cprintf(“==============================”);
gotoxy(24,18); cprintf(“/”);
gotoxy(24,19); cprintf(“|”);
gotoxy(24,20); cprintf(“\\”);
gotoxy(25,20); cprintf(“==============================”);
gotoxy(55,18); cprintf(“\\”);
gotoxy(55,19); cprintf(“|”);
gotoxy(55,20); cprintf(“/”);
textcolor(LIGHTBLUE+BLINK);
gotoxy(31,22); cprintf(“…PLEASE WAIT…”);
for(cnt=0;cnt<30;cnt++) {
textcolor(GREEN);
gotoxy(25+cnt,19); cprintf(“%c”,1);
delay(400);
}
}
void menu(int tekan) {
_setcursortype(_NOCURSOR);
clrscr();
textcolor(CYAN);
gotoxy(2, 6); cprintf(“=== MAIN MENU ===”);
gotoxy(2, 9); cprintf(“1. Start Game”);
gotoxy(2,11); cprintf(“2. View Help”);
gotoxy(2,13); cprintf(“Esc. Quit Game”);
textcolor(CYAN+BLINK);
gotoxy(2,3); cprintf(“WELCOME TO SPACE INVADER”);
tekan=getch();
switch(tekan) {
case’1′ : break;
case’2′ : {
clrscr();
textcolor(GREEN);
gotoxy(2, 2); cprintf(“W = Move Up”);
gotoxy(2, 4); cprintf(“S = Move Down”);
gotoxy(2, 6); cprintf(“A = Move Left”);
gotoxy(2, 8); cprintf(“D = Move Right”);
gotoxy(2,10); cprintf(“Enter = Fire”);
gotoxy(2,13); cprintf(“Esc = Quit Game”);
textcolor(GREEN+BLINK);
gotoxy(5,20);
cprintf(“…Press Any Key To Continue…”);
getch();
break;
}
case 27 : exit(10);
}
}
void pesawat(int xp, int yp) {
_setcursortype(_NOCURSOR);
textcolor(RED);
gotoxy(xp,yp-1); cprintf(“*”);
textcolor(LIGHTBLUE);
gotoxy(xp,yp); cprintf(“|”);
gotoxy(xp-1,yp+1); cprintf(“|-|”);
gotoxy(xp-1,yp+2); cprintf(“/ \\”);
}
void gerak(int input) {
_setcursortype(_NOCURSOR);
switch(input) {
case ‘d’ : xp++; break;
case ‘a’ : xp–; break;
case ‘w’ : yp–; break;
case ’s’ : yp++; break;
}
}
void bullet(int xp, int yp) {
_setcursortype(_NOCURSOR);
for(xb=xp,yb=yp-2,yh=yb+1;xb>xt,yb>yt;yb–,yh–) {
gotoxy(xb,yb);
textcolor(RED);
cprintf(“*”);
gotoxy(xb,yh);
printf(” “);
delay(100);
}
}
void kena(int xt, int yt) {
_setcursortype(_NOCURSOR);
hp++;
stg++;
gotoxy(xt,yt);
delay(350);
printf(” “);
printf(“+1 HP”);
delay(350);
}
void main()
{
_setcursortype(_NOCURSOR);
textmode(C80);
loading(cnt);
delay(300);
menu(tekan);
delay(300);
randomize();
do {
fflush(stdin);
xt=random(50)+3;
yt=random(10)+1;
do {
clrscr();
fflush(stdin);
textcolor(YELLOW);
gotoxy(74,22); cprintf(“HP = %d”,hp);
gotoxy(71,24); cprintf(“STAGE = %d”,stg);
pesawat(xp,yp);
if(xp<=2) xp++;
else if(xp>=55) xp–;
else if(yp<=13) yp++;
else if(yp>=22) yp–;
textcolor(LIGHTGREEN);
gotoxy(xt,yt); cprintf(“%c”,2);
input=getch();
gerak(input);
if(input==13) {
bullet(xp,yp);
if(xb==xt && yb==yt) {
kena(xt,yt);
xt=random(50)+3;
yt=random(10)+1;
}
else {
gotoxy(xb,yb-1);
textcolor(LIGHTRED);
cprintf(“-1 HP”);
delay(400);
hp–;
}
}
if(hp==0 || input==27) {
break;
}
if(stg>10) {
break;
}
}
while(input!=27);
clrscr();
if(stg>10) {
textcolor(LIGHTMAGENTA);
gotoxy(30,7); cprintf(“THANK YOU FOR PLAYING”);
getch();
clrscr();
break;
}
else {
textcolor(LIGHTMAGENTA);
gotoxy(36,10); cprintf(“YOU LOSE”);
gotoxy(22,15); cprintf(“DO YOU WANT TO PLAY AGAIN ? … [Y/N]“);
input=getch();
if(input==121) {
clrscr();
hp=3;
stg=1;
continue;
}
else if(input==110) break;
clrscr();
break;
}
}
while(hp>0);
}