Exemplo n.º 1
0
// Level-independant setup logic
void init() {

	REG_DISPCTL = MODE0 | BG2_ENABLE | SPRITE_ENABLE;

	REG_BG0CNT = CBB(0) | SBB(26) | BG_SIZE0 | COLOR256 | 0; 	// Priority 0
	REG_BG1CNT = CBB(1) | SBB(27) | BG_SIZE0 | COLOR256 | 1;	// Priority 1
	REG_BG2CNT = CBB(2) | SBB(28) | BG_SIZE1 | COLOR256 | 2;	// Priority 2 

	// Put Sprite on Screen
	loadSpritePalette(sprite_actorPal);
	DMANow(3, sprite_actorTiles, &CHARBLOCKBASE[4], sprite_actorTilesLen / 2);

	// DMA background 0
	loadPalette(pause_screenPal);
	DMANow(3, pause_screenMap, &SCREENBLOCKBASE[26], pause_screenMapLen / 2);
	DMANow(3, pause_screenTiles, &CHARBLOCKBASE[0], pause_screenTilesLen / 2);

	// Initialize level-independant player values
	player.deltaRow = 1;
	player.deltaCol = 0;
	player.isRunning = 0;
	player.isJumping = 0;
	player.frameCount = 0;
	player.width = 16;
	player.height = 16;
	player.currentFrame = 0;
	player.facing = 0; 	// Facing to the right (1 is facing to the left)

	canJump = 0; // subject to change depending how beginning is designed

	hideSprites();

	// Season-indicator icon position for all levels
	icon.row = 5;
	icon.col = 219;

}
Exemplo n.º 2
0
//Set Control Registers for Video and Timers
void setRegister()
{
	REG_DISPCTL = MODE0 | BG0_ENABLE;
	REG_BG0HOFS = 0;
	REG_BG0VOFS = 0;

	REG_BG0CNT = BG_SIZE0 | SBB(31) |  CBB(0);
	REG_DISPCTL = MODE0 | BG0_ENABLE | OBJ_ENABLE;

	REG_TM2CNT = 0;
    REG_TM2D = -0x4000;
    REG_TM2CNT = TM_FREQ_1024 | TM_IRQ;
	

	
	// Setup sound
    REG_SOUNDCNT_X = SND_ENABLED;
    
    REG_SOUNDCNT_L = 0;
    REG_SOUNDCNT_H = SND_OUTPUT_RATIO_100 |
                        DSA_OUTPUT_RATIO_100 |
                        DSA_OUTPUT_TO_RIGHT |
                        DSA_TIMER0 |
                        DSA_FIFO_RESET |
                        DSB_OUTPUT_RATIO_100 |
                        DSB_OUTPUT_TO_LEFT |
                        DSB_TIMER1 |
                        DSB_FIFO_RESET;
    // DMA to play sound on DSA
    DMA[1].src = beep;
    DMA[1].dst = REG_FIFO_A;
    DMA[1].cnt = DMA_DESTINATION_FIXED |
                    DMA_REPEAT |
                    DMA_AT_REFRESH;

    // Timer 0 is used to play the beeps (DSA)
    REG_TM0D = -1522; // Value for 11025 Hz
    REG_TM0CNT = TM_FREQ_1;
	//DMA to play sound on DSB
    DMA[2].src = flute;
    DMA[2].dst = REG_FIFO_B;
    DMA[2].cnt = DMA_DESTINATION_FIXED |
                    DMA_REPEAT |
                    DMA_AT_REFRESH;
	// Timer 1 is used to play the background music (DSB)
    REG_TM1D = -380; // Value for 44100 Hz
    REG_TM1CNT = TM_FREQ_1;
}
Exemplo n.º 3
0
int main(void)
{
	//Initializing Program variables
    int i;
	int visible = 1;
	int press = 1;
	int oldSprite = 0;
	int currentSprite = 0;
    ObjAttr shadowOAM[128];

    REG_DISPCTL = MODE0 | BG0_ENABLE | OBJ_ENABLE;

    // Load background palette
    for(i=0; i<256; i++)
    {
        PALETTE[i] = backgroundPal[i];
    }

    // Load background tile images
    for(i=0; i<backgroundTilesLen/2; i++)
    {
        CHARBLOCKBASE[0].tileimg[i] = backgroundTiles[i];
    }

	//Make Map
    for(i=0; i<1024; i++)
	{
		SCREENBLOCKBASE[28].tilemap[i] = 1;
	}

    REG_BG0CNT = SBB(28) | CBB(0) | COLOR256 | BG_SIZE0;

	//Define Sprites
    Sprite sprites[NUMSPRITES] = {{16,16,SPRITEOFFSET16(0,0),ATTR0_SQUARE,ATTR1_SIZE32,32,32,1,1},
						{0,0,SPRITEOFFSET16(0,8),ATTR0_SQUARE,ATTR1_SIZE32,32,32,1,1},
						{0,0,SPRITEOFFSET16(0,16),ATTR0_SQUARE,ATTR1_SIZE32,32,32,1,1},
						{5,100,SPRITEOFFSET16(0,24),ATTR0_SQUARE,ATTR1_SIZE32,32,32,1,1},
						{0,0,SPRITEOFFSET16(4,0),ATTR0_SQUARE,ATTR1_SIZE32,32,32,1,1},
						{0,0,SPRITEOFFSET16(4,8),ATTR0_SQUARE,ATTR1_SIZE32,32,32,1,1},
						{0,0,SPRITEOFFSET16(4,16),ATTR0_SQUARE,ATTR1_SIZE32,32,32,1,1},
						{0,0,SPRITEOFFSET16(4,16),ATTR0_SQUARE,ATTR1_SIZE32,32,32,1,1}};

    // Load sprite palette
    for(i=0; i<256; i++)
    {
        SPRITEPAL[i] = spritePalette[i];
    }

    // Load sprite images
    for(i=0; i<8192/2; i++)
    {
        CHARBLOCKBASE[4].tileimg[i] = spriteTiles[i];
    }

    
	// Set attributes for all active sprites
	for(i=0; i<NUMSPRITES; i++)
	{
		shadowOAM[i].attr0 = sprites[i].row | ATTR0_8BPP | sprites[i].shape;
		shadowOAM[i].attr1 = sprites[i].col | sprites[i].size;
		shadowOAM[i].attr2 = sprites[i].start | ATTR2_PALETTE_BANK(0);
	}

	//Hide Sprites
	for(i=0; i<128; i++)
	{
		shadowOAM[i].attr0 = ATTR0_HIDE;
	}


	waitForVblank();

	//Move Sprites to Mem
	for(i=0; i<128; i++)
	{
		SPRITEMEM[i] = shadowOAM[i];
	}

    while(FOREVER)
    {

		//Check for Movement and change direction
		if(KEY_DOWN_NOW(BUTTON_UP))
		{
			shadowOAM[currentSprite].attr0 = ATTR0_HIDE;
			sprites[currentSprite].row -= sprites[currentSprite].rdel;
			oldSprite = currentSprite;
			currentSprite = 2;
			sprites[currentSprite].col = sprites[oldSprite].col;
			sprites[currentSprite].row = sprites[oldSprite].row;
		}


		if(KEY_DOWN_NOW(BUTTON_DOWN))
		{
			shadowOAM[currentSprite].attr0 = ATTR0_HIDE;
			sprites[currentSprite].row += sprites[currentSprite].rdel;
			oldSprite = currentSprite;
			currentSprite = 0;
			sprites[currentSprite].col = sprites[oldSprite].col;
			sprites[currentSprite].row = sprites[oldSprite].row;
		}

		if(KEY_DOWN_NOW(BUTTON_LEFT))
		{
			shadowOAM[currentSprite].attr0 = ATTR0_HIDE;
			sprites[currentSprite].col -= sprites[currentSprite].cdel;
			oldSprite = currentSprite;
			currentSprite = 6;
			sprites[currentSprite].col = sprites[oldSprite].col;
			sprites[currentSprite].row = sprites[oldSprite].row;
			
		}

		if(KEY_DOWN_NOW(BUTTON_RIGHT))
		{
			shadowOAM[currentSprite].attr0 = ATTR0_HIDE;
			sprites[currentSprite].col += sprites[currentSprite].cdel;
			oldSprite = currentSprite;
			currentSprite = 5;
			sprites[currentSprite].col = sprites[oldSprite].col;
			sprites[currentSprite].row = sprites[oldSprite].row;
		}

		//Check for second sprites visibility
		if(KEY_DOWN_NOW(BUTTON_START) && press)
		{
			if(visible)
				visible = 0;
			else
				visible = 1;
			waitForVblank();
			press = 0;
		}

		if(!KEY_DOWN_NOW(BUTTON_START))
		{
			press = 1;
		}

		//Collision Detection
		if(sprites[currentSprite].row < HEIGHTMIN)
		{
		   sprites[currentSprite].row = HEIGHTMIN;
		}

		if(sprites[currentSprite].col < WIDTHMIN)
		{
		   sprites[currentSprite].col = WIDTHMIN;
		}

		if(sprites[currentSprite].row + sprites[currentSprite].height > HEIGHTMAX)
		{
		   sprites[currentSprite].row = HEIGHTMAX - sprites[currentSprite].height;
		}

		if(sprites[currentSprite].col + sprites[currentSprite].width > WIDTHMAX)
		{
		   sprites[currentSprite].col = WIDTHMAX - sprites[currentSprite].width;
		}

		//Move Sprites to Memory
		shadowOAM[currentSprite].attr0 = sprites[currentSprite].row | ATTR0_8BPP | sprites[currentSprite].shape;
		shadowOAM[currentSprite].attr1 = (MASK&sprites[currentSprite].col) | sprites[currentSprite].size;
		shadowOAM[currentSprite].attr2 = sprites[currentSprite].start | ATTR2_PALETTE_BANK(0);

		if(visible)
		{
		   shadowOAM[3].attr0 = sprites[3].row | ATTR0_8BPP | sprites[3].shape;
		   shadowOAM[3].attr1 = (MASK&sprites[3].col) | sprites[3].size;
		   shadowOAM[3].attr2 = sprites[3].start | ATTR2_PALETTE_BANK(0);
		}
		else
		{
			shadowOAM[3].attr0 = ATTR0_HIDE;
		}

		waitForVblank();

		for(i=0; i<NUMSPRITES; i++)
		{
		   SPRITEMEM[i] = shadowOAM[i];
		}
    }
    return 0;
}
Exemplo n.º 4
0
void showLevel(int level) {
   int i;
    
   /*****************************************************************
    *
    *  Step 1 -- Tile Images
    *
    *  This data tells us what each different tile will look like
    *  It will be copied into a character block
    *
    ****************************************************************/
   
   /*****************************************************************
    *
    *  Step 2 -- Screen Image (map)
    *
    *	The numbers in this array tell us which tile we want in each
    *  tile location on the screen. We will copy this data into a
    *  screen block
    *
    ****************************************************************/
    
   /*****************************************************************
    *
    *  Step 3 -- Palette
    *
    ****************************************************************/
   
    /*****************************************************************
     *
     *  Step 4 -- Store Tile Images
     *
     ****************************************************************/
    int nTiles = 256;
    int total = nTiles*64/2;
            
    switch(level) {
        case 1:
            for(i=0; i < total; i++) {	// There are 10 tiles. Each tile is described by 64 chars
                                       // but we are storing them two to a short so we are
                                       // storing data in 64/2 shorts per tile
                //CHARBLOCKBASE[0].tileimg[i] = myTileImages[i*2] | (myTileImages[i*2+1]<<8);
                CHARBLOCKBASE[0].tileimg[i] = Level1Tiles[i*2] | (Level1Tiles[i*2+1]<<8);
            }
            break;
    }
     
    /*****************************************************************
     *
     *  Step 5 -- Store map
     *
     ****************************************************************/
    int totalMap; 
    switch(level) {
        case 1:
            totalMap = 32*32; //1024
            loadMapBlock(0, Level1Map);
            
            for(i=0; i < totalMap; i++) {
                //SCREENBLOCKBASE[31].tilemap[i] = Level1Map[i];
                //SCREENBLOCKBASE[30].tilemap[i] = myScreenMap[i];
                SCREENBLOCKBASE[28].tilemap[i] = myBackgroundMap[i];
            }
            break;
     }
     
    /*****************************************************************
     *
     *  Step 6 -- Store palette
     *
     ****************************************************************/
     switch(level) {
        case 1:
            //loadPalette(myPalette);
            loadPalette(Level1Pal);
            break;
     }
     
    /*****************************************************************
     *
     *  Step 7 -- Set image controls
     *
     ****************************************************************/
    //REG_DISPCTL = MODE0 | BG0_ENABLE | BG1_ENABLE | BG2_ENABLE;
    //SETMODE(MODE0 | BG0_ENABLE | BG1_ENABLE | BG2_ENABLE | SPRITE_ENABLE);
    SETMODE(MODE0 | BG0_ENABLE | /*BG1_ENABLE |*/ BG2_ENABLE | SPRITE_ENABLE);
    
    REG_BG0HOFS = 0;
    REG_BG0VOFS = 0;
    
    // MyGUI: Texts,... Comment out this line to turn off BG0
    //REG_BG0CNT = BG_SIZE0 | SBB(31) | COLOR256 | CBB(0);
    // Game
    REG_BG0CNT = BG_SIZE0 | SBB(30) | COLOR256 | CBB(0);
    // Background
    REG_BG2CNT = BG_SIZE0 | SBB(28) | COLOR256 | CBB(0);


    // DeuXieme part ;)   // 30
    //REG_BG1CNT = BG_SIZE0 | SBB(31) | COLOR256 | CBB(0);    
    
}
Exemplo n.º 5
0
int main(void)
{
    int i;
	int diceRoll = 0;
	int diceRoll2 = 0;
	int bet = 0;
	int payOut = 0;
	int count = 0;

	u16 myPalette[] = {BLACK, WHITE, RED, GREEN, BLUE}; //Make Colors

	for(i=0; i<16384/2; i++) //Stores Text Tiles
	{
	 CHARBLOCKBASE[1].tileimg[i] = fontdata_8x8[i*2] | (fontdata_8x8[i*2+1]<<8);
	}

	for(i=0; i<1600/2; i++) //Stores Dice Tiles
	{
	 CHARBLOCKBASE[0].tileimg[i] = dice_8x8[i*2] | (dice_8x8[i*2+1]<<8);
	}

	for(i=0; i<5; i++) //Stores Palette Colors
	{
	 PALETTE[i] = myPalette[i];
	}

    REG_DISPCTL = MODE0 | BG0_ENABLE | BG1_ENABLE;
    REG_BG0HOFS = 0;
    REG_BG0VOFS = 0;

    REG_BG0CNT = BG_SIZE0 | SBB(30) | COLOR256 | CBB(0);  //Layer for Dice
    REG_BG1CNT = BG_SIZE0 | SBB(31) | COLOR256 | CBB(1);  //Layer for Text

    STATE gameState = TITLE; //Sets Initial Game State

    while(1)
    {
    	switch(gameState)
    	{
    	case TITLE:
    		titleScreen();
    		while(KEY_DOWN_NOW(BUTTON_START)){};
			while(!KEY_DOWN_NOW(BUTTON_START))
			{
				count++; //Time Count for Seeding
			}
			srand(count);//Random Seed
    		gameState = CHOOSELINE;
    		clearTextScreen();
    		waitForVblank();
    		break;
    	case CHOOSELINE:
    		chooseLineScreen();
    		//Checks for Bet Type
    		while(!KEY_DOWN_NOW(BUTTON_A) && !KEY_DOWN_NOW(BUTTON_B)){}
    		if(KEY_DOWN_NOW(BUTTON_A))
			{
				gameState = PASSLINEBET;
			}

			if(KEY_DOWN_NOW(BUTTON_B))
			{
				gameState = DONTPASSLINEBET;
			}
    		while(KEY_DOWN_NOW(BUTTON_A) || KEY_DOWN_NOW(BUTTON_B)){}
			clearTextScreen();
    		waitForVblank();
    		break;
    	case PASSLINEBET:
    		passLineScreen();
    		//Checks for Bet Amount
    		while(!KEY_DOWN_NOW(BUTTON_A) && !KEY_DOWN_NOW(BUTTON_B)){}

			if(KEY_DOWN_NOW(BUTTON_A))
			{
				bet = 5;
			}

			if(KEY_DOWN_NOW(BUTTON_B))
			{
				bet = 25;
			}

    		while(KEY_DOWN_NOW(BUTTON_A) || KEY_DOWN_NOW(BUTTON_B)){}

    		//Rolls Dice and Computes Results
    		putText(12,0,"Bet Accepted");
    		waitForVblank();
    		putText(14,0, "Rolling");
    		waitForVblank();
    		diceRoll = rollDice(18,2,50);
    		waitForVblank();
    		if(diceRoll == 7 || diceRoll == 11)
    		{
    			gameState = WIN;
    		}
    		else if(diceRoll == 2 || diceRoll == 3 || diceRoll == 12)
    		{
    			gameState = LOSE;
    		}
    		else
    		{
    			putText(16,0,"Press Start to Roll Again");
    			waitForVblank();
    			while(!KEY_DOWN_NOW(BUTTON_START))
				{
				}
    			diceRoll2 = rollDice(18,9,50);
    			waitForVblank();
    			if(diceRoll == diceRoll2)
    			{
    				gameState = WIN;
    			}
    			else if(diceRoll == 7)
    			{
    				gameState = LOSE;
    			}
    			else
    			{
    				gameState = LOSE;
    			}
    		}
    		putText(12,16,"Press Start");
    		putText(14,16,"to See Result");
    		waitForVblank();
    		while(!KEY_DOWN_NOW(BUTTON_START))
			{
			}
    		clearTextScreen();
    		clearMainScreen();
    		waitForVblank();
    		break;
    	case DONTPASSLINEBET:
    		dontPassLineScreen();
    		//Checks for Bet Amount
    		while(!KEY_DOWN_NOW(BUTTON_A) && !KEY_DOWN_NOW(BUTTON_B)){}

			if(KEY_DOWN_NOW(BUTTON_A))
			{
				bet = 5;
			}

			if(KEY_DOWN_NOW(BUTTON_B))
			{
				bet = 25;
			}

			while(KEY_DOWN_NOW(BUTTON_A) || KEY_DOWN_NOW(BUTTON_B)){}

			//Rolls Dice and Computes Results
			putText(12,0,"Bet Accepted");
			waitForVblank();
			putText(14,0, "Rolling");
			waitForVblank();
			diceRoll = rollDice(18,2,50);
			waitForVblank();
			if(diceRoll == 7 || diceRoll == 11)
			{
				gameState = LOSE;
			}
			else if(diceRoll == 2 || diceRoll == 3 || diceRoll == 12)
			{
				gameState = WIN;
			}
			else
			{
				putText(16,0,"Press Start to Roll Again");
				waitForVblank();
				while(!KEY_DOWN_NOW(BUTTON_START))
				{
				}
				diceRoll2 = rollDice(18,9,50);
				waitForVblank();
				if(diceRoll == diceRoll2)
				{
					gameState = LOSE;
				}
				else if(diceRoll == 7)
				{
					gameState = WIN;
				}
				else
				{
					gameState = WIN;
				}
			}
			putText(12,16,"Press Start");
			putText(14,16,"to See Result");
			waitForVblank();
			while(!KEY_DOWN_NOW(BUTTON_START))
			{
			}
			clearTextScreen();
			clearMainScreen();
			waitForVblank();
    		break;
    	case WIN:
    		payOut = 2*bet;
    		winScreen(payOut);
    		while(KEY_DOWN_NOW(BUTTON_START)){}
    		while(!KEY_DOWN_NOW(BUTTON_START))
			{
			}
			gameState = TITLE;
			clearTextScreen();
			waitForVblank();
    		break;
    	case LOSE:
    		loseScreen();
    		while(KEY_DOWN_NOW(BUTTON_START)){}
    		while(!KEY_DOWN_NOW(BUTTON_START))
			{
			}
			gameState = TITLE;
			clearTextScreen();
			waitForVblank();
    		break;
    	}
    }

   return 0;
}
Exemplo n.º 6
0
void pause() {
	REG_DISPCTL = MODE0 | BG3_ENABLE | SPRITE_ENABLE;
	REG_BG3CNT = CBB(0) | SBB(28) | BG_SIZE3 | COLOR256;
	loadPalette(stats_screenPal);
	DMANow(3, (unsigned int*)stats_screenTiles, &CHARBLOCKBASE[0], stats_screenTilesLen);
	DMANow(3, (unsigned int*)stats_screenMap, &SCREENBLOCKBASE[28], stats_screenMapLen);

	//sets up selector arrow
	shadowOAM[127].attr0 = 56 | ATTR0_8BPP | ATTR0_SQUARE;
	shadowOAM[127].attr1 = 25 | ATTR1_SIZE8;
	shadowOAM[127].attr2 = 772;

	//sets up points remaining indicator
	shadowOAM[126].attr0 = 32 | ATTR0_8BPP | ATTR0_SQUARE;
	shadowOAM[126].attr1 = 106 | ATTR1_SIZE8;
	shadowOAM[126].attr2 = 800;

	//sets up vitality points indicator
	shadowOAM[125].attr0 = 57 | ATTR0_8BPP | ATTR0_SQUARE;
	shadowOAM[125].attr1 = 90 | ATTR1_SIZE8;
	shadowOAM[125].attr2 = 802;
	
	//sets up strength points indicator
	shadowOAM[124].attr0 = 73 | ATTR0_8BPP | ATTR0_SQUARE;
	shadowOAM[124].attr1 = 90 | ATTR1_SIZE8;
	shadowOAM[124].attr2 = 802;

	//Disable unused sprites
	int i;
	for (i=0; i<128; ++i) {
		OAM[i].attr0 = ATTR0_HIDE;
	}

	//This loop keeps the background from being redrawn continously
	int button_pushed = 0;
	while (!button_pushed) {
		OAM[127] = shadowOAM[127];
		OAM[126] = shadowOAM[126];
		OAM[125] = shadowOAM[125];
		OAM[124] = shadowOAM[124];

		shadowOAM[126].attr2 = 800 + (2 * points);

		key_poll();
		if (key_hit(BUTTON_A) || (key_hit(BUTTON_B)))
			button_pushed = 1;

		if (key_hit(BUTTON_UP) && (selector_position > 0)) {
			--selector_position;
			shadowOAM[127].attr0 = 56 | ATTR0_8BPP | ATTR0_SQUARE;
		}
		if (key_hit(BUTTON_DOWN) && (selector_position < 1)) {
			++selector_position;
			shadowOAM[127].attr0 = 72 | ATTR0_8BPP | ATTR0_SQUARE;
		}
		if (key_hit(BUTTON_RIGHT) && (selector_position == 0) && (points > 0)) {
			++playerHealth;
			--points;
			shadowOAM[125].attr2 = 800 + (2 * playerHealth);
		}
		if (key_hit(BUTTON_LEFT) && (selector_position == 0) && (playerHealth > 1)) {
			--playerHealth;
			++points;
			shadowOAM[125].attr2 = 800 + (2 * playerHealth);
		}
		if (key_hit(BUTTON_RIGHT) && (selector_position == 1) && (points > 0)) {
			++player_damage;
			--points;
			shadowOAM[124].attr2 = 800 + (2 * player_damage);
		}
		if (key_hit(BUTTON_LEFT) && (selector_position == 1) && (player_damage > 1)) {
			--player_damage;
			++points;
			shadowOAM[124].attr2 = 800 + (2 * player_damage);
		}
	}

	if (key_hit(BUTTON_A)) {
		int i;
		for (i=0; i<128; ++i) {
			OAM[i].attr0 = ATTR0_HIDE;
		}
		state = GAME_OVERWORLD;
	}
}
Exemplo n.º 7
0
//=====================Main
int main(void) {
    //Set Video Control
    REG_DISPCNT = BG2_ENABLE | BG1_ENABLE | BG0_ENABLE | MODE_0 | OBJ_ENABLE;
    
    //tells the Background 0 control register
    //where the screen map is, the tiles, the color, and size0=256x256
    //background 1 is the collision map
    REG_BG0CNT=  CBB(0) | SBB(8) | COLOR16 | BG_SIZE0;
    REG_BG1CNT=  CBB(2) | SBB(10) | COLOR16 | BG_SIZE2;
    REG_BG2CNT=  CBB(3) | SBB(12) | COLOR16 | BG_SIZE2;
    
    //sets the BG's vertical and horz offsets to 0
    REG_BG0HOFS=0;
    REG_BG0VOFS=20;
    REG_BG1HOFS=0;
    REG_BG1VOFS=0;
    REG_BG2HOFS=0;
    REG_BG2VOFS=0;

    int i;
    int speed=3;
    int hoff=0;
    int voff=0;
    
     //loads the picture pallet
     //This is the same for all backgrounds
     for(i=0;i<background0PalLen/2;i++)
        PALETTE_MEM[i]=background0Pal[i];
    
    //===========================================Sprites
    ObjAttr shadowOAM[128];

    //defining sprites with room for more
    Sprite spriteArray[NUMSPRITES]={
        {WALKINGROW, 16, SPRITEOFFSET16(0,0), ATTR0_TALL, ATTR1_SIZE64, 32, 64, TRUE}
        }
        
typedef struct {
    int printRow;
    int printCol;
    int arrayLocation;
    int shape;
    int size;
    int height;
    int width;
    int active;
} Sprite;

    //Loads sprite tiles
    for(i=0; i<characterSpritesTilesLen/2; i++)
        charbase[4].tileimg[i] = characterSpritesTiles[i];

    //set attributes of the sprite in the duplicate mem
    for(i=0; i<NUMSPRITES; i++)
    {
        shadowOAM[i].attr0 = spriteArray[i].row | ATTR0_4BPP | spriteArray[i].shape;
        shadowOAM[i].attr1 = spriteArray[i].col | spriteArray[i].size;
        shadowOAM[i].attr2 = spriteArray[i].start | ATTR2_PALETTE_BANK(0);
    }

    //hides all sprites except for main guy
    for(i=0; i<128; i++)
    {
        if(!spriteArray[i].active)
            shadowOAM[i].attr0 = ATTR0_HIDE;
    }

    waitForVblank();

    // Copy shadow into real
    for(i=0; i<128; i++)
    {
        SPRITEMEM[i] = shadowOAM[i];
    }
    
    while(1) {
        //LOADS BACKGROUND 0
        //loads all the tiles and collision map
        for(i=0;i<background0TilesLen/2;i++)
            charbase[3].tileimg[i]=background0Tiles[i];
        //loads the map
        for(i=0;i<background0MapLen/2;i++)
            screenbase[12].tilemap[i]=background0Map[i];

        //LOADS BACKGROUND 1
        //loads all the tiles and collision map
        for(i=0;i<background1TilesLen/2;i++)
            charbase[2].tileimg[i]=background1Tiles[i];
        //loads the map
        for(i=0;i<background1MapLen/2;i++)
            screenbase[10].tilemap[i]=background1Map[i];

        //LOADS BACKGROUND 2
        //loads all the tiles and collision map
        for(i=0;i<background2TilesLen/2;i++)
            charbase[0].tileimg[i]=background2Tiles[i];
        //loads the map
        for(i=0;i<background2MapLen/2;i++)
            screenbase[8].tilemap[i]=background2Map[i];
        
        // these keys move the background around the screen
        if(KEY_DOWN_NOW(BUTTON_RIGHT))hoff+=speed;
        if(KEY_DOWN_NOW(BUTTON_LEFT))hoff-=speed;
        if(KEY_DOWN_NOW(BUTTON_UP))voff-=speed;
        if(KEY_DOWN_NOW(BUTTON_DOWN))voff+=speed;
        
        REG_BG0HOFS=hoff;
        //REG_BG0VOFS=voff;
        REG_BG1HOFS=hoff/20;
        //REG_BG1VOFS=voff/20;
        
        waitForVBlank();
    }
 return 0;
}
Exemplo n.º 8
0
void debayer_ccm_uyvy(unicap_data_buffer_t *destbuf, unicap_data_buffer_t *srcbuf,
                      debayer_data_t *data) {
    int i, j;
    int dest_offset = 0;
    unsigned char *dest = destbuf->data;
    unsigned char *source = srcbuf->data;
    int width = destbuf->format.size.width;
    int height = destbuf->format.size.height;

    for (j = 2; j < height - 2; j += 2) {
        int lineoffset = j * width;
        dest_offset = j * width * 2 + 2;

        for (i = 1; i < width - 2;) {
            int r, g, b;
            int g1 = source[lineoffset + i - 1];
            int g2 = source[lineoffset + i + 1];
            int g3 = source[(lineoffset + i) - width];
            int g4 = source[lineoffset + i + width];

            int d1 = ABS(g1 - g2);
            int d2 = ABS(g3 - g4);

            b = source[lineoffset + i];
            r = (((int)source[((lineoffset + i) - width) + 1] +
                  (int)source[(lineoffset + i + width) + 1] +
                  (int)source[((lineoffset + i) - width) - 1] +
                  (int)source[(lineoffset + i + width) - 1]) /
                 4);

            if (d1 < d2) {
                g = (g1 + g2) / 2;
            } else {
                g = (g3 + g4) / 2;
            }

            if (data->use_ccm) {
                r = CLIP((r * CRR(data->ccm) + g * CRG(data->ccm) + b * CRB(data->ccm)) / 1024);
                g = CLIP((r * CGR(data->ccm) + g * CGG(data->ccm) + b * CGB(data->ccm)) / 1024);
                b = CLIP((r * CBR(data->ccm) + g * CBG(data->ccm) + b * CBB(data->ccm)) / 1024);
            } else if (data->use_rbgain) {
                r = CLIP((r * data->rgain) / 1024);
                b = CLIP((b * data->bgain) / 1024);
            }

            dest[dest_offset++] = YUV_V(r, g, b);
            dest[dest_offset++] = YUV_Y(r, g, b);

            i++;

            g = g2;
            b = ((int)source[(lineoffset + i) - 1] + (int)source[(lineoffset + i) + 1]) / 2;
            r = ((int)source[(lineoffset + i) - width] + (int)source[lineoffset + i + width]) / 2;

            if (data->use_ccm) {
                r = CLIP((r * CRR(data->ccm) + g * CRG(data->ccm) + b * CRB(data->ccm)) / 1024);
                g = CLIP((r * CGR(data->ccm) + g * CGG(data->ccm) + b * CGB(data->ccm)) / 1024);
                b = CLIP((r * CBR(data->ccm) + g * CBG(data->ccm) + b * CBB(data->ccm)) / 1024);
            } else if (data->use_rbgain) {
                r = CLIP((r * data->rgain) / 1024);
                b = CLIP((b * data->bgain) / 1024);
            }

            dest[dest_offset++] = YUV_U(r, g, b);
            dest[dest_offset++] = YUV_Y(r, g, b);

            i++;
        }

        lineoffset += width;
        dest_offset = (j + 1) * width * 2 + 4;

        for (i = 2; i < width - 3;) {
            int r, g, b;
            int g1 = source[lineoffset + i - 1];
            int g2 = source[lineoffset + i + 1];
            int g3 = source[(lineoffset + i) - width];
            int g4 = source[lineoffset + i + width];

            int d1 = ABS(g1 - g2);
            int d2 = ABS(g3 - g4);

            r = source[lineoffset + i];

            if (d1 < d2) {
                g = (g1 + g2) / 2;
            }

            else {
                g = (g3 + g4) / 2;
            }

            b = (((int)source[((lineoffset + i) - width) + 1] +
                  (int)source[(lineoffset + i + width) + 1] +
                  (int)source[((lineoffset + i) - width) - 1] +
                  (int)source[(lineoffset + i + width) - 1]) /
                 4);

            if (data->use_ccm) {
                r = CLIP((r * CRR(data->ccm) + g * CRG(data->ccm) + b * CRB(data->ccm)) / 1024);
                g = CLIP((r * CGR(data->ccm) + g * CGG(data->ccm) + b * CGB(data->ccm)) / 1024);
                b = CLIP((r * CBR(data->ccm) + g * CBG(data->ccm) + b * CBB(data->ccm)) / 1024);
            } else if (data->use_rbgain) {
                r = CLIP((r * data->rgain) / 1024);
                b = CLIP((b * data->bgain) / 1024);
            }

            dest[dest_offset++] = YUV_U(r, g, b);
            dest[dest_offset++] = YUV_Y(r, g, b);

            i++;

            g = g2;
            r = ((int)source[(lineoffset + i) - 1] + (int)source[(lineoffset + i) + 1]) / 2;
            b = ((int)source[(lineoffset + i) - width] + (int)source[lineoffset + i + width]) / 2;

            if (data->use_ccm) {
                r = CLIP((r * CRR(data->ccm) + g * CRG(data->ccm) + b * CRB(data->ccm)) / 1024);
                g = CLIP((r * CGR(data->ccm) + g * CGG(data->ccm) + b * CGB(data->ccm)) / 1024);
                b = CLIP((r * CBR(data->ccm) + g * CBG(data->ccm) + b * CBB(data->ccm)) / 1024);
            } else if (data->use_rbgain) {
                r = CLIP((r * data->rgain) / 1024);
                b = CLIP((b * data->bgain) / 1024);
            }

            dest[dest_offset++] = YUV_V(r, g, b);
            dest[dest_offset++] = YUV_Y(r, g, b);

            i++;
        }
    }
}
Exemplo n.º 9
0
void debayer_ccm_rgb24_edge(unicap_data_buffer_t *destbuf, unicap_data_buffer_t *srcbuf,
                            debayer_data_t *data) {
    int i, j;
    int dest_offset = 0;
    rgb24pixel_t *dest = (rgb24pixel_t *)destbuf->data;
    unsigned char *source = srcbuf->data;
    int width = destbuf->format.size.width;
    int height = destbuf->format.size.height;

    for (j = 2; j < height - 2; j += 2) {
        int lineoffset = j * width;
        dest_offset = j * width + 1;

        for (i = 1; i < width - 2;) {
            rgb24pixel_t pixel;

            int g1 = source[lineoffset + i - 1];
            int g2 = source[lineoffset + i + 1];
            int g3 = source[(lineoffset + i) - width];
            int g4 = source[lineoffset + i + width];

            int d1 = ABS(g1 - g2);
            int d2 = ABS(g3 - g4);

            pixel.c.r = source[lineoffset + i];
            pixel.c.b = (((int)source[((lineoffset + i) - width) + 1] +
                          (int)source[(lineoffset + i + width) + 1] +
                          (int)source[((lineoffset + i) - width) - 1] +
                          (int)source[(lineoffset + i + width) - 1]) /
                         4);

            if (d1 < d2) {
                pixel.c.g = (g1 + g2) / 2;
            } else {
                pixel.c.g = (g3 + g4) / 2;
            }

            if (data->use_ccm) {
                pixel.c.r = CLIP((pixel.c.r * CRR(data->ccm) + pixel.c.g * CRG(data->ccm) +
                                  pixel.c.b * CRB(data->ccm)) /
                                 1024);
                pixel.c.g = CLIP((pixel.c.r * CGR(data->ccm) + pixel.c.g * CGG(data->ccm) +
                                  pixel.c.b * CGB(data->ccm)) /
                                 1024);
                pixel.c.b = CLIP((pixel.c.r * CBR(data->ccm) + pixel.c.g * CBG(data->ccm) +
                                  pixel.c.b * CBB(data->ccm)) /
                                 1024);
            } else if (data->use_rbgain) {
                pixel.c.r = CLIP((pixel.c.r * data->rgain) / 4096);
                pixel.c.b = CLIP((pixel.c.b * data->bgain) / 4096);
            }

            dest[dest_offset++].combined = pixel.combined;

            i++;

            pixel.c.g = g2;
            pixel.c.r = ((int)source[(lineoffset + i) - 1] + (int)source[(lineoffset + i) + 1]) / 2;
            pixel.c.b =
                ((int)source[(lineoffset + i) - width] + (int)source[lineoffset + i + width]) / 2;

            if (data->use_ccm) {
                pixel.c.r = CLIP((pixel.c.r * CRR(data->ccm) + pixel.c.g * CRG(data->ccm) +
                                  pixel.c.b * CRB(data->ccm)) /
                                 1024);
                pixel.c.g = CLIP((pixel.c.r * CGR(data->ccm) + pixel.c.g * CGG(data->ccm) +
                                  pixel.c.b * CGB(data->ccm)) /
                                 1024);
                pixel.c.b = CLIP((pixel.c.r * CBR(data->ccm) + pixel.c.g * CBG(data->ccm) +
                                  pixel.c.b * CBB(data->ccm)) /
                                 1024);
            } else if (data->use_rbgain) {
                pixel.c.r = CLIP((pixel.c.r * data->rgain) / 4096);
                pixel.c.b = CLIP((pixel.c.b * data->bgain) / 4096);
            }

            dest[dest_offset++].combined = pixel.combined;

            i++;
        }

        lineoffset += width;
        dest_offset = (j + 1) * width + 2;

        for (i = 2; i < width - 3;) {
            rgb24pixel_t pixel;
            int g1 = source[lineoffset + i - 1];
            int g2 = source[lineoffset + i + 1];
            int g3 = source[(lineoffset + i) - width];
            int g4 = source[lineoffset + i + width];

            int d1 = ABS(g1 - g2);
            int d2 = ABS(g3 - g4);

            pixel.c.b = source[lineoffset + i];

            if (d1 < d2) {
                pixel.c.g = (g1 + g2) / 2;
            } else {
                pixel.c.g = (g3 + g4) / 2;
            }

            pixel.c.r = (((int)source[((lineoffset + i) - width) + 1] +
                          (int)source[(lineoffset + i + width) + 1] +
                          (int)source[((lineoffset + i) - width) - 1] +
                          (int)source[(lineoffset + i + width) - 1]) /
                         4);

            if (data->use_ccm) {
                pixel.c.r = CLIP((pixel.c.r * CRR(data->ccm) + pixel.c.g * CRG(data->ccm) +
                                  pixel.c.b * CRB(data->ccm)) /
                                 1024);
                pixel.c.g = CLIP((pixel.c.r * CGR(data->ccm) + pixel.c.g * CGG(data->ccm) +
                                  pixel.c.b * CGB(data->ccm)) /
                                 1024);
                pixel.c.b = CLIP((pixel.c.r * CBR(data->ccm) + pixel.c.g * CBG(data->ccm) +
                                  pixel.c.b * CBB(data->ccm)) /
                                 1024);
            } else if (data->use_rbgain) {
                pixel.c.r = CLIP((pixel.c.r * data->rgain) / 4096);
                pixel.c.b = CLIP((pixel.c.b * data->bgain) / 4096);
            }

            dest[dest_offset++].combined = pixel.combined;

            i++;

            pixel.c.g = g2;
            pixel.c.b = ((int)source[(lineoffset + i) - 1] + (int)source[(lineoffset + i) + 1]) / 2;
            pixel.c.r =
                ((int)source[(lineoffset + i) - width] + (int)source[lineoffset + i + width]) / 2;

            if (data->use_ccm) {
                pixel.c.r = CLIP((pixel.c.r * CRR(data->ccm) + pixel.c.g * CRG(data->ccm) +
                                  pixel.c.b * CRB(data->ccm)) /
                                 1024);
                pixel.c.g = CLIP((pixel.c.r * CGR(data->ccm) + pixel.c.g * CGG(data->ccm) +
                                  pixel.c.b * CGB(data->ccm)) /
                                 1024);
                pixel.c.b = CLIP((pixel.c.r * CBR(data->ccm) + pixel.c.g * CBG(data->ccm) +
                                  pixel.c.b * CBB(data->ccm)) /
                                 1024);
            } else if (data->use_rbgain) {
                pixel.c.r = CLIP((pixel.c.r * data->rgain) / 4096);
                pixel.c.b = CLIP((pixel.c.b * data->bgain) / 4096);
            }

            dest[dest_offset++].combined = pixel.combined;

            i++;
        }
    }
}
Exemplo n.º 10
0
int main(void)
{
    while(1)
    {
		previousSpriteState = spriteState;
        pollKeys();
		enableSounds();
		setupInterrupts();


		switch(state)
		{
			case SPLASH:
			{
				REG_DISPCNTL = BG2_ENABLE | MODE3;
				fillPicture((u16 *)splashBitmap);

				if (BUTTON_PRESSED(START_BUTTON))
				{
					state = GAME;
				}
				if (BUTTON_PRESSED(SELECT_BUTTON))
				{
					state = INSTRUCTIONS;
				}
			break;
			}

			case INSTRUCTIONS:
			{
				fillPicture((u16 *)instructionsBitmap);
				if (BUTTON_PRESSED(SELECT_BUTTON))
				{
					state = SPLASH;
				}
				break;
			}
			
			case GAME:
			{

				//load tiles
				DMA_MEMORY[3].source = backgroundTiles;
				DMA_MEMORY[3].destination = &CHARBLOCK[0];
				DMA_MEMORY[3].control = 12000 | DMA_ON;

				//load map
				DMA_MEMORY[3].source = backgroundMap;
				DMA_MEMORY[3].destination = &SCREENBLOCK[27];
				DMA_MEMORY[3].control = 4096 | DMA_ON;

				//load pallette
				DMA_MEMORY[3].source = backgroundPal;
				DMA_MEMORY[3].destination = PAL_MEM;
				DMA_MEMORY[3].control = 256 | DMA_ON;


				//load the sprites into memory
				DMA_MEMORY[3].source = playerTiles;
				DMA_MEMORY[3].destination = &CHARBLOCK[4];
				DMA_MEMORY[3].control = 16384 | DMA_ON;

				DMA_MEMORY[3].source = playerPal;
				DMA_MEMORY[3].destination = SPRITE_PALETTE;
				DMA_MEMORY[3].control = 256 | DMA_ON;
			    
			    
				//Hide all sprites
				int i;
				for(i=0; i<128; i++)
				{
					OAM[i].attr0 |= ATTR0_HIDE;
				}

				//Set Mode 0 BG 0 and Enable sprites. then set up the sprites
				REG_DISPCNTL = MODE0 | BG0_ENABLE | SPRITE_ENABLE;
				REG_BG0CNT = BG_8BPP | BG_REG_64x64 | CBB(0) | SBB(27);

				REG_TM0CNT = 0;
				DMA[1].cnt = 0;

				REG_TM0D   = timerintervalA;       
				REG_TM0CNT = TIMER_ON;

				DMA[1].src = bgsound;
				DMA[1].dst = REG_FIFO_A;
				DMA[1].cnt = DMA_ON | START_ON_FIFO_EMPTY |
							 DMA_32 | DMA_REPEAT |
							 DMA_DESTINATION_FIXED;

				startA = vblankcountA;

				while(1){

					shadowOAM[0].attr0 = (playerRow & MASKROW) | ATTR0_TALL | ATTR0_REGULAR | ATTR0_8BPP;
					shadowOAM[0].attr1 = (playerCol & MASKCOL)| ATTR1_SIZE32;
					shadowOAM[0].attr2 = (SPRITEOFFSET16(0,0));

					shadowOAM[1].attr0 = badguyRow | ATTR0_TALL | ATTR0_REGULAR | ATTR0_8BPP;
					shadowOAM[1].attr1 = badguyCol | ATTR1_SIZE32;
					shadowOAM[1].attr2 = (SPRITEOFFSET16(0,8));

					pollKeys();
					bigRow = playerRow + vOff;
					bigCol = playerCol + hOff;

				switch(spriteState)
				{
					case STILL:
					{
						shadowOAM[0].attr2 = (SPRITEOFFSET16(0,0));
						break;
					}

					case MOVING:
					{
						if((walkCounter%2)==1)
							shadowOAM[0].attr2 = (SPRITEOFFSET16(0,4));
						else if((walkCounter%2==0))
						{
						shadowOAM[0].attr2 = (SPRITEOFFSET16(0,0)); 
						}
						break;
					}

				}	
				

					if(BUTTON_HELD(A_BUTTON) && BUTTON_HELD(B_BUTTON))
					{
						//load tiles
						DMA_MEMORY[3].source = cheatbackgroundTiles;
						DMA_MEMORY[3].destination = &CHARBLOCK[0];
						DMA_MEMORY[3].control = 11456 | DMA_ON;

						//load map
						DMA_MEMORY[3].source = cheatbackgroundMap;
						DMA_MEMORY[3].destination = &SCREENBLOCK[27];
						DMA_MEMORY[3].control = 4096 | DMA_ON;

						//load pallette
						DMA_MEMORY[3].source = cheatbackgroundPal;
						DMA_MEMORY[3].destination = PAL_MEM;
						DMA_MEMORY[3].control = 256 | DMA_ON;
					}
					if (BUTTON_HELD(RIGHT_BUTTON))
					{
						spriteState=MOVING;
						walkCounter++;
						if(collisionmapBitmap[((bigRow+playerHeight)*collMapSize)+(bigCol+playerCVel+playerWidth)]==WHITE)
						{
							if(playerCol<(SCREEN_WIDTH-(playerWidth+5))){
								playerCol+=playerCVel;
							}
							else if(hOff<(collMapSize-SCREEN_WIDTH))
							{
								hOff+=playerCVel;
							}
						}
					}
					if (BUTTON_HELD(LEFT_BUTTON))
					{
						spriteState=MOVING;
						walkCounter++;
						if(collisionmapBitmap[((bigRow+playerHeight)*collMapSize)+(bigCol+playerCVel)]==WHITE)
						{
							if(playerCol>(0))
							{
								playerCol-=playerCVel;
							}
							else if(hOff>(SCREEN_WIDTH-collMapSize))
							{
								hOff-=playerCVel;
							}
						}
					}
					if (BUTTON_HELD(UP_BUTTON))
					{
						spriteState=MOVING;
						walkCounter++;
						//Check collision and move
						if((collisionmapBitmap[(((bigRow-playerRVel)*collMapSize)+(bigCol+playerWidth))]==WHITE)&&
							(collisionmapBitmap[(((bigRow-playerRVel)*collMapSize)+(bigCol))]==WHITE))
						{
							if(playerRow>30)
							{
								playerRow-=playerRVel;
							}
							else if(vOff>0)
							{
								vOff-=playerRVel;
							}
						}
						
					}
					if (BUTTON_HELD(DOWN_BUTTON))
					{
						spriteState=MOVING;
						walkCounter++;
						//Check collision and move
						if((collisionmapBitmap[(((bigRow+playerHeight+playerRVel)*collMapSize)+(bigCol+playerWidth))]==WHITE)&&
							(collisionmapBitmap[(((bigRow+playerHeight+playerRVel)*collMapSize)+(bigCol))]==WHITE))
						{

							if(playerRow<(SCREEN_HEIGHT-(playerHeight)))
							{
								playerRow+=playerRVel;
							}
							else if(vOff<(collMapSize-SCREEN_HEIGHT))
							{
								vOff+=playerRVel;
							}
						if((playerRow > 440) && (playerCol > 464))
						{
							state = WIN;
						}
						}


					}
					if (BUTTON_PRESSED(START_BUTTON))
					{
							REG_TM1CNT = 0;
							DMA[2].cnt = 0;
						
							REG_TM1D   = timerintervalB;       
							REG_TM1CNT = TIMER_ON;

							DMA[2].src = bark;
							DMA[2].dst = REG_FIFO_B;
							DMA[2].cnt = DMA_ON | START_ON_FIFO_EMPTY |
										 DMA_32 | DMA_REPEAT |
										 DMA_DESTINATION_FIXED;

							startB = vblankcountB;
					}
					if (BUTTON_PRESSED(SELECT_BUTTON))
					{
						//waitForNoKey();
						state = PAUSE;
					}
					
					waitForVBlank();
					OAM[0] = shadowOAM[0];
					OAM[1] = shadowOAM[1];

					REG_BG0HOFS = hOff;
					REG_BG0VOFS = vOff;

				}

			}

				case WIN:
				{
					while(1);
				}

				case PAUSE:
				{
					if(BUTTON_PRESSED(SELECT_BUTTON))
					{
						state=GAME;
					}
				}

		}

	}

    return 0;
}