Example #1
0
// Function: main()
int main(int argc, char ** argv)
{
    PA_Init();    // Initializes PA_Lib
    PA_InitVBL(); // Initializes a standard VBL
    PA_InitText(1,1);
    Drawable cursor(0,0,0);
    cursor.Load(0, 0, (void*)pal_cursor, (void*)gfx_cursor, OBJ_SIZE_16X16, 1);
    setupRotations();
    u8 c = 0;
    u8 x = 0;
    u8 y = 0;
    for (y = 0; y != 8; ++y) {
        for (x = 0; x != 8; ++x) {
            u16 i = y*8+x;
            if (grid[i] == 1) {
                Tower tower = Tower(SPRITE_TOWER_BASE+c, x*16, y*16);
                tower.Load(0, 1, (void*)pal_tower, (void*)gfx_tower, OBJ_SIZE_16X16, 1);
                tower_list.push_back(tower);
                PA_SetSpriteRotEnable(0, tower.sprite, c);
                ++c;
            }
        }
    }

    s16 angle = 0;

	// Infinite loop to keep the program running
	while (1)
	{
	    u8 i = 0;
        for (tlist_it it = tower_list.begin(); it != tower_list.end(); ++it) {
            angle = (*it).GetAngleTo(cursor);
            PA_SetRotsetNoZoom(0, i, angle);
            ++i;
        }
        PA_OutputText(1, 0, 0, "Angle: %03d", angle);
        PA_OutputText(1, 0, 1, "Angle2: %03d", angle);
        PA_OutputText(1, 0, 2, "Cursor: %03d,%03d", cursor.position.x, cursor.position.y);
        if (Stylus.Held) {
            cursor.position.x = Stylus.X;
            cursor.position.y = Stylus.Y;
        } else {
            cursor.position.x += (Pad.Held.Right - Pad.Held.Left);
            cursor.position.y += (Pad.Held.Down - Pad.Held.Up);
        }
        cursor.Draw();
        PA_WaitForVBL();
	}

	return 0;
} // End of main()
Example #2
0
int main(void){

	PA_Init();
	PA_InitVBL();
	
	PA_InitText(1,0); // On the top screen

	PA_LoadSpritePal(0, 0, (void*)sprite0_Pal);

	PA_CreateSprite(0, 0,(void*)vaisseau_Sprite, OBJ_SIZE_32X32,1, 0, 128-16, 96-16); // Create the ship in the center...
	PA_SetSpriteRotEnable(0,0,0);// Enable rotations and use Rotset 0... 
	
	s32 x = (128) << 8; // ship x position in 8bit fixed point
	s32 y = (96) << 8; // Y
	u16 angle = 0; // direction in which to move !
	
	

	while(1)
	{
		angle = PA_GetAngle(x>>8, y>>8, Stylus.X, Stylus.Y);
		PA_SetRotsetNoZoom(0, 0, angle); // Turn the ship in the correct direction
		
		if (Stylus.Held){ // Move forward
			x += PA_Cos(angle);
			y -= PA_Sin(angle);
		}

		PA_OutputText(1, 5, 10, "Angle : %d  ", angle);
	
		PA_SetSpriteXY(0, 0, (x>>8)-16, (y>>8)-16); // Sprite position converted to normal...
		
		PA_WaitForVBL();

	}
	return 0;
}
Example #3
0
void setupRotations() {
    u16 r;
    for (r = 0; r < 511; r+= 64) {
      PA_SetRotsetNoZoom(0, r/64, r);
    }
}