예제 #1
0
파일: gghost.c 프로젝트: kivan117/gghost
/**
 * \brief Blanks this game's eeprom slot.
 *
 * Used on first run to avoid garbage data in high score list. Could be used to intentionally wipe scores too, but isn't right now.
 */
void wipeEeprom(void)
{
	struct EepromBlockStruct ebs;//create temp eeprom block struct for use
	ebs.id = save_block; //assign temp struct to this game's eeprom block id

	for(u8 i = 0; i < 30; i++) //cycle through all 30 data bytes and set them to 0
		ebs.data[i] = 0x00;

	ebs.data[17] = 0x17; //set magic number so the block will check out as being good in the future
	EepromWriteBlock(&ebs); //write to eeprom
}
예제 #2
0
파일: misc.c 프로젝트: Aliandrana/uzebox
void loadEeprom(){
    //load eeprom savegame
    u8 code=EepromReadBlock(EEPROM_ID,(struct EepromBlockStruct*)&saveGame);
    if(code==EEPROM_ERROR_BLOCK_NOT_FOUND || saveGame.blankMarker==0xffffffff){
    	//setup eeprom save game block
    	saveGame.id=EEPROM_ID;
    	struct EepromBlockStruct* ptr=(struct EepromBlockStruct*)&saveGame;
    	for(u8 i=0;i<30;i++){
    		ptr->data[i]=0;
    	}
    	EepromWriteBlock((struct EepromBlockStruct*)&saveGame);
    }

}
예제 #3
0
파일: gghost.c 프로젝트: kivan117/gghost
/**
 * \brief Accepts a numerical score, saves it to eeprom if it's high enough.
 * \param hiscore the value to compare and possibly save to eeprom
 */
void SaveScore(u8 hiscore)
{
	struct EepromBlockStruct ebs; //create a temporary eeprom block struct for use
	ebs.id = save_block; //assign it to this game's eeprom block number

	//compare input score to topscores array, if input score is high enough, insert the score in the correct position
	//initially had some problems getting searching and sorting to work with scores.
	//it wasn't actually at all related to this function though, it was a problem elsewhere. need to refactor this to just use a for loop like it was before.
	u8 index = 0;
	bool searching=true;
	while(searching)
	{
		if(index > 9)
			searching=false;
		if(topscores[index] < hiscore)
		{
			for(u8 k = 9; k > index; k--)
			{
				topscores[k] = topscores[k-1];
			}
			topscores[index]=hiscore;
			searching=false;
		}
		index++;
	}

	//topscores array accurately reflects our top 10, so assign them to the temp eeprom block struct
	for(u8 h = 0; h < 10; h++)
	{
		ebs.data[h] = topscores[h];
	}

	ebs.data[17] = 0x17; //THIS IS KEY, we check this value to make sure the block is formatted correctly whenever the game is initially booted up

	EepromWriteBlock(&ebs); //actually write the data to eeprom
}
예제 #4
0
파일: Atomix.c 프로젝트: Aliandrana/uzebox
/**
 * Game loop
 */
