Trabajando en la sección de juego y el jugador

This commit is contained in:
2022-10-02 20:23:06 +02:00
parent b6225d2d2f
commit 4ac7496eff
10 changed files with 202 additions and 387 deletions

View File

@@ -3,84 +3,84 @@ frameHeight=24
[animation]
name=walk
speed=8
speed=5
loop=0
frames=0,1,2,3
[/animation]
[animation]
name=stand
speed=8
speed=10
loop=0
frames=4,5,6,7
[/animation]
[animation]
name=walk_1C
speed=8
speed=5
loop=0
frames=8,9,10,11
[/animation]
[animation]
name=stand_1C
speed=8
speed=10
loop=0
frames=12,13,14,15
[/animation]
[animation]
name=walk_2C
speed=8
speed=5
loop=0
frames=16,17,18,19
[/animation]
[animation]
name=stand_2C
speed=8
speed=10
loop=0
frames=20,21,22,23
[/animation]
[animation]
name=walk_shoot
speed=8
name=sideshoot
speed=5
loop=0
frames=24,25,26,27
[/animation]
[animation]
name=stand_shoot
speed=8
name=centershoot
speed=10
loop=0
frames=28,29,30,31
[/animation]
[animation]
name=walk_shoot_1C
speed=8
name=sideshoot_1C
speed=5
loop=0
frames=32,33,34,35
[/animation]
[animation]
name=stand_shoot_1C
speed=8
name=centershoot_1C
speed=10
loop=0
frames=36,37,38,39
[/animation]
[animation]
name=walk_shoot_2C
speed=8
name=sideshoot_2C
speed=5
loop=0
frames=40,41,42,43
[/animation]
[animation]
name=stand_shoot_2C
speed=8
name=centershoot_2C
speed=10
loop=0
frames=44,45,46,47
[/animation]

View File

@@ -3,7 +3,7 @@ frameHeight=24
[animation]
name=default
speed=8
speed=5
loop=0
frames=0,1,2,3
[/animation]

View File

@@ -3,112 +3,112 @@ frameHeight=24
[animation]
name=walk
speed=8
speed=5
loop=0
frames=0,1,2,3
[/animation]
[animation]
name=stand
speed=8
speed=10
loop=0
frames=4,5,6,7
[/animation]
[animation]
name=walk_1C
speed=8
speed=5
loop=0
frames=8,9,10,11
[/animation]
[animation]
name=stand_1C
speed=8
speed=10
loop=0
frames=12,13,14,15
[/animation]
[animation]
name=walk_pwr
speed=8
speed=5
loop=0
frames=16,17,18,19
[/animation]
[animation]
name=stand_pwr
speed=8
speed=10
loop=0
frames=20,21,22,23
[/animation]
[animation]
name=walk_1C_pwr
speed=8
speed=5
loop=0
frames=24,25,26,27
[/animation]
[animation]
name=stand_1C_pwr
speed=8
speed=10
loop=0
frames=28,29,30,31
[/animation]
[animation]
name=walk_shoot
speed=8
name=sideshoot
speed=5
loop=0
frames=32,33,34,35
[/animation]
[animation]
name=stand_shoot
speed=8
name=centershoot
speed=10
loop=0
frames=36,37,38,39
[/animation]
[animation]
name=walk_shoot_1C
speed=8
name=sideshoot_1C
speed=5
loop=0
frames=40,41,42,43
[/animation]
[animation]
name=stand_shoot_1C
speed=8
name=centershoot_1C
speed=10
loop=0
frames=44,45,46,47
[/animation]
[animation]
name=walk_shoot_pwr
speed=8
name=sideshoot_pwr
speed=5
loop=0
frames=48,49,50,51
[/animation]
[animation]
name=stand_shoot_pwr
speed=8
name=centershoot_pwr
speed=10
loop=0
frames=52,53,54,55
[/animation]
[animation]
name=walk_shoot_1C_pwr
speed=8
name=sideshoot_1C_pwr
speed=5
loop=0
frames=56,57,58,59
[/animation]
[animation]
name=stand_shoot_1C_pwr
speed=8
name=centershoot_1C_pwr
speed=10
loop=0
frames=60,61,62,63
[/animation]

