예제 #1
0
void Enemy::draw() {
	if((s_x + 7 > 0) && (s_x < 256) && (s_y + 7 > 0) && (s_y < 192)) { // If the sprite is on the screen
		// Draw the sprite on the screen
		oamSet(&oamMain, s_i, s_x, s_y, 0,
			   15, s_size, s_format, s_gfx, -1,
			   false, false, false, false, false);
	} else {
		oamClearSprite(&oamMain, s_i); // Clear the sprite
	}
}
예제 #2
0
void VisualElement::update_position(void)
{
	for (unsigned short i = 0; i < SPRITE_POSITIONS; ++i) {

		st_sprite& sprite = s_SpritePositions[i];

		if (sprite.in_use == false) {
			continue;
		}

		int new_x = sprite.offset->x;
		int new_y = sprite.offset->y;

		/* Give extra offset to correctly place the other sprite. */
		if (i != SPRITE_PIVOT_INDEX) {
			//debug("new: %d,%d", new_x, new_y);
			new_x +=  s_SpritePositions[SPRITE_PIVOT_INDEX].offset->x - TILE_8PX_TO_PX(VisualElement::s_PivotOffset_8px->x);
			new_y +=  s_SpritePositions[SPRITE_PIVOT_INDEX].offset->y - TILE_8PX_TO_PX(VisualElement::s_PivotOffset_8px->y);
			//debug("bef: %d,%d", new_x, new_y);

			/* Verify if the sprite is inside the showing bounds (otherwise, it will be appearing
			 * every multiples of "screen size offset")
			 */
			if ( ((new_x + TILE_SIZE_32PX) < 0) || ((new_y + TILE_SIZE_32PX) < 0) ||
					(new_x > SCREEN_WIDTH) || (new_y > SCREEN_HEIGHT)) {
				oamClearSprite(&oamMain, i);
				continue;
			}
		}

		oamSet(&oamMain,
				i,
				new_x, new_y,
				0, 0,
				SpriteSize_32x32,
				SpriteColorFormat_256Color,
				sprite.mem_addr,
				-1,
				false,
				sprite.hide,
				false, false, false);
	}
}
예제 #3
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);	
	}
}