Esempio n. 1
0
	//Callback invoked by UzeboxCore.Initialize()
	void DisplayLogo(){
	
		#if INTRO_LOGO !=0
			#define LOGO_X_POS 8
			
			InitMusicPlayer(logoInitPatches);
			screenSections[0].tileTableAdress=uzeboxlogo;
					
			//draw logo
			ClearVram();
			WaitVsync(15);		


			#if INTRO_LOGO == 1 
				TriggerFx(0,0xff,true);
			#endif

			DrawMap(LOGO_X_POS,12,map_uzeboxlogo);
			WaitVsync(3);
			DrawMap(LOGO_X_POS,12,map_uzeboxlogo2);
			WaitVsync(2);
			DrawMap(LOGO_X_POS,12,map_uzeboxlogo);

			#if INTRO_LOGO == 2
				SetMasterVolume(0xc0);
				TriggerNote(3,0,16,0xff);
			#endif 
		
			WaitVsync(65);
			ClearVram();
			WaitVsync(20);
		#endif	
	}
Esempio n. 2
0
	//Callback invoked by UzeboxCore.Initialize()
	void DisplayLogo(){
	
		#if INTRO_LOGO !=0
			#define LOGO_X_POS 18
			
			InitMusicPlayer(logoInitPatches);
			SetTileTable(uzeboxlogo);
					
			//draw logo
			ClearVram();
			WaitVsync(15);		


			#if INTRO_LOGO == 1 
				TriggerFx(0,0xff,true);
			#endif

			DrawMap2(LOGO_X_POS,12,map_uzeboxlogo);
			WaitVsync(6);
			DrawMap2(LOGO_X_POS,12,map_uzeboxlogo2);
			WaitVsync(4);
			DrawMap2(LOGO_X_POS,12,map_uzeboxlogo);

			#if INTRO_LOGO == 2
				SetMasterVolume(0xc0);
				TriggerNote(3,0,16,0xff);
			#endif 
		
			WaitVsync(64);
			ClearVram();
			WaitVsync(20);
		#endif	
	}
Esempio n. 3
0
int main(){

	//Set the font and tiles to use.
	//Always invoke before any ClearVram()
	SetTileTable(font);


	//Clear the screen (fills the vram with tile zero)
	ClearVram();

	//define background color for text rows 10,12 & 14
	backgroundColor[10]=2;
	backgroundColor[12]=6;
	backgroundColor[14]=2;

	//Prints a string on the screen. Note that PSTR() is a macro 
	//that tells the compiler to store the string in flash.
	Print(0,10,PSTR("012345678901234567890123456789012345678901234567890123456789"));
	Print(9,12,PSTR("HIGH RESOLUTION MODE DEMO 60X28 - 6X8 TILES"));
	Print(0,14,PSTR("012345678901234567890123456789012345678901234567890123456789"));
	

	while(1);

} 
Esempio n. 4
0
void WinGame(){

	while(GetMasterVolume()){
		if(GetMasterVolume() > 4)
			SetMasterVolume(GetMasterVolume()-4);
		else{
			StopSong();
			break;
		}
		WaitVsync(1);
	}
	FadeOut(9,true);
	SetTileTable(font_tiles);
	ClearVram();
	WaitVsync(45);
	SetMasterVolume(BB_MASTER_VOLUME);
	//TriggerNote(4,24,8,255);//StartSong(main_song);
	FadeIn(2,false);
	TextWriter(1,0,epilogue_string);
	while(1){
		WaitVsync(1);
		if(padState & BTN_START && !(oldPadState & BTN_START))
			break;
	}
	FadeOut(7,true);
}
Esempio n. 5
0
/**
 * \brief Draws Main Menu screen.
 */
void drawMainMenu()
{
	//setup cursor position for use with this menu screen
	menu_x = fakemod((drawX+9),VRAM_TILES_H);
	menu_y = 15;
	ClearVram(); //wipe screen
	drawFrame(); //draw up generic menu frame

	//draw fancy title. broken into pieces so it can be reused as much as possible to save space
	DrawMap2(fakemod((drawX+7),VRAM_TILES_H),4,title_gh);
	DrawMap2(fakemod((drawX+13),VRAM_TILES_H),4,title_o);
	DrawMap2(fakemod((drawX+16),VRAM_TILES_H),4,title_st);
	DrawMap2(fakemod((drawX+21),VRAM_TILES_H),4,title_y);
	DrawMap2(fakemod((drawX+9),VRAM_TILES_H),9,title_gh);
	DrawMap2(fakemod((drawX+15),VRAM_TILES_H),10,title_moon);
	DrawMap2(fakemod((drawX+18),VRAM_TILES_H),9,title_st);

	//draw menu options
	Print(fakemod((drawX+11),VRAM_TILES_H),15,PSTR("START GAME"));
	Print(fakemod((drawX+11),VRAM_TILES_H),17,PSTR("HI SCORES"));
	Print(fakemod((drawX+11),VRAM_TILES_H),19,PSTR("SOUND:"));
	//draw copyright info
	Print(fakemod((drawX+4),VRAM_TILES_H),24,PSTR("(C) 2015 JAMES ELLIOTT"));
	//draw on/off next to sound option
	refreshMainMenuSound();
}
Esempio n. 6
0
int main()
{
	ClearVram();
	SetTileTable(graphicsTiles);
	Screen.overlayTileTable = overlayTiles;
	
	for(int y=0;y<32;y++){
		for(int x=0;x<32;x++){
			SetTile(x,y,0);
		}	
	}

	Screen.scrollHeight = SCREEN_SCROLL_HEIGHT;
	Screen.overlayHeight = SCREEN_OVERLAY_HEIGHT;

	Map_Init();
	int cameraSpeed = 1;
	
	while(1)
	{
		uint16_t joypad = ReadJoypad(0);
		
		if((joypad & BTN_A))
		{
			cameraSpeed = 4;
		}
		else
		{
			cameraSpeed = 1;
		}
		
		if((joypad & BTN_LEFT) && Camera_Position.x > cameraSpeed)
		{
			Camera_Position.x -= cameraSpeed;
		}
		if((joypad & BTN_RIGHT) && Camera_Position.x < (Map_Header.width - MAP_TILE_SCROLL_WRAP_X - 1) * MAP_TILE_PIXEL_SIZE - cameraSpeed)
		{
			Camera_Position.x += cameraSpeed;
		}
		if((joypad & BTN_UP) && Camera_Position.y > cameraSpeed)
		{
			Camera_Position.y -= cameraSpeed;
		}
		if((joypad & BTN_DOWN) && Camera_Position.y < (Map_Header.height - MAP_TILE_SCROLL_WRAP_Y - 1) * MAP_TILE_PIXEL_SIZE - cameraSpeed)
		{
			Camera_Position.y += cameraSpeed;
		}
		
		Map_Update();
//		Screen.scrollX = Camera_Position.x;
	//	Screen.scrollY = Camera_Position.y;

		WaitVsync(1);
	}
	
	return 0;
}
Esempio n. 7
0
/**
 * Does complete refresh of game screen
 */
void refresh_game_screen() {
	ClearVram();
	DrawMap2(0, 0, tiles_screen);
	draw_field();
	draw_molecule(SCREEN_MOLECULE_X, SCREEN_MOLECULE_Y);
	draw_statistics();
	draw_name();
	draw_cursor();
}
Esempio n. 8
0
/**
 * \brief Performs setup and re-initialization needed before each new game.
 *
 * Resets the player score, resets variables for drawing columns, sets a new random ghost color, moves the player back to the starting position, erases columns from last game,
 * turns scrolling back on and makes the player visible again.
 */
