Ejemplo n.º 1
0
void _main(void)
{
	OldInt1 = GetIntVec (AUTO_INT_1);
	OldInt2 = GetIntVec (AUTO_INT_2);
	SetIntVec (AUTO_INT_1, DUMMY_HANDLER);
  SetIntVec (AUTO_INT_2, myint2);
  	
	pSnd_EnableSound ();
	pSnd_InstallSound ();
	
	pSnd_PlayMode (MONO);
	pSnd_SetTempo (90);
		
	pSnd_PlaySound_voice1 (channel);
	
	pSnd_SetState (ALLVOICES);
	
	while ((_keytest (RR_ESC)!=TRUE) && (pSnd_VoiceState()));
		
	pSnd_UninstallSound ();
	pSnd_DisableSound ();
	
	SetIntVec (AUTO_INT_1, OldInt1);
	SetIntVec (AUTO_INT_2, OldInt2);
}
Ejemplo n.º 2
0
void _main(void)
{
  OldInt5 = GetIntVec (AUTO_INT_5);
  SetIntVec (AUTO_INT_5, MyInt5);
  while (!kbhit()) printf_xy (50, 50, "Counter = %d  ", Counter);
  SetIntVec (AUTO_INT_5, OldInt5);
  GKeyFlush ();
}
Ejemplo n.º 3
0
static inline void Cleanup(void) {
	GrayOff();
	SetIntVec(AUTO_INT_1,interrupt1);
	free(virtual_dark);
	free(virtual_light);
	free(dbuffer);
}
Ejemplo n.º 4
0
void _main(void) {

   INT_HANDLER int1 = GetIntVec(AUTO_INT_1);
   INT_HANDLER int5 = GetIntVec(AUTO_INT_5);
   SetIntVec(AUTO_INT_1, DUMMY_HANDLER);
   SetIntVec(AUTO_INT_5, DUMMY_HANDLER);
   GrayOn();  ////  everything above is just magic, you need it but
//don't need to understand it.
   clrscr();

   Sprite8(0,0,8,square,GetPlane(0),SPRT_XOR);
   Sprite8(8,0,8,square,GetPlane(1),SPRT_XOR);
   Sprite8(16,0,8,square,GetPlane(0),SPRT_XOR);
   Sprite8(16,0,8,square,GetPlane(1),SPRT_XOR);

   while(!_keytest(RR_ENTER));

   GrayOff();
   SetIntVec(AUTO_INT_1, int1);
   SetIntVec(AUTO_INT_5, int5);

}
Ejemplo n.º 5
0
void _main(void)
{
  INT_HANDLER ai1,ai5;
  void *bloc=malloc(BIG_VSCREEN_SIZE*2+LCD_SIZE*2); // 1 big_vscreen et 1 écran virtuel
  void *vecran,*big_vscreen;
  LCD_BUFFER backbuffer;

  LCD_save(backbuffer);

  if(!bloc)
    return;

// Initialisations
  vecran=bloc;

  big_vscreen=bloc+LCD_SIZE*2;

  ai1=GetIntVec(AUTO_INT_1);
  ai5=GetIntVec(AUTO_INT_5);
  SetIntVec(AUTO_INT_1,DUMMY_HANDLER);
  SetIntVec(AUTO_INT_5,DUMMY_HANDLER);

  if(GrayOn())
  {
    RenderMaps(big_vscreen,vecran);
    GrayOff();
  }

  SetIntVec(AUTO_INT_1,ai1);
  SetIntVec(AUTO_INT_5,ai5);

  free(bloc);
  LCD_restore(backbuffer);
  GKeyFlush();
  ST_helpMsg(EXTGRAPH_VERSION_PWDSTR);
}
Ejemplo n.º 6
0
static inline int Gray_prep(void) {
	// turn interrupts off and set up a fake interrupt for graymode to use.
	interrupt1 = GetIntVec(AUTO_INT_1);
	SetIntVec(AUTO_INT_1, DUMMY_HANDLER);
	
	if (!GrayOn())
		return QUIT;
	
	dbuffer = malloc(GRAYDBUFFER_SIZE); // allocate space for double-buffering
	if (!dbuffer)
		return QUIT;
	
	GrayDBufInit(dbuffer); // enable double-buffering
	return 0;
}
Ejemplo n.º 7
0
//=============================================================================
// as usual our main function ...
//=============================================================================
void _main(void) {
    LCD_BUFFER  lcd;
    LCD_BUFFER  doublebuffer;
    short       i;
    short       ball_to_update;
    INT_HANDLER oldint1        = GetIntVec(AUTO_INT_1);  // fetch default interrupt handler
    INT_HANDLER oldint5        = GetIntVec(AUTO_INT_5);  // fetch default interrupt handler

    // save screen
    LCD_save(lcd);

    // install dummy interrupt handlers for AUTO_INT1 and AUTO_INT5
    SetIntVec(AUTO_INT_1,DUMMY_HANDLER);
    SetIntVec(AUTO_INT_5,DUMMY_HANDLER);

    do {
        // clear doublebuffer
        memset(doublebuffer,0,LCD_SIZE);
        for (i=0;i<NR_BALLS;i++) {
            // NOTE: DRAWSPRITE is a macro defined at the beginning of this file!
            DRAWSPRITE(balls[i].x,balls[i].y);
        }


        // copy double buffer to visible screen
        FastCopyScreen_R(doublebuffer,LCD_MEM);

        for (ball_to_update=0;ball_to_update<NR_BALLS;ball_to_update++) {
            // calculate new position of ball which should get updated
            CalcNewPosition(&balls[ball_to_update],max_x,max_y);


            // loop over all possible combinations and check for collision ...
            for (i=0;i<NR_BALLS;i++) {
                if (i==ball_to_update) continue; // don't check against myself

                // NOTE: TESTCOLLIDE is a macro defined at the beginning of this file!
                if (TESTCOLLIDE(balls[ball_to_update].newx,balls[ball_to_update].newy,balls[i].newx,balls[i].newy)) {
                    // collision detected -> exchange dirx/diry of involved balls
                    ExchangeDirections(&balls[ball_to_update],&balls[i]);

                    // recalculate new position of ball which should get updated
                    CalcNewPosition(&balls[ball_to_update],max_x,max_y);

                    // if we still stick together than this opponent then this
                    // is not the right target to change my direction ...
                    if (TESTCOLLIDE(balls[ball_to_update].newx,balls[ball_to_update].newy,balls[i].newx,balls[i].newy)) {
                        ExchangeDirections(&balls[ball_to_update],&balls[i]);
                        CalcNewPosition(&balls[ball_to_update],max_x,max_y);
                    }
                }
            }

            // NOTE: this demo is somewhat sloppy. Normally we should not
            //       proceed if a collision is detected AND we shouldn't do the
            //       VERY simple collision detection routine above.
            //       But I don't care about this. It seems to be good enough
            //       to demonstrate the bouncing balls ...
            balls[ball_to_update].x = balls[ball_to_update].newx;
            balls[ball_to_update].y = balls[ball_to_update].newy;
        }
    }
    while (!EscapePressed());

    // restore old interrupt handlers
    SetIntVec(AUTO_INT_1,oldint1);
    SetIntVec(AUTO_INT_5,oldint5);

    // restore screen
    LCD_restore(lcd);

    // empty the keyboard buffer and write "powered by ..." string
    GKeyFlush();
    ST_helpMsg(EXTGRAPH_VERSION_PWDSTR);

}
Ejemplo n.º 8
0
// Main Function
void _main(void) {
	// This is where the level map is defined
	// The map is 12 blocks of height 8 tall, and that fills the screen
	// 0s are blank, 1s are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20] = {
		{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
		{8,7,0,0,0,9,7,9,7,0,0,0,0,0,9,8,8,8,8,8},
		{0,0,7,0,9,0,0,0,0,7,0,0,0,9,0,0,0,0,0,0},
		{0,0,0,8,0,0,0,0,0,0,7,0,9,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,9,7,0,0},
		{0,0,0,0,0,0,0,9,7,0,0,0,0,0,0,9,0,0,7,0},
		{0,9,8,8,7,0,9,0,0,7,0,0,0,0,9,0,0,0,0,8},
		{8,0,0,0,0,8,0,0,0,0,7,0,0,9,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,7,9,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};	
	int key=0;
	int laser = 0;
	int justLaser = 0;
	int missile = 0;
	int justMissile = 0;
	int missileSlow = 2;
	short int keys[8];
	POSITION laserPos;
	POSITION oldLaserPos;
	POSITION missilePos;
	POSITION oldMissilePos;
	POSITION oldRType;
	POSITION rTypePos = {0,4};
	int score = 0;
	int forward = 0;
	//int map_x_location=0;
	//POSITION pos = {80,5};
	//int pos = 0;
	INT_HANDLER interrupt1 = GetIntVec(AUTO_INT_1);  // this will save auto int 1

	// print a simple title and disclaimer
	clrscr();
	printf("A game by Ben Cherry \nversion 0.2 Beta \nUse at your own risk! \nreport any bugs to me\nArrow keys - move ship\n2nd-fire straight laser\ndiamond-fire down missile\nDestroy the blocks!\nGame may become unstable\npast the ground raise!\nPress Enter to Begin");
	while (ngetchx() != KEY_ENTER){}   
	clrscr();

	// seed the random numbers
	randomize();
	
	// get the key masks	
	getKeyMasks(keys);

	// DESTROY auto-interrupt 1 so as not to mess up _rowread
	SetIntVec(AUTO_INT_1,DUMMY_HANDLER);

	if (!GrayOn ()) return;

	Draw_Map(map1, rTypePos, laserPos, laser, missilePos, missile);
	
	
	// the main game loop
	while (!quit()) {
		
		// if the user has a missile out, deal with it
		if (missile && missileSlow == 2) {
			missileSlow = 1;
			oldMissilePos = missilePos;
			missilePos.x++;
			missilePos.y++;
			if (missilePos.x > 20) missile = 0;
			if (blowWall(missilePos,map1)) {
				map1[missilePos.y][missilePos.x]-=2;//= 0;
				/**/score++;
				/**/if (map1[missilePos.y][missilePos.x] < 0) map1[missilePos.y][missilePos.x] = 0;
				missile = 0;
				justMissile = 0;
				Draw_Map(map1,rTypePos,laserPos,laser,missilePos,missile);
			}
			// if the shot was just fired, then there wont be one to erase
			if (!justMissile && missile) {
				moveMissile(oldMissilePos,missilePos);
			} else if (missile) {
				drawMissile(missilePos);
				justMissile = 0;
			}
		} else {
			missileSlow++;
		}
		
		// if the user has a laser shot that is still going, continue it
		if (laser) {
			oldLaserPos = laserPos;
			laserPos.x++;
			if (laserPos.x > 20) laser=0;
			if (blowWall(laserPos,map1)) {
				map1[laserPos.y][laserPos.x]--; //= 0;
				/**/if (map1[laserPos.y][laserPos.x] == 0) score++;
				laser = 0;
				justLaser = 0;
				Draw_Map(map1,rTypePos,laserPos,laser, missilePos, missile);				
			}
			// if the shot was just fired, then there wont be one to erase
			if (!justLaser && laser) {
				moveLaser(oldLaserPos,laserPos);
			} else if (laser){
				drawLaser(laserPos);
				justLaser = 0;
			}
		}	
		
		// scroll the screen forward one block every third time through the main loop
		if (forward == 3) {
		randMap(&map1);
		//rTypePos.x++;
		forward = 0;
		Draw_Map(map1,rTypePos,laserPos,laser, missilePos, missile);
		} else {
			forward++;
		}
		
		// if you ran into a wall, quit
		if (detectWall(rTypePos,map1)) break;
		
		
		
		key = _rowread(ARROW_ROW);
		
		// if the user pressed right, move the ship right
		if (key & keys[RIGHT]) {
			oldRType = rTypePos;
			rTypePos.x++;
			if (rTypePos.x > 20) rTypePos.x--;
			if (!detectWall(rTypePos,map1)){
				moveRType(oldRType,rTypePos);
			}	else {
				//rTypePos.x--;
				break;
			}
		}	
			// If the user pressed left, move the ship left			
			if (key & keys[LEFT]) {
				oldRType = rTypePos;
				//rTypePos.x--;
				if (rTypePos.x - 1 >= 0) rTypePos.x--;
				if (!detectWall(rTypePos,map1)){
					moveRType(oldRType,rTypePos);
				} else {
					//rTypePos.x++;
					break;
				}
			}
			
			// if the user pressed up, move the ship up
			if (key & keys[UP]) {
					oldRType = rTypePos;				
					//rTypePos.y--;	
					if (rTypePos.y - 1 >= 0) rTypePos.y--;
					if (!detectWall(rTypePos,map1))	{		
						moveRType(oldRType,rTypePos);
					} else {
						//rTypePos.y++;
						break;
					}	
			}	
			
			// if the user pressed down, move the ship down
			if (key & keys[DOWN]) {
					oldRType = rTypePos;
					rTypePos.y++;
					if (rTypePos.y > 12) rTypePos.y = 12;
					if (!detectWall(rTypePos,map1)) {
						moveRType(oldRType,rTypePos);
					} else {
						//rTypePos.y--;
						break;
					}
			}
			
			// if 2nd was pushed, fire the laser
			if (key & keys[SECOND]) {
				if (!laser) {
				justLaser = 1;
				laser = 1;
				laserPos.x = rTypePos.x + 1;
				laserPos.y = rTypePos.y;
				}
			}
			
			// if diamond was pushed fire the downward missiles
			if (key & keys[DIAMOND]) {
				if (!missile) {
					justMissile = 1;
					missile = 1;
					missileSlow = 2;
					missilePos.x = rTypePos.x;
					missilePos.y = rTypePos.y;
				}
			}
			
			// slow down the program because _rowread is too fast
			delay();
		}
		
		// somehow the user left the game, either by crashing or quitting, so make sure to disable all changes		
		GrayOff();
		SetIntVec(AUTO_INT_1,interrupt1);
		clrscr();
		printf("You destroyed %d blocks!",score);
		while (ngetchx() != KEY_ENTER){}
	}
Ejemplo n.º 9
0
// the main function
void _main(void) {
    unsigned int difficulty = NORMAL;
    short int key=0;
    short int keys[8];
    unsigned int level_num = 1;
    unsigned short int score = 0;
    int done = 0;
    unsigned int money = 0;
    int cannon_level = 1;
    int missile_level = 0;
    char map[12][MAP_SIZE];

    // seed the random numbers
    randomize();
    // get the key masks
    getKeyMasks(keys);


    INT_HANDLER interrupt1 = GetIntVec(AUTO_INT_1);  // this will save auto int 1

    // draw title screen and wait for keypress
    GrayOn();
    drawTitle(2);
    ngetchx();

    //draw background title screen and menu
    drawTitle(1);
    drawWords(difficulty);
    POSITION pointer = {10,0};
    drawPointer(pointer);
    // the menu loop
    while (1) {
        key = ngetchx();
        if (key == KEY_ENTER && pointer.y != OPTIONS) {
            if (pointer.y == PLAY) break;
            if (pointer.y == HIGH_SCORES) printHiScores();
            if (pointer.y == HELP) doHelp();
            if (pointer.y == ABOUT) {
                SetIntVec(AUTO_INT_1,interrupt1);
                GrayOff();
                exit(0);
            }
            GraySetAMSPlane(LIGHT_PLANE);
            clrscr();
            GraySetAMSPlane(DARK_PLANE);
            clrscr();
            drawTitle(1);
            drawWords(difficulty);
            pointer=(POSITION) {
                10,0
            };
            drawPointer(pointer);
        }
        if (key == KEY_LEFT && pointer.y == OPTIONS && difficulty < VERY_EASY) {
            difficulty+=1;
            GraySetAMSPlane(LIGHT_PLANE);
            clrscr();
            GraySetAMSPlane(DARK_PLANE);
            clrscr();
            drawTitle(1);
            drawPointer(pointer);
            drawWords(difficulty);
        }
        if (key == KEY_RIGHT && pointer.y == OPTIONS && difficulty > IMPOSSIBLE)  {
            difficulty-=1;
            GraySetAMSPlane(LIGHT_PLANE);
            clrscr();
            GraySetAMSPlane(DARK_PLANE);
            clrscr();
            drawTitle(1);
            drawPointer(pointer);
            drawWords(difficulty);
        }
        if (key == KEY_UP || key == KEY_DOWN) drawPointer(pointer);
        if (key == KEY_UP && pointer.y > 0) pointer.y--;
        if (key == KEY_DOWN && pointer.y < 4) pointer.y++;
        if (key == KEY_UP || key == KEY_DOWN) drawPointer(pointer);
    }
    key = 0;
    // turn off gray, so we can destroy auto-int-1 and not mess it up
    GrayOff();

    // DESTROY auto-interrupt 1 so as not to mess up _rowread
    SetIntVec(AUTO_INT_1,DUMMY_HANDLER);

    // turn gray back on
    GrayOn();

    // randomize the map
    randomMap(difficulty, map, level_num);
    //the main game loop
    while (!quit() && !done) {
        done = 0;
        int fin = 0;
        int win = 0;
        int forward = 0;
        int map_x_location = 0;
        int laser = 0;
        int justLaser = 0;
        int missile = 0;
        int justMissile = 0;
        int missileSlow = 2;
        POSITION laserPos;
        POSITION oldLaserPos;
        POSITION missilePos;
        POSITION oldMissilePos;
        POSITION oldShip;
        POSITION ShipPos = {0,5};

        // we need to disable gray temporarily to do the shop screen...
        GrayOff();
        SetIntVec(AUTO_INT_1, interrupt1);
        shop(&money, &cannon_level, &missile_level);
        SetIntVec(AUTO_INT_1, DUMMY_HANDLER);
        GrayOn();

        // draws the level
        Draw_Map(map_x_location, map, ShipPos, laserPos, laser, missilePos, missile);


        // the loop for the action in the level
        while (!quit()) {

            // if the user has a missile out, deal with it
            if (missile && missileSlow == 2) {
                missileSlow = 1;
                oldMissilePos = missilePos;
                missilePos.x++;
                missilePos.y+=missile;
                if (missilePos.x > map_x_location + 20) missile = 0;
                if (missilePos.y < 0 || missilePos.y > 12) {
                    missile = 0;
                    eraseMissile(missilePos, map_x_location);
                }
                if (blowWall(missilePos,map)) {
                    if (map[missilePos.y][missilePos.x] < 4) {
                        map[missilePos.y][missilePos.x]-=3;
                        if (map[missilePos.y][missilePos.x] == 0) {
                            score++;
                            money+=BLOCK_VALUE;
                        }
                    }
                    if (map[missilePos.y][missilePos.x] < 0) map[missilePos.y][missilePos.x] = 0;
                    missile = 0;
                    justMissile = 0;
                    Draw_Map(map_x_location,map,ShipPos,laserPos,laser,missilePos,missile);
                }
                // if the shot was just fired, then there wont be one to erase
                if (!justMissile && missile == 1) {
                    moveMissile(oldMissilePos,missilePos,map_x_location);
                } else if (missile == 1) {
                    drawMissile(missilePos,map_x_location);
                    justMissile = 0;
                } else if (!justMissile && missile == -1) {
                    moveUpMissile(oldMissilePos, missilePos, map_x_location);
                } else if (missile == -1) {
                    drawUpMissile(missilePos, map_x_location);
                    justMissile = 0;
                }

            } else {
                missileSlow++;
            }

            // if the user has a laser shot that is still going, continue it
            if (laser) {
                oldLaserPos = laserPos;
                laserPos.x++;
                if (laserPos.x > map_x_location + 20) laser=0;
                if (blowWall(laserPos,map)) {
                    if (map[laserPos.y][laserPos.x] < 4) {
                        map[laserPos.y][laserPos.x]-=cannon_level;
                        if (map[laserPos.y][laserPos.x] <= 0) {
                            score++;
                            money+=BLOCK_VALUE;
                            map[laserPos.y][laserPos.x] = 0;
                        }
                    } else if (map[laserPos.y][laserPos.x] == 4 && cannon_level == 4) {
                        map[laserPos.y][laserPos.x] = 1;
                    }
                    laser = 0;
                    justLaser = 0;
                    Draw_Map(map_x_location,map,ShipPos,laserPos,laser, missilePos, missile);
                }
                // if the shot was just fired, then there wont be one to erase
                if (!justLaser && laser) {
                    moveLaser(oldLaserPos,laserPos,map_x_location);
                } else if (laser) {
                    drawLaser(laserPos,map_x_location);
                    justLaser = 0;
                }
            }

            // scroll the screen forward one block every (difficulty) time through the main loop
            if (forward == difficulty) {
                map_x_location++;
                ShipPos.x++;
                forward = 0;
                if (map_x_location >= MAP_SIZE - 20) {
                    win = 1;
                    level_num++;
                    break;
                }
                // if you ran into a wall, quit
                if (detectWall(ShipPos,map)) {
                    win = 1;
                    score /= 2 ;
                    break;
                }
                Draw_Map(map_x_location,map,ShipPos,laserPos,laser, missilePos, missile);
            } else {
                forward++;
            }

            // if you ran into a wall, quit
            if (detectWall(ShipPos,map)) {
                win = 1;
                score = 0;
                break;
            }

            if (_rowread(~((short)(1<<1))) & (1<<6) && _rowread(~((short)(1<<2))) & (1<<6)) {
                win = 1;
                level_num++;
                break;
            }

            // get keypresses
            key = _rowread(ARROW_ROW);

            // if the user pressed right, move the ship right
            if (key & keys[RIGHT]) {
                oldShip = ShipPos;
                ShipPos.x++;
                if (ShipPos.x > map_x_location + 18) ShipPos.x--;
                if (!detectWall(ShipPos,map)) {
                    moveShip(oldShip,ShipPos,map_x_location);
                }	else {
                    win = 1;
                    score = 0;
                    break;
                }
            }
            // If the user pressed left, move the ship left
            if (key & keys[LEFT]) {
                oldShip = ShipPos;
                ShipPos.x--;
                if (ShipPos.x < map_x_location) ShipPos.x++;
                if (!detectWall(ShipPos,map)) {
                    moveShip(oldShip,ShipPos,map_x_location);
                } else {
                    win = 1;
                    score = 0;
                    break;
                }
            }

            // if the user pressed up, move the ship up
            if (key & keys[UP]) {
                oldShip = ShipPos;
                if (ShipPos.y - 1 < 0) {
                    ShipPos.y = 0;
                } else {
                    ShipPos.y--;
                }
                if (!detectWall(ShipPos,map))	{
                    moveShip(oldShip,ShipPos,map_x_location);
                } else {
                    win = 1;
                    score = 0;
                    break;
                }
            }

            // if the user pressed down, move the ship down
            if (key & keys[DOWN]) {
                oldShip = ShipPos;
                ShipPos.y++;
                if (ShipPos.y > 10) ShipPos.y = 10;
                if (!detectWall(ShipPos,map)) {
                    moveShip(oldShip,ShipPos,map_x_location);
                } else {
                    win = 1;
                    score = 0;
                    break;
                }
            }

            // if 2nd was pushed, fire the laser
            if (key & keys[SECOND]) {
                if (!laser) {
                    justLaser = 1;
                    laser = 1;
                    laserPos.x = ShipPos.x + 1;
                    laserPos.y = ShipPos.y;
                }
            }

            // if diamond was pushed fire the downward missiles
            if (key & keys[DIAMOND]) {
                if (missile_level == 3 || missile_level == 1) {
                    if (!missile) {
                        justMissile = 1;
                        missile = 1;
                        missileSlow = 2;
                        missilePos.x = ShipPos.x;
                        missilePos.y = ShipPos.y;
                    }
                }
            }

            // if shift was pushed fire the upward missiles
            if (key & keys[SHIFT]) {
                if (missile_level == 2 || missile_level == 3) {
                    if (!missile) {
                        justMissile = 1;
                        missile = -1;
                        missileSlow = 2;
                        missilePos.x = ShipPos.x;
                        missilePos.y = ShipPos.y;
                    }
                }
            }

            /*if (key & keys[ALPHA]) {
            score += 10;
            }*/
            // slow down the program because _rowread is too fast
            delay();
        }



        // back to the overall game loop
        if (win) {
            if (level_num <= LEVEL_NUM) {
                won(difficulty, map, level_num);
            } else {
                fin = 1;
                break;
            }
        }
    }

    // the user left, either by winning or quitting, so make sure everything is reset so the calc will be fine
    GrayOff();
    SetIntVec(AUTO_INT_1,interrupt1);
    hiScoresGo(score, difficulty, level_num);
}
Ejemplo n.º 10
0
// Main Function
void _main(void)
{	
	// declare variables
	char keys[8]; getKeyMasks(keys);
	BITS bit= {0,0,0,0,0,0,0,0};
	char arrow_key=0;
	POSITION thingPOS= {0,0};
	POSITION mapPOS= {0,0};
	// main menu
	title();
	
	// prepare for GRAYSCALE AND ROWREAD
	interrupt1 = GetIntVec(AUTO_INT_1);
	SetIntVec(AUTO_INT_1,DUMMY_HANDLER);
	
	while (1) {
		
		// initialize
		bit.one=0;
		thingPOS= (POSITION){0,0};
		
		// a blank slate
		ClrScr();
		
		//setup game, draw screen, etc
		draw(thing,thingPOS,mapPOS);
		makeMap(mapPOS);
		while (!button(ARROW_ROW,keys[UP]));
		
		while(!button(TI89_ESCROW,TI89_ESCKEY) && !bit.one) {
			// the game loop
			arrow_key=_rowread(ARROW_ROW);
			bit=(BITS){0,0,0,0,0,0,0,0};
			
			//get input
			if (arrow_key) {
				if (arrow_key & keys[UP]) bit.yup=1;
				if (arrow_key & keys[RIGHT]) bit.xright=1;
				if (arrow_key & keys[DOWN]) bit.ydown=1;
				if (arrow_key & keys[LEFT]) bit.xleft=1;
			}
			
			// test gunner is within dimension
			if (dim(thingPOS,bit)) {
				bit.draw=1;
				thingPOS.x+=bit.xright+(-bit.xleft);
				thingPOS.y+=bit.yup+(-bit.ydown);
			}
			
			if (bit.draw) {
			mapPOS.x=thingPOS.x-10;
			mapPOS.y=thingPOS.y-5;
			if (mapPOS.x<0) mapPOS.x=0;
			else if (mapPOS.x>11) mapPOS.x=11;
			if (mapPOS.y<0) mapPOS.y=0;
			else if (mapPOS.y>20) mapPOS.y=20;
			}
			
			// if movement=true, draw new position
			if (bit.draw) {
				ClrScr();
				makeMap(mapPOS);
				draw(thing,thingPOS,mapPOS);
			}
			
			//delay
			delay(6);
		} 
		if (!bit.one) {
			SetIntVec(AUTO_INT_1,interrupt1);
			return;
		}	  														//while !quit and !done
	} 																														//infinite loop
}