View File

@@ -3,14 +3,14 @@ frameHeight=24
[animation]
name=walk
speed=8
speed=5
loop=0
frames=0,1,2,3
[/animation]
[animation]
name=stand
speed=8
speed=10
loop=0
frames=4,5,6,7
[/animation]

30
data/menu/gameover.men Normal file
View File

@@ -0,0 +1,30 @@
font_png=smb2.png
font_txt=smb2.txt
sound_cancel=menu_cancel.wav
sound_accept=menu_select.wav
sound_move=menu_move.wav
name=GAME OVER
x=0
y=112
backgroundType=0
backgroundColor=0,0,0,255
areElementsCenteredOnX=true
isCenteredOnX=true
centerX=128
selector_color=84,110,122,0
selector_text_color=255,122,0
defaultActionWhenCancel=1
[item]
text=SI
hPaddingDown=2
[/item]
[item]
text=NO
[/item]

30
data/menu/pause.men Normal file
View File

@@ -0,0 +1,30 @@
font_png=smb2.png
font_txt=smb2.txt
sound_cancel=menu_cancel.wav
sound_accept=menu_select.wav
sound_move=menu_move.wav
name=PAUSE
x=0
y=96
backgroundType=1
backgroundColor=41,57,65,240
areElementsCenteredOnX=true
isCenteredOnX=true
centerX=128
selector_color=255,122,0,255
selector_text_color=255,255,255
defaultActionWhenCancel=0
[item]
text=SI
hPaddingDown=2
[/item]
[item]
text=NO
[/item]

View File

@@ -9,8 +9,8 @@ Director::Director(std::string path)
{
// Inicializa variables
section.name = PROG_SECTION_TITLE;
section.subsection = TITLE_SECTION_1;
section.name = PROG_SECTION_GAME;
section.subsection = GAME_SECTION_PLAY_1P;
// Crea el objeto que controla los ficheros de recursos
asset = new Asset(path.substr(0, path.find_last_of("\\/")) + "/../");
@@ -240,6 +240,8 @@ bool Director::setFileList()
// Menus
asset->add("data/menu/title.men", t_data);
asset->add("data/menu/options.men", t_data);
asset->add("data/menu/pause.men", t_data);
asset->add("data/menu/gameover.men", t_data);
return asset->check();
}

View File

@@ -51,8 +51,8 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
mTextNokia2 = new Text(mAsset->get("nokia2.png"), mAsset->get("nokia2.txt"), mRenderer);
mTextNokiaBig2 = new Text(mAsset->get("nokia_big2.png"), mAsset->get("nokia_big2.txt"), mRenderer);
mMenuGameOver = new Menu(mRenderer, mAsset, mInput);
mMenuPause = new Menu(mRenderer, mAsset, mInput);
mMenuGameOver = new Menu(mRenderer, mAsset, mInput, mAsset->get("gameover.men"));
mMenuPause = new Menu(mRenderer, mAsset, mInput, mAsset->get("pause.men"));
mFade = new Fade(mRenderer);
mEventHandler = new SDL_Event();
@@ -337,33 +337,33 @@ void Game::init()
mFade->init(0x27, 0x27, 0x36);
// Inicializa el objeto con el menu de pausa
mMenuPause->setName("PAUSE");
mMenuPause->setPos(0, 12 * BLOCK);
mMenuPause->setBackgroundType(MENU_BACKGROUND_SOLID);
mMenuPause->addItem(mLang->getText(46), 2);
mMenuPause->addItem(mLang->getText(47), 0);
mMenuPause->setDefaultActionWhenCancel(0);
mMenuPause->setBackgroundColor({0x29, 0x39, 0x41}, 240);
mMenuPause->setSelectorColor({0xFF, 0x7A, 0x00}, 255);
mMenuPause->setSelectorTextColor({0xFF, 0xFF, 0xFF});
mMenuPause->centerMenuOnX(SCREEN_CENTER_X);
mMenuPause->centerMenuElementsOnX();
//mMenuPause->setName("PAUSE");
//mMenuPause->setPos(0, 12 * BLOCK);
//mMenuPause->setBackgroundType(MENU_BACKGROUND_SOLID);
//mMenuPause->addItem(mLang->getText(46), 2);
//mMenuPause->addItem(mLang->getText(47), 0);
//mMenuPause->setDefaultActionWhenCancel(0);
//mMenuPause->setBackgroundColor({0x29, 0x39, 0x41}, 240);
//mMenuPause->setSelectorColor({0xFF, 0x7A, 0x00}, 255);
//mMenuPause->setSelectorTextColor({0xFF, 0xFF, 0xFF});
//mMenuPause->centerMenuOnX(SCREEN_CENTER_X);
//mMenuPause->centerMenuElementsOnX();
// Inicializa el objeto con el menu de la pantalla de game over
mMenuGameOver->setName("GAME OVER");
mMenuGameOver->setPos(0, PLAY_AREA_CENTER_Y + BLOCK * 4);
mMenuGameOver->setBackgroundType(MENU_BACKGROUND_TRANSPARENT);
mMenuGameOver->addItem(mLang->getText(48), 2);
mMenuGameOver->addItem(mLang->getText(49));
mMenuGameOver->setDefaultActionWhenCancel(1);
mMenuGameOver->setBackgroundColor({0, 0, 0}, 255);
mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 255);
mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 0);
mMenuGameOver->setSelectorTextColor({0xFF, 0xFF, 0xFF});
mMenuGameOver->setSelectorTextColor({0xFF, 0xF1, 0x76});
mMenuGameOver->setSelectorTextColor({0xFF, 0x7A, 0x00});
mMenuGameOver->centerMenuOnX(SCREEN_CENTER_X);
mMenuGameOver->centerMenuElementsOnX();
//mMenuGameOver->setName("GAME OVER");
//mMenuGameOver->setPos(0, PLAY_AREA_CENTER_Y + BLOCK * 4);
//mMenuGameOver->setBackgroundType(MENU_BACKGROUND_TRANSPARENT);
//mMenuGameOver->addItem(mLang->getText(48), 2);
//mMenuGameOver->addItem(mLang->getText(49));
//mMenuGameOver->setDefaultActionWhenCancel(1);
//mMenuGameOver->setBackgroundColor({0, 0, 0}, 255);
//mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 255);
//mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 0);
//mMenuGameOver->setSelectorTextColor({0xFF, 0xFF, 0xFF});
//mMenuGameOver->setSelectorTextColor({0xFF, 0xF1, 0x76});
//mMenuGameOver->setSelectorTextColor({0xFF, 0x7A, 0x00});
//mMenuGameOver->centerMenuOnX(SCREEN_CENTER_X);
//mMenuGameOver->centerMenuElementsOnX();
// Sprites
mClouds1a->setSpriteClip(256, 0, 256, 52);
@@ -1756,9 +1756,9 @@ void Game::renderBalloons()
// Crea un globo nuevo en el vector de globos
Uint8 Game::createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture)
{
Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, texture, mRenderer);
balloons.push_back(b);
return (Uint8)(balloons.size() - 1);
//Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, texture, mRenderer);
//balloons.push_back(b);
//return (Uint8)(balloons.size() - 1);
}
// Crea una PowerBall

View File