static void gameSetup()
{
	randomSky();
	//fill screen with tile 1 again to erase menu
	ClearVram();

	for(u8 i = 0; i < 4; i++) //reset column data with 0's to start fresh
	{
		pipe_x[i] = 0;
		pipe_y[i] = 0;
	}
	for(u8 k = 0; k < 32; k++)
	{
		bg[k] = 1;
	}

	//reset all score data from last game to 0
	score = 0;//score = 0;
	score_ones=0;
	score_tens=0;
	score_hundreds=0;

	fake_x = 80; //reset how far we've flown
	player_x = 80; //reset player position
	player_y = 40;
	yspeed = 0; //make sure we start at 0 speed

	//draw the background
	for(u8 i = 0; i < VRAM_TILES_H; i++)
	{
		pipe_alarm=2; //make sure we never draw a column while we're drawing the starting screen
		loadNextStripe(); //go through each column and draw the background
	}

	//select a random color for the ghost and set the appropriate sprite
	ghost_color=(prng()%3); //the ghost has 3 frames and 3 color options, so we set the active sprite to the frame count (0 - 2) + the color (0, 3, or 6) to get the correct sprite
	ghost_color=(ghost_color+(ghost_color<<1));
	current_sprite = player_sprites[current_frame+ghost_color];
	//assign and move the player image to start the new game
	MoveSprite(0,player_x,player_y,3,3);
	MapSprite2(0,current_sprite,0);
	//make player visible
	SetSpriteVisibility(true);

	//reset variables to draw new columns correctly
	current_pipe=0;
	build_pipe=0;
	pipe_alarm = 1;
	pipe_col_drawn = 0;

	//turn scrolling on to begin the game
	scrollingOn=true;

}
void init(MainStruct *mains, PlayerStruct players[], char nrplayers, GameStruct *game, ItemStruct zombie[MAX_ZOMBIES], ItemStruct shots[][2])
{
	ClearVram();
	srand(game->frames);

	//Set everything to 0
	memset(mains, 0, sizeof(MainStruct));
	memset(players, 0, sizeof(PlayerStruct)*nrplayers);
	memset(game, 0, sizeof(GameStruct));
	memset(zombie, 0, sizeof(ItemStruct)*MAX_ZOMBIES);
	memset(shots, 0, sizeof(ItemStruct)*4);
	memset(sprites, 0, sizeof(struct SpriteStruct)*32);

	//init graphics as well
	initgraphics(mains);
	setoverlay(nrplayers);

	for(int p = 0; p < nrplayers; p++)
	{
		//Main char sprites and guns
		players[p].sprite.nrsprite = 1 + 4 * p;
		players[p].sprite.animcount = 0;
		players[p].sprite.nranim = 1 + 22 * p;

		sprites[players[p].sprite.nrsprite].tileIndex=1 + 22 * p;
		sprites[players[p].sprite.nrsprite+1].tileIndex=11 + 22 * p;
		sprites[players[p].sprite.nrsprite].x = sprites[players[p].sprite.nrsprite+1].x = players[p].x;
		sprites[players[p].sprite.nrsprite].y = players[p].y;
		sprites[players[p].sprite.nrsprite+1].y = players[p].y + TILE_HEIGHT;

		//Init the shots as well.
		for(int i = 0; i < 2; i++)
		{
			shots[p][i].sprite.nrsprite = players[p].sprite.nrsprite + 2 + i;	
			shots[p][i].sprite.nranim = 64;
			shots[p][i].x = shots[p][i].y = DISABLED_SPRITE;
			shots[p][i].kill = NOT_ZOMBIE;
			sprites[shots[p][i].sprite.nrsprite].tileIndex = 64;
		}

		//init player variables
		players[p].x = 72 + 10 * p; //entry point yeah!
		players[p].y = 166;
		players[p].life = 3;
		players[p].gundelay = 35;
	}

	//init various game variables
	game->zombies = 1;
	initzombie(&(zombie[0]), mains, 9);

	return;
}
Esempio n. 10
0
int main(){

	unsigned int i;
	unsigned int j;

	ClearVram();
	SetBorderColor(0xBFU);

	/* Fill VRAM */

	for (i = 0U; i < VRAM_SIZE; i++){
		aram[i * 2U     ] = (i     ) & 0xFFU;
		aram[i * 2U + 1U] = (i * 3U) & 0xFFU;
	}

	for (i = 0U; i < VRAM_SIZE; i++){
		vram[i] = (i * 5U) & 0xFFU;
	}

	/* Bitmap modes */

	palette[0] = 0x00U;
	palette[1] = 0xC0U;
	palette[2] = 0x38U;
	palette[3] = 0xF8U;
	palette[4] = 0x07U;
	palette[5] = 0xC7U;
	palette[6] = 0x3FU;
	palette[7] = 0xFFU;

	SetTileTableRow(M40_TILEROW_3BPP, 8U);
	SetTileTableRow(M40_TILEROW_3BPP, 9U);
	SetTileTableRow(M40_TILEROW_3BPP, 10U);
	SetTileTableRow(M40_TILEROW_3BPP, 11U);

	SetTileTableRow(M40_TILEROW_1BPP, 12U);
	SetTileTableRow(M40_TILEROW_1BPP, 13U);
	SetTileTableRow(M40_TILEROW_1BPP, 14U);
	SetTileTableRow(M40_TILEROW_1BPP, 15U);

	for (j = 0U; j < 16U; j ++){
		for (i = 0U; i < 32U; i ++){
			PutPixel(i + (j << 1) + 0U, i + 32U, j);
			PutPixel(i + (j << 1) + 1U, i + 32U, j);
		}
	}

	while(1);

}
Esempio n. 11
0
/**
 * Called by the assembler initialization routines, should not be called directly.
 */
void InitConsole(void){

#if INTRO_LOGO ==1 
	InitMusicPlayer(initPatches);	
	SetTileTable(uzeboxlogo);
	SetFontTable(uzeboxlogo);
	
	//draw logo
	ClearVram();
	WaitVsync(15);

	TriggerFx(0,0xff,true);
	DrawMap(LOGO_X_POS,12,map_uzeboxlogo);
	WaitVsync(3);
	DrawMap(LOGO_X_POS,12,map_uzeboxlogo2);
	WaitVsync(2);
	DrawMap(LOGO_X_POS,12,map_uzeboxlogo);
	WaitVsync(40);

	ClearVram();
	WaitVsync(20);
#endif
}
Esempio n. 12
0
/**
 * \brief Helper function to draw the reusable menu frame.
 */
