Ejemplo n.º 1
0
//  Keep the dart stationary relative to the dartboard (move with the dartboard), also allows dart to 
//  scroll off the screen, hides any darts that are entirely off the screen
void Dart::UpdateDart(int BGPos[]) {
	
	int actualloc[2];
	bool wrapping[2] = {false, false};
	actualloc[0] = loc[0] - BGPos[0]-2*8;
	actualloc[1] = loc[1] - BGPos[1]-2*8;

	if (actualloc[0] < 0) {
		actualloc[0] += 512;
		wrapping[0] = true;
	} 
	if (actualloc[1] < 0) {
		actualloc[1] += 256;
		wrapping[1] = true;
	}
	
	Animate();

	if ((wrapping[0] == true && actualloc[0]+8*8 < 512) || (wrapping[1] == true && actualloc[1]+8*8 < 256) ||
		(wrapping[0] == false && actualloc[0] > SCREEN_WIDTH) || (wrapping[1] == false && actualloc[1] > SCREEN_HEIGHT)) {
		SetObject(dartnumber,
		  ATTR0_SHAPE(0) | ATTR0_8BPP | ATTR0_REG | ATTR0_Y(0) | ATTR0_HIDE,
		  ATTR1_SIZE(2) | ATTR1_X(0),
		  ATTR2_ID8(64) | ATTR2_PRIO(2));				
	} else {		
		SetObject(dartnumber,
		  ATTR0_SHAPE(0) | ATTR0_8BPP | ATTR0_REG | ATTR0_Y(actualloc[1]) | ATTR0_AFF | ATTR0_AFF_DBL,
		  ATTR1_SIZE(2) | ATTR1_X(actualloc[0]) | ATTR1_AFF(dartnumber-1),
		  ATTR2_ID8(64) | ATTR2_PRIO(2));	  
	}
	
}
Ejemplo n.º 2
0
void spawnMonster(){
	bool type = true;
	bool dir = true;
	if(rand()%3 == 0)type = false;
	if(rand()%2 == 0)dir = false;
	
	int startFrame = 32;
	if(type)startFrame = 16;
	
	int i = 0;
	
	if(enemies.size() < MAX_ENEMIES){
		enemies.push_back(Monster(116,0,type));
		i = enemies.size()-1;
	}else{
		for(int k = 0; k < MAX_ENEMIES; k++){
			if(enemies.at(k).isDead()){
				enemies[k] = Monster(116,0,type);
				i = k;
				break;
			}
		}
	}
	
	SetObject(i+3,
			ATTR0_SHAPE(0) | ATTR0_8BPP | ATTR0_REG | ATTR0_Y(enemies.at(i).getY()),
			ATTR1_SIZE(!type) | ATTR1_X(enemies.at(i).getX()),
			ATTR2_ID8(startFrame));
			
	enemies.at(i).setDir(dir);
}
Ejemplo n.º 3
0
void drawText(int x, int y, std::string string){
	int startPos = activeLetters;
	for(int i = 0; i < string.length(); i++){
		activeLetters++;
		SetObject(startPos+i+45,
	          ATTR0_SHAPE(0) | ATTR0_8BPP | ATTR0_REG | ATTR0_Y(y),
			  ATTR1_SIZE(0) | ATTR1_X(x+(i*8)),
			  ATTR2_ID8(string.at(i) + 64));
	}
}
Ejemplo n.º 4
0
void gameInit(){
	(&player)->~Player();
    new (&player) Player(116,76);
	
	for(int i = 0; i < enemies.size(); i++){
		enemies.at(i).setDead(true);
	}
	
	for(int i = 0; i < bullets.size(); i++){
		bullets.at(i).setDead(true);
	}
	
	(&crate)->~Crate();
    new (&crate) Crate(0,0,0);
	
	weapon = 1;
	score = 0;

	//Set-up Objects
	ClearObjects();
	
	//Weapon
	int shape = 0;
	if(weapon == 8)shape = 1;
	SetObject(0,
	          ATTR0_SHAPE(shape) | ATTR0_8BPP | ATTR0_REG | ATTR0_Y(player.getY()+1),
			  ATTR1_SIZE(0) | ATTR1_X(player.getX()+4),
			  ATTR2_ID8(22+weapon));
	
	//Crate
	SetObject(1,
	          ATTR0_SHAPE(0) | ATTR0_8BPP | ATTR0_REG | ATTR0_Y(crate.getY()),
			  ATTR1_SIZE(0) | ATTR1_X(crate.getX()),
			  ATTR2_ID8(14));
	
	//Player
	SetObject(2,
	          ATTR0_SHAPE(0) | ATTR0_8BPP | ATTR0_REG | ATTR0_Y(player.getY()),
			  ATTR1_SIZE(0) | ATTR1_X(player.getX()),
			  ATTR2_ID8(1));
}
Ejemplo n.º 5
0
    Cursor(int objId)
    {
        _id = objId;

        SetObject(_id,
                  ATTR0_SHAPE(0) | ATTR0_8BPP | ATTR0_REG | ATTR0_Y(0),
                  ATTR1_SIZE(1) | ATTR1_X(0),
                  ATTR2_ID8(0));

        _x = 0;
        _y = 0;

        SetObjectX(_id, (_x + BOARD_OFFSET_X / 2) * 16);
        SetObjectY(_id, (_y + BOARD_OFFSET_Y / 2) * 16);
    }