void game() {
	while (level < LEVEL_COUNT) {
		level++;
	MENU:
		menu();

		load_level();
		refresh_game_screen();

		while (!is_level_done()) {

			int buttons = ReadJoypad(0);
			char* cursor_field_ptr = &(level_field[cursor_x + cursor_y * LEVEL_FIELD_WIDTH]);

			if (holding_atom) {
				if ((buttons & (BTN_A | BTN_B | BTN_X | BTN_Y))) {
					while (ReadJoypad(0) & (BTN_A | BTN_B | BTN_X | BTN_Y)) {};
					*cursor_field_ptr = holding_atom;
					holding_atom = false;
					draw_field();
					play_sound(SOUND_LEVEL_RELEASE);
				}
				if (buttons & BTN_LEFT) {
					draw_field();
					if (level_field[(cursor_x - 1) + cursor_y * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
						moves++;
						while (level_field[(cursor_x - 1) + cursor_y * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
							play_sound(SOUND_LEVEL_MOVE);
							for (uint8_t i = 0; i < TILE_WIDTH; i++) {
								sprites[SPRITE_CURSOR].x--;
								draw_statistics();
								WaitVsync(1);
							}
							cursor_x--;
							distance++;
						}
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
				if (buttons & BTN_RIGHT) {
					draw_field();
					if (level_field[(cursor_x + 1) + cursor_y * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
						moves++;
						while (level_field[(cursor_x + 1) + cursor_y * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
							play_sound(SOUND_LEVEL_MOVE);
							for (uint8_t i = 0; i < TILE_WIDTH; i++) {
								sprites[SPRITE_CURSOR].x++;
								draw_statistics();
								WaitVsync(1);
							}
							cursor_x++;
							distance++;
						}
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
				if (buttons & BTN_UP) {
					draw_field();
					if (level_field[cursor_x + (cursor_y - 1) * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
						moves++;
						while (level_field[cursor_x + (cursor_y - 1) * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
							play_sound(SOUND_LEVEL_MOVE);
							for (uint8_t i = 0; i < TILE_WIDTH; i++) {
								sprites[SPRITE_CURSOR].y--;
								draw_statistics();
								WaitVsync(1);
							}
							cursor_y--;
							distance++;
						}
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
				if (buttons & BTN_DOWN) {
					draw_field();
					if (level_field[cursor_x + (cursor_y + 1) * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
						moves++;
						while (level_field[cursor_x + (cursor_y + 1) * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
							play_sound(SOUND_LEVEL_MOVE);
							for (uint8_t i = 0; i < TILE_WIDTH; i++) {
								sprites[SPRITE_CURSOR].y++;
								draw_statistics();
								WaitVsync(1);
							}
							cursor_y++;
							distance++;
						}
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
			} else {
				if ((buttons & (BTN_A | BTN_B | BTN_X | BTN_Y))) {
					if ((*cursor_field_ptr >= TILE_FIRST_ATOM) && (*cursor_field_ptr <= TILE_LAST_ATOM)) {
						while (ReadJoypad(0) & (BTN_A | BTN_B | BTN_X | BTN_Y)) {};
						holding_atom = *cursor_field_ptr;
						*cursor_field_ptr = TILE_FLOOR;
						draw_field();
						play_sound(SOUND_LEVEL_CATCH);
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
				if (buttons & BTN_LEFT) {
					if (cursor_x > 0) {
						for (uint8_t i = 0; i < TILE_WIDTH; i++) {
							sprites[SPRITE_CURSOR].x--;
							WaitVsync(1);
						}
						cursor_x--;
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
				if (buttons & BTN_RIGHT) {
					if (cursor_x < LEVEL_FIELD_WIDTH - 1) {
						for (uint8_t i = 0; i < TILE_WIDTH; i++) {
							sprites[SPRITE_CURSOR].x++;
							WaitVsync(1);
						}
						cursor_x++;
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
				if (buttons & BTN_UP) {
					if (cursor_y > 0) {
						for (uint8_t i = 0; i < TILE_WIDTH; i++) {
							sprites[SPRITE_CURSOR].y--;
							WaitVsync(1);
						}
						cursor_y--;
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
				if (buttons & BTN_DOWN) {
					if (cursor_y < LEVEL_FIELD_HEIGHT - 1) {
						for (uint8_t i = 0; i < TILE_WIDTH; i++) {
							sprites[SPRITE_CURSOR].y++;
							WaitVsync(1);
						}
						cursor_y++;
					} else {
						play_sound(1);
					}
				}
			}
			if (buttons & BTN_SELECT) {
				play_sound(SOUND_MENU_SELECT);
				goto MENU;
			}
			if (buttons & BTN_START) {
				play_sound(SOUND_MENU_SELECT);
				while (ReadJoypad(0) & BTN_START);
				load_level();
				refresh_game_screen();
			}

			draw_cursor();
			draw_statistics();
			WaitVsync(5);
		}

		hide_sprites();
		play_sound(SOUND_LEVEL_CLEARED);
		WaitVsync(60);

		// mark level as cleared
		eeprom_data.data[level / 8] |= 1 << (level % 8);
		EepromWriteBlock(&eeprom_data);
	}
}
예제 #5
0
파일: misc.c 프로젝트: Aliandrana/uzebox
void saveEeprom(){
	EepromWriteBlock((struct EepromBlockStruct*)&saveGame);
}