void drawFrame(void)
{
	SetSpriteVisibility(false); //turn off sprites for now, the menus only use background tiles anyway

	//to minimize weird problems with drawing a static screen due to mode 3 scrolling, or VRAM_TIES_H vs SCREEN_TILES_H (or something, couldn't figure it out)
	//scroll the game back to its starting position then turn scrolling back off
	scrollingOn=true;
	while(scroll != 0) //reset to align edge of screen to a tile, not part way in between
	{
		processScrollSpeed();
	}
	while(drawX != (VRAM_TILES_H-1)) //scroll until the screen is aligned with its starting position (tile position 0 at far left)
	{
		processScrollSpeed();
	}
	scrollingOn=false;


	ClearVram(); //clear screen to prep for drawing the frame

	u8 drawXTemp = fakemod((drawX+2),VRAM_TILES_H);//variable used for tracking horizontal position of tiles as we draw them. drawing is done top to bottom left to right

	SetTile(drawXTemp, 1, FRAME_TL); //place top left corner tile
	for(u8 y=2; y<VRAM_TILES_V-2; y++)//draw lefthand border
	{
		SetTile(drawXTemp, y, FRAME_L);
	}
	SetTile(drawXTemp, VRAM_TILES_V-2, FRAME_BL); //place bottom left corner tile

	for(u8 x=0; x<24; x++)//draw middle portion of frame until we reach the right hand side
	{
		drawXTemp=fakemod((drawXTemp+1),VRAM_TILES_H);
		SetTile(drawXTemp, 1, FRAME_T); //draw top piece
		for(u8 y=2; y<VRAM_TILES_V-2; y++) //fill middle with black
		{
			SetTile(drawXTemp, y, BLACK);
		}
		SetTile(drawXTemp, VRAM_TILES_V-2, FRAME_B); //draw bottom piece
	}

	drawXTemp=fakemod((drawXTemp+1),VRAM_TILES_H);
	SetTile(drawXTemp, 1, FRAME_TR); //place top right corner tile
	for(u8 y=2; y<VRAM_TILES_V-2; y++) //draw righthand border
	{
		SetTile(drawXTemp, y, FRAME_R);
	}
	SetTile(drawXTemp, VRAM_TILES_V-2, FRAME_BR); //place bottom right corner tile

}
Esempio n. 13
0
/**
 * \brief Draws local high score menu.
 *
 * Uses the values saved in the topscores array, not eeprom values, this allows displaying scores separately from saving/loading.
 */
void drawLocalHighScoreMenu(void)
{
	//set cursor for use with this menu (may one day be needed for scrolling)
	menu_x = fakemod((drawX+9),VRAM_TILES_H);
	menu_y = 15;
	ClearVram(); //blank screen
	drawFrame(); //draw generic gui frame
	Print(fakemod((drawX+6),VRAM_TILES_H),3,PSTR("LOCAL TOP SCORES:")); //write menu title at top of screen

	for(u8 i = 0; i < 10; i++) //print scores 1 - 10 from topscores array
	{
		PrintInt(fakemod((drawX+17),VRAM_TILES_H),6+(i<<1),topscores[i], false);
		PrintInt(fakemod((drawX+11),VRAM_TILES_H),6+(i<<1),i+1, false);
		Print(fakemod((drawX+12),VRAM_TILES_H),6+(i<<1),PSTR("."));
	}
}
Esempio n. 14
0
/**
 * \brief Performs some basic initialization functions.
 *
 * Sets up our graphics, initializes a few variables for convenience, loads saved scores and gets the music going.
 */
static void initialSetup()
{
	SetSpritesTileTable(ghost_sprites); //sets the tiles to be used for our various sprites
	SetFontTilesIndex(TITLE_TILES_SIZE); //tiles for the font were included immediately after the include for background tiles
	                               //therefore this says how many tiles in memory to move forward from the first one
	                               //in order to find the beginning of the font tiles
	SetTileTable(title_tiles); //sets the tiles to be used for the normal background tiles in the game
	                     //fonts use this and the index above to set font tiles
	InitMusicPlayer(patches); //initialize the sound engine
	SetMasterVolume(0xff); //set volume to max
	StartSong(midisong); //start playing the main theme
	ClearVram(); //fill entire screen with first tile in the tileset (blank the screen)

	//set up some convenience variables for changing player image and drawing the score
	player_sprites[0]=ghost0;
	player_sprites[1]=ghost1;
	player_sprites[2]=ghost2;
	player_sprites[3]=ghost3;
	player_sprites[4]=ghost4;
	player_sprites[5]=ghost5;
	player_sprites[6]=ghost6;
	player_sprites[7]=ghost7;
	player_sprites[8]=ghost8;
	numbers[0]=num0;
	numbers[1]=num1;
	numbers[2]=num2;
	numbers[3]=num3;
	numbers[4]=num4;
	numbers[5]=num5;
	numbers[6]=num6;
	numbers[7]=num7;
	numbers[8]=num8;
	numbers[9]=num9;

	//checks if our desired eeprom block is setup correctly,
	//if not, it wipes it so we don't have to deal with garbage data in the high score list
	if(checkEeprom()==1)
	{
		wipeEeprom();
	}
	//load our top 10 saved scores from eeprom
	LoadScore(0, 9);
}
Esempio n. 15
0
/**
 * \brief Draws the custom intro
 */