Ejemplo n.º 6
0
int spawnBullet(int type){
	int i = 0;
	int count = 0;
	
	if(bullets.size() < MAX_BULLETS){
		bullets.push_back(Bullet(player.getX(), player.getY(), type, weapon));
		i = bullets.size()-1;
	}else{
		for(int k = 0; k < MAX_BULLETS; k++){
			if(bullets.at(k).getType() == 7)count++;
			if(bullets.at(k).isDead()){
				if(type == 7){
					if(player.getDir())bullets[k] = Bullet(player.getX()+(count*8),player.getY(),type, weapon);
					else bullets[k] = Bullet(player.getX()-(count*8),player.getY(),type, weapon);
					i = k;
				}else{
					bullets[k] = Bullet(player.getX(),player.getY(),type, weapon);
					i = k;
				}
				break;
			}
		}
	}
	
	SetObject(i+24,
			ATTR0_SHAPE(0) | ATTR0_8BPP | ATTR0_REG | ATTR0_Y(bullets.at(i).getY()),
			ATTR1_SIZE(0) | ATTR1_X(bullets.at(i).getX()),
			ATTR2_ID8(bullets.at(i).getFrame()));
			
	bullets.at(i).setDir(player.getDir());
	if(!bullets.at(i).getDir()){
		ObjBuffer[i+24].attr1 |= ATTR1_HFLIP;
	}
	
	return i;
}
Ejemplo n.º 7
0
/**
Updates all gba objects in Level
*/
void Level::UpdateLevelObjects(int framecounter)
{
	DetermineBackgroundOffsets();
	ApplyEntityOffsets();
	
	REG_BG2HOFS = backgroundoffsetx;
	REG_BG2VOFS = backgroundoffsety;
	
	uint16_t facing = 0;
	
	if (player.direction == player.LEFT)
	{
		facing = ATTR1_HFLIP;
	}
	
	int playertileoffset = 0;
	if (player.IsMoving())
	{
		if ((framecounter % 15 == 0) && ((!paused) || (!indimensionsmenu)))
		{
			player.animationframe = !player.animationframe;
		}
		
		if (player.animationframe == true)
		{
			playertileoffset = 2;
		}
		else
		{
			playertileoffset = 4;
		}
	}
	
	if (player.isholding)
	{
		//Allows for height change when carrying cubes on the head
		SetObject(player.GetObjNum(),
		  ATTR0_SHAPE(2) | ATTR0_8BPP | ATTR0_REG
		    | ATTR0_Y(player.drawy + cube[player.cubeheld].GetHeight()),	
		  ATTR1_SIZE(2) | ATTR1_X(player.drawx) | facing,
		  ATTR2_ID8(playertileoffset) | ATTR2_PRIO(2));
	}
	else
	{
		SetObject(player.GetObjNum(),
		  ATTR0_SHAPE(2) | ATTR0_8BPP | ATTR0_REG | ATTR0_Y(player.drawy),
		  ATTR1_SIZE(2) | ATTR1_X(player.drawx) | facing,
		  ATTR2_ID8(playertileoffset) | ATTR2_PRIO(2));
	}
	
	int cubetile = 6 + DimensionTileOffset(curdimension);
	
	//Draw cubes
	for (int i = 0; i < numofcubes; i++)
	{
		SetObject(cube[i].GetObjNum(),
		  ATTR0_SHAPE(0) | ATTR0_8BPP | ATTR0_REG | ATTR0_Y(cube[i].drawy),
		  ATTR1_SIZE(1) | ATTR1_X(cube[i].drawx),
		  ATTR2_ID8(cubetile) | ATTR2_PRIO(2));
	}
	
	UpdateObjects();
}
Ejemplo n.º 8
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;
		}
	}

}