示例#1
0
void SpriteRenderer::updateSpritePositions(IN const ProcessInfo& info)
{
	initSprites(vertexes.size()/4, set->particles.size());

	cameraPosition = info.camera.getPosition();

	int cnt = set->particles.size();
	for(int i = 0; i < cnt; i++)
	{
		int i4 = i*4;
        v3 dx;
        v3 dy;
		calculateSprite(info.camera,
						set->particles[i]->position,
                        POSITION_GLOBAL,
						v2(set->particles[i]->size, set->particles[i]->size),
						align,
						customAlign,
						vertexes[i4 + 0],
						vertexes[i4 + 1],
						vertexes[i4 + 2],
						vertexes[i4 + 3],
						normals[i4 + 0],
                        dx,
                        dy);

		normals[i4 + 1] = normals[i4 + 2] = normals[i4 + 3] = normals[i4 + 0];

        if (life_blend)
        {
            texCoords2[i*4 + 0].x = texCoords2[i*4 + 1].x = texCoords2[i*4 + 2].x = texCoords2[i*4 + 3].x = clamp(set->particles[i]->life);
            texCoords2[i*4 + 0].y = texCoords2[i*4 + 1].y = texCoords2[i*4 + 2].y = texCoords2[i*4 + 3].y = 0.0;
        }
	}
}
示例#2
0
static void SpriteInit(bool EnabledBlend,u16 alpha)
{
  if(EnabledBlend==false) alpha=15;
  
  initSprites();
  updateOAM(12);
  
  s32 spx[12],spy[12];
  
  spx[ 0]=0; spy[ 0]=0;
  spx[ 1]=1; spy[ 1]=0;
  spx[ 2]=2; spy[ 2]=0;
  spx[ 3]=3; spy[ 3]=0;
  spx[ 4]=0; spy[ 4]=1;
  spx[ 5]=1; spy[ 5]=1;
  spx[ 6]=2; spy[ 6]=1;
  spx[ 7]=3; spy[ 7]=1;
  spx[ 8]=0; spy[ 8]=2;
  spx[ 9]=1; spy[ 9]=2;
  spx[10]=2; spy[10]=2;
  spx[11]=3; spy[11]=2;
  
  for(u32 idx=0;idx<12;idx++){
    SetSprite(idx,1,(8*8)+(8*spx[idx])+((8*8*4)*spy[idx]),alpha);
    
    s32 px=spx[idx]*64;
    s32 py=spy[idx]*64;
    
    SetPosSprite(idx,(s32)px,(s32)py,EnabledBlend);
  }
  
  updateOAM(12);
}
示例#3
0
文件: main.cpp 项目: Patater/manual
int main() {
    /* Turn on the 2D graphics core. */
    powerOn(POWER_ALL_2D);

    /*
     *  Configure the VRAM and background control registers.
     *
     *  Place the main screen on the bottom physical screen. Then arrange the
     *  VRAM banks. Next, confiure the background control registers.
     */
    lcdMainOnBottom();
    initVideo();
    initBackgrounds();

    /* Set up a few sprites. */
    SpriteInfo spriteInfo[SPRITE_COUNT];
    OAMTable *oam = new OAMTable();
    initOAM(oam);
    initSprites(oam, spriteInfo);

    /* Display the backgrounds. */
    displayStarField();
    displayPlanet();
    displaySplash();

    /* Make the ship object. */
    static const int SHUTTLE_OAM_ID = 0;
    SpriteEntry * shipEntry = &oam->oamBuffer[SHUTTLE_OAM_ID];
    SpriteRotation * shipRotation = &oam->matrixBuffer[SHUTTLE_OAM_ID];
    Ship * ship = new Ship(&spriteInfo[SHUTTLE_OAM_ID]);

    /* Accelerate the ship for a little while to make it move. */
    for (int i = 0; i < 10; i++) {
        ship->accelerate();
    }

    for (;;) {
        /* Update the game state. */
        ship->moveShip();

        /* Update sprite attributes. */
        MathVector2D<float> position = ship->getPosition();
        shipEntry->x = (int)position.x;
        shipEntry->y = (int)position.y;
        rotateSprite(shipRotation, -ship->getAngleDeg());

        /*
         *  Update the OAM.
         *
         *  We have to copy our copy of OAM data into the actual OAM during
         *  VBlank (writes to it are locked during other times).
         */
        swiWaitForVBlank();
        updateOAM(oam);
    }

    return 0;
}
示例#4
0
HRESULT ManagementSprite::init(ID3D11Device* p_device)
{
	HRESULT hr = S_OK;

	initSprites();
	initSpriteCollection();

	hr = initVertexBuffer(p_device);
	if(SUCCEEDED(hr))
		hr = initIndexBuffer(p_device);

	return hr;
}
示例#5
0
////////////////////////////////////////////////////////////////////////////////
// CTOR / DTOR                                                                //
////////////////////////////////////////////////////////////////////////////////
Paddle::Paddle() :
    //HouseKeeping
    m_basePosition(Lore::Vector2::Zero()),
    m_speed       (Lore::Vector2::Zero()),
    m_hitBox      (Lore::Rectangle::Empty()),
    m_lives       (kInitialLivesCount),
    //Movement
    m_maxX(0),
    m_minX(0)
    //m_spritesInfoVec - Initialized in initSprites
{
    initSprites();
}
//Usings
USING_NS_GAMEKABOOM