void drawIntro(void)
{
	ClearVram(); //wipe screen each frame
	frame_tick--;
	if(frame_tick == 0) //animation alarm has been reached, reset alarm and change sprite to next frame
	{
		frame_tick = 8; //reset alarm
		current_frame++; //move forward to next animation frame
		if(current_frame == max_frames)
		{
			current_frame=0;
		}
		current_sprite = player_sprites[current_frame]; //change our tracking variable to the correct sprite based on new frame
		MapSprite2(0, current_sprite, 0); //actually reassign the sprites in memory to the correct images
	}
	MoveSprite(0, player_x, player_y, 3, 3); //position ghost sprite
	DrawMap2(13,12,map_uzeboxlogo); //draw uzebox logo and name
    if((player_x > 104)&&(player_x<108)) //at the right moment, draw the shiny reflection on the logo
        DrawMap2(13,12,map_uzeboxlogo2);
}
Esempio n. 16
0
int main(){


SetTileTable(tiles);			//Set the tileset to use (set this first)
SetFontTilesIndex(TILES_SIZE);	//Set the tile number in the tilset that contains the first font
ClearVram();					//Clear the screen (fills the vram with tile zero)

long sectorStart;

sdCardInitNoBuffer();

sectorStart = sdCardFindFileFirstSectorFlash(fileName);

if(sectorStart == 0){
	Print(0,0,PSTR("FILE HELLWRLD.TXT NOT FOUND ON SD CARD"));
} else {

    sdCardCueSectorAddress(sectorStart);


    /*

    HELLO WORLD FROM THE SD CARD
    VERTICAL TEXT
    DOUBLE SPACES
    DOUBLE LINE SPACING DOUBLE LINE SPACING  DOUBLE LINE SPACING DOUBLE LINE SPACING
    RUN2SPANXFOR16BITINDEX

	*/

    // sdCardDirectReadSimple(uint8_t *dest, uint16_t count);
    // sdDirectRead(uint8_t *dest, uint16_t count, uint8_t span, uint8_t run);
    //
    //
    // HELLO WORLD FROM THE SD CARD
    // Read 28 bytes of test straight to VRAM
    // sdCardDirectReadSimple(address, length) == sdDriectReadSimple(address, length, 0, 0)
    // That is SPAN = 0 RUN = 0

    sdCardDirectReadSimple(&vram[COORD(0,0)], 28);    // HELLO WORLD
    sdCardSkipBytes(1);                           // Skip the CR/LF

    // VERTICAL TEXT
    // SPAN = 39
    // RUN = 1
    //
    // Every 1 (RUN) byte skip 39 (SPAN) bytes
    //
    // Screen width = 40 so 39 is screen width - 1

    sdCardDirectRead(&vram[COORD(0,2)], 13, 39, 1);   // VERTICAL TEXT
    sdCardSkipBytes(1);                           // Skip the CR/LF

    // DOUBLE SPACES
    // SPAN = 1
    // RUN = 1
    //
    // Every 1 (RUN) byte skip 1 (SPAN) bytes

    sdCardDirectRead(&vram[COORD(3,2)], 13, 1, 1);    // DOUBLE SPACES
    sdCardSkipBytes(1);                           // Skip the CR/LF

    // DOUBLE SPACES
    // SPAN = 39
    // RUN = 80
    //
    // Every 40 (RUN) bytes skip 39 (SPAN) bytes
    // 40 is one whole line of text
    // 39 is (40-1)

    sdCardDirectRead(&vram[COORD(0,17)], 80, 39, 40); // DOUBLE LINE SPACING
    sdCardSkipBytes(1);                           // Skip the CR/LF

    // 16 bit modes
    // SPAN = 38
    // RUN = 2
    //
    // Every 2 (RUN) bytes skip 38 (SPAN) bytes
    // 2 bytes = 16 bits.  So modes with a 16 bit tile index could use this to fill in a column
    // 38 is (40-2)

    sdCardDirectRead(&vram[COORD(20,4)], 22, 38, 2);  // 16 BIT MODES
}

while(1);

}
Esempio n. 17
0
char introscreen(GameStruct* game)
{
	unsigned char counter;
	unsigned int joypad;

	ClearVram();
	memset(sprites, 0, sizeof(struct SpriteStruct)*32);

	SetFontTilesIndex(49);
	screenSections[1].flags = SCT_PRIORITY_BG;
	screenSections[0].tileTableAdress = zombienator_title;
	screenSections[1].scrollX = screenSections[1].scrollY = 0;
	setoverlay(0);

	game->menupos = counter = 0;

	DrawMap2(0,6, title_map);
	for(int i = 0; i < 22; i++)
		SetTile(i, 10, 27 + i);

	for(;;)
	{
		WaitVsync(1);
		Fill(0,13, SCREEN_TILES_H, SCREEN_TILES_V - 13, 0);

		Print(5, 14, singlestr);
		Print(5, 15, multistr);
		Print(5, 16, highstr);
		Print(3, 14 + game->menupos, selectstr);
		joypad = 0;
		counter++;
		game->frames++;
		
		if(counter >= 15)
		{
			counter = 0;
			while(!(joypad&(BTN_START|BTN_SELECT|BTN_UP|BTN_DOWN)))
			{
				joypad = ReadJoypad(0);
				switch(joypad&(BTN_START|BTN_SELECT|BTN_UP|BTN_DOWN))
				{
					case BTN_START:
					case BTN_SELECT:
						if(game->menupos == 0)
							return 1;
						else if(game->menupos == 1)
							return 2;
						break;
					case BTN_UP:
						if(game->menupos > 0 )
							game->menupos--;
						else
							game->menupos = 2;
						break;
					case BTN_DOWN:
						if(game->menupos < 2)
							game->menupos++;
						else
							game->menupos = 0;
						break;
				}
			}
		}
	}


	return 0;
}
Esempio n. 18
0
/**
 * Main menu (level selection)
 */
