trabajando los items
This commit is contained in:
@@ -33,5 +33,5 @@ frames=36,37,38,39,40,41,42,43,44,45
|
|||||||
name=pop
|
name=pop
|
||||||
speed=5
|
speed=5
|
||||||
loop=-1
|
loop=-1
|
||||||
frames=48,49,50,51,52,53,54,55,56,57,58,59
|
frames=60,61,62,63,64,65,66,67,68,69,70,71
|
||||||
[/animation]
|
[/animation]
|
||||||
@@ -33,5 +33,5 @@ frames=36,37,38,39,40,41,42,43,44,45
|
|||||||
name=pop
|
name=pop
|
||||||
speed=5
|
speed=5
|
||||||
loop=-1
|
loop=-1
|
||||||
frames=48,49,50,51,52,53,54,55,56,57,58,59
|
frames=60,61,62,63,64,65,66,67,68,69,70,71
|
||||||
[/animation]
|
[/animation]
|
||||||
@@ -33,5 +33,5 @@ frames=36,37,38,39,40,41,42,43,44,45
|
|||||||
name=pop
|
name=pop
|
||||||
speed=5
|
speed=5
|
||||||
loop=-1
|
loop=-1
|
||||||
frames=48,49,50,51,52,53,54,55,56,57,58,59
|
frames=60,61,62,63,64,65,66,67,68,69,70,71
|
||||||
[/animation]
|
[/animation]
|
||||||
@@ -29,9 +29,16 @@ loop=0
|
|||||||
frames=36,37,38,39,40,41,42,43,44,45
|
frames=36,37,38,39,40,41,42,43,44,45
|
||||||
[/animation]
|
[/animation]
|
||||||
|
|
||||||
|
[animation]
|
||||||
|
name=powerball
|
||||||
|
speed=20
|
||||||
|
loop=0
|
||||||
|
frames=48
|
||||||
|
[/animation]
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=pop
|
name=pop
|
||||||
speed=5
|
speed=5
|
||||||
loop=-1
|
loop=-1
|
||||||
frames=48,49,50,51,52,53,54,55,56,57,58,59
|
frames=60,61,62,63,64,65,66,67,68,69,70,71
|
||||||
[/animation]
|
[/animation]
|
||||||
9
data/gfx/item_clock.ani
Normal file
9
data/gfx/item_clock.ani
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
frameWidth=16
|
||||||
|
frameHeight=16
|
||||||
|
|
||||||
|
[animation]
|
||||||
|
name=default
|
||||||
|
speed=10
|
||||||
|
loop=0
|
||||||
|
frames=0,1
|
||||||
|
[/animation]
|
||||||
BIN
data/gfx/item_clock.png
Normal file
BIN
data/gfx/item_clock.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 334 B |
9
data/gfx/item_coffee.ani
Normal file
9
data/gfx/item_coffee.ani
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
frameWidth=16
|
||||||
|
frameHeight=16
|
||||||
|
|
||||||
|
[animation]
|
||||||
|
name=default
|
||||||
|
speed=10
|
||||||
|
loop=0
|
||||||
|
frames=0,1
|
||||||
|
[/animation]
|
||||||
BIN
data/gfx/item_coffee.png
Normal file
BIN
data/gfx/item_coffee.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 462 B |
9
data/gfx/item_coffee_machine.ani
Normal file
9
data/gfx/item_coffee_machine.ani
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
frameWidth=23
|
||||||
|
frameHeight=29
|
||||||
|
|
||||||
|
[animation]
|
||||||
|
name=default
|
||||||
|
speed=10
|
||||||
|
loop=0
|
||||||
|
frames=0,1,2,3
|
||||||
|
[/animation]
|
||||||
BIN
data/gfx/item_coffee_machine.png
Normal file
BIN
data/gfx/item_coffee_machine.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 553 B |
9
data/gfx/item_points1_disk.ani
Normal file
9
data/gfx/item_points1_disk.ani
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
frameWidth=16
|
||||||
|
frameHeight=16
|
||||||
|
|
||||||
|
[animation]
|
||||||
|
name=default
|
||||||
|
speed=10
|
||||||
|
loop=0
|
||||||
|
frames=0,1
|
||||||
|
[/animation]
|
||||||
BIN
data/gfx/item_points1_disk.png
Normal file
BIN
data/gfx/item_points1_disk.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 263 B |
9
data/gfx/item_points2_gavina.ani
Normal file
9
data/gfx/item_points2_gavina.ani
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
frameWidth=16
|
||||||
|
frameHeight=16
|
||||||
|
|
||||||
|
[animation]
|
||||||
|
name=default
|
||||||
|
speed=10
|
||||||
|
loop=0
|
||||||
|
frames=0,1
|
||||||
|
[/animation]
|
||||||
BIN
data/gfx/item_points2_gavina.png
Normal file
BIN
data/gfx/item_points2_gavina.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 422 B |
9
data/gfx/item_points3_pacmar.ani
Normal file
9
data/gfx/item_points3_pacmar.ani
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
frameWidth=16
|
||||||
|
frameHeight=16
|
||||||
|
|
||||||
|
[animation]
|
||||||
|
name=default
|
||||||
|
speed=10
|
||||||
|
loop=0
|
||||||
|
frames=0,1
|
||||||
|
[/animation]
|
||||||
BIN
data/gfx/item_points3_pacmar.png
Normal file
BIN
data/gfx/item_points3_pacmar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 388 B |
@@ -201,8 +201,20 @@ bool Director::setFileList()
|
|||||||
asset->add("data/gfx/game_bg.png", t_bitmap);
|
asset->add("data/gfx/game_bg.png", t_bitmap);
|
||||||
asset->add("data/gfx/game_text.png", t_bitmap);
|
asset->add("data/gfx/game_text.png", t_bitmap);
|
||||||
asset->add("data/gfx/intro.png", t_bitmap);
|
asset->add("data/gfx/intro.png", t_bitmap);
|
||||||
asset->add("data/gfx/items.png", t_bitmap);
|
|
||||||
asset->add("data/gfx/logo.png", t_bitmap);
|
asset->add("data/gfx/logo.png", t_bitmap);
|
||||||
|
asset->add("data/gfx/items.png", t_bitmap);
|
||||||
|
asset->add("data/gfx/item_points1_disk.png", t_bitmap);
|
||||||
|
asset->add("data/gfx/item_points1_disk.ani", t_data);
|
||||||
|
asset->add("data/gfx/item_points2_gavina.png", t_bitmap);
|
||||||
|
asset->add("data/gfx/item_points2_gavina.ani", t_data);
|
||||||
|
asset->add("data/gfx/item_points3_pacmar.png", t_bitmap);
|
||||||
|
asset->add("data/gfx/item_points3_pacmar.ani", t_data);
|
||||||
|
asset->add("data/gfx/item_clock.png", t_bitmap);
|
||||||
|
asset->add("data/gfx/item_clock.ani", t_data);
|
||||||
|
asset->add("data/gfx/item_coffee.png", t_bitmap);
|
||||||
|
asset->add("data/gfx/item_coffee.ani", t_data);
|
||||||
|
asset->add("data/gfx/item_coffee_machine.png", t_bitmap);
|
||||||
|
asset->add("data/gfx/item_coffee_machine.ani", t_data);
|
||||||
|
|
||||||
asset->add("data/gfx/title_bg_tile.png", t_bitmap);
|
asset->add("data/gfx/title_bg_tile.png", t_bitmap);
|
||||||
asset->add("data/gfx/title_coffee.png", t_bitmap);
|
asset->add("data/gfx/title_coffee.png", t_bitmap);
|
||||||
|
|||||||
@@ -2086,7 +2086,7 @@ LTexture *Game::balloonTexture(int kind)
|
|||||||
|
|
||||||
else if (kind == 3 || kind == 7)
|
else if (kind == 3 || kind == 7)
|
||||||
{
|
{
|
||||||
return balloon4Texture;
|
return balloon3Texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (kind == 4 || kind == 8 || kind == 9)
|
else if (kind == 4 || kind == 8 || kind == 9)
|
||||||
@@ -2214,7 +2214,7 @@ void Game::checkPlayerItemCollision(Player *player)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
item->erase();
|
item->disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2255,12 +2255,12 @@ void Game::checkBulletBalloonCollision()
|
|||||||
{
|
{
|
||||||
if (droppeditem != ITEM_COFFEE_MACHINE)
|
if (droppeditem != ITEM_COFFEE_MACHINE)
|
||||||
{
|
{
|
||||||
createItem(mTextureItems, mRenderer, balloon->getPosX(), balloon->getPosY(), droppeditem);
|
createItem(balloon->getPosX(), balloon->getPosY(), droppeditem);
|
||||||
JA_PlaySound(mSoundItemDrop);
|
JA_PlaySound(mSoundItemDrop);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
createItem(mTextureItems, mRenderer, players[index]->getPosX(), 0, droppeditem);
|
createItem(players.at(index)->getPosX(), 0, droppeditem);
|
||||||
mCoffeeMachineEnabled = true;
|
mCoffeeMachineEnabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2327,7 +2327,7 @@ void Game::updateItems()
|
|||||||
for (auto item : items)
|
for (auto item : items)
|
||||||
{
|
{
|
||||||
item->update();
|
item->update();
|
||||||
if (item->floorCollision())
|
if (item->isOnFloor())
|
||||||
{
|
{
|
||||||
JA_PlaySound(mSoundCollision);
|
JA_PlaySound(mSoundCollision);
|
||||||
mEffect.shake = true;
|
mEffect.shake = true;
|
||||||
@@ -2413,12 +2413,28 @@ Uint8 Game::dropItem()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea un objeto item
|
// Crea un objeto item
|
||||||
void Game::createItem(LTexture *texture, SDL_Renderer *renderer, Uint8 type, float x, float y)
|
void Game::createItem(Uint8 type, float x, float y)
|
||||||
{
|
{
|
||||||
Item *i = new Item(texture, renderer, type, x, y);
|
Item *i = new Item(mRenderer, mAsset, type, x, y);
|
||||||
items.push_back(i);
|
items.push_back(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Vacia el vector de items
|
||||||
|
void Game::freeItems()
|
||||||
|
{
|
||||||
|
if (items.empty() == false)
|
||||||
|
{
|
||||||
|
for (int i = items.size() - 1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
if (items.at(i)->isEnabled() == false)
|
||||||
|
{
|
||||||
|
delete items.at(i);
|
||||||
|
items.erase(items.begin() + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Crea un objeto SmartSprite para mostrar la puntuación al coger un objeto
|
// Crea un objeto SmartSprite para mostrar la puntuación al coger un objeto
|
||||||
void Game::createItemScoreSprite(int x, int y, SmartSprite *sprite)
|
void Game::createItemScoreSprite(int x, int y, SmartSprite *sprite)
|
||||||
{
|
{
|
||||||
@@ -2691,6 +2707,7 @@ void Game::updatePlayField()
|
|||||||
// Vacia los vectores
|
// Vacia los vectores
|
||||||
freeBullets();
|
freeBullets();
|
||||||
freeBalloons();
|
freeBalloons();
|
||||||
|
freeItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el fondo
|
// Actualiza el fondo
|
||||||
@@ -2787,6 +2804,8 @@ void Game::renderPlayField()
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderFlashEffect();
|
renderFlashEffect();
|
||||||
|
|
||||||
|
mText->write(0, 0, std::to_string(balloons.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestiona el nivel de amenaza
|
// Gestiona el nivel de amenaza
|
||||||
@@ -2825,45 +2844,45 @@ void Game::checkGameInput()
|
|||||||
const int index = 0;
|
const int index = 0;
|
||||||
if (mDemo.dataFile[mDemo.counter].left == 1)
|
if (mDemo.dataFile[mDemo.counter].left == 1)
|
||||||
{
|
{
|
||||||
players[index]->setInput(INPUT_LEFT);
|
players.at(index)->setInput(INPUT_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mDemo.dataFile[mDemo.counter].right == 1)
|
if (mDemo.dataFile[mDemo.counter].right == 1)
|
||||||
{
|
{
|
||||||
players[index]->setInput(INPUT_RIGHT);
|
players.at(index)->setInput(INPUT_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mDemo.dataFile[mDemo.counter].noInput == 1)
|
if (mDemo.dataFile[mDemo.counter].noInput == 1)
|
||||||
{
|
{
|
||||||
players[index]->setInput(INPUT_NULL);
|
players.at(index)->setInput(INPUT_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mDemo.dataFile[mDemo.counter].fire == 1)
|
if (mDemo.dataFile[mDemo.counter].fire == 1)
|
||||||
{
|
{
|
||||||
if (players[index]->canFire())
|
if (players.at(index)->canFire())
|
||||||
{
|
{
|
||||||
players[index]->setInput(INPUT_BUTTON_2);
|
players.at(index)->setInput(INPUT_BUTTON_2);
|
||||||
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index);
|
createBullet(players.at(index)->getPosX() + (players.at(index)->getWidth() / 2) - 4, players.at(index)->getPosY() + (players.at(index)->getHeight() / 2), BULLET_UP, players.at(index)->isPowerUp(), index);
|
||||||
players[index]->setFireCooldown(10);
|
players.at(index)->setFireCooldown(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mDemo.dataFile[mDemo.counter].fireLeft == 1)
|
if (mDemo.dataFile[mDemo.counter].fireLeft == 1)
|
||||||
{
|
{
|
||||||
if (players[index]->canFire())
|
if (players.at(index)->canFire())
|
||||||
{
|
{
|
||||||
players[index]->setInput(INPUT_BUTTON_1);
|
players.at(index)->setInput(INPUT_BUTTON_1);
|
||||||
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index);
|
createBullet(players.at(index)->getPosX() + (players.at(index)->getWidth() / 2) - 4, players.at(index)->getPosY() + (players.at(index)->getHeight() / 2), BULLET_UP, players.at(index)->isPowerUp(), index);
|
||||||
players[index]->setFireCooldown(10);
|
players.at(index)->setFireCooldown(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mDemo.dataFile[mDemo.counter].fireRight == 1)
|
if (mDemo.dataFile[mDemo.counter].fireRight == 1)
|
||||||
{
|
{
|
||||||
if (players[index]->canFire())
|
if (players.at(index)->canFire())
|
||||||
{
|
{
|
||||||
players[index]->setInput(INPUT_BUTTON_3);
|
players.at(index)->setInput(INPUT_BUTTON_3);
|
||||||
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index);
|
createBullet(players.at(index)->getPosX() + (players.at(index)->getWidth() / 2) - 4, players.at(index)->getPosY() + (players.at(index)->getHeight() / 2), BULLET_UP, players.at(index)->isPowerUp(), index);
|
||||||
players[index]->setFireCooldown(10);
|
players.at(index)->setFireCooldown(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -384,7 +384,10 @@ private:
|
|||||||
Uint8 dropItem();
|
Uint8 dropItem();
|
||||||
|
|
||||||
// Crea un objeto item
|
// Crea un objeto item
|
||||||
void createItem(LTexture *texture, SDL_Renderer *renderer, Uint8 type, float x, float y);
|
void createItem(Uint8 type, float x, float y);
|
||||||
|
|
||||||
|
// Vacia el vector de items
|
||||||
|
void freeItems();
|
||||||
|
|
||||||
// Crea un objeto SmartSprite
|
// Crea un objeto SmartSprite
|
||||||
void createItemScoreSprite(int x, int y, SmartSprite *sprite);
|
void createItemScoreSprite(int x, int y, SmartSprite *sprite);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *mAsset
|
|||||||
|
|
||||||
// Reserva memoria para los punteros
|
// Reserva memoria para los punteros
|
||||||
mEventHandler = new SDL_Event();
|
mEventHandler = new SDL_Event();
|
||||||
mItemTexture = new LTexture(mRenderer,mAsset->get("items.png"));
|
mItemTexture = new LTexture(mRenderer, mAsset->get("items.png"));
|
||||||
mSprite = new Sprite(0, 0, GAME_WIDTH, GAME_HEIGHT, mItemTexture, mRenderer);
|
mSprite = new Sprite(0, 0, GAME_WIDTH, GAME_HEIGHT, mItemTexture, mRenderer);
|
||||||
mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer);
|
mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer);
|
||||||
|
|
||||||
@@ -28,26 +28,14 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *mAsset
|
|||||||
// Destructor
|
// Destructor
|
||||||
Instructions::~Instructions()
|
Instructions::~Instructions()
|
||||||
{
|
{
|
||||||
mRenderer = nullptr;
|
|
||||||
mScreen = nullptr;
|
|
||||||
mAsset = nullptr;
|
|
||||||
mLang = nullptr;
|
|
||||||
|
|
||||||
mItemTexture->unload();
|
mItemTexture->unload();
|
||||||
delete mItemTexture;
|
delete mItemTexture;
|
||||||
mItemTexture = nullptr;
|
|
||||||
|
|
||||||
delete mSprite;
|
delete mSprite;
|
||||||
mSprite = nullptr;
|
|
||||||
|
|
||||||
delete mEventHandler;
|
delete mEventHandler;
|
||||||
mEventHandler = nullptr;
|
|
||||||
|
|
||||||
delete mText;
|
delete mText;
|
||||||
mText = nullptr;
|
|
||||||
|
|
||||||
SDL_DestroyTexture(mBackbuffer);
|
SDL_DestroyTexture(mBackbuffer);
|
||||||
mBackbuffer = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa las variables necesarias para la sección 'Instructions'
|
// Inicializa las variables necesarias para la sección 'Instructions'
|
||||||
@@ -87,7 +75,9 @@ void Instructions::run(Uint8 mode)
|
|||||||
mSection.subsection = TITLE_SECTION_1;
|
mSection.subsection = TITLE_SECTION_1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
mManualQuit = true;
|
mManualQuit = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,9 +87,8 @@ void Instructions::run(Uint8 mode)
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
mTicks = SDL_GetTicks();
|
mTicks = SDL_GetTicks();
|
||||||
|
|
||||||
// Modo automático
|
|
||||||
if (mode == INSTRUCTIONS_MODE_AUTO)
|
if (mode == INSTRUCTIONS_MODE_AUTO)
|
||||||
{
|
{ // Modo automático
|
||||||
mCounter++;
|
mCounter++;
|
||||||
|
|
||||||
if (mCounter == INSTRUCTIONS_COUNTER)
|
if (mCounter == INSTRUCTIONS_COUNTER)
|
||||||
@@ -108,9 +97,8 @@ void Instructions::run(Uint8 mode)
|
|||||||
mSection.subsection = TITLE_SECTION_1;
|
mSection.subsection = TITLE_SECTION_1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Modo manual
|
|
||||||
else
|
else
|
||||||
{
|
{ // Modo manual
|
||||||
++mCounter %= 60000;
|
++mCounter %= 60000;
|
||||||
|
|
||||||
if (mManualQuit)
|
if (mManualQuit)
|
||||||
@@ -153,7 +141,9 @@ void Instructions::run(Uint8 mode)
|
|||||||
mText->writeShadowed(84, 156, mLang->getText(21), shdwTxtColor);
|
mText->writeShadowed(84, 156, mLang->getText(21), shdwTxtColor);
|
||||||
|
|
||||||
if ((mode == INSTRUCTIONS_MODE_MANUAL) && (mCounter % 50 > 14))
|
if ((mode == INSTRUCTIONS_MODE_MANUAL) && (mCounter % 50 > 14))
|
||||||
|
{
|
||||||
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, GAME_HEIGHT - 12, mLang->getText(22), 1, orangeColor, 1, shdwTxtColor);
|
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, GAME_HEIGHT - 12, mLang->getText(22), 1, orangeColor, 1, shdwTxtColor);
|
||||||
|
}
|
||||||
|
|
||||||
// Disquito
|
// Disquito
|
||||||
mSprite->setPos(destRect1);
|
mSprite->setPos(destRect1);
|
||||||
@@ -201,9 +191,13 @@ void Instructions::run(Uint8 mode)
|
|||||||
|
|
||||||
// Establece la ventana del backbuffer
|
// Establece la ventana del backbuffer
|
||||||
if (mode == INSTRUCTIONS_MODE_AUTO)
|
if (mode == INSTRUCTIONS_MODE_AUTO)
|
||||||
|
{
|
||||||
window.y = std::max(8, GAME_HEIGHT - mCounter + 100);
|
window.y = std::max(8, GAME_HEIGHT - mCounter + 100);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
window.y = 0;
|
window.y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Copia el backbuffer al renderizador
|
// Copia el backbuffer al renderizador
|
||||||
SDL_RenderCopy(mRenderer, mBackbuffer, nullptr, &window);
|
SDL_RenderCopy(mRenderer, mBackbuffer, nullptr, &window);
|
||||||
|
|||||||
235
source/item.cpp
235
source/item.cpp
@@ -2,120 +2,107 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Item::Item(LTexture *texture, SDL_Renderer *renderer, Uint8 type, float x, float y)
|
Item::Item(SDL_Renderer *renderer, Asset *asset, Uint8 type, float x, float y)
|
||||||
{
|
{
|
||||||
mSprite = new AnimatedSprite(texture, renderer);
|
std::string filePNG;
|
||||||
|
std::string fileANI;
|
||||||
mClass = type;
|
|
||||||
mEnabled = true;
|
|
||||||
mTimeToLive = 600;
|
|
||||||
mPosX = x;
|
|
||||||
mPosY = y;
|
|
||||||
mWidth = 16;
|
|
||||||
mHeight = 16;
|
|
||||||
mVelX = -1.0f + ((rand() % 5) * 0.5f);
|
|
||||||
mVelY = -4.0f;
|
|
||||||
mAccelX = 0.0f;
|
|
||||||
mAccelY = 0.2f;
|
|
||||||
mFloorCollision = false;
|
|
||||||
mCollider.r = mWidth / 2;
|
|
||||||
shiftColliders();
|
|
||||||
|
|
||||||
mSprite->setAnimationFrames(0, 0, 0, 48, mWidth, mHeight);
|
|
||||||
mSprite->setAnimationFrames(0, 1, 0, 64, mWidth, mHeight);
|
|
||||||
mSprite->setCurrentFrame(0);
|
|
||||||
mSprite->setAnimationCounter(0);
|
|
||||||
mSprite->setAnimationSpeed(0, 10);
|
|
||||||
mSprite->setAnimationLoop(0, true);
|
|
||||||
mSprite->setSpriteClip(mSprite->getAnimationClip(0, 0));
|
|
||||||
mSprite->setPosX(mPosX);
|
|
||||||
mSprite->setPosY(mPosY);
|
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case NO_KIND:
|
|
||||||
mEnabled = false;
|
|
||||||
mTimeToLive = 0;
|
|
||||||
mPosX = 0;
|
|
||||||
mPosY = 0;
|
|
||||||
mWidth = 0;
|
|
||||||
mHeight = 0;
|
|
||||||
mVelX = 0;
|
|
||||||
mVelY = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ITEM_POINTS_1_DISK:
|
case ITEM_POINTS_1_DISK:
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 0, 16 * 0, mWidth, mHeight);
|
filePNG = asset->get("item_points1_disk.png");
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 0, 16 * 1, mWidth, mHeight);
|
fileANI = asset->get("item_points1_disk.ani");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_POINTS_2_GAVINA:
|
case ITEM_POINTS_2_GAVINA:
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 1, 16 * 0, mWidth, mHeight);
|
filePNG = asset->get("item_points2_gavina.png");
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 1, 16 * 1, mWidth, mHeight);
|
fileANI = asset->get("item_points2_gavina.ani");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_POINTS_3_PACMAR:
|
case ITEM_POINTS_3_PACMAR:
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 2, 16 * 0, mWidth, mHeight);
|
filePNG = asset->get("item_points3_pacmar.png");
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 2, 16 * 1, mWidth, mHeight);
|
fileANI = asset->get("item_points3_pacmar.ani");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_CLOCK:
|
case ITEM_CLOCK:
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 3, 16 * 0, mWidth, mHeight);
|
filePNG = asset->get("item_clock.png");
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 3, 16 * 1, mWidth, mHeight);
|
fileANI = asset->get("item_clock.ani");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_COFFEE:
|
case ITEM_COFFEE:
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 5, 16 * 0, mWidth, mHeight);
|
filePNG = asset->get("item_coffee.png");
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 5, 16 * 1, mWidth, mHeight);
|
fileANI = asset->get("item_coffee.ani");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_COFFEE_MACHINE:
|
case ITEM_COFFEE_MACHINE:
|
||||||
mWidth = 32;
|
filePNG = asset->get("item_coffee_machine.png");
|
||||||
mHeight = 32;
|
fileANI = asset->get("item_coffee_machine.ani");
|
||||||
mPosX = (((int)x + (PLAY_AREA_WIDTH / 2)) % (PLAY_AREA_WIDTH - mWidth - 5)) + 2;
|
|
||||||
mPosY = PLAY_AREA_TOP - mHeight;
|
|
||||||
mVelX = 0.0f;
|
|
||||||
mVelY = -0.1f;
|
|
||||||
mAccelY = 0.1f;
|
|
||||||
mSprite->setAnimationFrames(0, 0, 32 * 0, 16 * 2, mWidth, mHeight);
|
|
||||||
mSprite->setAnimationFrames(0, 1, 32 * 1, 16 * 2, mWidth, mHeight);
|
|
||||||
mSprite->setAnimationFrames(0, 2, 32 * 2, 16 * 2, mWidth, mHeight);
|
|
||||||
mSprite->setAnimationFrames(0, 3, 32 * 3, 16 * 2, mWidth, mHeight);
|
|
||||||
mSprite->setPosX(mPosX);
|
|
||||||
mSprite->setPosY(mPosY);
|
|
||||||
mCollider.r = 10;
|
|
||||||
shiftColliders();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
texture = new LTexture(renderer, filePNG);
|
||||||
|
sprite = new AnimatedSprite(texture, renderer, fileANI);
|
||||||
|
|
||||||
|
this->type = type;
|
||||||
|
enabled = true;
|
||||||
|
timeToLive = 600;
|
||||||
|
accelX = 0.0f;
|
||||||
|
floorCollision = false;
|
||||||
|
|
||||||
|
if (type == ITEM_COFFEE_MACHINE)
|
||||||
|
{
|
||||||
|
width = 32;
|
||||||
|
height = 32;
|
||||||
|
posX = (((int)x + (PLAY_AREA_WIDTH / 2)) % (PLAY_AREA_WIDTH - width - 5)) + 2;
|
||||||
|
posY = PLAY_AREA_TOP - height;
|
||||||
|
velX = 0.0f;
|
||||||
|
velY = -0.1f;
|
||||||
|
accelY = 0.1f;
|
||||||
|
collider.r = 10;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
width = 16;
|
||||||
|
height = 16;
|
||||||
|
posX = x;
|
||||||
|
posY = y;
|
||||||
|
velX = -1.0f + ((rand() % 5) * 0.5f);
|
||||||
|
velY = -4.0f;
|
||||||
|
accelY = 0.2f;
|
||||||
|
collider.r = width / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprite->setPosX(posX);
|
||||||
|
sprite->setPosY(posY);
|
||||||
|
shiftColliders();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Item::~Item()
|
Item::~Item()
|
||||||
{
|
{
|
||||||
delete mSprite;
|
delete texture;
|
||||||
mSprite = nullptr;
|
delete sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Centra el objeto en la posición X
|
// Centra el objeto en la posición X
|
||||||
void Item::allignTo(int x)
|
void Item::allignTo(int x)
|
||||||
{
|
{
|
||||||
mPosX = float(x - (mWidth / 2));
|
posX = float(x - (width / 2));
|
||||||
|
|
||||||
if (mPosX < PLAY_AREA_LEFT)
|
if (posX < PLAY_AREA_LEFT)
|
||||||
{
|
{
|
||||||
mPosX = PLAY_AREA_LEFT + 1;
|
posX = PLAY_AREA_LEFT + 1;
|
||||||
}
|
}
|
||||||
else if ((mPosX + mWidth) > PLAY_AREA_RIGHT)
|
else if ((posX + width) > PLAY_AREA_RIGHT)
|
||||||
{
|
{
|
||||||
mPosX = float(PLAY_AREA_RIGHT - mWidth - 1);
|
posX = float(PLAY_AREA_RIGHT - width - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Posición X,Y del sprite
|
// Posición X,Y del sprite
|
||||||
mSprite->setPosX(int(mPosX));
|
sprite->setPosX(int(posX));
|
||||||
mSprite->setPosY(int(mPosY));
|
sprite->setPosY(int(posY));
|
||||||
|
|
||||||
// Alinea el circulo de colisión con el objeto
|
// Alinea el circulo de colisión con el objeto
|
||||||
shiftColliders();
|
shiftColliders();
|
||||||
@@ -124,15 +111,15 @@ void Item::allignTo(int x)
|
|||||||
// Pinta el objeto en la pantalla
|
// Pinta el objeto en la pantalla
|
||||||
void Item::render()
|
void Item::render()
|
||||||
{
|
{
|
||||||
if (mEnabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
if (mTimeToLive > 200)
|
if (timeToLive > 200)
|
||||||
{
|
{
|
||||||
mSprite->render();
|
sprite->render();
|
||||||
}
|
}
|
||||||
else if (mTimeToLive % 20 > 10)
|
else if (timeToLive % 20 > 10)
|
||||||
{
|
{
|
||||||
mSprite->render();
|
sprite->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,71 +127,73 @@ void Item::render()
|
|||||||
// Actualiza la posición y estados del objeto
|
// Actualiza la posición y estados del objeto
|
||||||
void Item::move()
|
void Item::move()
|
||||||
{
|
{
|
||||||
mFloorCollision = false;
|
floorCollision = false;
|
||||||
|
|
||||||
// Calcula la nueva posición
|
// Calcula la nueva posición
|
||||||
mPosX += mVelX;
|
posX += velX;
|
||||||
mPosY += mVelY;
|
posY += velY;
|
||||||
|
|
||||||
// Aplica las aceleraciones a la velocidad
|
// Aplica las aceleraciones a la velocidad
|
||||||
mVelX += mAccelX;
|
velX += accelX;
|
||||||
mVelY += mAccelY;
|
velY += accelY;
|
||||||
|
|
||||||
// Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido
|
// Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido
|
||||||
if ((mPosX < PLAY_AREA_LEFT) || (mPosX + mWidth > PLAY_AREA_RIGHT))
|
if ((posX < PLAY_AREA_LEFT) || (posX + width > PLAY_AREA_RIGHT))
|
||||||
{
|
{
|
||||||
// Corregir posición
|
// Corregir posición
|
||||||
mPosX -= mVelX;
|
posX -= velX;
|
||||||
|
|
||||||
// Invertir sentido
|
// Invertir sentido
|
||||||
mVelX = -mVelX;
|
velX = -velX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si se sale por arriba rebota (excepto la maquina de café)
|
// Si se sale por arriba rebota (excepto la maquina de café)
|
||||||
if ((mPosY < PLAY_AREA_TOP) && !(mClass == ITEM_COFFEE_MACHINE))
|
if ((posY < PLAY_AREA_TOP) && !(type == ITEM_COFFEE_MACHINE))
|
||||||
{
|
{
|
||||||
// Corrige
|
// Corrige
|
||||||
mPosY = PLAY_AREA_TOP;
|
posY = PLAY_AREA_TOP;
|
||||||
|
|
||||||
// Invierte el sentido
|
// Invierte el sentido
|
||||||
mVelY = -mVelY;
|
velY = -velY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si el objeto se sale por la parte inferior
|
// Si el objeto se sale por la parte inferior
|
||||||
if (mPosY + mHeight > PLAY_AREA_BOTTOM)
|
if (posY + height > PLAY_AREA_BOTTOM)
|
||||||
{
|
{
|
||||||
// Corrige
|
// Corrige
|
||||||
mPosY -= mVelY;
|
posY -= velY;
|
||||||
|
|
||||||
// Detiene el objeto
|
// Detiene el objeto
|
||||||
mVelY = 0;
|
velY = 0;
|
||||||
mVelX = 0;
|
velX = 0;
|
||||||
mAccelX = 0;
|
accelX = 0;
|
||||||
mAccelY = 0;
|
accelY = 0;
|
||||||
mPosY = PLAY_AREA_BOTTOM - mHeight;
|
posY = PLAY_AREA_BOTTOM - height;
|
||||||
if (mClass == ITEM_COFFEE_MACHINE)
|
if (type == ITEM_COFFEE_MACHINE)
|
||||||
mFloorCollision = true;
|
{
|
||||||
|
floorCollision = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la posición del sprite
|
// Actualiza la posición del sprite
|
||||||
mSprite->setPosX(int(mPosX));
|
sprite->setPosX(int(posX));
|
||||||
mSprite->setPosY(int(mPosY));
|
sprite->setPosY(int(posY));
|
||||||
|
shiftColliders();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pone a cero todos los valores del objeto
|
// Pone a cero todos los valores del objeto
|
||||||
void Item::erase()
|
void Item::disable()
|
||||||
{
|
{
|
||||||
// init(NO_KIND, 0, 0, nullptr, nullptr);
|
enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el objeto a su posicion, animación y controla los contadores
|
// Actualiza el objeto a su posicion, animación y controla los contadores
|
||||||
void Item::update()
|
void Item::update()
|
||||||
{
|
{
|
||||||
if (mEnabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
move();
|
move();
|
||||||
shiftColliders();
|
sprite->animate();
|
||||||
mSprite->animate();
|
|
||||||
updateTimeToLive();
|
updateTimeToLive();
|
||||||
checkTimeToLive();
|
checkTimeToLive();
|
||||||
}
|
}
|
||||||
@@ -213,76 +202,70 @@ void Item::update()
|
|||||||
// Actualiza el contador
|
// Actualiza el contador
|
||||||
void Item::updateTimeToLive()
|
void Item::updateTimeToLive()
|
||||||
{
|
{
|
||||||
if (mTimeToLive > 0)
|
if (timeToLive > 0)
|
||||||
{
|
{
|
||||||
mTimeToLive--;
|
timeToLive--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si el objeto sigue vivo
|
// Comprueba si el objeto sigue vivo
|
||||||
void Item::checkTimeToLive()
|
void Item::checkTimeToLive()
|
||||||
{
|
{
|
||||||
if (mTimeToLive == 0)
|
if (timeToLive == 0)
|
||||||
erase();
|
disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
float Item::getPosX()
|
float Item::getPosX()
|
||||||
{
|
{
|
||||||
return mPosX;
|
return posX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
float Item::getPosY()
|
float Item::getPosY()
|
||||||
{
|
{
|
||||||
return mPosY;
|
return posY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int Item::getWidth()
|
int Item::getWidth()
|
||||||
{
|
{
|
||||||
return mWidth;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int Item::getHeight()
|
int Item::getHeight()
|
||||||
{
|
{
|
||||||
return mHeight;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int Item::getClass()
|
int Item::getClass()
|
||||||
{
|
{
|
||||||
return mClass;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
bool Item::isEnabled()
|
bool Item::isEnabled()
|
||||||
{
|
{
|
||||||
return mEnabled;
|
return enabled;
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void Item::setEnabled(bool value)
|
|
||||||
{
|
|
||||||
mEnabled = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
circle_t &Item::getCollider()
|
circle_t &Item::getCollider()
|
||||||
{
|
{
|
||||||
return mCollider;
|
return collider;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alinea el circulo de colisión con la posición del objeto
|
// Alinea el circulo de colisión con la posición del objeto
|
||||||
void Item::shiftColliders()
|
void Item::shiftColliders()
|
||||||
{
|
{
|
||||||
mCollider.x = int(mPosX + (mWidth / 2));
|
collider.x = int(posX + (width / 2));
|
||||||
mCollider.y = int(mPosY + (mHeight / 2));
|
collider.y = int(posY + (height / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Informa si el objeto ha colisionado con el suelo
|
// Informa si el objeto ha colisionado con el suelo
|
||||||
bool Item::floorCollision()
|
bool Item::isOnFloor()
|
||||||
{
|
{
|
||||||
return mFloorCollision;
|
return floorCollision;
|
||||||
}
|
}
|
||||||
@@ -20,30 +20,35 @@
|
|||||||
class Item
|
class Item
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
float mPosX; // Posición X del objeto
|
// Objetos
|
||||||
float mPosY; // Posición Y del objeto
|
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
Uint8 mWidth; // Ancho del objeto
|
AnimatedSprite *sprite; // Sprite con los graficos del objeto
|
||||||
Uint8 mHeight; // Alto del objeto
|
LTexture *texture; // Objeto con los graficos del item
|
||||||
float mVelX; // Velocidad en el eje X
|
|
||||||
float mVelY; // Velocidad en el eje Y
|
|
||||||
float mAccelX; // Aceleración en el eje X
|
|
||||||
float mAccelY; // Aceleración en el eje Y
|
|
||||||
bool mFloorCollision; // Indica si el objeto colisiona con el suelo
|
|
||||||
|
|
||||||
AnimatedSprite *mSprite; // Sprite con los graficos del objeto
|
// Variables
|
||||||
|
float posX; // Posición X del objeto
|
||||||
Uint8 mClass; // Especifica el tipo de objeto que es
|
float posY; // Posición Y del objeto
|
||||||
bool mEnabled; // Especifica si el objeto está habilitado
|
Uint8 width; // Ancho del objeto
|
||||||
circle_t mCollider; // Circulo de colisión del objeto
|
Uint8 height; // Alto del objeto
|
||||||
|
float velX; // Velocidad en el eje X
|
||||||
|
float velY; // Velocidad en el eje Y
|
||||||
|
float accelX; // Aceleración en el eje X
|
||||||
|
float accelY; // Aceleración en el eje Y
|
||||||
|
bool floorCollision; // Indica si el objeto colisiona con el suelo
|
||||||
|
Uint8 type; // Especifica el tipo de objeto que es
|
||||||
|
bool enabled; // Especifica si el objeto está habilitado
|
||||||
|
circle_t collider; // Circulo de colisión del objeto
|
||||||
|
|
||||||
// Alinea el circulo de colisión con la posición del objeto
|
// Alinea el circulo de colisión con la posición del objeto
|
||||||
void shiftColliders();
|
void shiftColliders();
|
||||||
|
|
||||||
|
// Actualiza la posición y estados del objeto
|
||||||
|
void move();
|
||||||
public:
|
public:
|
||||||
Uint16 mTimeToLive; // Temporizador con el tiempo que el objeto está presente
|
Uint16 timeToLive; // Temporizador con el tiempo que el objeto está presente
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Item(LTexture *texture, SDL_Renderer *renderer, Uint8 type, float x, float y);
|
Item(SDL_Renderer *renderer, Asset *asset, Uint8 type, float x, float y);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Item();
|
~Item();
|
||||||
@@ -54,11 +59,9 @@ public:
|
|||||||
// Pinta el objeto en la pantalla
|
// Pinta el objeto en la pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Actualiza la posición y estados del objeto
|
|
||||||
void move();
|
|
||||||
|
|
||||||
// Pone a cero todos los valores del objeto
|
// Pone a cero todos los valores del objeto
|
||||||
void erase();
|
void disable();
|
||||||
|
|
||||||
// Actualiza al objeto a su posicion, animación y controla los contadores
|
// Actualiza al objeto a su posicion, animación y controla los contadores
|
||||||
void update();
|
void update();
|
||||||
@@ -87,14 +90,11 @@ public:
|
|||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
bool isEnabled();
|
bool isEnabled();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setEnabled(bool value);
|
|
||||||
|
|
||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
circle_t &getCollider();
|
circle_t &getCollider();
|
||||||
|
|
||||||
// Informa si el objeto ha colisionado con el suelo
|
// Informa si el objeto ha colisionado con el suelo
|
||||||
bool floorCollision();
|
bool isOnFloor();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user