////////////////////////////////////////////////////////////////////////////////
// CTOR / DTOR                                                                //
////////////////////////////////////////////////////////////////////////////////
SplashScene::SplashScene()
{
    Lore::WindowManager::instance()->setClearColor(Lore::Color::White());

    initSprites();
    initTimers ();
    initSounds ();
}
CreditsState::CreditsState(Font f, TextureManager* tM) {
	font = f;
	
	texManager = tM;

	phase = 0;

	initTexts();
	initSprites(texManager);

	objects.emplace_back(new Player(texManager, &bullets, 3, 80.f, 470.f));
	objects.emplace_back(new Enemy(texManager, &bullets, 1, 1200.f, 90.f, 0.f, 0.f));

	objects[PLAYER]->setShooting(true);
}
示例#8
0
文件: dual3D.c 项目: Almamu/portalDS
void initD3D()
{
	int x,y,i;
	
	videoSetMode(MODE_3_3D);
	videoSetModeSub(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_2D_BMP_256);
    vramSetPrimaryBanks(VRAM_A_TEXTURE,VRAM_B_TEXTURE,VRAM_C_SUB_BG,VRAM_D_SUB_SPRITE);
	vramSetBankH(VRAM_H_LCD);
	vramSetBankI(VRAM_I_LCD);
	
	REG_BG0CNT = BG_PRIORITY(1);
	
	REG_BG2CNT_SUB = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(1);
        REG_BG2PA_SUB = 1 << 8;
        REG_BG2PB_SUB = 0;
        REG_BG2PC_SUB = 0;
        REG_BG2PD_SUB = 1 << 8;
		
        REG_BG2X_SUB = 0;
        REG_BG2Y_SUB = 0;
	
	initSprites();
	
	d3dSpriteRotations[0].hdx=256;
	d3dSpriteRotations[0].hdy=0;
	d3dSpriteRotations[0].vdx=0;
	d3dSpriteRotations[0].vdy=256;
	
	i=0;
	
	for (y = 0; y < 3; y++)
	{
		for (x = 0; x < 4; x++) {
			d3dSprites[i].attribute[0] = ATTR0_BMP | ATTR0_SQUARE | (64 * y);
			d3dSprites[i].attribute[1] = ATTR1_SIZE_64 | (64 * x);
			d3dSprites[i].attribute[2] = ATTR2_ALPHA(1) | (8 * 32 * y) | (8 * x);
			i++;
		}
	}
	
	updateOAM();
	d3dScreen=true;
}
示例#9
0
文件: main.c 项目: ndelanou/PCWorms
int main(int argc, char** argv)
{
	{
		time_t t1;
		t1 = time(NULL);
		logFile = fopen("../assets/logAndResult/log.txt", "w+");
		if (logFile == NULL)
			exit(EXIT_FAILURE);
		fprintf(logFile, "Start of session : %s\n\n", ctime(&t1));
	};
	if (initSprites() < 0) // Ouverture des fichiers sprites
	{
		fclose(logFile);
		exit(EXIT_FAILURE);
	}
	strcpy(globalVar.savePath, DEFAULTPATH);
	if (mainFenetre() < 0)
	{
		fprintf(logFile, "mainFenetre : FAILURE.\n");
	}
	return 0;
}
示例#10
0
Manager::Manager() : env( SDL_putenv(const_cast<char*>("SDL_VIDEO_CENTERED=center")) ),
  	io( IOManager::getInstance() ),
  	clock( Clock::getInstance() ),
  	screen( io.getScreen() ),
  	backRed( Gamedata::getInstance().getXmlInt("backRed") ),
  	backGreen( Gamedata::getInstance().getXmlInt("backGreen") ),
  	backBlue( Gamedata::getInstance().getXmlInt("backBlue") ),
  	sprites(), 
	planes(),
	worlds(),
	curWorld(NULL),
  	backWorld("back", Gamedata::getInstance().getXmlInt("backFactor") ),
  	viewport( Viewport::getInstance() ),
  	currentSprite(-1),
  	currentWorld(SELECT),
	menuSound(),
  	showInfo(true),
	level(1),
	life(3),
	score(0),
  	player(new Player("player", PLAYER, EAST, 1.0, 1.0, 0)),
	explodingPlayer(NULL),
	isDead(false),
	gameOver(false),
  	health(new Health()),
	magic(new Magic()),
	enemies(),
	explodingEnemies()
{
	player -> setVelocity(Vector2f(0, 0));
	player -> setPosition(Vector2f(0, 200));
  	initSprites(); //initial all the sprites
  	viewport.setObjectToTrack(player);
  	if(SDL_Init(SDL_INIT_VIDEO) != 0){
  	  throw string("Unable to initialize SDL: ");
	}
  	atexit(SDL_Quit);
}
示例#11
0
    MapLevel::MapLevel(Context& context, std::size_t level, sf::Image& levelData, b2World& world)
        : mContext(context)
        , mWorld(LevelWidth, std::vector<Tile>(LevelHeight))
        , mBoxWorld(world)
        , mTexture(context.getTexture(Textures::GameAtlas))
        , mDestinationList()
        , mSourceList()
        , mEntities()
    {
        LOG_CALL("MapLevel::MapLevel");

        // Reset Box2D world
        LOG_DEBUG("Clearing Box2D world from entities: %d to remove.", mBoxWorld.GetBodyCount());
        b2Body* body = world.GetBodyList();
        while (nullptr != body) {

            b2Body* nextBody = body->GetNext();
            world.DestroyBody(body);
            body = nextBody;
        }

        // Create Box2D world boundaries
        b2utils::createGround(mBoxWorld, 20.f, 300.f, 40.f, 600.f);
        b2utils::createGround(mBoxWorld, 780.f, 300.f, 40.f, 600.f);

        b2utils::createGround(mBoxWorld, 400.f, 18.f, 800.f, 36.f);
        b2utils::createGround(mBoxWorld, 400.f, 582.f, 800.f, 36.f);

        loadLevel(level, levelData);
        initSprites();

        //mDebugPlayerSpawn.setFillColor(sf::Color::Yellow);
        //LOG_DEBUG("Player spawn position: (%d, %d)", mPlayerSpawnPos.x, mPlayerSpawnPos.y);
        //mDebugPlayerSpawn.setPosition(WorldOffsetX + TileWidth * mPlayerSpawnPos.x, WorldOffsetY + TileHeight * mPlayerSpawnPos.y);
        //mDebugPlayerSpawn.setSize(sf::Vector2f(24.f, 24.f));
    }
