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
int main()
{
	// Set display options.
	// DCNT_MODE0 sets mode 0, which provides four tiled backgrounds.
	// DCNT_OBJ enables objects.
	// DCNT_OBJ_1D make object tiles mapped in 1D (which makes life easier).
	REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1 | DCNT_BG2 | DCNT_OBJ;
	
	REG_BG0CNT = BG_CBB(0) | BG_SBB(30) | BG_8BPP | BG_REG_32x32 | BG_PRIO(0);
	
	REG_BG1CNT = BG_CBB(0) | BG_SBB(29) | BG_8BPP | BG_REG_32x32 | BG_PRIO(1);
	
	REG_BG2CNT = BG_CBB(0) | BG_SBB(25) | BG_8BPP | BG_REG_64x64 | BG_PRIO(2);
	REG_BG2HOFS = 0;
	REG_BG2VOFS = 0;
	
	ClearObjects();
	
	SetPaletteBG(1, RGB(31, 31, 31)); // white
	
	//Load each tile in font_bold into it's corresponding position in charblock 0
	for (int i = 0; i < 128; i++)
	{
		LoadTile8(0, i, font_bold[i]);
	}
	
	DrawText(5, (SCREEN_HEIGHT / 16) - 2, "DECEPTIVE DIMENSIONS");
	DrawText(5, (SCREEN_HEIGHT / 16), "Press start to begin");
	
	Buttons buttons;
	int framecounter = 0;
	
	//Title screen (under construction)
	while (true)
	{
		buttons.Update();
		
		if (buttons.StartJustPressed())
		{
			break;
		}
		
		WaitVSync();	
	}
	
	while (true)
	{
		//Load Custom spritesheet
		LoadPaletteObjData(0, spritesheet4Pal, sizeof spritesheet4Pal);
		LoadPaletteBGData(0, backgroundnewnewPal, sizeof backgroundnewnewPal);
		LoadTileData(4, 0, spritesheet4Tiles, sizeof spritesheet4Tiles);
		LoadTileData(0, 0, backgroundnewnewTiles, sizeof backgroundnewnewTiles);
		
		int levelnumber = 1;
		
		Level level(levelnumber);
		
		for (int screenblock = 21; screenblock < 31; screenblock++)
		{
			level.FillScreenblock(screenblock, 0);
		}
		
		level.DrawBackground(level.curdimension);
		
		bool gamerunning = true;
		
		//Main game loop
		while (gamerunning)
		{
			buttons.Update();
			
			gamerunning = level.CheckIfLevelComplete();
			level.TakeInput(buttons);
			level.MoveObjects();
			level.Draw();
			level.UpdateLevelObjects(framecounter);

			framecounter++;
			
			WaitVSync();
			FlipBuffers();
		}
		
		//Reload each tile in font_bold into it's corresponding position in charblock 0
		for (int i = 0; i < 128; i++)
		{
			LoadTile8(0, i, font_bold[i]);
		}
		
		SetPaletteBG(0, RGB(0, 0, 0)); // black
		SetPaletteBG(1, RGB(31, 31, 31)); // white		
		
		for (int screenblock = 25; screenblock < 31; screenblock++)
		{
			for (int y = 0; y < 32; y++)
			{
				for (int x = 0; x < 32; x++)
				{
					SetTile(screenblock, x, y, 0);
				}
			}
		}
		
		level.player.drawx = SCREEN_WIDTH;
		
		SetObject(level.player.GetObjNum(),
		  ATTR0_SHAPE(2) | ATTR0_8BPP | ATTR0_HIDE,
		  ATTR1_SIZE(2) | ATTR1_X(level.player.drawx),
		  ATTR2_ID8(0) | ATTR2_PRIO(2));
		
		UpdateObjects();
		
		DrawText(6, (SCREEN_HEIGHT / 16) - 2, "That's all folks!!");
		DrawText(3, (SCREEN_HEIGHT / 16), "Press start to try again");
		
		while (true)
		{
			buttons.Update();
			
			if (buttons.StartJustPressed())
			{
				break;
			}
			
			WaitVSync();
		}
	}
}
Ejemplo n.º 9
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;
		}
	}

}