void menu() {
	uint8_t scroll = 0;
	uint8_t delay = false;
	uint8_t e_traj_offset1 = 0;
	uint8_t e_traj_offset2 = ELECTRON_TRAJECTORY_LAST_STEP / 2;

	unsigned int joypad;

	ClearVram();
	hide_sprites();

	for (uint8_t sprite_id = 0; sprite_id < 6; sprite_id++) {
		sprites[sprite_id].tileIndex = TILE_FIRST_ELECTRON + sprite_id;
	}

	DrawMap2(2, 2, logo_logo_map);

	// credits
	Print(2, 23, PSTR("2011 UZEBOX ATOMIX"));
	Print(2, 24, PSTR("PROGRAM: MARTIN SUSTEK"));
	Print(2, 25, PSTR("LEVEL DESIGN: ANDREAS WUEST"));

	// initial scroll position
	scroll = (level - 1);
	if ((level - 1) < SCREEN_MENU_LEVEL_LINES) {
		scroll = 0;
	}
	if ((level - 1) > LEVEL_COUNT - SCREEN_MENU_LEVEL_LINES) {
		scroll = LEVEL_COUNT - SCREEN_MENU_LEVEL_LINES;
	}

	while (true) {
		WaitVsync(1);

		// electrons animation
		e_traj_offset1++;
		if (e_traj_offset1 > ELECTRON_TRAJECTORY_LAST_STEP) {
			e_traj_offset1 = 0;
		}
		e_traj_offset2++;
		if (e_traj_offset2 > ELECTRON_TRAJECTORY_LAST_STEP) {
			e_traj_offset2 = 0;
		}
		sprites[0].x = (SCREEN_ELECTRON_X + pgm_read_byte(e_traj_1x + e_traj_offset1));
		sprites[0].y = (SCREEN_ELECTRON_Y + pgm_read_byte(e_traj_1y + e_traj_offset1));
		sprites[1].x = (SCREEN_ELECTRON_X + pgm_read_byte(e_traj_2x + e_traj_offset2));
		sprites[1].y = (SCREEN_ELECTRON_Y + pgm_read_byte(e_traj_2y + e_traj_offset2));
		sprites[2].x = (SCREEN_ELECTRON_X + pgm_read_byte(e_traj_3x + e_traj_offset1));
		sprites[2].y = (SCREEN_ELECTRON_Y + pgm_read_byte(e_traj_3y + e_traj_offset1));
		sprites[3].x = (SCREEN_ELECTRON_X + pgm_read_byte(e_traj_1x + e_traj_offset2));
		sprites[3].y = (SCREEN_ELECTRON_Y + pgm_read_byte(e_traj_1y + e_traj_offset2));
		sprites[4].x = (SCREEN_ELECTRON_X + pgm_read_byte(e_traj_2x + e_traj_offset1));
		sprites[4].y = (SCREEN_ELECTRON_Y + pgm_read_byte(e_traj_2y + e_traj_offset1));
		sprites[5].x = (SCREEN_ELECTRON_X + pgm_read_byte(e_traj_3x + e_traj_offset2));
		sprites[5].y = (SCREEN_ELECTRON_Y + pgm_read_byte(e_traj_3y + e_traj_offset2));

		for (uint8_t i = 0; i < SCREEN_MENU_LEVEL_LINES; i++) {
			uint8_t current_level = (i + 1 + scroll);
			if ((current_level > 0) && (current_level <= 50)) {
				uint8_t y = 11 + i;
				// level number
				PrintByte(3, y, current_level, false);

				// level name (shorten and pad with spaces)
				for (uint8_t j = 0; j < 24; j++) {
					char ch = pgm_read_byte(levels + (current_level - 1) * LEVEL_BYTE_SIZE + j);
					if (ch == '\0') {
						ch = ' ';
					}
					PrintChar(6 + j, y, ch);
				}

				// level done yet symbol
				if (eeprom_data.data[current_level / 8] & 1 << (current_level % 8)) {
					PrintChar(4, y, FONT_TICK);
				} else {
					PrintChar(4, y, ' ');
				}

				// cursor symbol
				if (current_level == level) {
					PrintChar(5, y, FONT_CURSOR);
				} else {
					PrintChar(5, y, ' ');
				}
			}
		}
		// molecule thumbnail
		draw_molecule(21, 2);

		// controls
		if (delay) {
			WaitVsync(4);
			delay = false;
		}
		joypad = ReadJoypad(0);
		if (joypad & BTN_UP) {
			if (level > 1) {
				play_sound(SOUND_MENU_MOVE);
				level--;
				if (scroll + 1 > level) {
					scroll--;
				}
				delay = true;
			} else {
				play_sound(SOUND_MENU_CANT_MOVE);
			}
		}
		if (joypad & BTN_DOWN) {
			if (level < LEVEL_COUNT) {
				play_sound(SOUND_MENU_MOVE);
				level++;
				if (scroll + SCREEN_MENU_LEVEL_LINES < level) {
					scroll++;
				}
				delay = true;
			} else {
				play_sound(SOUND_MENU_CANT_MOVE);
			}
		}
		if (joypad & BTN_START) {
			hide_sprites();
			play_sound(SOUND_MENU_SELECT);
			return;
		}

	}
}
Esempio n. 19
0
int main()
{
	// clear the video
	ClearVram(); 
	
	// init the music
	InitMusicPlayer(patches);

	// show the intro screen
	DoIntro();
	
	// joystick previous states
	int padPrev[2] = {0,0};
	
	// now the game loop
	while(1)
	{
		// wait for v sync
		WaitVsync(1);
		
		// load the next state if we need to
		if(nextState > 0)
		{
			// set the new game state and reset the next state
			gameState = nextState;
			nextState = 0;
			
			// fade out
			FadeOut(1, true);
			
			// init the state
			if(gameState == STATE_MAINMENU)
				InitState_MainMenu();
			else if(gameState == STATE_PLAYING)
				InitState_Playing();
			else if(gameState == STATE_HOWTOPLAY)
				InitState_HowToPlay();
			else if(gameState == STATE_CREDITS)
				InitState_Credits();
			else if(gameState == STATE_PLAYERSTART)
				InitState_PlayerStart();
			else if(gameState == STATE_GAMEOVER)
				InitState_GameOver();
		}
		
		// handle the input
		padHeld[0] = ReadJoypad(0);
		padPressed[0] = padHeld[0] & (padHeld[0] ^ padPrev[0]);
		padReleased[0] = padPrev[0] & (padHeld[0] ^ padPrev[0]);
		padPrev[0] = padHeld[0];
		padHeld[1] = ReadJoypad(0);//1);
		padPressed[1] = padHeld[1] & (padHeld[1] ^ padPrev[1]);
		padReleased[1] = padPrev[1] & (padHeld[1] ^ padPrev[1]);
		padPrev[1] = padHeld[1];
		
		// handle the states
		if(gameState == STATE_MAINMENU)
			DoState_MainMenu();
		else if(gameState == STATE_PLAYING)
			DoState_Playing();
		else if(gameState == STATE_HOWTOPLAY)
			DoState_HowToPlay();
		else if(gameState == STATE_CREDITS)
			DoState_Credits();
		else if(gameState == STATE_PLAYERSTART)
			DoState_PlayerStart();
		else if(gameState == STATE_GAMEOVER)
			DoState_GameOver();
	}
}
Esempio n. 20
0
int main(){
	SetTileTable(cTesterTiles);
	SetSpritesTileTable(cursor);
	ClearVram();

	EnableSnesMouse(0,map_cursor);

	//Print the basic stuff on the screen
	DrawMap2(5,26,map_copyright);
	DrawMap2(0,13,map_divider);
	//Detect controller types
	cType[0] = 255; 
	cType[1] = 255; 
	//The controller vars
	int btnHeld[2] = {0,0};
	int btnPressed[2] = {0,0};
	int btnReleased[2] = {0,0};
	int btnPrev[2] = {0,0};
	//Main loop
	while(1){
		//20fps
		WaitVsync(1);
		//Update the controller vars
		btnHeld[0] = ReadJoypad(0);
		btnHeld[1] = ReadJoypad(1);
		btnPressed[0] = btnHeld[0] & (btnHeld[0] ^ btnPrev[0]);
		btnPressed[1] = btnHeld[1] & (btnHeld[1] ^ btnPrev[1]);
		btnReleased[0] = btnPrev[0] & (btnHeld[0] ^ btnPrev[0]);
		btnReleased[1] = btnPrev[1] & (btnHeld[1] ^ btnPrev[1]);
		//Check if controllers changed
		if((DetectControllers() & 3) != cType[0]){
			cType[0] = DetectControllers() & 3;
			Fill(0,0,30,13,0);
			if(cType[0] == GAMEPAD){
				DrawMap2(9,2,map_gamepad);
			}
			else if(cType[0] == MOUSE){
				DrawMap2(12,2,map_mouse);
				DrawMap2(1,4,map_warning);
			}
			else if(cType[0] == NOTHING){
				DrawMap2(9,6,map_nocontroller);
			}
		}
		if((DetectControllers() & 12) / 4 != cType[1]){
			cType[1] = (DetectControllers() & 12) / 4;
			Fill(0,14,30,12,0);
			if(cType[1] == GAMEPAD){
				DrawMap2(9,15,map_gamepad);
				SetSpriteVisibility(false);
			}
			else if(cType[1] == MOUSE){
				DrawMap2(12,15,map_mouse);
				SetSpriteVisibility(true);
				EnableSnesMouse(0,map_cursor);
			}
			else if(cType[1] == NOTHING){
				DrawMap2(9,19,map_nocontroller);
				SetSpriteVisibility(false);
			}
		}
		//Update the buttons
		for(unsigned int i = 0; i < 2; i++){
			if(cType[i] == MOUSE){
				//Check pressed buttons
				if(btnPressed[i] & BTN_MOUSE_LEFT){
					DrawMap2(14,4 + 13*i,map_pmouseb);
				}
				if(btnPressed[i] & BTN_MOUSE_RIGHT){
					DrawMap2(16,4 + 13*i,map_pmouseb);
				}
				//Check released
				if(btnReleased[i] & BTN_MOUSE_LEFT){
					DrawMap2(14,4 + 13*i,map_mouseb);
				}
				if(btnReleased[i] & BTN_MOUSE_RIGHT){
					DrawMap2(16,4 + 13*i,map_mouseb);
				}
			}
			else if(cType[i] == GAMEPAD){
				//Check pressed
				if(btnPressed[i] & BTN_UP){
					DrawMap2(11,6 + 13*i,map_pdpad);
				}
				if(btnPressed[i] & BTN_DOWN){
					DrawMap2(11,8 + 13*i,map_pdpad);
				}
				if(btnPressed[i] & BTN_LEFT){
					DrawMap2(10,7 + 13*i,map_pdpad);
				}
				if(btnPressed[i] & BTN_RIGHT){
					DrawMap2(12,7 + 13*i,map_pdpad);
				}
				if(btnPressed[i] & BTN_START){
					DrawMap2(16,6 + 13*i,map_pstart);
				}
				if(btnPressed[i] & BTN_SELECT){
					DrawMap2(14,6 + 13*i,map_pstart);
				}
				if(btnPressed[i] & BTN_A){
					DrawMap2(20,7 + 13*i,map_pbutton);
				}
				if(btnPressed[i] & BTN_B){
					DrawMap2(19,8 + 13*i,map_pbutton);
				}
				if(btnPressed[i] & BTN_X){
					DrawMap2(19,6 + 13*i,map_pbutton);
				}
				if(btnPressed[i] & BTN_Y){
					DrawMap2(18,7 + 13*i,map_pbutton);
				}
				if(btnPressed[i] & BTN_SL){
					DrawMap2(10,4 + 13*i,map_pbumper);
				}
				if(btnPressed[i] & BTN_SR){
					DrawMap2(18,4 + 13*i,map_pbumper);
				}
				if(btnReleased[i] & BTN_UP){
					DrawMap2(11,6 + 13*i,map_dpad);
				}
				if(btnReleased[i] & BTN_DOWN){
					DrawMap2(11,8 + 13*i,map_dpad);
				}
				if(btnReleased[i] & BTN_LEFT){
					DrawMap2(10,7 + 13*i,map_dpad);
				}
				if(btnReleased[i] & BTN_RIGHT){
					DrawMap2(12,7 + 13*i,map_dpad);
				}
				if(btnReleased[i] & BTN_START){
					DrawMap2(16,6 + 13*i,map_start);
				}
				if(btnReleased[i] & BTN_SELECT){
					DrawMap2(14,6 + 13*i,map_start);
				}
				if(btnReleased[i] & BTN_A){
					DrawMap2(20,7 + 13*i,map_button);
				}
				if(btnReleased[i] & BTN_B){
					DrawMap2(19,8 + 13*i,map_button);
				}
				if(btnReleased[i] & BTN_X){
					DrawMap2(19,6 + 13*i,map_button);
				}
				if(btnReleased[i] & BTN_Y){
					DrawMap2(18,7 + 13*i,map_button);
				}
				if(btnReleased[i] & BTN_SL){
					DrawMap2(10,4 + 13*i,map_bumper);
				}
				if(btnReleased[i] & BTN_SR){
					DrawMap2(18,4 + 13*i,map_bumper);
				}
			}
		}
		btnPrev[0] = btnHeld[0];
		btnPrev[1] = btnHeld[1];
	}
} 
Esempio n. 21
0
int main(){	

	unsigned char i,c,x,y,spr;
	
	ClearVram();
		
	//initialize stuff
	InitMusicPlayer(patches);
	SetMasterVolume(0xc0); //crank up the volume a bit since the sample is not too loud

	SetSpritesTileTable(cubes_tileset);
	SetSpritesOptions(SPR_OVERFLOW_CLIP);

	//To allocate/deallocate a player's voice
	//tracks[0].allocated=false;
	//tracks[1].allocated=false;
	//tracks[2].allocated=false;


	//start the beat loop
	TriggerNote(3,1,23,0xff);

	
 	//Define the screen sections. 

	for(i=0;i<9;i++){
		screenSections[i].tileTableAdress=spritedemo_tileset;
	}

	screenSections[0].height=76;	
	screenSections[0].flags=SCT_PRIORITY_SPR;

	screenSections[1].height=2;
	screenSections[1].vramBaseAdress=vram+(32*37);
	screenSections[1].flags=SCT_PRIORITY_BG;

	screenSections[2].height=3;
	screenSections[2].vramBaseAdress=vram+(32*37);
	screenSections[2].flags=SCT_PRIORITY_BG;
	screenSections[2].scrollY=2;

	screenSections[3].height=3;
	screenSections[3].vramBaseAdress=vram+(32*37);
	screenSections[3].flags=SCT_PRIORITY_BG;
	screenSections[3].scrollY=5;

	screenSections[4].height=40;
	screenSections[4].vramBaseAdress=vram+(32*32);
	screenSections[4].flags=SCT_PRIORITY_SPR;

	screenSections[5].height=3;
	screenSections[5].vramBaseAdress=vram+(32*38);
	screenSections[5].flags=SCT_PRIORITY_BG;

	screenSections[6].height=3;
	screenSections[6].vramBaseAdress=vram+(32*38);
	screenSections[6].flags=SCT_PRIORITY_BG;
	screenSections[6].scrollY=3;

	screenSections[7].height=2;
	screenSections[7].vramBaseAdress=vram+(32*38);
	screenSections[7].flags=SCT_PRIORITY_BG;
	screenSections[7].scrollY=6;

	screenSections[8].height=76;
	screenSections[8].flags=SCT_PRIORITY_SPR;
	screenSections[8].scrollY=132;

	Fill(0,37,32,1,1);
	Fill(0,38,32,1,2);


	for(y=0;y<30;y+=4){
		for(x=0;x<30;x+=5){
			DrawMap2(x,y,map_bg);
		}
	}

	DrawMap2(0,32,map_logo);

	for(i=22;i<32;i++){
		DrawMap2(i,32,map_bar);
	}
	
	srand(18);
	c=1;
	spr=1;
	for(i=0;i<7;i++){
		//randomize positions
		cubes[i].x=((unsigned char)(rand() % 110))+2;
		cubes[i].y=((unsigned char)(rand() % 180))+2;

		cubes[i].rotation=((unsigned char)(rand() % 7));

		if((unsigned char)(rand() % 16)<10){
			cubes[i].xdir=1;
		}else{
			cubes[i].xdir=-1;
		}

		if((unsigned char)(rand() % 16)<8){
			cubes[i].ydir=1;
		}else{
			cubes[i].ydir=-1;
		}


	}

	c=0;
	char w1=0,w2=0;
	while(1){

		//syncronize gameplay on vsync (30 hz)	
		WaitVsync(1);

		w2++;
		if(w2==3){
			sx3++;
			if(sx3>X_SCROLL_WRAP) sx3=0;		
			
			screenSections[1].scrollX=sx3;	
			screenSections[7].scrollX=sx3;	
			
			w2=0;
		}

		w1++;
		if(w1==2){
			sx2++;
			if(sx2>=X_SCROLL_WRAP) sx2=0;		
			
			screenSections[2].scrollX=sx2;	
			screenSections[6].scrollX=sx2;	
			
			w1=0;
		}

		sx++;
		if(sx>=X_SCROLL_WRAP) sx=0;

		screenSections[3].scrollX=sx;	
		screenSections[4].scrollX=sx;
		screenSections[5].scrollX=sx;	

		screenSections[0].scrollY++;
		screenSections[8].scrollY++;



		spr=1;
		for(i=0;i<7;i++){
	
			cubes[i].x+=cubes[i].xdir;
			cubes[i].y+=cubes[i].ydir;
			
			if(cubes[i].x>123 && cubes[i].xdir==1){
				cubes[i].xdir=-1;
			}
			if(cubes[i].x<9 && cubes[i].xdir==-1){
				cubes[i].xdir=1;
			}

			cubes[i].y+=cubes[i].ydir;
			if(cubes[i].y>=196 && cubes[i].ydir==1){
				cubes[i].ydir=-1;
			}
			if(cubes[i].y<10 && cubes[i].ydir==-1){
				cubes[i].ydir=1;
			}
		

			if(c==0){
				cubes[i].rotation++;
				if(cubes[i].rotation==14)cubes[i].rotation=0;

				sprites[spr+0].tileIndex=(cubes[i].rotation*2)+1;
				sprites[spr+1].tileIndex=(cubes[i].rotation*2)+1+1;
				sprites[spr+2].tileIndex=(cubes[i].rotation*2)+1+29;
				sprites[spr+3].tileIndex=(cubes[i].rotation*2)+1+30;
			}

			
				sprites[spr+0].x=cubes[i].x;
				sprites[spr+0].y=cubes[i].y;

				sprites[spr+1].x=cubes[i].x+6;
				sprites[spr+1].y=cubes[i].y;

				sprites[spr+2].x=cubes[i].x;
				sprites[spr+2].y=cubes[i].y+8;

				sprites[spr+3].x=cubes[i].x+6;
				sprites[spr+3].y=cubes[i].y+8;
		
			spr+=4;
			c+=128;
		}

		processControls();

		
	
	}
}
Esempio n. 22
0
int main(){


	SetUserPostVsyncCallback(&VsyncCallBack);



	while(1){
		vmode=0;
		vmode_text_lines=SCREEN_TILES_V;
		paused=true;
		u8 option=0;


		do{
			option=Title();
			if(option==1){
				DisplayHowToPlay();
			}
		}while(option!=0);

		ClearVram();

		SetTileTable(font);
		SetFontTilesIndex(0);
		CreateStatusBar();


		//SetTile(0,0,91);
		//SetTile(1,0,92);
		//Print(1,0,PSTR("Started  Generation:       SELECT=Menu"));


		vmode_text_lines=1;
		//vmode=1;
		vmode_grid_col=9;//82;
		vmode_page=0;

		cursor_x=44;
		cursor_y=25;

		//R-pentamino
		//PutPixel(40,30,1,0);
		//PutPixel(41,30,1,0);
		//PutPixel(39,31,1,0);
		//PutPixel(40,31,1,0);
		//PutPixel(40,32,1,0);



		//u16 joy;

		inMainLoop=true;
		bool gameEnd=false;
		while(1){

			WaitVsync(1);

			if(!paused){
				ComputeNextStep();
				vmode_page^=1;
				gen++;

			}
		
			if(keyAction!=ACTION_NONE){
				switch(keyAction){
					case ACTION_STARTSTOP:
						paused=!paused;
						keyAction=ACTION_NONE;
						break;
					case ACTION_OPENMENU:
						if(OpenMenu()==1){
							gameEnd=true;
							inMainLoop=false;
						}
						keyAction=ACTION_NONE;
						break;
				}

			}

			UpdateStatusBar();
			if(gameEnd)break;
		}
	}

} 
Esempio n. 23
0
u8 OpenMenu(){

	ClearTextVram();
	
	SetTileTable(tiles);
	SetFontTilesIndex(TILES_SIZE);

	//Show object types
	Print(6,2,PSTR("Select life object to insert"));
	Print(5,3,PSTR("at the current cursor position"));

	Print(7,7,PSTR("Glider"));
	Print(7,8,PSTR("Lightweight spaceship (LWSS)"))	;
	Print(7,9,PSTR("R-Pentamino"));
	Print(7,10,PSTR("Gosper glider gun"));

	Print(7,11,PSTR("Clear field"));
	Print(7,12,PSTR("Exit game"));


	//slide in menu
	WaitVsync(1);
	Fill(0,0,40,1,0);
	for(u8 i=1;i<29;i++){
		WaitVsync(1);
		vmode_text_lines=i;
	}


	s8 option=0,x=5,y=7;
	u16 joy,prevJoy=0;
	while(1){
		WaitVsync(1);
		joy=ReadJoypad(0);
		if(prevJoy==0){
			if (joy==BTN_UP){
				if(option>0) option--;

			}else if (joy==BTN_DOWN){
				if(option<5)option++;

			}else if(joy==BTN_SELECT){
				break;
			}else if(joy==BTN_START){
				switch(option){
					case 0:
						glider(cursor_x,cursor_y);
						break;

					case 1:
						lwss(cursor_x,cursor_y);
						break;
	
					case 2:
						rPentamino(cursor_x,cursor_y);
						break;					

					case 3:
						gliderGun(cursor_x,cursor_y);
						break;	

					case 4:
						ClearVram();
						break;

					default:						
						while(ReadJoypad(0)!=0);
						return 1;  //signal game end, back to main menu
				}
	
				break;
			}
		}
		prevJoy=joy;
		AnimateCursor(x,y+option);
	}

	while(ReadJoypad(0)!=0);

	//close menu
	for(u8 i=29;i>0;i--){
		WaitVsync(1);
		vmode_text_lines=i;
	}
	ClearTextVram();
	SetTileTable(font);
	SetFontTilesIndex(0);
	CreateStatusBar();
	
	return 0;
}
Esempio n. 24
0
int main(){	
	TriggerFx(0,0,0);


	ClearVram();
	InitMusicPlayer(patches);
	SetMasterVolume(0x40);
	StartSong(midisong);

	SetSpritesTileTable(mario_sprites_tileset);
	SetFontTilesIndex(SMB_TILESET_SIZE);
	SetTileTable(smb_tileset);

    Screen.scrollHeight = 23;
	

    Screen.overlayHeight=4;
    Screen.overlayTileTable=smb_tileset;
	DrawMap2(0,Screen.scrollHeight,map_hud);
	
	unsigned char c;
	for(int y=0;y<22;y++){
		for(int x=0;x<30;x++){
			c=pgm_read_byte(&(map_main[(y*MAP_MAIN_WIDTH)+x+2]));
			SetTile(x,y+1,c);
		}	
	}


	dx=0;
	sx=50;
	sy=169-32+8;
	sprDir=1;

	goombaX[0]=17; //159;
	goombaDir[0]=-1;
	goombaAnim[0]=0;
	goombaSpr[0]=0;
	goombaSprIndex[0]=6;

	goombaX[1]=65 ;//201;
	goombaDir[1]=1;
	goombaAnim[1]=0;
	goombaSpr[1]=0;
	goombaSprIndex[1]=10;


	MapSprite2(0,map_rwalk1,0);
	MapSprite2(6,map_rgoomba1,SPRITE_FLIP_X);
	MapSprite2(10,map_rgoomba2,0);



	g=0;
	MoveSprite(0,sx,sy,2,3);
	Scroll(0,-1);

	MoveSprite(goombaSprIndex[0],goombaX[0],176,2,2);
	MoveSprite(goombaSprIndex[1],goombaX[1],176,2,2);

	Screen.scrollY=0;
	Screen.overlayHeight=4;//OVERLAY_LINES;

	
	while(1){
		WaitVsync(1);
	

		processControls();

		if((active&1)!=0){
			PerformActions();
			MoveSprite(0,sx,sy+dy,2,3);
		}else{
			MoveSprite(0,sx,230,2,3);
		}



		//animate goombas
		for(g=0;g<2;g++){
		

				if(goombaX[g]<=0 && goombaDir[g]==-1){
					goombaDir[g]=1;
				}
		
				if(goombaX[g] >= (215+15) && goombaDir[g]==1){
					goombaDir[g]=-1;
			
				}
		
				goombaX[g]+=goombaDir[g];
				goombaAnim[g]++;

				if(goombaAnim[g]==8){
					goombaSpr[g]^=1;
					goombaAnim[g]=0;
				}

				if(goombaSpr[g]==0){
					MapSprite2(goombaSprIndex[g],map_rgoomba1,goombaDir[g]!=1?SPRITE_FLIP_X:0);
				}else{
					MapSprite2(goombaSprIndex[g],map_rgoomba2,goombaDir[g]!=1?SPRITE_FLIP_X:0);
				}

				MoveSprite(goombaSprIndex[g],goombaX[g],176-32+8,2,2);
			

		}
	

	}		
	
}
Esempio n. 25
0
/**
 * \brief The main game loop. This just cycles endlessly, it uses the game's 'state' to determine which screen to show and what to do.
 */