@@ -9,10 +9,10 @@ Player::Player(SDL_Renderer *renderer, Asset *asset, float x, int y)
this->asset = asset;
// Reserva memoria para los objetos
legsTexture = new LTexture(renderer, asset->get("new_player_legs.png"));
bodyTexture = new LTexture(renderer, asset->get("new_player_body.png"));
headTexture = new LTexture(renderer, asset->get("new_player_head.png"));
deathTexture = new LTexture(renderer, asset->get("new_player_death.png"));
legsTexture = new LTexture(renderer, asset->get("new_player1_legs.png"));
bodyTexture = new LTexture(renderer, asset->get("new_player1_body.png"));
headTexture = new LTexture(renderer, asset->get("new_player1_head.png"));
deathTexture = new LTexture(renderer, asset->get("new_player1_death.png"));
legsSprite = new AnimatedSprite(legsTexture, renderer, asset->get("new_player1_legs.ani"));
bodySprite = new AnimatedSprite(bodyTexture, renderer, asset->get("new_player1_body.ani"));
headSprite = new AnimatedSprite(headTexture, renderer, asset->get("new_player1_head.ani"));
@@ -57,17 +57,16 @@ void Player::init()
invulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
powerUp = false;
powerUpCounter = PLAYER_POWERUP_COUNTER;
powerUpHeadOffset = 0;
extraHit = false;
coffees = 0;
input = true;
// Establece la altura y el ancho del jugador
width = 3 * BLOCK;
height = 3 * BLOCK;
width = 24;
height = 24;
// Establece el tamaño del circulo de colisión
mCollider.r = 7;
collider.r = 7;
// Actualiza la posición del circulo de colisión
shiftColliders();
@@ -88,154 +87,20 @@ void Player::init()
// Inicia el contador para la cadencia de disparo
cooldown = 10;
// Establece el alto y ancho del sprite
legsSprite->setWidth(width);
legsSprite->setHeight(height);
bodySprite->setWidth(width);
bodySprite->setHeight(height);
headSprite->setWidth(width);
headSprite->setHeight(height);
// Establece la posición del sprite
legsSprite->setPosX(int(posX));
legsSprite->setPosX(posX);
legsSprite->setPosY(posY);
bodySprite->setPosX(int(posX));
bodySprite->setPosX(posX);
bodySprite->setPosY(posY);
headSprite->setPosX(int(posX));
headSprite->setPosX(posX);
headSprite->setPosY(posY);
// Inicializa las variables para la animación
legsSprite->setCurrentFrame(0);
legsSprite->setAnimationCounter(0);
bodySprite->setCurrentFrame(0);
bodySprite->setAnimationCounter(0);
headSprite->setCurrentFrame(0);
headSprite->setAnimationCounter(0);
// Establece la velocidad de cada animación
legsSprite->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_STOP, 10);
legsSprite->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 5);
legsSprite->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 5);
bodySprite->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_LEFT, 5);
bodySprite->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_LEFT, 5);
bodySprite->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 5);
bodySprite->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 5);
bodySprite->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_STOP, 10);
bodySprite->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_UP, 5);
headSprite->setAnimationSpeed(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 5);
headSprite->setAnimationSpeed(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 5);
headSprite->setAnimationSpeed(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 5);
headSprite->setAnimationSpeed(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 5);
headSprite->setAnimationSpeed(PLAYER_ANIMATION_HEAD_WALKING_STOP, 10);
headSprite->setAnimationSpeed(PLAYER_ANIMATION_HEAD_FIRING_UP, 5);
// Establece si la animación se reproduce en bucle
legsSprite->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_STOP, true);
legsSprite->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_LEFT, true);
legsSprite->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, true);
bodySprite->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_LEFT, true);
bodySprite->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_LEFT, true);
bodySprite->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_RIGHT, true);
bodySprite->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_RIGHT, true);
bodySprite->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_STOP, true);
bodySprite->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_UP, true);
headSprite->setAnimationLoop(PLAYER_ANIMATION_HEAD_WALKING_LEFT, true);
headSprite->setAnimationLoop(PLAYER_ANIMATION_HEAD_FIRING_LEFT, true);
headSprite->setAnimationLoop(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, true);
headSprite->setAnimationLoop(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, true);
headSprite->setAnimationLoop(PLAYER_ANIMATION_HEAD_WALKING_STOP, true);
headSprite->setAnimationLoop(PLAYER_ANIMATION_HEAD_FIRING_UP, true);
// Establece los frames de cada animación
legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 0, width * 0, height * 0, width, height);
legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 1, width * 1, height * 0, width, height);
legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 2, width * 2, height * 0, width, height);
legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 3, width * 3, height * 0, width, height);
legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 0, width * 0, height * 1, width, height);
legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 1, width * 1, height * 1, width, height);
legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 2, width * 2, height * 1, width, height);
legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 3, width * 3, height * 1, width, height);
legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 0, width * 0, height * 2, width, height);
legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 1, width * 1, height * 2, width, height);
legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 2, width * 2, height * 2, width, height);
legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 3, width * 3, height * 2, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 0, width * 0, height * 0, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 1, width * 1, height * 0, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 2, width * 2, height * 0, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 3, width * 3, height * 0, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 0, width * 0, height * 1, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 1, width * 1, height * 1, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 2, width * 2, height * 1, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 3, width * 3, height * 1, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 0, width * 0, height * 2, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 1, width * 1, height * 2, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 2, width * 2, height * 2, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 3, width * 3, height * 2, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 0, width * 0, height * 3, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 1, width * 1, height * 3, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 2, width * 2, height * 3, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 3, width * 3, height * 3, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 0, width * 0, height * 4, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 1, width * 1, height * 4, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 2, width * 2, height * 4, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 3, width * 3, height * 4, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 0, width * 0, height * 5, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 1, width * 1, height * 5, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 2, width * 2, height * 5, width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 3, width * 3, height * 5, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 0, width * 0, height * 0, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 1, width * 1, height * 0, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 2, width * 2, height * 0, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 3, width * 3, height * 0, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 0, width * 0, height * 1, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 1, width * 1, height * 1, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 2, width * 2, height * 1, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 3, width * 3, height * 1, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 0, width * 0, height * 2, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 1, width * 1, height * 2, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 2, width * 2, height * 2, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 3, width * 3, height * 2, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 0, width * 0, height * 3, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 1, width * 1, height * 3, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 2, width * 2, height * 3, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 3, width * 3, height * 3, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 0, width * 0, height * 4, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 1, width * 1, height * 4, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 2, width * 2, height * 4, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 3, width * 3, height * 4, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 0, width * 0, height * 5, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 1, width * 1, height * 5, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 2, width * 2, height * 5, width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 3, width * 3, height * 5, width, height);
// Selecciona un frame para pintar
legsSprite->setSpriteClip(legsSprite->getAnimationClip(PLAYER_ANIMATION_LEGS_WALKING_STOP, 0));
bodySprite->setSpriteClip(bodySprite->getAnimationClip(PLAYER_ANIMATION_BODY_WALKING_STOP, 0));
headSprite->setSpriteClip(headSprite->getAnimationClip(PLAYER_ANIMATION_HEAD_WALKING_STOP, 0));
legsSprite->setCurrentAnimation("stand");
bodySprite->setCurrentAnimation("stand");
headSprite->setCurrentAnimation("stand");
}
// Actua en consecuencia de la entrada recibida
@@ -326,7 +191,7 @@ void Player::setWalkingStatus(Uint8 status)
if (statusWalking != status)
{
statusWalking = status;
legsSprite->setCurrentFrame(0);
// legsSprite->setCurrentFrame(0);
}
}
@@ -337,169 +202,52 @@ void Player::setFiringStatus(Uint8 status)
if (statusFiring != status)
{
statusFiring = status;
bodySprite->setCurrentFrame(0);
headSprite->setCurrentFrame(0);
// bodySprite->setCurrentFrame(0);
// headSprite->setCurrentFrame(0);
}
}
// Establece la animación correspondiente al estado
void Player::setAnimation()
{
// Actualiza los frames de la animación en función del número de cafes
for (int i = 0; i < 4; i++)
// Crea cadenas de texto para componer el nombre de la animación
std::string aBodyCoffees = "";
std::string aHeadCoffees = "";
if (coffees > 0)
{
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, i, width * i, height * (0 + (6 * coffees)), width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, i, width * i, height * (1 + (6 * coffees)), width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, i, width * i, height * (2 + (6 * coffees)), width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, i, width * i, height * (3 + (6 * coffees)), width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, i, width * i, height * (4 + (6 * coffees)), width, height);
bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, i, width * i, height * (5 + (6 * coffees)), width, height);
aBodyCoffees = coffees == 1 ? "_1C" : "_2C";
aHeadCoffees = "_1C";
}
// Actualiza los frames de la animación en función de si se tiene el PowerUp
for (int i = 0; i < 4; i++)
{
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, i, (width * i) + powerUpHeadOffset, height * (0 + (6 * coffees)), width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, i, (width * i) + powerUpHeadOffset, height * (1 + (6 * coffees)), width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, i, (width * i) + powerUpHeadOffset, height * (2 + (6 * coffees)), width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, i, (width * i) + powerUpHeadOffset, height * (3 + (6 * coffees)), width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, i, (width * i) + powerUpHeadOffset, height * (4 + (6 * coffees)), width, height);
headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, i, (width * i) + powerUpHeadOffset, height * (5 + (6 * coffees)), width, height);
const std::string aPowerUp = powerUp ? "_pwr" : "";
const std::string aWalking = statusWalking == PLAYER_STATUS_WALKING_STOP ? "stand" : "walk";
const std::string aFiring = statusFiring == PLAYER_STATUS_FIRING_UP ? "centershoot" : "sideshoot";
const SDL_RendererFlip flipWalk = statusWalking == PLAYER_STATUS_WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
const SDL_RendererFlip flipFire = statusFiring == PLAYER_STATUS_FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
// Establece la animación a partir de las cadenas
legsSprite->setCurrentAnimation(aWalking);
legsSprite->setFlip(flipWalk);
if (statusFiring == PLAYER_STATUS_FIRING_NO)
{ // No esta disparando
bodySprite->setCurrentAnimation(aWalking + aBodyCoffees);
bodySprite->setFlip(flipWalk);
headSprite->setCurrentAnimation(aWalking + aHeadCoffees);
headSprite->setFlip(flipWalk);
}
else
{ // Está disparando
bodySprite->setCurrentAnimation(aFiring + aBodyCoffees);
bodySprite->setFlip(flipFire);
headSprite->setCurrentAnimation(aFiring + aHeadCoffees + aPowerUp);
headSprite->setFlip(flipFire);
}
switch (statusWalking)
{
case PLAYER_STATUS_WALKING_LEFT:
legsSprite->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_LEFT);
// Actualiza las animaciones de los sprites
legsSprite->animate();
switch (statusFiring)
{
case PLAYER_STATUS_FIRING_UP:
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_UP);
bodySprite->animate();
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_UP);
headSprite->animate();
break;
case PLAYER_STATUS_FIRING_LEFT:
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_LEFT);
bodySprite->animate();
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_LEFT);
headSprite->animate();
break;
case PLAYER_STATUS_FIRING_RIGHT:
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
bodySprite->animate();
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_RIGHT);
headSprite->animate();
break;
case PLAYER_STATUS_FIRING_NO:
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_LEFT);
bodySprite->animate();
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_LEFT);
headSprite->animate();
break;
default:
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_STOP);
bodySprite->animate();
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_STOP);
headSprite->animate();
break;
}
break;
case PLAYER_STATUS_WALKING_RIGHT:
legsSprite->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_RIGHT);
legsSprite->animate();
switch (statusFiring)
{
case PLAYER_STATUS_FIRING_UP:
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_UP);
bodySprite->animate();
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_UP);
headSprite->animate();
break;
case PLAYER_STATUS_FIRING_LEFT:
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_LEFT);
bodySprite->animate();
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_LEFT);
headSprite->animate();
break;
case PLAYER_STATUS_FIRING_RIGHT:
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
bodySprite->animate();
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_RIGHT);
headSprite->animate();
break;
case PLAYER_STATUS_FIRING_NO:
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_RIGHT);
bodySprite->animate();
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_RIGHT);
headSprite->animate();
break;
default:
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_STOP);
bodySprite->animate();
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_STOP);
headSprite->animate();
break;
}
break;
case PLAYER_STATUS_WALKING_STOP:
legsSprite->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_STOP);
legsSprite->animate();
switch (statusFiring)
{
case PLAYER_STATUS_FIRING_UP:
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_UP);
bodySprite->animate();
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_UP);
headSprite->animate();
break;
case PLAYER_STATUS_FIRING_LEFT:
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_LEFT);
bodySprite->animate();
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_LEFT);
headSprite->animate();
break;
case PLAYER_STATUS_FIRING_RIGHT:
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
bodySprite->animate();
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_RIGHT);
headSprite->animate();
break;
case PLAYER_STATUS_FIRING_NO:
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_STOP);
bodySprite->animate();
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_STOP);
headSprite->animate();
break;
default:
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_STOP);
bodySprite->animate();
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_STOP);
headSprite->animate();
break;
}
break;
default:
legsSprite->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_STOP);
legsSprite->animate();
break;
}
}
// Obtiene el valor de la variable
@@ -531,10 +279,14 @@ bool Player::canFire()
{
// Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador
if (cooldown > 0)
{
return false;
}
else
{
return true;
}
}
// Establece el valor de la variable
void Player::setFireCooldown(int time)
@@ -549,8 +301,10 @@ void Player::updateCooldown()
{
cooldown--;
if (powerUp)
{
cooldown--;
}
}
else
{
setFiringStatus(PLAYER_STATUS_FIRING_NO);
@@ -782,14 +536,14 @@ Uint8 Player::getCoffees()
// Obtiene el circulo de colisión
circle_t &Player::getCollider()
{
return mCollider;
return collider;
}
// Actualiza el circulo de colisión a la posición del jugador
void Player::shiftColliders()
{
mCollider.x = int(posX + (width / 2));
mCollider.y = int(posY + (height / 2));
collider.x = int(posX + (width / 2));
collider.y = int(posY + (height / 2));
}
// Obtiene el puntero a la textura con los gráficos de la animación de morir
@@ -809,20 +563,20 @@ void Player::updatePowerUpHeadOffset()
{
if (!powerUp)
{
powerUpHeadOffset = 0;
//powerUpHeadOffset = 0;
}
else
{
powerUpHeadOffset = 96;
//powerUpHeadOffset = 96;
if (powerUpCounter < 300)
{
if (powerUpCounter % 10 > 4)
{
powerUpHeadOffset = 96;
//powerUpHeadOffset = 96;
}
else
{
powerUpHeadOffset = 0;
//powerUpHeadOffset = 0;
}
}
}

View File

@@ -86,9 +86,8 @@ private:
bool extraHit; // Indica si el jugador tiene un toque extra
Uint8 coffees; // Indica cuantos cafes lleva acumulados
bool powerUp; // Indica si el jugador tiene activo el modo PowerUp
Uint8 powerUpHeadOffset; // Variable para dibujar la cabeza normal o la del powerup
bool input; // Indica si puede recibir ordenes de entrada
circle_t mCollider; // Circulo de colisión del jugador
circle_t collider; // Circulo de colisión del jugador
// Actualiza el circulo de colisión a la posición del jugador
void shiftColliders();