Thread: Help on first game

  1. #1
    C maniac
    Join Date
    Aug 2004
    Location
    Cyberwarping to Middle Earth
    Posts
    154

    Question Help on first game

    I am trying to create a simple game that I call RACER.
    My attempts all use DOS graphics. Every so once in a while, I get an error message: "Windows protection error. You need to restart your computer." and then shuts down after 30 seconds.
    Any suggestions?

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Does this only occur when running your game? Because it sounds like a virus or something. If it's not a virus, you're probably doing something very bad. Let's see some code (we can't help you otherwise).
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Post some code which crashes - preferably not too much.
    It's obvious that you're doing something wrong, but we could be a lot more specific if we had some code to look at.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    C maniac
    Join Date
    Aug 2004
    Location
    Cyberwarping to Middle Earth
    Posts
    154
    Hunter2, it only happens when I am running my game.


    Main.CPP:
    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 GRAPH_H
    void writepix(int x, int y, int color) {
    	union REGS r;
    	r.h.ah = 12;
    	r.h.al = color;
    	r.x.dx = x;
    	r.x.cx = y;
    	int86(0x10, &r, &r);
    }
    #define GRAPH_H
    #endif
    MGF.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
    Last edited by kawk; 08-12-2004 at 01:36 PM. Reason: No code posted

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > char line[64000];
    DOS programs have an absolute upper limit of stack space of 64K
    Unless you do something special, I think the default is only a couple of K or so.

    > MGF_FILE open(char file[]) {
    That structure is also close to 64K in size, and you're attempting to return it BY VALUE
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    C maniac
    Join Date
    Aug 2004
    Location
    Cyberwarping to Middle Earth
    Posts
    154
    Salem, It doesn't work even if I reduce the size of line[64000] to 100. Any other suggestions?

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Yeah, your return type is still 64K

    > void display(MGF_FILE mgf, int x, int y) {
    And again, another 64K block on the stack
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    C maniac
    Join Date
    Aug 2004
    Location
    Cyberwarping to Middle Earth
    Posts
    154
    Salem, how about if I comment those all out, and look at MGF_CAR instead? I never use
    MGF_FILE, at least not that I know of.
    Last edited by kawk; 08-12-2004 at 02:39 PM. Reason: Spelling error

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Open Source / Semi Open source game idea. Help needed
    By CaptainPatent in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 05-16-2007, 10:44 AM
  3. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 03:46 PM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM