diff --git a/data/room/01.room b/data/room/01.room index 378c88c..cee5924 100644 --- a/data/room/01.room +++ b/data/room/01.room @@ -12,8 +12,8 @@ roomRight=02.room [/tilemap] [enemy] -tileset=paco.png -animation=paco.ani +tileset=diskette.png +animation=diskette.ani width=16 height=16 x=1 @@ -28,8 +28,8 @@ color=red [/enemy] [enemy] -tileset=paco.png -animation=paco.ani +tileset=diskette.png +animation=diskette.ani width=16 height=16 x=5 @@ -45,7 +45,7 @@ color=yellow [item] tileset=items.png -tile=0 +tile=1 x=1 y=7 counter=6 @@ -53,7 +53,7 @@ counter=6 [item] tileset=items.png -tile=0 +tile=1 x=17 y=8 counter=7 @@ -63,7 +63,7 @@ counter=7 [item] tileset=items.png -tile=0 +tile=1 x=12 y=12 counter=1 @@ -71,7 +71,7 @@ counter=1 [item] tileset=items.png -tile=0 +tile=1 x=13 y=12 counter=2 @@ -79,7 +79,7 @@ counter=2 [item] tileset=items.png -tile=0 +tile=1 x=14 y=12 counter=3 @@ -87,7 +87,7 @@ counter=3 [item] tileset=items.png -tile=0 +tile=1 x=15 y=12 counter=4 @@ -95,7 +95,7 @@ counter=4 [item] tileset=items.png -tile=0 +tile=1 x=16 y=12 counter=5 diff --git a/media/enemies/diskette.ani b/media/enemies/diskette.ani new file mode 100644 index 0000000..b9685cb --- /dev/null +++ b/media/enemies/diskette.ani @@ -0,0 +1,10 @@ +frames_per_row=4 +frame_width=16 +frame_height=16 + +[animation] +name=default +speed=8 +loop=0 +frames=0,1,2,3 +[/animation] \ No newline at end of file diff --git a/media/enemies/diskette.png b/media/enemies/diskette.png new file mode 100644 index 0000000..f138f89 Binary files /dev/null and b/media/enemies/diskette.png differ diff --git a/media/items/items.png b/media/items/items.png index aabdc93..18ed563 100644 Binary files a/media/items/items.png and b/media/items/items.png differ diff --git a/source/director.cpp b/source/director.cpp index a578dd8..ac6d91d 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -184,6 +184,8 @@ bool Director::setFileList() asset->add("/media/enemies/wave.ani", data); asset->add("/media/enemies/sigmasua.png", bitmap); asset->add("/media/enemies/sigmasua.ani", data); + asset->add("/media/enemies/diskette.png", bitmap); + asset->add("/media/enemies/diskette.ani", data); asset->add("/media/player/player.png", bitmap); asset->add("/media/player/player.ani", data); diff --git a/source/game.cpp b/source/game.cpp index 2c5b58e..972343b 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -79,8 +79,6 @@ void Game::checkEventHandler() } else if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0)) { - //test->update(); - switch (eventHandler->key.keysym.scancode) { case SDL_SCANCODE_ESCAPE: diff --git a/source/player.cpp b/source/player.cpp index c5c2de0..2b0c602 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -22,7 +22,7 @@ Player::Player(player_t ini, std::string tileset, std::string animation, SDL_Ren border = BORDER_TOP; invincible = false; - jump_ini = ini.jump_ini; + jumpIni = ini.jumpIni; state = ini.state; prevState = state; @@ -74,7 +74,24 @@ Player::Player(player_t ini, std::string tileset, std::string animation, SDL_Ren jumpSound.push_back(JA_LoadSound(asset->get("jump23.wav").c_str())); jumpSound.push_back(JA_LoadSound(asset->get("jump24.wav").c_str())); + fallSound.push_back(JA_LoadSound(asset->get("jump11.wav").c_str())); + fallSound.push_back(JA_LoadSound(asset->get("jump12.wav").c_str())); + fallSound.push_back(JA_LoadSound(asset->get("jump13.wav").c_str())); + fallSound.push_back(JA_LoadSound(asset->get("jump14.wav").c_str())); + fallSound.push_back(JA_LoadSound(asset->get("jump15.wav").c_str())); + fallSound.push_back(JA_LoadSound(asset->get("jump16.wav").c_str())); + fallSound.push_back(JA_LoadSound(asset->get("jump17.wav").c_str())); + fallSound.push_back(JA_LoadSound(asset->get("jump18.wav").c_str())); + fallSound.push_back(JA_LoadSound(asset->get("jump19.wav").c_str())); + fallSound.push_back(JA_LoadSound(asset->get("jump20.wav").c_str())); + fallSound.push_back(JA_LoadSound(asset->get("jump21.wav").c_str())); + fallSound.push_back(JA_LoadSound(asset->get("jump22.wav").c_str())); + fallSound.push_back(JA_LoadSound(asset->get("jump23.wav").c_str())); + fallSound.push_back(JA_LoadSound(asset->get("jump24.wav").c_str())); + r = {0, 0, 0, 0}; + jumpCounter = 0; + fallCounter = 0; } // Destructor @@ -153,8 +170,8 @@ void Player::checkInput() { setState(s_jumping); vy = -maxVY; - jump_ini = y; - JA_PlaySound(jumpSound[0]); + jumpIni = y; + jumpCounter = 0; } } @@ -207,11 +224,21 @@ void Player::checkState() { vx = 0.0f; vy = maxVY; + fallCounter++; + playFallSound(); } else if (state == s_standing) { vy = 0.0f; + jumpCounter = 0; + fallCounter = 0; + } + + else if (state == s_jumping) + { + jumpCounter++; + playJumpSound(); } } @@ -221,7 +248,7 @@ void Player::switchBorders() if (border == BORDER_TOP) { y = PLAY_AREA_BOTTOM - h - 1; - jump_ini += 128; + jumpIni += 128; } else if (border == BORDER_BOTTOM) { @@ -424,147 +451,6 @@ void Player::move() } } - //-------------------------------------------------------------- - - // Calcula la nueva posición del jugador y compensa en caso de colisión - /*x += vx; - - // Comprueba colisiones con muros - if (checkWalls()) - { - // Recoloca - if (vx > 0.0f) - { - x = (int)x - ((int)x + w) % tileSize; - } - else - { - x = (int)x + tileSize - ((int)x % tileSize); - } - } - - // Comprueba colisiones con rampas solo si esta quieto o cayendo - else if (vy >= 0.0f) - { - - tile_e slope = checkSlopes(); - tile_e slope2 = checkSlopes2(); - debug->add("SLOPE = " + std::to_string(slope)); - debug->add("SLOPE2 = " + std::to_string(slope2)); - if (slope != t_empty) - { // Cuesta hacia la derecha - if (slope == t_slope_r) - { // Recoloca - y = -h + room->getSlopeHeight(feet[1], t_slope_r); - debug->add("feet[1] = " + std::to_string(feet[1].y)); - } - - // Cuesta hacia la izquierda - if (slope == t_slope_l) - { // Recoloca - y = -h + room->getSlopeHeight(feet[0], t_slope_l); - debug->add("feet[0] = " + std::to_string(feet[0].y)); - } - } - else if (slope2 != t_empty) - { // Cuesta hacia la derecha - if (slope2 == t_slope_r) - { // Recoloca - y = -h + room->getSlopeHeight(underFeet[1], t_slope_r); - debug->add("ufeet[1] = " + std::to_string(underFeet[1].y)); - } - - // Cuesta hacia la izquierda - if (slope2 == t_slope_l) - { // Recoloca - y = -h + room->getSlopeHeight(underFeet[0], t_slope_l); - debug->add("ufeet[0] = " + std::to_string(underFeet[0].y)); - } - } - } - - y += vy; - if (checkWalls()) - { - // Recoloca - if (vy > 0.0f) - { // Bajando - y -= ((int)y + h) % tileSize; - setState(s_standing); - vy = 0.0f; - } - else - { // Subiendo - y += tileSize - ((int)y % tileSize); - setState(s_falling); - vy = maxVY; - } - } - else - // Si no colisiona con los muros, haz comprobaciones extra - { - const int a = (lastPosition.y + h - 1) / tileSize; - const int b = ((int)y + h - 1) / tileSize; - const bool tile_change = a != b; - - bool going_down = vy >= 0.0f; - bool tile_aligned = ((int)y + h) % tileSize == 0; - - // Si está cayendo y hay cambio de tile o está justo sobre uno - if (going_down && (tile_aligned || tile_change)) - { - // Comprueba si tiene uno de los pies sobre una superficie - if (isOnFloor()) - { // Y deja al jugador de pie - setState(s_standing); - vy = 0.0f; - - // Si ademas ha habido un cambio de tile recoloca al jugador - if (tile_change && !checkSlopes2()) - { - y = ((int)y - ((int)y % tileSize)); - } - } - - // Si tiene ambos pies sobre el vacío y no está saltando - else if (state != s_jumping) - { - setState(s_falling); - vy = maxVY; - } - } - - going_down = vy >= 0.0f; - tile_aligned = ((int)y + h) % tileSize == 0; - - // Si simplemente está cayendo (sin mirar si hay cambio de tile o si está justo sobre uno) - if (going_down) - { - if (state != s_jumping) - { - setState(s_falling); - vy = maxVY; - } - - // Si está alineado con el tile mira el suelo (para que no lo mire si está - // dentro de un tile atravesable y lo deje a medias) - if (tile_aligned) - { - if (isOnFloor()) - { - setState(s_standing); - vy = 0.0f; - } - } - // EXPERIMENTAL - else if (checkSlopes()) - { - setState(s_standing); - vy = 0.0f; - } - } - }*/ - // Actualiza la posición del sprite sprite->setPosX(x); sprite->setPosY(y); @@ -583,12 +469,37 @@ void Player::animate() void Player::checkJumpEnd() { if (state == s_jumping) + { if (vy > 0) - if (y >= jump_ini) + { + if (y >= jumpIni) { // Si alcanza la altura de salto inicial, pasa al estado de caída setState(s_falling); vy = maxVY; + jumpCounter = 0; } + } + } +} + +// Calcula y reproduce el sonido de salto +void Player::playJumpSound() +{ + if (jumpCounter % 4 == 0) + { + JA_PlaySound(jumpSound[jumpCounter / 4]); + } + debug->add("JUMP: " + std::to_string(jumpCounter / 4)); +} + +// Calcula y reproduce el sonido de caer +void Player::playFallSound() +{ + if (fallCounter % 4 == 0) + { + JA_PlaySound(fallSound[std::min((fallCounter / 4), (int)fallSound.size() - 1)]); + } + debug->add("FALL: " + std::to_string(fallCounter / 4)); } // Comprueba si el jugador tiene suelo debajo de los pies @@ -657,73 +568,6 @@ bool Player::checkWalls() return wall; } -// Comprueba si el jugador está en una rampa -tile_e Player::checkSlopes() -{ - // Actualiza los puntos de colisión - updateFeet(); - - bool slope_l = false; - bool slope_r = false; - - // Comprueba si ha colisionado con una rampa - for (auto f : feet) - { - slope_l |= (room->getTile(f) == t_slope_l); - slope_r |= (room->getTile(f) == t_slope_r); - } - - if (slope_l) - { - return t_slope_l; - } - - if (slope_r) - { - return t_slope_r; - } - - return t_empty; -} - -// Comprueba si el jugador está en una rampa -tile_e Player::checkSlopes2() -{ - // Actualiza los puntos de colisión - updateFeet(); - - bool slope_l = false; - bool slope_r = false; - bool wall = false; - bool passable = false; - - // Comprueba si ha colisionado con una rampa - for (auto f : underFeet) - { - slope_l |= (room->getTile(f) == t_slope_l); - slope_r |= (room->getTile(f) == t_slope_r); - wall |= (room->getTile(f) == t_wall); - passable |= (room->getTile(f) == t_passable); - } - - if (wall || passable) - { - return t_empty; - } - - if (slope_l) - { - return t_slope_l; - } - - if (slope_r) - { - return t_slope_r; - } - - return t_empty; -} - // Obtiene algunos parametros del jugador player_t Player::getSpawnParams() { @@ -733,7 +577,7 @@ player_t Player::getSpawnParams() params.y = y; params.vx = vx; params.vy = vy; - params.jump_ini = jump_ini; + params.jumpIni = jumpIni; params.state = state; params.flip = sprite->getFlip(); diff --git a/source/player.h b/source/player.h index b27ae8b..0a3903b 100644 --- a/source/player.h +++ b/source/player.h @@ -27,7 +27,7 @@ struct player_t float y; float vx; float vy; - int jump_ini; + int jumpIni; state_e state; SDL_RendererFlip flip; }; @@ -60,9 +60,12 @@ public: int border; // Indica en cual de los cuatro bordes se encuentra bool invincible; // Si es invencible, no puede morir SDL_Rect lastPosition; // Contiene la ultima posición del jugador, por si hay que deshacer algun movimiento - int jump_ini; // Valor del eje Y en el que se inicia el salto + int jumpIni; // Valor del eje Y en el que se inicia el salto float maxVY; // Velocidad máxima que puede alcanzar al desplazarse en vertical std::vector jumpSound; // Vecor con todos los sonidos del salto + std::vector fallSound; // Vecor con todos los sonidos de la caída + int jumpCounter; // Cuenta el tiempo de salto + int fallCounter; // Cuenta el tiempo de caida SDL_Rect r; // Comprueba las entradas y modifica variables @@ -89,6 +92,12 @@ public: // Comprueba si ha finalizado el salto al alcanzar la altura de inicio void checkJumpEnd(); + // Calcula y reproduce el sonido de salto + void playJumpSound(); + + // Calcula y reproduce el sonido de caer + void playFallSound(); + // Comprueba si el jugador tiene suelo debajo de los pies bool isOnFloor(); @@ -98,12 +107,6 @@ public: // Comprueba que el jugador no atraviese ninguna pared bool checkWalls(); - // Comprueba si el jugador está en una rampa - tile_e checkSlopes(); - - // Comprueba si el jugador está en una rampa - tile_e checkSlopes2(); - // Actualiza los puntos de colisión void updateColliderPoints(); diff --git a/source/title.cpp b/source/title.cpp index d1a73ae..fa1c59e 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -73,6 +73,31 @@ void Title::checkEventHandler() section.subsection = 0; break; + case SDL_SCANCODE_F: + screen->switchVideoMode(); + texture->reLoad(); + break; + + case SDL_SCANCODE_F1: + screen->setWindowSize(1); + texture->reLoad(); + break; + + case SDL_SCANCODE_F2: + screen->setWindowSize(2); + texture->reLoad(); + break; + + case SDL_SCANCODE_F3: + screen->setWindowSize(3); + texture->reLoad(); + break; + + case SDL_SCANCODE_F4: + screen->setWindowSize(4); + texture->reLoad(); + break; + default: break; }