// Main Function
void _main(void)
{

	ST_helpMsg("F800+rom idx FLINE executed");	//ST_helpMsg is automatically a fline instuction due to USE_FLINE_ROM_CALLS
	ngetchx();
	//asm(".word 0xF800+0x29b");	//idle

asm("
TestBsr:
	.word 0xFFF0
	.long (TestBsrFunc-TestBsr)-2
	bra BsrTestFinished
	
TestBsrFunc:
	rts

BsrTestFinished:
	");
	ST_helpMsg("$FFF0 FLINE executed");ngetchx();
	
	asm("bra TestBra");
	asm("retBra:");
	ST_helpMsg("$FFF1 FLINE executed");ngetchx();
	

	asm(".word 0xFFF2
	   .word 0x19E*4 /* ClrScr */");
	ST_helpMsg("FFF2 index*4 FLINE executed");ngetchx();
}
Ejemplo n.º 2
0
void _main(void) {
    LCD_BUFFER backbuffer;
    unsigned char buffer[100*5*4];
    unsigned short i,j;

    LCD_save(backbuffer);

    ST_helpMsg("Sprite8Get() Demo - Press Key");
    ngetchx();

    for (j=0;j<64;j++) {
        for (i=0;i<20;i++) {
            Sprite8Get_R(j+(i<<3),0,100,backbuffer,((unsigned char*)buffer)+100*i);
        }
        ClrScr();
        for (i=0;i<20;i++) {
            Sprite8_OR_R(i<<3,0,100,((unsigned char*)buffer)+100*i,LCD_MEM);
        }
    }

    ST_helpMsg("Sprite16Get() Demo - Press Key");
    ngetchx();

    for (j=0;j<64;j++) {
        for (i=0;i<10;i++) {
            Sprite16Get_R(j+(i<<4),0,100,backbuffer,((unsigned short*)buffer)+100*i);
        }
        ClrScr();
        for (i=0;i<10;i++) {
            Sprite16_OR_R(i<<4,0,100,((unsigned short*)buffer)+100*i,LCD_MEM);
        }
    }

    ST_helpMsg("Sprite32Get() Demo - Press Key");
    ngetchx();

    for (j=0;j<64;j++) {
        for (i=0;i<5;i++) {
            Sprite32Get_R(j+(i<<5),0,100,backbuffer,((unsigned long*)buffer)+100*i);
        }
        ClrScr();
        for (i=0;i<5;i++) {
            Sprite32_OR_R(i<<5,0,100,((unsigned long*)buffer)+100*i,LCD_MEM);
        }
    }

    LCD_restore(backbuffer);
    GKeyFlush();
    ST_helpMsg(EXTGRAPH_VERSION_PWDSTR);
}
Ejemplo n.º 3
0
// tests the score for a new hi-score
void hiScoresGo(unsigned long int score, unsigned int difficulty, unsigned int level_num) {
    clrscr();
    hiScores[0].score = scoreCompute(score, difficulty, level_num);
    if (hiScores[0].score > hiScores[5].score) {
        getName(hiScores[0].score);
        hiScores[5] = hiScores[0];
        if (hiScores[0].score > hiScores[4].score) {
            hiScores[5] = hiScores[4];
            hiScores[4] = hiScores[0];
            if (hiScores[0].score > hiScores[3].score) {
                hiScores[4] = hiScores[3];
                hiScores[3] = hiScores[0];
                if (hiScores[0].score > hiScores[2].score) {
                    hiScores[3] = hiScores[2];
                    hiScores[2] = hiScores[0];
                    if (hiScores[0].score > hiScores[1].score) {
                        hiScores[2] = hiScores[1];
                        hiScores[1] = hiScores[0];
                    }
                }
            }
        }
    }	else {
        printf("You failed to achieve\na new High Score\nYour Score was:\n%lu", hiScores[0].score);
        while (ngetchx()!= KEY_ENTER);
        clrscr();
    }
    printHiScores();
}
Ejemplo n.º 4
0
/*===========================================================================*/
void _main(void) {
    short         i,j;
    unsigned long measure_val;
    char          tmpstr[50] = "Measuring, please wait ...";
    short         modes[6]   = { A_REPLACE,A_XOR,A_REVERSE,A_XOR,A_REPLACE,A_REVERSE};
    LCD_BUFFER    screen;

    LCD_save(screen);

    FontSetSys(F_4x6);

    OSFreeTimer(USER_TIMER);
    OSRegisterTimer(USER_TIMER,INITIAL_TIMER_VALUE);

    ClearScreen();
    DrawStr(0,0,tmpstr,A_REPLACE);

    do {
        //---------------------------------------------------------------------
        // built-in OS line drawing routine ...
        //---------------------------------------------------------------------
        OSTimerRestart(USER_TIMER);
        for (j=0;j<6 && !kbhit();j++) {
            short used_mode = modes[j];
            for (i=0;  i<160;i++) DrawLine(80,50,i,8,   used_mode);
            for (i=8;  i<100;i++) DrawLine(80,50,159,i, used_mode);
            for (i=159;i>=0; i--) DrawLine(80,50,i,99,  used_mode);
            for (i=99; i>=8; i--) DrawLine(80,50,0,i,   used_mode);
        }
        measure_val = OSTimerCurVal(USER_TIMER);
        sprintf(tmpstr,"OS Routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val);
        memset(LCD_MEM,0,30*8);
        DrawStr(0,0,tmpstr,A_REPLACE);

        if (kbhit()) break;

        //---------------------------------------------------------------------
        // new line drawing routine ...
        //---------------------------------------------------------------------
        OSTimerRestart(USER_TIMER);
        for (j=0;j<6 && !kbhit();j++) {
            short used_mode = modes[j];
            for (i=0;  i<160;i++) FastDrawLine_R(LCD_MEM,80,50,i,8,   used_mode);
            for (i=8;  i<100;i++) FastDrawLine_R(LCD_MEM,80,50,159,i, used_mode);
            for (i=159;i>=0; i--) FastDrawLine_R(LCD_MEM,80,50,i,99,  used_mode);
            for (i=99; i>=8; i--) FastDrawLine_R(LCD_MEM,80,50,0,i,   used_mode);
        }
        measure_val = OSTimerCurVal(USER_TIMER);
        sprintf(tmpstr,"Own Routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val);
        memset(LCD_MEM,0,30*8);
        DrawStr(0,0,tmpstr,A_REPLACE);
    }
    while (!kbhit());

    ngetchx();
    OSFreeTimer(USER_TIMER);
    LCD_restore(screen);
    GKeyFlush();
    ST_helpMsg(EXTGRAPH_VERSION_PWDSTR);
}
Ejemplo n.º 5
0
// function to let the user type in a name for the hi-scores
void getName(unsigned long int score) {
    int key = 0;
    int x = 0;
    int y = 45;
    int back = 0;
    clrscr();
    GrayOff();
    FontSetSys(F_8x10);
    printf_xy(20,0,"New High Score!");
    printf_xy(60,12,"%lu", score);
    FontSetSys(F_4x6);
    printf_xy(53,95,"Jet Blaster v 1.0 by Ben Cherry");
    FontSetSys(F_6x8);
    printf_xy(11,25,"Please Enter Your Name:");
    while (key != KEY_ENTER) {
        key = ngetchx();
        if (key == KEY_BACKSPACE) {
            if (x>0) x--;
            key = (int)' ';
            back = 1;
        }
        if (x <= 9 && key != KEY_ENTER) {
            printf_xy(6*x+50,y,"%c",(char)key);
            hiScores[0].name[x] = key;
        }
        if (!back && x <= 9) x++;
        if (back) back--;
    }
    clrscr();
}
Ejemplo n.º 6
0
// prints the hi-score table
void printHiScores(void) {
    int i = 0;
    GraySetAMSPlane(DARK_PLANE);
    clrscr();
    GraySetAMSPlane(LIGHT_PLANE);
    clrscr();
    GraySetAMSPlane(DARK_PLANE);
    FontSetSys(F_8x10);
    DrawStr(36,0,"Jet Blaster",A_NORMAL);
    DrawStr(36,12,"High Scores",A_NORMAL);
    FontSetSys(F_4x6);
    DrawStr(53,95,"Jet Blaster v 1.0 by Ben Cherry",A_NORMAL);
    FontSetSys(F_6x8);
    for (i = 1; i <= 5; i++) {
        printf_xy(10,i*9 + 26,"%d. %s - %lu",i,hiScores[i].name,hiScores[i].score);
    }
    GraySetAMSPlane(LIGHT_PLANE);
    FontSetSys(F_8x10);
    printf_xy(36,0,"Jet Blaster");
    printf_xy(36,12,"High Scores");
    FontSetSys(F_4x6);
    printf_xy(53,95,"Jet Blaster v 1.0 by Ben Cherry");
    FontSetSys(F_6x8);
    for (i = 1; i <= 5; i++) {
        printf_xy(10,i*9 + 26,"%d. %s - %lu",i,hiScores[i].name,hiScores[i].score);
    }
    while (ngetchx() != KEY_ENTER);
    GraySetAMSPlane(DARK_PLANE);
    clrscr();
    GraySetAMSPlane(LIGHT_PLANE);
    clrscr();
}
Ejemplo n.º 7
0
void _main(void) {
  GrayOn();
  clrscr();
  GraySprite16_XOR_R(8, 8, 16, ball_C0, ball_C1, GetPlane(0), GetPlane(1));
  ngetchx();
  GrayOff();
}
Ejemplo n.º 8
0
void _main(void)
{
  float a, b, c, d;
  char buffer[200];
  clrscr ();
  puts ("a=");
  a = atof (gets (buffer));
  puts ("b=");
  b = atof (gets (buffer));
  puts ("c=");
  c = atof (gets (buffer));
  if (is_nan (a) || is_nan (b) || is_nan (c)) return;
  d = b * b - 4. * a * c;
  if (d >= 0.)
    {
      float x1, x2;
      x1 = (-b + sqrt (d)) / (2. * a);
      x2 = (-b - sqrt (d)) / (2. * a);
      printf ("\nx1=%f\nx2=%f", x1, x2);
    }
  else
    {
      float re, im;
      re = -b / (2. * a);
      im = fabs (sqrt (-d) / (2. * a));
      printf ("\nx1=%f-%f*i\nx2=%f+%f*i", re, im, re, im);
    }
  ngetchx();
}
Ejemplo n.º 9
0
// Main Function
void _main(void){
	int a;
	a=NULL;
	clrscr();
	if(a)printf("NULL is true\n");
	if(!a)printf("NULL is false\n");
	ngetchx();
}
Ejemplo n.º 10
0
// Main Function
void _main(void)
{
    unsigned char object[]= {0b01100111,0b01100101,0b01110100,0b00100000,0b01101111,0b01110101,0b01110100,0b00100000,0b01101101,0b01101111,0b01110010,0b01100101,0b00101110};
    clrscr();
    Sprite8(10,10,13,object,LCD_MEM,SPRT_XOR);
    ngetchx();
    clrscr();
}
Ejemplo n.º 11
0
// Main Function
void _main(void)
{
  static unsigned char rpn[] = {END_TAG, VAR_X_TAG, 1, 1, POSINT_TAG,
    VAR_X_TAG, 3, 1, POSINT_TAG, SUB_TAG, 2, 1, POSINT_TAG, VAR_X_TAG,
    POW_TAG, 4, 1, POSINT_TAG, ADD_TAG, MUL_TAG, DIV_TAG, INTEGRATE_TAG};
  NG_rationalESI (rpn + sizeof (rpn) - 1);
  WinClr (DeskTop);
  Print2DExpr (Parse2DExpr (top_estack, FALSE), DeskTop, 0, 50);
  ngetchx ();
}
Ejemplo n.º 12
0
// Main Function
void _main(void)
{
  TRY
    push_quantum (VAR_T_TAG);
    push_parse_text ("sin(t)+sin(2t)");
    cmd_graph (top_estack);
    ngetchx ();
    cmd_disphome ();
  ONERR
  ENDTRY
}
Ejemplo n.º 13
0
void _main(void)
{
    while( TRUE )
    {
        clrscr();
        printWelcomeScreen();

        clrscr();
        play();

        ngetchx();
    }
}
Ejemplo n.º 14
0
void _main(void) {
 unsigned long *p=(unsigned long *)4;
 unsigned long firstlong=*(unsigned long *)0;
 clrscr();
 try_again:
 while (*(p++)!=firstlong) {
  if ((unsigned long)p>=0x600000) return;
 }
 if (memcmp(p-1,0,1000)) goto try_again;
 printf("%lp\n",p-1);
 ngetchx();
 goto try_again;
}
Ejemplo n.º 15
0
// draws the help screen
void doHelp(void) {
    drawTitle(1);
    GraySetAMSPlane(LIGHT_PLANE);
    clrscr();
    printf("Jet Blaster Controls\n\nArrow keys - Move Ship\nDiamond, Shift - Missiles\nSecond - Cannon");
    GraySetAMSPlane(DARK_PLANE);
    clrscr();
    printf("Jet Blaster Controls\n\nArrow keys - Move Ship\nDiamond, Shift - Missiles\nSecond - Cannon");
    while (ngetchx()!=KEY_ENTER);
    GraySetAMSPlane(LIGHT_PLANE);
    clrscr();
    GraySetAMSPlane(DARK_PLANE);
    clrscr();
}
Ejemplo n.º 16
0
// Main Function
void _main(void) {
	typedef struct {
		long int score;
		char * name;
	} hiscore;
	int i = 0;
	hiscore hiScoreArray[5] = {{20000,"ben cherry"},{20000,"ben cherry"},{20000,"ben cherry"},{20000,"ben cherry"},{20000,"ben cherry"}};
	clrscr();
	FontSetSys(F_8x10);
	printf_xy(36,0,"Jet Blaster");
	printf_xy(36,12,"High Scores");
	FontSetSys(F_4x6);
	printf_xy(53,95,"Jet Blaster v 1.0 by Ben Cherry");
	FontSetSys(F_6x8);
	for (i = 0; i <= 4; i++) {
		printf_xy(10,i*9 + 26,"%d. %s - %d",i+1,hiScoreArray[i].name,hiScoreArray[i].score);
	}
	ngetchx();
}
Ejemplo n.º 17
0
// draws the shop screen
void shop(unsigned int *money, int *cannon_level, int *missile_level) {
    int key = 0;
    while (key != KEY_ENTER) {
        clrscr();
        printf("You have $%d\n", *money);
        if (*cannon_level < 4) printf("Your cannons are level %d\n", *cannon_level);
        if (*cannon_level == 1) printf("Upgrade cannon - $%d\n", CANNON_UPGRADE_2);
        if (*cannon_level == 2) printf("Upgrade cannon - $%d\n", CANNON_UPGRADE_3);
        if (*cannon_level == 3) printf("Upgrade cannon - $%d\n", CANNON_UPGRADE_4);
        if (*missile_level == 0 || *missile_level == 2) printf("Down missiles  - $%d\n", MISSILES_COST);
        if (*missile_level == 0 || *missile_level == 1) printf("Up Missiles    - $%d\n", MISSILES_COST);
        if (*cannon_level < 4 ) printf("Press F1 to buy cannon\n");
        if (*missile_level < 3) printf("Up/down to buy missile\n");
        if (*cannon_level >= 4 && *missile_level >= 3) printf("You have it all!!\n");
        printf("Press enter to leave\n");
        key = ngetchx();
        if (key == KEY_F1 && *cannon_level == 1 && *money >= CANNON_UPGRADE_2) {
            *cannon_level+=1;
            *money -= CANNON_UPGRADE_2;
        } else if (key == KEY_F1 && *cannon_level == 2 && *money >= CANNON_UPGRADE_3) {
            *cannon_level+=1;
            *money -= CANNON_UPGRADE_3;
        } else if (key == KEY_F1 && *cannon_level == 3 && *money >= CANNON_UPGRADE_4) {
            *cannon_level+=1;
            *money -= CANNON_UPGRADE_4;
        }
        if (key == KEY_DOWN && *money >= MISSILES_COST) {
            if (*missile_level == 0 || *missile_level == 2) {
                *missile_level+=1;
                *money -= MISSILES_COST;
            }
        } else if (key == KEY_UP && *money >= MISSILES_COST) {
            if (*missile_level == 0 || *missile_level == 1) {
                *missile_level+=2;
                *money -= MISSILES_COST;
            }
        }
        //if (key == KEY_F5) *money+=1000;
    }
    GKeyFlush();
}
Ejemplo n.º 18
0
void _main(void)
{
  short l,c,k;
  void *vecran;
  LCD_BUFFER backbuffer;

  LCD_save(backbuffer);

  if(!(vecran=malloc(LCD_SIZE)))
    return;

  l=c=0;

  do
  {
    DrawTiles16B(MAP_WIDTH,&map[l][c],vecran,sprts);

    FastCopyScreen_R(vecran,LCD_MEM);
/*
    memcpy(LCD_MEM,vecran,LCD_SIZE);
*/

    k=ngetchx();
    if(k==KEY_RIGHT && c<MAP_WIDTH-15)
      c++;
    if(k==KEY_LEFT && c>0)
      c--;
    if(k==KEY_DOWN && l<MAP_HEIGHT-8)
      l++;
    if(k==KEY_UP && l>0)
      l--;

  } while(k!=KEY_ESC);

  free(vecran);
  LCD_restore(backbuffer);
  GKeyFlush();
  ST_helpMsg(EXTGRAPH_VERSION_PWDSTR);
}
Ejemplo n.º 19
0
// Main Function
void _main(void)
{
	// declare the sprite positions
	int x1 = 20, y1 = 20, direction1 = RIGHT;
	int x2 = 40, y2 = 40, direction2 = LEFT;
	int x3 = 60, y3 = 60, direction3 = RIGHT;
	int x4 = 80, y4 = 80, direction4 = LEFT;
	int x5 = 50, y5 = 50, direction5 = RIGHT;
	
	// keycode variable
	int key = 0;
	
	// Define the pins
	unsigned char pinsprt[] = {0x18,0x3C,0x18,0x38,0x7C,0x7C,0x7C,0x38};
	unsigned long int balsprt[] = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
																 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
																 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
																 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
																 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
																 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
																 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
																 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,};

	// clear the screen
	ClrScr();
	
	// Annotate the display
	DrawStr(0, 0, "These Are Bowling Pins!", A_NORMAL);
	
	// draw the sprites
	Sprite8(x1, y1, SPRITE_HEIGHT, pinsprt, LCD_MEM, SPRT_XOR);
	Sprite8(x2, y2, SPRITE_HEIGHT, pinsprt, LCD_MEM, SPRT_XOR);
	Sprite8(x3, y3, SPRITE_HEIGHT, pinsprt, LCD_MEM, SPRT_XOR);
	Sprite8(x4, y4, SPRITE_HEIGHT, pinsprt, LCD_MEM, SPRT_XOR);
	Sprite32(x5, y5, 32, balsprt, LCD_MEM, SPRT_XOR);
	
	// wait for a key before exit
	ngetchx();
}
Ejemplo n.º 20
0
// Main Function
void _main(void)
{
  HANDLE menu_handle = MenuNew (2, 240, 18);
  MenuAddText (menu_handle, 0, "First", 1, DMF_TOP_SUB);
  MenuAddText (menu_handle, 1, "Subitem 1.1", 5, DMF_CHILD_SUB);
  MenuAddText (menu_handle, 5, "Subitem 1.1.1", 8, DMF_CHILD_SUB);
  MenuAddText (menu_handle, 5, "Subitem 1.1.2", 9, DMF_CHILD);
  MenuAddText (menu_handle, 8, "Subitem 1.1.1.1", 10, DMF_CHILD);
  MenuAddText (menu_handle, 1, "Subitem 1.2", 6, DMF_CHILD);
  MenuAddText (menu_handle, 0, "Second", 2, DMF_TOP_SUB);
  MenuAddText (menu_handle, 2, "Subitem 2.1", 7, DMF_CHILD);
  MenuAddText (menu_handle, -1, "Third", 3, DMF_TOP);
  MenuAddText (menu_handle, -1, "Fourth", 4, DMF_TOP);
  HANDLE exec_handle = MenuBegin (NULL, 0, 0, MBF_HMENU, menu_handle);
  short result;
  do {
    result = MenuKey (exec_handle, ngetchx ());
  } while (result == M_NOTMENUKEY);
  MenuEnd (exec_handle);
  MenuUpdate ();
  push_shortint (result);
}
Ejemplo n.º 21
0
Archivo: t2048.c Proyecto: 1cook/t2048
// Main Function
void _main( void ){
	//Create or load savefile
	SAVE gameState;
	if(readSave(&gameState))
		makeSave(&gameState);
	writeSave(&gameState); /*just to test whether writing is possible here
	so the player doesn't spend a long time and lose their progress*/
	//Buffer for the text at the bottom of the
	scoreString = (char*)malloc(60*sizeof(char));
	if(scoreString == NULL)
		exit(ER_MEMORY);
	
	//Pause menu
	pauseMenu = PopupNew(strConv[11], 50);
	if(pauseMenu == H_NULL)
		memkill(4, ER_MEMORY);
		PopupAddText(pauseMenu, -1, "New Game", 1);
		PopupAddText(pauseMenu, 0, "Options", 2);
			PopupAddText(pauseMenu,2,"Toggle Animations",5);
			PopupAddText(pauseMenu,2,"Reset Save Data",6);
			PopupAddText(pauseMenu, -1, "Exit", 3);
			PopupAddText(pauseMenu, -1, "About", 4);
	
	//Hiscore Name Entry
	nameBox = DialogNewSimple(140,35);
	if(nameBox == H_NULL)
		memkill(3, ER_MEMORY);
		DialogAddTitle(nameBox,"NEW HISCORE!",BT_OK,BT_NONE);
		DialogAddRequest(nameBox,3,14,"Name:", 0, 10, 14);
	
	//Game Over Entry
	gameOver = PopupNew("GAME OVER!", 40);
	if(gameOver == H_NULL)
		memkill(2, ER_MEMORY);
		PopupAddText(gameOver,-1,"Try Again",1);
		PopupAddText(gameOver,-1,"Exit",2);
	
	
	//About Dialouge
	aboutBox = DialogNewSimple(140,80);
	if(aboutBox == H_NULL)
		memkill(1, ER_MEMORY);	
		DialogAddTitle(aboutBox,"ABOUT",BT_OK,BT_NONE);

			DialogAddText(aboutBox, 3, 13, "2048: A sliding tile puzzle");
			DialogAddText(aboutBox, 3, 21, "Ti68k port by Harrison Cook");
			DialogAddText(aboutBox, 3, 29, "Original game by Gabriele Cirulli");
			DialogAddText(aboutBox, 3, 37, "\"Based on\" 1024 by Veewo Studio");
			DialogAddText(aboutBox, 3, 45, "\"Conceptually Similar to\":");
			DialogAddText(aboutBox, 3, 52, "Threes by Asher Vollmer");
			DialogAddText(aboutBox, 3, 59, "Built using TIGCC");
	
	ClrScr();
	FontSetSys(F_8x10);
	randomize();
	short int key;
	for(;;){
		ClrScr();
		drawGrid(gameState.grid);
		sprintf(scoreString, "Score: %lu Hiscore: %lu by %s", gameState.score, gameState.bscore, gameState.name);
		if(!isGridAvailable(gameState.grid)){
			
			if(gameState.score > gameState.bscore){
					DialogDo(nameBox,CENTER,CENTER,	gameState.name,NULL);
					gameState.bscore = gameState.score;
					FontSetSys(F_8x10);
			}
			gameState.score = 0;
			initGrid(gameState.grid);
			switch(PopupDo(gameOver,CENTER,CENTER,0)){
			case 1:
				continue;
				break;
			default:
				goto endGame;
				
			}
		}
		ST_helpMsg(scoreString);
		nodraw:
		ST_busy(ST_IDLE);
		key = ngetchx();
		ST_busy(ST_BUSY);
		ST_helpMsg(scoreString);
		char move = 4;
		if(key == KEY_UP)
			move = UP;
		else if(key == KEY_RIGHT)
			move = RIGHT;
		else if(key == KEY_DOWN)
			move = DOWN;
		else if(key == KEY_LEFT)
			move = LEFT;
		else if(key == KEY_OFF || key==KEY_ON)
			//Turn the calculator off during a game. Resume it later
			off();
		else if(key == KEY_ESC){ //Brings up the pause menu
			switch (PopupDo(pauseMenu,CENTER,CENTER,0)){
				case 1: //1. New Game
					gameState.score = 0;
					initGrid(gameState.grid);
					break;
				//case 2: //2. Options
					//this is a submenu
				case 3: //3: Exit
					endGame:
					writeSave(&gameState);
					memkill(0,0);
					break;
				case 4: //4: About
					DialogDo(aboutBox,CENTER,CENTER,NULL,NULL);
					//Dialog sets the font weirdly, set it back
					FontSetSys(F_8x10);
					break;
				case 5: //1. Toggle Animations
					gameState.animations = !gameState.animations;
					break;
				case 6: //2. Reset Saved Data
					makeSave(&gameState);
					break;
			}
		}
		else goto nodraw;
		if(move < 4){
			if(isDirectionAvailable(gameState.grid, move)){
				shiftGrid(gameState.grid,move,&gameState.score, gameState.animations);
				pushNewTile(gameState.grid);
			}
			else goto nodraw;
		}
	}
}
Ejemplo n.º 22
0
/*===========================================================================*/
static inline short Test32(void) {
    unsigned long  measure_val;
    char           tmpstr[100];
    short          x,y;
    long           count;

    //-------------------------------------------------------------------------
    // original sprite functions
    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32(x,y,8,spritedata32,LCD_MEM,SPRT_AND);
            Sprite32(x,y,8,spritedata32,LCD_MEM,SPRT_OR);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"TIGCCLIB AND+OR: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    if (ngetchx() == KEY_ESC) return KEY_ESC;

#if __TIGCCLIB_VERSION__ >= 272
    //-------------------------------------------------------------------------
    // original sprite functions with RPLC (GCC4TI 0.96 Beta 10+)
    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32(x,y,8,spritedata32,LCD_MEM,SPRT_RPLC);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"TIGCCLIB RPLC: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    if (ngetchx() == KEY_ESC) return KEY_ESC;
#endif

    //-------------------------------------------------------------------------
    // modified sprite functions using separate and/or
    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32_AND_R(x,y,8,spritedata32,LCD_MEM);
            Sprite32_OR_R(x,y,8,spritedata32,LCD_MEM);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"ExtGraph AND+OR: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    if (ngetchx() == KEY_ESC) return KEY_ESC;

    //-------------------------------------------------------------------------
    // modified sprite functions using just one call
    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32_MASK_R(x,y,8,spritedata32,spritedata32,LCD_MEM);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"ExtGraph MASK: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    if (ngetchx() == KEY_ESC) return KEY_ESC;

    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32_BLIT_R(x,y,8,spritedata32,0x00000000,LCD_MEM);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"ExtGraph BLIT: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    if (ngetchx() == KEY_ESC) return KEY_ESC;

    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32_RPLC_R(x,y,8,spritedata32,LCD_MEM);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"ExtGraph RPLC: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    if (ngetchx() == KEY_ESC) return KEY_ESC;

    //-------------------------------------------------------------------------
    // original sprite functions
    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32(x,y,8,spritedata32,LCD_MEM,SPRT_XOR);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"TIGCCLIB AND+OR: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    if (ngetchx() == KEY_ESC) return KEY_ESC;

    //-------------------------------------------------------------------------
    // modified sprite functions using just one call
    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32_XOR_R(x,y,8,spritedata32,LCD_MEM);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"ExtGraph XOR: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    return ngetchx();
}
Ejemplo n.º 23
0
void _main(void)            // main entry point is function _main
{
  clrscr ();                // clear the screen and reset print position
  printf ("Hello world!");  // do you know what this is?
  ngetchx ();               // wait for a keypress
}
Ejemplo n.º 24
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 ground blocks, and 2s are the other blocks
	/*int map1[12][82] = { 
	{0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,2,2,2,0,0,0,2,2,2,2,2,2,2,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0},
	{0,0,0,2,0,0,0,0,2,2,0,0,0,2,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,2,2,0,0,0,2,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,2,0,0,2,0,0,2,2,0,0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,2,0,2,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0},
	{0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,2,0,2,0,2,0,2,2,2,0,0,0,0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,2,0,2,0,2,0,2,2,2,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,0,0,0,2,0,0,2,2,0,0,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,0,0,0,2,0,0,2,2,0,0,0,0,0,2,2,0,2,0,2,0,2,0,0,0,0,0},
	{0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,0,0,0,0,2,0,0,0,2,0,2,2,2,0,0,0,0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,0,0,0,0,2,0,0,0,2,0,2,2,2,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,0,0,0,2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,0,0,0,2,0,2,0,0,0,0,0},
	{0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,2,0,0,0,0,0,0,0,2,2,0,2,0,2,2,2,0,0,0,0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,2,2,2,0,2,2,0,0,0,0,0,0,0,2,2,0,2,0,2,2,2,0,0,0},
	{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};*/
	
	int map1[12][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.º 25
0
_main() {
  SCR_RECT SCREEN = {{0, 0, LCD_WIDTH-1, LCD_HEIGHT-1}};
  SCR_RECT rect = {{0, 0, HEIGHT-1, HEIGHT-1}};

  short attr = A_XOR; // Default replace value: A_XOR

  // Parses arguments
  ESI argptr;
  InitArgPtr(argptr);
  int argtype = GetArgType(argptr);
  if (argtype == POSINT_TAG) {
    int num = GetIntArg(argptr);
    // 2. *** YOUR CODE HERE ***
  }

  // Initializes a rectangle bitmap of HEIGHT x HEIGHT
  char mask [BITMAP_SIZE];
  int i = 0;
  while (i < BITMAP_SIZE) {
    mask[i] = 0xFF; // Change this value to get different masks!
    i++;
  }
  BitmapInit(&rect, mask);

  // Puts the rectangle onto the screen
  DRAW;

  int c;
  // Main loop for getting keyboard input
  while ((c = ngetchx()) != ENTER_KEY) {
    // Erases old bitmap
    DRAW;
    switch (c) { // Moves bitmap around
    case LEFT_KEY:
      if (rect.xy.x0 - 5 >= 0) {
        rect.xy.x0 -=5;
        rect.xy.x1 -=5;
      }
      break;
    case RIGHT_KEY:
      if (rect.xy.x1 + 5 < LCD_WIDTH) {
        rect.xy.x0 +=5;
        rect.xy.x1 +=5;
      }
      break;
    case UP_KEY:
      if (rect.xy.y0 - 5 >= 0) {
        rect.xy.y0 -=5;
        rect.xy.y1 -=5;
      }
      break;
    case DOWN_KEY:
      if (rect.xy.y1 + 5 < LCD_HEIGHT) {
        rect.xy.y0 +=5;
        rect.xy.y1 +=5;
      }
      break;
    }
    // Draws new bitmap
    DRAW;
  }
}
Ejemplo n.º 26
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.º 27
0
/*===========================================================================*/
void _main(void) {
    short         i,j;
    unsigned long measure_val;
    char          tmpstr[50] = "Measuring, please wait ...";
    short         modes[4]   = {COLOR_LIGHTGRAY,COLOR_DARKGRAY,COLOR_BLACK,COLOR_WHITE};
    LCD_BUFFER    screen;

    LCD_save(screen);
    if (!GrayOn()) return;

    OSFreeTimer(USER_TIMER);
    OSRegisterTimer(USER_TIMER,INITIAL_TIMER_VALUE);

    GrayClearScreen_R();

    GrayDrawStrExt(0,0,tmpstr,A_REPLACE|A_CENTERED|A_SHADOWED,F_4x6);

    do {
        //---------------------------------------------------------------------
        // built-in OS line drawing routine ...
        //---------------------------------------------------------------------
        OSTimerRestart(USER_TIMER);
        for (j=0;j<4 && !kbhit();j++) {
            short used_color = modes[j];
            for (i=0;  i<160;i++) GrayDrawLine(80,50,i,8,   used_color);
            for (i=8;  i<100;i++) GrayDrawLine(80,50,159,i, used_color);
            for (i=159;i>=0; i--) GrayDrawLine(80,50,i,99,  used_color);
            for (i=99; i>=8; i--) GrayDrawLine(80,50,0,i,   used_color);
        }
        measure_val = OSTimerCurVal(USER_TIMER);
        sprintf(tmpstr,"OS routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val);

        GrayDrawRect(0,0,239,7,COLOR_WHITE,RECT_FILLED);
        GrayDrawStrExt(0,0,tmpstr,A_REPLACE | A_CENTERED | A_SHADOWED,F_4x6);

        if (kbhit()) break;

        //---------------------------------------------------------------------
        // new line drawing routine ...
        //---------------------------------------------------------------------
        OSTimerRestart(USER_TIMER);
        for (j=0;j<4 && !kbhit();j++) {
            short used_color = modes[j];
            for (i=0;  i<160;i++) GrayFastDrawLine2B_R(GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),80,50,i,8,   used_color);
            for (i=8;  i<100;i++) GrayFastDrawLine2B_R(GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),80,50,159,i, used_color);
            for (i=159;i>=0; i--) GrayFastDrawLine2B_R(GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),80,50,i,99,  used_color);
            for (i=99; i>=8; i--) GrayFastDrawLine2B_R(GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),80,50,0,i,   used_color);
        }
        measure_val = OSTimerCurVal(USER_TIMER);
        sprintf(tmpstr,"Own routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val);
        GrayDrawRect(0,0,239,8,COLOR_WHITE,RECT_FILLED);
        GrayDrawStrExt(0,0,tmpstr,A_REPLACE | A_CENTERED | A_SHADOWED,F_4x6);
    }
    while (!kbhit());

    ngetchx();
    OSFreeTimer(USER_TIMER);

    GrayOff();
    LCD_restore(screen);
    GKeyFlush();
    ST_helpMsg(EXTGRAPH_VERSION_PWDSTR);
}
Ejemplo n.º 28
0
/*===========================================================================*/
void _main(void) {
    short         i,j;
    unsigned long measure_val;
    char          tmpstr[50] = "Measuring, please wait ...";
    static const short modes[4] = {COLOR_LIGHTGRAY,COLOR_DARKGRAY,COLOR_BLACK,COLOR_WHITE};
    unsigned short clippedcoord[4];
    LCD_BUFFER    screen;

    LCD_save(screen);

    OSFreeTimer(USER_TIMER);
    OSRegisterTimer(USER_TIMER,INITIAL_TIMER_VALUE);

    if (!GrayOn()) goto end;

    //---------------------------------------------------------------------
    // built-in OS line drawing routine ...
    //---------------------------------------------------------------------
    GrayClearScreen_R();
    OSTimerRestart(USER_TIMER);
    for (j=0;j<4;j++) {
        short used_color = modes[j];
        for (i=-40;  i<280;i++) GrayDrawClipLine(120,64,i,-40,used_color);
        for (i=-40;  i<168;i++) GrayDrawClipLine(120,64,280,i,used_color);
        for (i=280;i>=-40; i--) GrayDrawClipLine(120,64,i,168,used_color);
        for (i=168;i>=-40; i--) GrayDrawClipLine(120,64,-40,i,used_color);
    }
    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"OS routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val);
    GrayDrawRect(0,0,239,7,COLOR_WHITE,RECT_FILLED);
    GrayDrawStrExt(0,0,tmpstr,A_NORMAL | A_CENTERED | A_SHADOWED,F_4x6);

    if (ngetchx() == KEY_ESC) goto end;

    
    //---------------------------------------------------------------------
    // new line drawing routine ...
    //---------------------------------------------------------------------
    GrayClearScreen_R();
    OSTimerRestart(USER_TIMER);
    for (j=0;j<4;j++) {
        short used_color = modes[j];
        for (i=-40;  i<280;i++) GrayClipDrawLine_R(120,64,i,-40,clippedcoord,used_color,GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),GrayFastDrawLine2B_R);
        for (i=-40;  i<280;i++) GrayClipDrawLine_R(120,64,280,i,clippedcoord,used_color,GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),GrayFastDrawLine2B_R);
        for (i=280;i>=-40; i--) GrayClipDrawLine_R(120,64,i,168,clippedcoord,used_color,GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),GrayFastDrawLine2B_R);
        for (i=168;i>=-40; i--) GrayClipDrawLine_R(120,64,-40,i,clippedcoord,used_color,GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),GrayFastDrawLine2B_R);
    }
    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"Own routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val);
    GrayDrawRect(0,0,239,7,COLOR_WHITE,RECT_FILLED);
    GrayDrawStrExt(0,0,tmpstr,A_NORMAL | A_CENTERED | A_SHADOWED,F_4x6);

    if (ngetchx() == KEY_ESC) goto end;


    GrayOff();
    ClrScr();
    //---------------------------------------------------------------------
    // built-in OS line drawing routine ...
    //---------------------------------------------------------------------
    OSTimerRestart(USER_TIMER);
    for (j=0;j<4;j++) {
        WIN_RECT rect = {120, 64, 0, -40};
        for (i=-40;  i<280;i++) {rect.x1 = i; DrawClipLine(&rect,&(SCR_RECT){{0, 0, 239, 127}},A_XOR); }
        for (i=-40;  i<168;i++) {rect.y1 = i; DrawClipLine(&rect,&(SCR_RECT){{0, 0, 239, 127}},A_XOR); }
        for (i=280;i>=-40; i--) {rect.x1 = i; DrawClipLine(&rect,&(SCR_RECT){{0, 0, 239, 127}},A_XOR); }
        for (i=168;i>=-40; i--) {rect.y1 = i; DrawClipLine(&rect,&(SCR_RECT){{0, 0, 239, 127}},A_XOR); }
    }
    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"OS routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val);
    GrayDrawRect2B(0,0,239,7,COLOR_WHITE,RECT_FILLED,LCD_MEM,LCD_MEM);
    GrayDrawStrExt2B(0,0,tmpstr,A_NORMAL | A_CENTERED,F_4x6,LCD_MEM,LCD_MEM);

    if (ngetchx() == KEY_ESC) goto end;

    //---------------------------------------------------------------------
    // new line drawing routine ...
    //---------------------------------------------------------------------
    ClrScr();
    OSTimerRestart(USER_TIMER);
    for (j=0;j<4;j++) {
        for (i=-40;  i<280;i++) ClipDrawLine_R(120,64,i,-40,clippedcoord,A_XOR,LCD_MEM,FastDrawLine_R);
        for (i=-40;  i<280;i++) ClipDrawLine_R(120,64,280,i,clippedcoord,A_XOR,LCD_MEM,FastDrawLine_R);
        for (i=280;i>=-40; i--) ClipDrawLine_R(120,64,i,168,clippedcoord,A_XOR,LCD_MEM,FastDrawLine_R);
        for (i=168;i>=-40; i--) ClipDrawLine_R(120,64,-40,i,clippedcoord,A_XOR,LCD_MEM,FastDrawLine_R);
    }
    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"Own routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val);
    GrayDrawRect2B(0,0,239,7,COLOR_WHITE,RECT_FILLED,LCD_MEM,LCD_MEM);
    GrayDrawStrExt2B(0,0,tmpstr,A_NORMAL | A_CENTERED,F_4x6,LCD_MEM,LCD_MEM);

    ngetchx();

    end:
    OSFreeTimer(USER_TIMER);
    GrayOff();
    LCD_restore(screen);
    GKeyFlush();
    ST_helpMsg(EXTGRAPH_VERSION_PWDSTR);
}
Ejemplo n.º 29
0
// drawHiScoreBoard - draws the hiscore board, and updates it with the hiscore from the latest game
void drawHiScoreBoard(unsigned long int newscore) {
	SCORE scores[MAX_HISCORES];
	short int loop, pos = -1;
	char name[10], str[50], *error = "File I/O Error";
	HANDLE dlg;

	// restore interrupt handlers
	OSSetSR(0x0000);

	if (!loadHiScores(scores)) {
		// cannot open hiscore file -- display error
		DlgMessage(error,"Unable to Load HiScore Data",BT_OK,BT_NONE);
		return;
	}

	// check if latest score is a highscore
	for (loop = (MAX_HISCORES - 1); loop >= 0; loop--) {
		if (newscore > scores[loop].score) {
			// new HiScore!!
			pos = loop;
		}
	}

	if (pos != -1) {
		// if we found a new hiscore
		if ((dlg = DialogNewSimple(DLGWIDTH,DLGHEIGHT)) == H_NULL) {
			DlgMessage("Memory Allocation Error","Not Enough Free Memory!",BT_OK,BT_NONE);
		} else {
			DialogAddTitle(dlg,"New Hiscore!",BT_OK,BT_NONE);
			DialogAddRequest(dlg,5,25,"Your Name:",0,9,11);

			sprintf(str,"You earned the #%hd hiscore position!",pos+1);
			DialogAddText(dlg,5,15,str);

			do {
				// truncate name variable
				name[0] = 0;
			} while (DialogDo(dlg,CENTER,CENTER,name,NULL) != KEY_ENTER);

			// free the dialog box memory
			HeapFree(dlg);

			// move the hiscore list down
			if (pos < (MAX_HISCORES - 1)) {
				for (loop = (MAX_HISCORES - 1); loop > pos; loop--) {
					scores[loop].score = scores[loop - 1].score;
					scores[loop].name[0] = 0;
					strcpy(scores[loop].name,scores[loop - 1].name);
				}
			}

			// fill in the new hiscore
			scores[pos].score = newscore;
			scores[pos].name[0] = 0;
			strcpy(scores[pos].name,name);

			if (!saveHiScores(scores)) {
				DlgMessage(error,"Unable to save HiScore Board",BT_OK,BT_NONE);
			}
		}
	}

	// display the hiscore board

	// clear the screen
	ClrScr();

	// draw the screen borders
	drawBorder();

	// draw the game logo
	drawLogo();

	FontSetSys(F_8x10);
	DrawStr(25,35,"Hiscore Board",A_NORMAL);
	FontSetSys(F_6x8);

	for (loop = 0; loop < 5; loop++) {
		printf_xy(20,50+loop*10,"#%hd %-9s %lu",loop+1,scores[loop].name,scores[loop].score);
	}

	ngetchx();

	// disable interrupts
	OSSetSR(0x0700);

	// wait for keypresses to dissipate
	delay(KEYDELAY);
}
Ejemplo n.º 30
0
// main menu
inline void title(void) {
	clrscr();
	DrawStr(LCD_WIDTH/2-30,LCD_HEIGHT/2-4,"HIT ENTER!",A_NORMAL);
	ngetchx();
}