int main(){
	//looping back and forth forever (cards against humanity reference)
	while(1)
	{
		//some basic prep work performed once before our custom intro
		if(game_state == INTRO)
		{
			initialSetup();
			initIntro();
		}
		//perform custom intro
		while(game_state == INTRO)
		{
			//wait until the next frame
			WaitVsync(1);
			drawIntro();
			processIntro();
		}
		//prep the main menu
		if(game_state == MAIN_MENU)
		{
			FadeOut(0,true);
			ClearVram();
			SetTileTable(title_tiles);
			SetFontTilesIndex(TITLE_TILES_SIZE);
			drawMainMenu();
			FadeIn(0,false);
		}
		//draw menu and handle input
		while(game_state == MAIN_MENU)
		{
			WaitVsync(1);
			drawMenuCursor();
			processMainMenu();
		}
		if(game_state== GAME)
		{
			//run our setup for the main game
			ClearVram();
			FadeOut(0,true);
			gameSetup();
			FadeIn(0,false);
		}
		//when we're in the gameplay portion, draw and accept input for the game
		while(game_state == GAME)
		{
			WaitVsync(1);
			processScrollSpeed(); //scrolls screen as appropriate
			updateCity(); //offsets city for parallax
			processControls(); //accepts and processes controller input
			processPlayerMotion(); //update player position
			processSprites(); //updates and moves player image to player position
		}
		if(game_state == HIGH_SCORES)
		{
			FadeOut(0,true);
			SetTileTable(title_tiles);
			SetFontTilesIndex(TITLE_TILES_SIZE);
			drawLocalHighScoreMenu(); //draw up the high score screen
			FadeIn(0,false);
			deathclock=120; //reset death timer to 2 seconds
			if(score > topscores[9])
			{
			    LoadScore(0, 9); //load top 10 saved high scores
			    SaveScore(score); //save our current score if it's high enough
			    drawLocalHighScoreMenu(); //draw up the high score screen
			}
		}
		//draw and accepts input for the local high score screen
		while(game_state == HIGH_SCORES)
		{
			WaitVsync(1);
			processHighScoreMenu();
		}
    }
}
Esempio n. 26
0
int main()
{
  unsigned char x,corner;
  unsigned char frames;
  unsigned int joypad;
  unsigned char player_x, player_y;
  unsigned char exit_x=0, exit_y=0;
  unsigned int z=0;
  int ay,ax,j; 

   SetFontTable(fonts);  // this tells Print___() commands what font to use
   ClearVram();          // clears out display memory (like a 'clear screen')

  //DDRD &= 0xF7; // These are used by the "power" switch and LED on the "Gamer" baseboard that 
  //PORTD|= 0x08; // is paired with the AVCore.  The 'power' button is used to switch mazes for now.
  
  



new_maze:
  for(ay=0; ay<Y_SIZE; ay++) 
  { 
    for(ax=0; ax<X_SIZE; ax++) 
      if(ax>0 && ay>0 && ax<X_SIZE-1 && ay<Y_SIZE-1) // fills the maze with walls, that are then 'drilled' out
        maze[ay][ax]=WALL; 
      else 
        maze[ay][ax]=BLANK; 
  } 

  ay=2; // 2,2 is the top left corner of the maze
  ax=2; 
  maze[ay][ax]=4; // starting state for the maze generator
  
  do 
  { 
    while(drill(&ay,&ax,(int)(rand()&0x03))) {}  // start drilling things out (using random)
    j=maze[ay][ax];                              // note that the first time the game runs, the maze will always be 
    maze[ay][ax]=BLANK;                          // the same because of the random number generator always starting
    if(j<4)                                      // in the same state.  (Normally I will 'sum' the contents of RAM
    {                                            // on power-up to make a random seed, but I don't know how to mess
      /* back-track */                           // with WinAVR's C-startup yet.)
      ax=ax-2*dx[j]; 
      ay=ay-2*dy[j]; 
    } 
  } while(j<4); 
 
 do{                                             // This generates a random position inside the maze to start the
 	do player_x=rand();                          // player.  Seems more interesting than a corner.
	while ((player_x>=X_SIZE-1)||(player_x<=1));
	do player_y=rand();
	while ((player_y>=Y_SIZE-1)||(player_y<=1));
	}	
 while (maze[player_y][player_x]==WALL);         // (repeats until it picks a random spot that's not a wall)
 
 maze[player_y][player_x]=PLAYER;                // place the player in the maze

 do                                              // here we choose a random number from 0-3, representing one of the
 	{                                            // four corners of the maze.
 	corner=rand()&0x03;
 	switch (corner)                              
 		{
	 	case 0:
			exit_x=2; exit_y=2; break;
		case 1:
			exit_x=X_SIZE-3; exit_y=2; break;
		case 2:
			exit_x=X_SIZE-3; exit_y=Y_SIZE-3;break;
		case 3:
			exit_x=2; exit_y=Y_SIZE-3; break;
 		}
	}
 while (abs(player_x-exit_x)<16);                // we compare the distance from the player to the exit (horizontally)
                                                 // and only accept the corner if it's relatively far away from the player
	                                             // (could use both x and y distance for better effect)
	maze[exit_y][exit_x]=EXIT;                   // place the exit in the maze
	
	redraw();                                    // draw the screen for the player

 
 // This is what happens when you turn a static demo into a 'game'
 // For a real game, you probably don't want to do this, but it works here and is simple...
 
 //while(PIND&0x04)       // if the button on the Gamer Baseboard isn't pressed
 while(ReadPowerSwitch()==0) // if the button on the Gamer Baseboard isn't pressed
 {z++;                  // the z counter is used later on for a seed for the random number generator (user interaction = randomness)
 joypad=ReadJoypad(0);  // get the joypad state

 WaitVsync(1);          // this waits a frame and essentially slows the gameplay down
 frames++;              // frame counter can be used for animations (later)
 if (joypad&0xff)       // if the D-pad has a bit or more pressed
 	{
 	maze[player_y][player_x]=BLANK;            // erase the old player position
 	if (joypad&BTN_DOWN)                           // down?
 		if (maze[player_y+1][player_x]!=WALL)  // don't move if a wall is blocking your path
			player_y++;                        // you could 'switch/case' these with breaks to easily disable diagonal moves...
	if (joypad&BTN_UP)                           // up?
	 	if (maze[player_y-1][player_x]!=WALL)
			player_y--;
 	if (joypad&BTN_LEFT)                           // left?
 		if (maze[player_y][player_x-1]!=WALL)
			player_x--;
	if (joypad&BTN_RIGHT)                           // right
 		if (maze[player_y][player_x+1]!=WALL)
			player_x++;
	if (maze[player_y][player_x]==EXIT)        // if the new position is the EXIT, you just won
		{
		maze[exit_y][exit_x]=PLAYER;           // place the player on top of the exit
		redraw();                              // draw the screen for the user
		Print(14,25,strWin);                   // prints the "YOU ESCAPED!" message
		WaitVsync(30);                         // and waits for a while.
		for (x=14;x<26;x++)                    // this loops over the "YOU ESCAPED!" message
			SetTile(x,25,11);                  // and erases it.
		break;                                 // this breaks out of the while(PIND...) loop, causing a new maze to be generated 
		}
	
	maze[player_y][player_x]=PLAYER;           // after the movement calculations, put the player in the new spot
 	}
 else
 	{
	// check for idle time                     // use the frame counter to make the player graphic change if you wait around. ;-)
	}

	srand(z);    // our player-influenced 'z' value is now used to reseed the random number generator, resulting in a 'new' maze
 
	redraw();    // redraw the screen to update new player position
 }

 goto new_maze;  // this is just a hack to go do everything over again.  Before anyone lectures me about using GOTO, think about
                 // why every CPU has a 'jump/goto' instruction in its assembly language and uses it-- frequently. :-) 
}