Exemplo n.º 1
0
void place_sprite(sprite_t *s, camera_t *c) {
	bool exist = s->obj != NULL;
	int screen_x = SCREEN_X(*s, *c);
	int screen_y = SCREEN_Y(*s, *c);
	
	ENGINE_DEBUGFMT("sprite in world at %d, %d on screen at %d, %d, exist: %d, height: %d", s->x, s->height, screen_x, screen_y, exist, SPRITE_HEIGHT(*s));
	
	if ((screen_y + SPRITE_HEIGHT(*s) < 0) ||
	    (screen_y > SCREEN_HEIGHT) ||
	    (screen_x + SPRITE_WIDTH(*s) < 0) ||
	    (screen_x > SCREEN_WIDTH)) {
		if (exist) {
			ENGINE_DEBUG("sprite left! deleting it");
			delete_sprite(s);
		}
		return;
	} else {
		if (!exist) {
			ENGINE_DEBUG("sprite on screen and needs to be created");
			s->obj = new_obj();
		}
	}
	obj_set_attr(s->obj,
	             s->shape | ATTR0_REG,
	             s->size,
	             ATTR2_PALBANK(s->palbank) | s->tile);
	obj_set_pos(s->obj, screen_x, screen_y);
}
Exemplo n.º 2
0
void reset_sprites() {
	int i=0;
	for (i=0; i<128; i++) {
		obj_set_attr(&obj_buffer[i],
			ATTR0_TALL | ATTR0_8BPP | ATTR0_HIDE,
			ATTR1_SIZE_16x32,
			ATTR2_PALBANK(0)
		);	
	}
}
Exemplo n.º 3
0
void init_olimar(OLIMAR* o)
{
   o->bb = { 30,30,16,24 };
   o->hp = 10;
   o->update = update_olimar;
   o->animate = animate_olimar;
   o->coll_cache = { 0,0,0 };
   
   
   
   obj_set_attr(o->obj_buf, 
	             ATTR0_TALL, 
	             ATTR1_SIZE_32x64, 
	             ATTR2_PALBANK(0) | 0);
	             
	pkm->attr0 |= ATTR0_4BPP;
}
Exemplo n.º 4
0
void init_game()
{
   //Initialization
   
   //Field_0
   memcpy(pal_bg_mem, bd_forestPal, bd_forestPalLen);
   memcpy(&tile_mem[0][0], bd_forestTiles, bd_forestTilesLen);
   memcpy(&se_mem[30][0], bd_forestMap, bd_forestMapLen);
   
   REG_BG0CNT = BG_CBB(0) | BG_SBB(30) | BG_4BPP | BG_REG_32x32 | BG_PRIO(1);
   
   //Bg_Forest
   memcpy(&pal_bg_bank[1], bg_forestPal, bg_forestPalLen);
   memcpy(&tile_mem[0][16], bg_forestTiles, bg_forestTilesLen);
   memcpy(&se_mem[28][0], bg_forestMap, bg_forestMapLen);
   
   REG_BG1CNT = BG_CBB(0) | BG_SBB(28) | BG_4BPP | BG_REG_64x32 | BG_PRIO(0);
   
   
   memcpy(&tile8_mem[4][0], pikmin_sheetTiles, pikmin_sheetTilesLen);
   memcpy(pal_obj_mem, pikmin_sheetPal, pikmin_sheetPalLen);
	
	
	REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1 | DCNT_OBJ| DCNT_OBJ_1D;
	
	oam_init(obj_buffer, 128);
	
	u32 tid=0, pb=0;
	
	OBJ_ATTR *pkm = &obj_buffer[0];
	
	obj_set_attr(pkm, 
	             ATTR0_TALL, 
	             ATTR1_SIZE_16x32, 
	             ATTR2_PALBANK(pb) | tid);
	             
	pkm->attr0 |= ATTR0_8BPP;
	
	oam_copy(oam_mem, obj_buffer, 1);
}
Exemplo n.º 5
0
void GraphicsManager::Draw(EntityManager* entity_manager)
{
	// Check for new renderable entities TODO

	// Get all renderable components
	vector<IComponent*> renderable_components = entity_manager->GetAllComponentsOfType(COMP_RENDER);

	int i = 0;
	// Iterate through the object components
	for (vector<IComponent*>::iterator it = renderable_components.begin(); it != renderable_components.end(); ++it)
	{
		RenderComponent* renderableComponent = (RenderComponent*)(*it);
		SpriteDefinition spriteDef = GetSpriteDefinition(renderableComponent->_id);

		int x = renderableComponent->_position.x;
		int y = renderableComponent->_position.y;

		if (x < 0)
			x = 511 + x;
		if (y < 0)
			y = 255 + y;

			
		
		SetObject(i, (spriteDef.shape << 14) | ATTR0_Y(y) | ATTR0_8BPP | ATTR0_AFF,
			ATTR1_SIZE(spriteDef.size) | ATTR1_X(x) | ATTR1_AFF(0),
			ATTR2_PALBANK(0) | ATTR2_ID4(spriteDef.char_bb_identifier));
		
		ObjAffine* renderAffine = &( (ObjAffine*) ObjBuffer)[0];
	
	
		//float theta = (float)(++player.angleDegrees % 360) * (M_PI/180);
		float angle = (float)(renderableComponent->_angleDegrees % 360) * (M_PI / 180);
		renderAffine->pa = float2fx( cos(angle) );
		renderAffine->pb = float2fx( -sin(angle) );	
		renderAffine->pc = float2fx( sin(angle) );
		renderAffine->pd = float2fx( cos(angle) );
		
		++i;
	}
	UpdateObjects();

	// Get all background components
	vector<IComponent*> background_components = entity_manager->GetAllComponentsOfType(COMP_BACKGROUND);

	// Iterate through the background components
	for (vector<IComponent*>::iterator it = background_components.begin(); it != background_components.end(); ++it)
	{
		BackgroundComponent* backgroundComponent = (BackgroundComponent*)(*it);

		
		// Scroll background
		if (backgroundComponent->_background_id == BG_PIPES)
		{
			REG_BG1HOFS = backgroundComponent->_integer_position.x;
		}
		
		// Update tiles
		if (backgroundComponent->_background_id == BG_PIPES || backgroundComponent->_background_id == BG_SCORE)
		{
			
			for (int x = 0; x < 32; x++)
			{
				for (int y = 0; y < 32; y++)
				{
					DisplayTile(x, y, backgroundComponent->_tiles[x][y], backgroundComponent->_screen_bb);
				}
			}
		}
		
		if (backgroundComponent->_update_screen)
		{
			for (int x = 0; x < 32; x++)
			{
				for (int y = 0; y < 32; y++)
				{
					DisplayTile(x, y, backgroundComponent->_tiles[x][y], backgroundComponent->_screen_bb);
				}
			}
			backgroundComponent->_update_screen = false;
		}
	}

}