Code:
#include <dos.h>
#include "MGF.H"
#include <conio.h>
#include <bios.h>
#include <stdio.h>
#define GRAPHMODE 0x13
#define TEXTMODE 0x02
struct track_sec {
int x;
int y;
int start;
} track_1[1000];
void iniz_track1() {
track_1[0].start = true;
track_1[0].x = track_1[0].y = 10;
}
void setmode13() {
union REGS r;
r.x.ax = GRAPHMODE;
int86(0x10, &r, &r);
}
int quit = false;
void restoretextmode() {
union REGS r;
r.x.ax = TEXTMODE;
int86(0x10, &r, &r);
}
int get_key() {
char key = '\0';
if(kbhit()) key = getch();
return key;
}
MGF_CAR you;
MGF_CAR you_90;
MGF_CAR you_180;
MGF_CAR you_270;
MGF_CAR erase;
MGF_CAR tree;
MGF_CAR comp;
MGF_CAR comp_90;
MGF_CAR comp_180;
MGF_CAR comp_270;
MGF_ROAD road;
void gameloop() {
you = open_car("you.mgf");
you_90= open_car("you_90.mgf");
you_180 = open_car("you_180.mgf");
you_270 = open_car("you_270.mgf");
erase = open_car("youerase.mgf");
tree = open_car("tree.mgf");
comp = open_car("comp.mgf");
comp_90=open_car("comp_90.mgf");
comp_180 = open_car("comp_180.mgf");
comp_270 = open_car("comp_270.mgf");
road = open_road("road1.mgf");
for(int x = 0; x < 200; x++) {
for(int y = 0; y < 200; y++) {
writepix(x, y, 33);
}
}
//cout>>"Ahhhh...."; getch();
int px = 10, py = 10, cy = 10, cx = 21;
int key;
fflush(stdin);
unsigned short type = 2;
display_road(road, 10, 10);
display_road(road, 31 ,10);
display_car(you_180, 10, 10);
display_car(comp_180 ,10, 21);
while(1) {
key = _bios_keybrd(_KEYBRD_READY);
fflush(stdin);
if((char)key == 's') {type += (type==4?-3:1); cy += 2; printf("R");} // Right SHIFT
if((char)key == 'q') {break;}
//if(key != 0) printf("%c", key);
else {
if(type == 1) px ++;
else if(type == 3) px--;
else if(type == 2) py ++;
else py --;
cy++;
delay(50);
}
//display_car(erase, py, px);
for(int x = py; x <= py+10; x ++) {
writepix(x, px, 50);
}
display_road(road, 10, 10);
display_road(road, 31, 10);
display_car((type==1?you_90:(type==2?you_180:(type==3?you_270:you))), py, px);
display_car((type==1?comp_90:(type==2?comp_180:(type==3?comp_270:you))), cy, cx);
//break;
}
/*display_car(you, 20, 20);
display_road(road, 130, 40);
display_car(you, 130, 40);
getch();
display_road(road, 130, 40);
display_car(you, 128, 40);
display_car(tree, 2, 100);
display_car(erase ,20, 20);
display_car(you, 18, 20);
display_car(comp, 100, 100);
getch();
display_car(erase, 100, 100);
display_car(comp_90, 100, 100);
getch();
//display_car(erase, 100, 100);
display_car(erase, 100, 100);
display_car(comp_180, 100, 100);
getch();
display_car(erase, 18, 20);
display_car(you, 16, 20);
getch();
display_car(erase, 100, 100);
display_car(comp_270, 100, 100);
getch();
display_car(erase, 16, 20);
display_car(you_90, 16, 20);
getch();
display_car(erase, 100, 100);
display_car(erase, 16, 20);
display_car(you_180, 16, 20);
getch();
display_car(erase, 16, 20);
display_car(you_270, 16, 20);
getch();
display_car(erase, 16, 20);
display_car(you_270, 16, 18);
getch();*/
}
int main() {
cout<<"RACER 1.00\n";
iniz_track1();
setmode13();
while(!quit) {
gameloop();
quit = true;
}
restoretextmode();
return 0;
}
Graphics.H:
Code:
#ifndef MGF_H
#include "graphics.h"
#include <fstream.h>
struct MGF_FILE {
//int colors;
char data[320][200];
int x;
int y;
};
struct MGF_ROAD {
//int colors;
char data[30][30];
int x;
int y;
};
struct MGF_CAR {
//int colors;
char data[10][10];
int x;
int y;
};
MGF_FILE open(char file[]) {
int x, y, array = 0;
MGF_FILE mgf;
char line[64000];
ifstream input(file);
input>>line; //Problem???
mgf.y = (int)line[0] - 33;
mgf.x = (int)line[1] - 33;
input>>line;
for(x = 0; x < mgf.y; x++) {
for(y = 0; y < mgf.x; y++, array++) {
mgf.data[x][y] = line[array];
}
}
input.close();
return mgf;
}
MGF_ROAD open_road(char file[]) {
int x, y, array = 0;
MGF_ROAD mgf;
char line[900];
ifstream input(file);
input>>line; //Problem???
mgf.y = (int)line[0] - 33;
mgf.x = (int)line[1] - 33;
input>>line;
for(x = 0; x < mgf.y; x++) {
for(y = 0; y < mgf.x; y++, array++) {
mgf.data[x][y] = line[array];
}
}
input.close();
return mgf;
}
MGF_CAR open_car(char file[]) {
int x, y, array = 0;
MGF_CAR mgf;
char line[100];
ifstream input(file);
input>>line; //Problem???
mgf.y = (int)line[0] - 33;
mgf.x = (int)line[1] - 33;
input>>line;
for(x = 0; x < mgf.y; x++) {
for(y = 0; y < mgf.x; y++, array++) {
mgf.data[x][y] = line[array];
}
}
input.close();
return mgf;
}
void display(MGF_FILE mgf, int x, int y) {
int a, b;
for(a = 0; a < mgf.x; a++) {
for(b = 0; b < mgf.y; b++) {
if(a + x < 320 && b + y < 200) {
writepix(a + x, b + y, (int)mgf.data[a][b]);
}
}
}
}
void display_car(MGF_CAR mgf, int x, int y) {
int a, b;
for(a = 0; a < mgf.x; a++) {
for(b = 0; b < mgf.y; b++) {
if(a + x < 320 && b + y < 200) {
if(mgf.data[a][b] != 126) writepix(a + x, b + y, (int)mgf.data[a][b]);
}
}
}
}
void display_road(MGF_ROAD mgf, int x, int y) {
int a, b;
for(a = 0; a < mgf.x; a++) {
for(b = 0; b < mgf.y; b++) {
if(a + x < 320 && b + y < 200) {
writepix(a + x, b + y, (int)mgf.data[a][b]);
}
}
}
}
MGF_FILE iniz() {
MGF_FILE mgf;
for(int x = 0; x < 320; x ++) {
for(int y = 0; y < 200; y ++) {
mgf.data[x][y] = 0;
}
}
mgf.x = 0;
mgf.y = 0;
//return mgf;
}
#define MGF_H
#endif