Example #1
0
ENTITY_STATUS CBonus::Think()
{
	if (!map.GetBonus(mapX, mapY)) 
	{
		status = DEAD;
	}
	return status;
}
Example #2
0
ENTITY_STATUS CPlayer::Think(){
	if (map.GetBonus(x/TILE_SIZE, y/TILE_SIZE)) 
	{
		if(map.GetBonus(x/TILE_SIZE, y/TILE_SIZE) == BONUS_BOMB) totalBombs++;
		if(map.GetBonus(x/TILE_SIZE, y/TILE_SIZE) == BONUS_SPEED) speed++;
		if(map.GetBonus(x/TILE_SIZE, y/TILE_SIZE) == BONUS_FLAME) flameLength++;

		map.PopBonus(x/TILE_SIZE, y/TILE_SIZE);
	}
	velx = 0;	//don't move left / right by default
	vely = 0;
	
	if(keystates[key[RIGHT]]){
		velx = PLAYER_SPEED + speed/2;		//move right
		dir = RIGHT;		//player graphic is facing right
	}
	if(keystates[key[LEFT]]){
		velx = -PLAYER_SPEED - speed/2;		//move left
		dir = LEFT;
	}
	if(keystates[key[UP]]){		//if the player isn't jumping already
		vely = -PLAYER_SPEED - speed/2;		//jump!
		dir = UP;
	}
	if(keystates[key[DOWN]]){	//if the player isn't jumping already
		vely = PLAYER_SPEED + speed/2;		//jump!
		dir = DOWN;
	}
	if(keystates[key[PLANT]]){
		if (!map.IsBomb(x/TILE_SIZE, y/TILE_SIZE))
		{
			if (plantedBombs < totalBombs)
			{
				plantedBombs++;
				vecBombs.push_back(CBomb(x - x%TILE_SIZE, y - y%TILE_SIZE, flameLength, this));
				map.PushBomb(x/TILE_SIZE, y/TILE_SIZE);
			}
		}
	}

	//check for collisions with the map
	if (velx > 0)
	{
		int pos = (x + w) / TILE_SIZE;
		int posNew = (x + w + velx) / TILE_SIZE;
		if (posNew != pos)
		{
			if (map.IsSolid(posNew, y/TILE_SIZE) || 
				map.IsSolid(posNew, (y + h - 1)/TILE_SIZE))
				x = (x + velx) / TILE_SIZE * TILE_SIZE + 29;
			else x += velx;
		}
		else x += velx;
	}		 
	else if (velx < 0)
	{	
		int pos = x / TILE_SIZE;
		int posNew = (x + velx) / TILE_SIZE;
		if (posNew != pos)
		{
			if (map.IsSolid(posNew, y/TILE_SIZE) || 
				map.IsSolid(posNew, (y + h - 1)/TILE_SIZE))
				x = (x + velx) / TILE_SIZE * TILE_SIZE + TILE_SIZE;
			else x += velx;
		}
		else x += velx;
	}
	if (vely > 0)
	{	
		int pos = (y + h) / TILE_SIZE;
		int posNew = (y + h + vely) / TILE_SIZE;
		if (posNew != pos)
		{
			if (map.IsSolid(x/TILE_SIZE, posNew) || 
				map.IsSolid((x + w - 1)/TILE_SIZE , posNew))
				y = (y + vely) / TILE_SIZE * TILE_SIZE + 29;
			else y += vely;
		}
		else y += vely;
	}		 
	else if (vely < 0)
	{	
		int pos = (y) / TILE_SIZE;
		int posNew = (y + vely) / TILE_SIZE;
		if (posNew != pos)
		{
			if (map.IsSolid(x/TILE_SIZE, posNew) || 
				map.IsSolid((x + w - 1)/TILE_SIZE , posNew))
				y = (y + vely) / TILE_SIZE * TILE_SIZE + TILE_SIZE;
			else y += vely;
		}
		else y += vely;
	}



	if (map.IsExplosion(x/TILE_SIZE, y/TILE_SIZE))
	{
		status = DEADANIM;
		deadFrame = SDL_GetTicks();
		deadTick = 0;
	}

	return status;
}