示例#12
0
static void resetEverything( void )
{
	initSprites( );

	launchFromPosition.x = 500.0f;
	launchFromPosition.y = 600.0f - 16.0f;

	getLaunchToPosition( );
	launchToSprite = createSprite( launchToImg, 1, launchToPosition, VEC2_ONE, 0.0f, COL_WHITE, 0 );

	initPanjandrums( );
	initTroops( );
	initExplosions( );
	initMines( );
	initBarbedWire( );
	initPits( );

	initParticles( );

	attackerHealth = MAX_HEALTH;
	defenderHealth = MAX_HEALTH;

	drumCount = MAX_DRUM_COUNT;
}
示例#13
0
int main() {
 
    //enable vram and map it to the right places
    vramSetMainBanks(   VRAM_A_MAIN_SPRITE,        //A and B maped consecutivly as sprite memory
                        VRAM_B_MAIN_SPRITE,        //this gives us 256KB which is the max
                        VRAM_C_MAIN_BG_0x06000000, //map C to background memory
                        VRAM_D_LCD                 //not using D
                        ); 
   
   //set the video mode
    videoSetMode(  MODE_0_2D | 
                   DISPLAY_SPR_ACTIVE |    //turn on sprites
                   DISPLAY_BG0_ACTIVE |    //turn on background 0
                   DISPLAY_SPR_1D |        //this is used when in tile mode
                   DISPLAY_SPR_1D_BMP      //and this in bitmap mode
                    );

  	
	consoleInit(0, 0,BgType_Text4bpp, BgSize_T_256x256, 31,0, true, true);
    
    //turn off the sprites
    initSprites();

	
// direct bitmap sprite
// print at using ansi escape sequence \x1b[line;columnH 
	iprintf("\x1b[1;1HDirect Bitmap:");
    sprites[0].attribute[0] = ATTR0_BMP | ATTR0_ROTSCALE_DOUBLE | 10; 
	sprites[0].attribute[1] = ATTR1_SIZE_32 | 20;
	sprites[0].attribute[2] = ATTR2_ALPHA(1)| 0;

	// red 32*32 square for 1d bitmap mode
	for(int i=0;i<32*32;i++)
		SPRITE_GFX[i]=RGB15(31,0,0)|(1<<15); //dont forget alpha bit

// 256 color sprite
// print at using ansi escape sequence \x1b[line;columnH 
	iprintf("\x1b[9;1H256 color:");
	sprites[1].attribute[0] = ATTR0_COLOR_256 | ATTR0_ROTSCALE_DOUBLE | 75;
	sprites[1].attribute[1] = ATTR1_SIZE_32 | 20; // size 64x64, x 10
	sprites[1].attribute[2] = 64;

    // Blue for 256 color sprite
	SPRITE_PALETTE[1]=RGB15(0,0,31);

    // blue 64*64 square for 256 color mode (must write two pixles at time)
	for(int i=0;i<32*16;i++)
		SPRITE_GFX[i+64*16]=(1<<8)|1;

// 16 color sprite
// print at using ansi escape sequence \x1b[line;columnH 
   	iprintf("\x1b[16;1H16 color:");
	sprites[2].attribute[0] = ATTR0_COLOR_16 | ATTR0_ROTSCALE_DOUBLE | 135;
	sprites[2].attribute[1] = ATTR1_SIZE_32 | 20;
	sprites[2].attribute[2] = ATTR2_PALETTE(1) | 96;

    //yellow for 16 color sprite (it is using palette 1 so colors 16-31)
    SPRITE_PALETTE[17]=RGB15(31,31,0);

    // yellow 32*32 square for 16 color mode (must write 4 pixels at a time)
	for(int i=0;i<32*8;i++)
		SPRITE_GFX[i+96*16]=(1<<12)|(1<<8)|(1<<4)|1;



	int angle=0;
    
    //we tied all our sprites to the same rotation attributes (0)
	spriteRotations[0].hdx=256;
	spriteRotations[0].hdy=0;
	spriteRotations[0].vdx=0;
	spriteRotations[0].vdy=256;

	while(1)
	{
		angle+=64;
		
		spriteRotations[0].hdx = cosLerp(angle) >> 4;
		spriteRotations[0].hdy = sinLerp(angle) >> 4;
		spriteRotations[0].vdx = -spriteRotations[0].hdy;
		spriteRotations[0].vdy = spriteRotations[0].hdx;
		
		swiWaitForVBlank();
		
		u32 display_temp = 0;

		scanKeys();
		if(keysDown()&KEY_A) {
		
			screenshotbmp("shot.bmp");

			display_temp=REG_DISPCNT;
			REG_DISPCNT=MODE_FB1;

		}

		if(keysUp()&KEY_A) {
		
			videoSetMode(  MODE_0_2D | 
				DISPLAY_SPR_ACTIVE |    //turn on sprites
				DISPLAY_BG0_ACTIVE |    //turn on background 0
				DISPLAY_SPR_1D |        //this is used when in tile mode
				DISPLAY_SPR_1D_BMP |    //and this in bitmap mode
				DCAP_OFFSET(1));
		}

		
		updateOAM();
	}
}
示例#14
0
void gamescreen()
{
  // set the mode for 2 text layers and two extended background layers
  videoSetMode(MODE_5_2D |
               //DISPLAY_BG1_ACTIVE |
               DISPLAY_BG3_ACTIVE |
               DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_LAYOUT
               );

  // set the first bank as background memory and the third as sub background memory
  // B and D are not used (if you want a bitmap greater than 256x256 you will need more
  // memory so another vram bank must be used and mapped consecutivly
  vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000, VRAM_B_MAIN_SPRITE, //VRAM_B_MAIN_BG_0x6020000,
                   VRAM_C_SUB_BG, VRAM_D_MAIN_BG_0x6020000);
  
  // set up our bitmap background
  BG3_CR     = BG_BMP8_512x256 | BG_WRAP_ON| BG_BMP_BASE(0);
  //BG2_CR     = BG_BMP8_256x256 | BG_BMP_BASE(8);
  
  BG1_CR = BG_32x32 | BG_TILE_BASE(0) | BG_MAP_BASE(8) | BG_256_COLOR;


  // these are rotation backgrounds so you must set the rotation attributes:
  // these are fixed point numbers with the low 8 bits the fractional part
  // this basicaly gives it a 1:1 translation in x and y so you get a nice flat bitmap
  BG3_XDX = 1 << 8;
  BG3_XDY = 0;
  BG3_YDX = 0;
  BG3_YDY = 1 << 8;

  BG2_XDX = 1 << 8;
  BG2_XDY = 0;
  BG2_YDX = 0;
  BG2_YDY = 1 << 8;


  //our bitmap looks a bit better if we center it so scroll down (256 - 192) / 2
  BG3_CX = 0;
  BG3_CY = 0;

  BG2_CX = 0;
  BG2_CY = 0;

  for(int i = 0; i < 512*256; i++)
    BG_GFX[i] = ((u16*)topscreen_img_bin)[i];

  for(int i = 0; i < 256; ++i)
    BG_PALETTE[i] = ((u16*)topscreen_pal_bin)[i];
  //for(int i = 0; i < 256; ++i)
  //BG_PALETTE[i] = ((u16*)numbers_pal_bin)[i];

        
  x = 0;
  y = 0;
  px = 128-32;
  py = 103;
  oldx = x;
  oldy = y;
  drag = false;
  touch_down = touchReadXY();

  initSprites();
  
  for(int i=0;i<256*256;i++)
    {
      SPRITE_GFX[i] = i % 256 | ((i % 256) << 8);
    }

  //for(int i = 0; i < 8*8*256/2; ++i)
  //    ((u16*)BG_TILE_RAM(0))[i] = ((u16*)numbers_img_bin)[i];

  //for(int i = 0; i < 32*32; ++i)
  //((u16*)BG_MAP_RAM(8))[i] = i%256;

  /*    for(int y=0;y<64; ++y)
        for(int x=0;x<32; ++x)
        {
        SPRITE_GFX[y*64+x] = ((u16*)sprite_img_bin)[y*32+x];
        }*/

  const u8* frames[16];
  frames[0]  = walk_frame00_img_bin;
  frames[1]  = walk_frame01_img_bin;
  frames[2]  = walk_frame02_img_bin;
  frames[3]  = walk_frame03_img_bin;
  frames[4]  = walk_frame04_img_bin;
  frames[5]  = walk_frame05_img_bin;
  frames[6]  = walk_frame06_img_bin;
  frames[7]  = walk_frame07_img_bin;
  frames[8]  = walk_frame08_img_bin;
  frames[9]  = walk_frame09_img_bin;
  frames[10] = walk_frame10_img_bin;
  frames[11] = walk_frame11_img_bin;
  frames[12] = walk_frame12_img_bin;
  frames[13] = walk_frame13_img_bin;
  frames[14] = walk_frame14_img_bin;
  frames[15] = walk_frame15_img_bin;

  const u8* pal_frames[16];
  pal_frames[0]  = walk_frame00_pal_bin;
  pal_frames[1]  = walk_frame01_pal_bin;
  pal_frames[2]  = walk_frame02_pal_bin;
  pal_frames[3]  = walk_frame03_pal_bin;
  pal_frames[4]  = walk_frame04_pal_bin;
  pal_frames[5]  = walk_frame05_pal_bin;
  pal_frames[6]  = walk_frame06_pal_bin;
  pal_frames[7]  = walk_frame07_pal_bin;
  pal_frames[8]  = walk_frame08_pal_bin;
  pal_frames[9]  = walk_frame09_pal_bin;
  pal_frames[10] = walk_frame10_pal_bin;
  pal_frames[11] = walk_frame11_pal_bin;
  pal_frames[12] = walk_frame12_pal_bin;
  pal_frames[13] = walk_frame13_pal_bin;
  pal_frames[14] = walk_frame14_pal_bin;
  pal_frames[15] = walk_frame15_pal_bin;

  for(int i=0;i<64*32; ++i)
    SPRITE_GFX[i] = ((u16*)sprite_img_bin)[i];

  for(int i=0;i<32*32/2; ++i)
    SPRITE_GFX[i+64*32] = ((u16*)use_icon_img_bin)[i];

  for(int i=0;i<64*32; ++i)
    SPRITE_GFX[i+ (64*32) + (32*16)] = ((u16*)smalldoor_img_bin)[i];

  for(int i=0;i<64*32; ++i)
    SPRITE_GFX[i] = ((u16*)walk_frame00_img_bin)[i];

  for(int i = 0; i < 256; ++i)
    SPRITE_PALETTE[i] = ((u16*)walk_frame00_pal_bin)[i];


  sprites[0].attribute[0] = ATTR0_SQUARE | ATTR0_TYPE_BLENDED | ATTR0_BMP | px;
  sprites[0].attribute[1] = ATTR1_SIZE_64 | py  | ATTR1_FLIP_Y;
  sprites[0].attribute[2] = ATTR2_ALPHA(3);

  sprites[1].attribute[0] = ATTR0_SQUARE | ATTR0_COLOR_256 | (192-32-8) | ATTR0_DISABLED;
  sprites[1].attribute[1] = ATTR1_SIZE_32 | (256-32-8);
  sprites[1].attribute[2] = 64*2;//64*64;//64*32;

  sprites[2].attribute[0] = ATTR0_SQUARE | ATTR0_COLOR_256 | 90-6;
  sprites[2].attribute[1] = ATTR1_SIZE_64 | 200+16+2;
  sprites[2].attribute[2] = 64*2+32;

  int frame_index = 0;
  int sx = 0;
  //int sy = 0;
  bool left = true;;

  if (subscreen_mode == PDA)
    init_pda();
  else
    init_doorminigame();

  while(1) 
    {
      swiWaitForVBlank();

      frame_index += 1;
      frame_index = frame_index % 80;

      //SPRITE_GFX[i] = ((u16*)numbers_img_bin)[i];


      // read the button states
      scanKeys();
      touch = touchReadXY();

      pressed = keysDown();	// buttons pressed this loop
      held = keysHeld();		// buttons currently held
      
      if (subscreen_mode != DIALOG)
        {
          sprites[0].attribute[0] = ATTR0_SQUARE | ATTR0_TYPE_BLENDED | ATTR0_COLOR_256 | mod(103,512);
          sprites[0].attribute[1] = ATTR1_SIZE_64 | mod(128-32,512) | (left ? 0: ATTR1_FLIP_X);
          sprites[0].attribute[2] = ATTR2_ALPHA(3);

          sprites[2].attribute[0] = ATTR0_SQUARE | ATTR0_TYPE_BLENDED | ATTR0_COLOR_256 | mod(90-6, 512);
          sprites[2].attribute[1] = ATTR1_SIZE_64 | mod((200+16+2 - px + 128-32 + door_pos/4),512);
          sprites[2].attribute[2] = ATTR2_ALPHA(1) | 64*2+32;
        }
      else
        {
          sprites[0].attribute[0] |=  ATTR0_DISABLED;
          sprites[1].attribute[0] |=  ATTR0_DISABLED;
          sprites[2].attribute[0] |=  ATTR0_DISABLED;
        }

      if ((held & KEY_L) && (held & KEY_R))
        swiSoftReset();

      if ((pressed & KEY_LEFT) || (pressed & KEY_RIGHT))
        {
          frame_index = 0;
        }

      if (held & KEY_LEFT)
        {
          left = true;
          px -= 1;
          sprites[0].attribute[1] = sprites[0].attribute[1] & ~ATTR1_FLIP_X;

          for(int i=0;i<64*32; ++i)
            SPRITE_GFX[i] = ((u16*)frames[frame_index/5])[i];
      
          for(int i = 0; i < 256; ++i)
            SPRITE_PALETTE[i] = ((u16*)pal_frames[frame_index/5])[i];
        }
      else if (held & KEY_RIGHT)
        {
          left = false;
          px += 1;
          sprites[0].attribute[1] = sprites[0].attribute[1] | ATTR1_FLIP_X;

          for(int i=0;i<64*32; ++i)
            SPRITE_GFX[i] = ((u16*)frames[frame_index/5])[i];
      
          for(int i = 0; i < 256; ++i)
            SPRITE_PALETTE[i] = ((u16*)pal_frames[frame_index/5])[i];
        }
      else
        {
          for(int i=0;i<64*32; ++i)
            SPRITE_GFX[i] = ((u16*)frames[0])[i];
      
          for(int i = 0; i < 256; ++i)
            SPRITE_PALETTE[i] = ((u16*)pal_frames[0])[i];
        }

      if (held & KEY_DOWN)
        py += 1;
      else if (held & KEY_UP)
        py -= 1;


      if ((px + 128) > 328-16 && 
          (px + 128) < (328+35+16))
        {
          sprites[1].attribute[0] &=  ~ATTR0_DISABLED;
          //if (pressed & KEY_X)
          //            {
          if (subscreen_mode == PDA)
            {
              init_doorminigame();
              subscreen_mode = DOOR_MINIGAME;
            }
          else if (subscreen_mode == DOOR_MINIGAME)
            {
              init_pda();
              subscreen_mode = PDA;
            }
          //}
        }
      else if ((px + 128) > 133-16 &&
               (px + 128) < 133-16+32)
        {
          init_dialog();
          subscreen_mode = DIALOG;
        }
      else
        {
          sprites[1].attribute[0] |= ATTR0_DISABLED;
          if (subscreen_mode == DOOR_MINIGAME)
            {
              init_pda();
              subscreen_mode = PDA;
            }
        }


      sx = px;
      //sx += 1;
      
      if ((held & KEY_TOUCH)  && drag)
        {
          x = oldx + (touch_down.px - touch.px);
          y = oldy + (touch_down.py - touch.py);
        }

      if (!(held & KEY_TOUCH))
        drag = false;
      
      if (subscreen_mode != DIALOG)
        {
          BG3_CX  = x*500 + sx<<8 ;
          BG3_CY  = y*500 + (32<<8);
        }
      //2_CX  = -x;
      //2_CY  = -y;
      
      update_subscreen();

      updateOAM();
    }
}
示例#15
0
文件: main.c 项目: bttf/petsounds
int main() {
	touchPosition touch;
	PrintConsole mainScreen;
	mySprite sprites[128];
	
	lcdMainOnBottom();
	initVideo();
	initBackgrounds();
	initConsole(&mainScreen);
	initSprites(sprites);
	
	//leftButtonOff
	oamSet(&oamMain, sprites[0].id, sprites[0].x, sprites[0].y, 0, 0, SpriteSize_64x64,
		SpriteColorFormat_16Color, sprites[0].gfx, -1, false, false, false, false, false);
	//rightButtonOff
	oamSet(&oamMain, sprites[2].id, sprites[2].x, sprites[2].y, 0, 0, SpriteSize_64x64,
		SpriteColorFormat_16Color, sprites[2].gfx, -1, false, false, false, false, false);
	
	int keys = keysDown();
	int currentSprite = 4;
	int moveLeft = 0;
	int moveRight = 0;
	int MOVE_SPEED = 21;
	while (true) {
		//consoleClear();
		scanKeys();
		touchRead(&touch);
		keys = keysHeld();
		
		if (keys) {
			if (keys & KEY_TOUCH) {
				touchRead(&touch);
				if (within(&touch, sprites[0])) {
					// leftButton clicked
					// leftButtonOn
					oamClearSprite(&oamMain, 0);
					oamSet(&oamMain, sprites[1].id, sprites[1].x, sprites[1].y, 0, 1, SpriteSize_64x64,
						SpriteColorFormat_16Color, sprites[1].gfx, -1, false, false, false, false, false);
					swiWaitForVBlank();
					oamUpdate(&oamMain);
					moveLeft = 1;
				}
				else if (within(&touch, sprites[2])) {
					// rightButton clicked
					// rightButtonOn
					oamClearSprite(&oamMain, 2);
					oamSet(&oamMain, sprites[3].id, sprites[3].x, sprites[3].y, 0, 1, SpriteSize_64x64,
						SpriteColorFormat_16Color, sprites[3].gfx, -1, false, false, false, false, false);
					swiWaitForVBlank();
					oamUpdate(&oamMain);
					moveRight = 1;
				}
				else if(within(&touch, sprites[currentSprite])) {
					mmEffectEx(&sprites[currentSprite].sfx);
				}
			}
		}
		else {
			//leftButtonOff
			oamClearSprite(&oamMain, 1);
			oamSet(&oamMain, sprites[0].id, sprites[0].x, sprites[0].y, 0, 0, SpriteSize_64x64,
				SpriteColorFormat_16Color, sprites[0].gfx, -1, false, false, false, false, false);
			//rightButtonOff
			oamClearSprite(&oamMain, 3);
			oamSet(&oamMain, sprites[2].id, sprites[2].x, sprites[2].y, 0, 0, SpriteSize_64x64,
				SpriteColorFormat_16Color, sprites[2].gfx, -1, false, false, false, false, false);
				
			if (moveLeft) {
				if ((currentSprite - 1) >= 4) {
					// move current sprite to the right and new one in from left
					int x1 = sprites[currentSprite].x;
					int x2 = -64;
					
					while (x1 < 280 || x2 < 96) {
						oamSet(&oamMain, sprites[currentSprite].id, x1, 
							sprites[currentSprite].y, 0, sprites[currentSprite].paletteAlpha, 
							SpriteSize_64x64, SpriteColorFormat_16Color, sprites[currentSprite].gfx, 
							-1, false, false, false, false, false);
						oamSet(&oamMain, sprites[currentSprite-1].id, x2, sprites[currentSprite-1].y,
							0, sprites[currentSprite-1].paletteAlpha, SpriteSize_64x64,
							SpriteColorFormat_16Color, sprites[currentSprite-1].gfx, -1, false, false,
							false, false, false);
						swiWaitForVBlank();
						oamUpdate(&oamMain);
						x1 += MOVE_SPEED;
						x2 += MOVE_SPEED;
					}
					currentSprite--;
				}
				moveLeft = 0;
			}
			else if (moveRight) {
				if ((currentSprite + 1) - SPRITECOUNT < 0) {
					// move current sprite to the left and new one from right
					int x1 = sprites[currentSprite].x;
					int x2 = 256;
					
					while (x1 > -80 || x2 > 96) {
						oamSet(&oamMain, sprites[currentSprite].id, x1, 
							sprites[currentSprite].y, 0, sprites[currentSprite].paletteAlpha, 
							SpriteSize_64x64, SpriteColorFormat_16Color, sprites[currentSprite].gfx, 
							-1, false, false, false, false, false);
						oamSet(&oamMain, sprites[currentSprite+1].id, x2, sprites[currentSprite+1].y,
							0, sprites[currentSprite+1].paletteAlpha, SpriteSize_64x64,
							SpriteColorFormat_16Color, sprites[currentSprite+1].gfx, -1, false, false,
							false, false, false);
						swiWaitForVBlank();
						oamUpdate(&oamMain);
						x1 -= MOVE_SPEED;
						x2 -= MOVE_SPEED;
					}
					currentSprite++;
				}
				moveRight = 0;
			}
		}
		
		//oamSet(oam, id, x, y, priority, palette_alpha, size, colorformat, gfxOffset, affineIndex,
		//sizedouble, hide, hflip, vflip, mosaic);
		//
		//gong
		consoleClear();
		printf("\x1b[3;3H%s", sprites[currentSprite].desc);
		oamSet(&oamMain, sprites[currentSprite].id, sprites[currentSprite].x, sprites[currentSprite].y, 0, sprites[currentSprite].paletteAlpha, SpriteSize_64x64, SpriteColorFormat_16Color,
			sprites[currentSprite].gfx, -1, false, false, false, false, false);
			
		swiWaitForVBlank();
		oamUpdate(&oamMain);	
	}
}
示例#16
0
文件: main.cpp 项目: Patater/manual
int main() {
    /* Turn on the 2D graphics core. */
    powerOn(POWER_ALL_2D);

    /*
     *  Configure the VRAM and background control registers.
     *
     *  Place the main screen on the bottom physical screen. Then arrange the
     *  VRAM banks. Next, confiure the background control registers.
     */
    lcdMainOnBottom();
    initVideo();
    initBackgrounds();

    /* Initialize maxmod using the memory based soundbank set up. */
    mmInitDefaultMem((mm_addr)soundbank_bin);

    /* Set up a few sprites. */
    SpriteInfo spriteInfo[SPRITE_COUNT];
    OAMTable *oam = new OAMTable();
    initOAM(oam);
    initSprites(oam, spriteInfo);

    /* Display the backgrounds. */
    displayStarField();
    displayPlanet();
    displaySplash();

    /*************************************************************************/

    /* Keep track of the touch screen coordinates. */
    touchPosition touch;

    /* Make the ship object. */
    static const int SHUTTLE_OAM_ID = 0;
    SpriteEntry * shipEntry = &oam->oamBuffer[SHUTTLE_OAM_ID];
    SpriteRotation * shipRotation = &oam->matrixBuffer[SHUTTLE_OAM_ID];
    Ship * ship = new Ship(&spriteInfo[SHUTTLE_OAM_ID]);

    /* Make the moon. */
    static const int MOON_OAM_ID = 1;
    SpriteEntry * moonEntry = &oam->oamBuffer[MOON_OAM_ID];
    SpriteInfo * moonInfo = &spriteInfo[MOON_OAM_ID];
    MathVector2D<int> * moonPos = new MathVector2D<int>();
    moonPos->x = moonEntry->x;
    moonPos->y = moonEntry->y;

    /* Set up sound data. */
    mmLoadEffect(SFX_THRUST);

    for (;;) {
        /* Update the game state. */
        updateInput(&touch);
        handleInput(ship, moonPos, moonInfo, &touch);
        ship->moveShip();

        /* Update ship sprite attributes. */
        MathVector2D<float> position = ship->getPosition();
        shipEntry->x = (int)position.x;
        shipEntry->y = (int)position.y;
        rotateSprite(shipRotation, -ship->getAngleDeg());
        /* Update moon sprite attributes. */
        moonEntry->x = (int)moonPos->x;
        moonEntry->y = (int)moonPos->y;

        /*
         *  Update the OAM.
         *
         *  We have to copy our copy of OAM data into the actual OAM during
         *  VBlank (writes to it are locked during other times).
         */
        swiWaitForVBlank();
        updateOAM(oam);
    }

    return 0;
}