diff --git a/source/const.h b/source/const.h index 57efd88..1301c83 100644 --- a/source/const.h +++ b/source/const.h @@ -47,13 +47,13 @@ const Uint8 ROOM_HEIGHT_IN_TILES = 14; const Uint16 GAME_WINDOW_WIDTH = 320; const Uint16 GAME_WINDOW_HEIGHT = 234; -const Uint8 TEST_ROOM = 118; // 161 -const Uint8 STARTING_ROOM = 2; -const Uint8 STARTING_PLAYER_TILE_X = 5; +const Uint8 TEST_ROOM = 190; // 161, 118 +const Uint8 STARTING_ROOM = 3; +const Uint8 STARTING_PLAYER_TILE_X = 2; const Uint8 STARTING_PLAYER_TILE_Y = 11; const Uint8 ENEMY_HITBOX_REDUCTION = 4; const Uint8 COOLDOWN_TIME = 50; -const Uint8 GRAVITY = 0; +const Uint8 GRAVITY = 1; const Uint8 MAX_SPEED_Y = 5; const Uint8 BASE_SPEED = 1; const Uint8 MAX_SPEED = 8; diff --git a/source/volcano.cpp b/source/volcano.cpp index af27a94..df1e28b 100644 --- a/source/volcano.cpp +++ b/source/volcano.cpp @@ -1,9 +1,16 @@ -// Volcano (abans "Rise of the Bal1") -// Programat i dissenyat per Sergio Valor @JailDesigner -// Editor, música i suport técnic per Raimon Zamora @JailDoc -// Gràfics per Diego Valor @JailBrother -// Començat un 19 de febrer de 2016 -// Repres un 14 de febrer de 2021 +/* + +Volcano (abans "Rise of the Bal1") +Programat i dissenyat per + Sergio Valor @JailDesigner +Editor, música i suport técnic per + Raimon Zamora @JailDoc +Gràfics per + Diego Valor @JailBrother +Començat un 19 de febrer de 2016 +Repres un 14 de febrer de 2021 + +*/ #include "volcano.h" #include @@ -17,7 +24,12 @@ JA_DeleteMusic(a); \ a = nullptr -Uint8 _GRAVITY = 0; +// DEBUG VARS +Uint8 _GRAVITY = 1; +Uint8 starting_rooms_to_test[4] = {3, 26, 100, 190}; +Uint8 starting_room = 0; +// END DEBUG VARS + void allocatePointers() { // Textures @@ -29,19 +41,6 @@ void allocatePointers() menu.sprite_animation = new LTexture(); player.sprite = new LTexture(); prog.sprite = new LTexture(); - - // Sounds - //game.sound_drop_enemy = new Mix_Chunk(); - //game.sound_drop_splat = new Mix_Chunk(); - //menu.sound_logo = new Mix_Chunk(); - //menu.sound_start = new Mix_Chunk(); - //player.sound_coin = new Mix_Chunk(); - //player.sound_death = new Mix_Chunk(); - //player.sound_jump = new Mix_Chunk(); - - // Music - //game.music = new Mix_Music(); - //menu.music = new Mix_Music(); } void deletePointers() @@ -65,10 +64,6 @@ void deletePointers() CLOSE_SOUND(player.sound_death); CLOSE_SOUND(player.sound_jump); - // Music - //game.music = new Mix_Music(); - //menu.music = new Mix_Music(); - delete[] map.tile; delete[] map.actor; } @@ -85,28 +80,13 @@ bool loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *rend return success; } -/*void CloseSound(JA_Sound sound) -{ - if (sound != nullptr) - JA_DeleteSound(sound); - sound = nullptr; -} - -void CloseMusic(JA_Music music) -{ - if (music != nullptr) - JA_DeleteMusic(music); - music = nullptr; -}*/ - void ClosePicture(LTexture *picture) { picture->free(); } +// Obtiene el valor del tile de la habitación actual Uint8 GetTile(Uint8 x, Uint8 y) -// Entrada: coordenades en tiles relativas a la habitación actual -// Salida: el valor del byte { long room_x = (map.room % 12) * ROOM_WIDTH_IN_TILES; long room_y = (map.room / 12) * ROOM_HEIGHT_IN_TILES; @@ -131,15 +111,15 @@ Uint8 ReadMapTile(Uint8 x, Uint8 y) Uint8 GetActor(Uint8 x, Uint8 y) { - Uint8 room_x = (map.room % 12) * ROOM_WIDTH_IN_TILES; - Uint8 room_y = (map.room / 12) * ROOM_HEIGHT_IN_TILES; + long room_x = (map.room % 12) * ROOM_WIDTH_IN_TILES; + long room_y = (map.room / 12) * ROOM_HEIGHT_IN_TILES; return map.actor[(room_x + x) + (room_y + y) * map.w]; } void SetActor(Uint8 x, Uint8 y, Uint8 valor) { - Uint8 room_x = (map.room % 12) * ROOM_WIDTH_IN_TILES; - Uint8 room_y = (map.room / 12) * ROOM_HEIGHT_IN_TILES; + long room_x = (map.room % 12) * ROOM_WIDTH_IN_TILES; + long room_y = (map.room / 12) * ROOM_HEIGHT_IN_TILES; map.actor[(room_x + x) + (room_y + y) * map.w] = valor; } @@ -266,51 +246,12 @@ void setExecutablePath(std::string path) executablePath = path.substr(0, path.find_last_of("\\/")); } -/*void LoadMap_old() -{ - std::string p = executablePath + "/" + FILE_MAP_VOLCANO.c_str(); - std::string filename = p.substr(p.find_last_of("\\/") + 1); - - SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b"); - const long file_size = SDL_RWsize(file); - Uint8 *buf = new Uint8[file_size]; - - if (file == NULL) - { - printf("Warning: Unable to open %s file\n", filename.c_str()); - } - else - { - printf("Reading file %s\n", filename.c_str()); - - SDL_RWread(file, buf, sizeof(Uint8), file_size); - SDL_RWclose(file); - - long size = (buf[0]) * (buf[1]); - map.tile = new Uint8[size]; - map.actor = new Uint8[size]; - - for (Uint16 i = 0; i < size; i++) - map.tile[i] = buf[i]; - - for (Uint16 i = 0; i < size; i++) - map.actor[i] = buf[i]; - } - - delete[] buf; -}*/ - void LoadMap() { std::string p = executablePath + "/" + FILE_MAP_VOLCANO.c_str(); std::string filename = p.substr(p.find_last_of("\\/") + 1); SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b"); - //Uint8 *w = new Uint8(); - //Uint8 *h = new Uint8(); - //Uint8 column = 0; - //Uint8 line = 0; - //Uint8 room = 0; if (file == NULL) { @@ -329,32 +270,13 @@ void LoadMap() map.actor = new Uint8[size]; for (Uint32 i = 0; i < size; i++) - { SDL_RWread(file, &map.tile[i], sizeof(Uint8), 1); - /*column++; - //std::cout << std::to_string(map.tile[i]); - printf("%-3s ", std::to_string(map.tile[i]).c_str()); - if (column == ROOM_WIDTH_IN_TILES) - { - column = 0; - line++; - printf(" --%s\n",std::to_string(line).c_str()); - } - if (line == ROOM_HEIGHT_IN_TILES) - { - line = 0; - printf("=========================^= ROOM #%-3s =^================================\n", std::to_string(room).c_str()); - room++; - }*/ - } for (Uint32 i = 0; i < size; i++) SDL_RWread(file, &map.actor[i], sizeof(Uint8), 1); SDL_RWclose(file); } - //delete w; - //delete h; } void LoadRoom(int num) @@ -745,6 +667,7 @@ void IniPlayer() player.jump_pressed_now = false; player.jump_pressed_before = false; player.standing = true; + player.invulnerable = true; player.jumpforce = 10; player.active_animation = 0; player.enabled = true; @@ -935,16 +858,19 @@ void EndGame() void KillPlayer() { - player.enabled = false; - player.cooldown = COOLDOWN_TIME; + if (!player.invulnerable) + { + player.enabled = false; + player.cooldown = COOLDOWN_TIME; - // Establece la animación de morir - if (player.direction == LEFT) - SetPlayerAnimation(PLAYER_ANIMATION_DYING_LEFT); - else - SetPlayerAnimation(PLAYER_ANIMATION_DYING_RIGHT); + // Establece la animación de morir + if (player.direction == LEFT) + SetPlayerAnimation(PLAYER_ANIMATION_DYING_LEFT); + else + SetPlayerAnimation(PLAYER_ANIMATION_DYING_RIGHT); - JA_PlaySound(player.sound_death, 0); + JA_PlaySound(player.sound_death, 0); + } } bool OnFloor() @@ -952,13 +878,13 @@ bool OnFloor() Uint8 tile_under_left_foot = ReadMapTile((player.dst_rect.x + 3) / MAP_TILE_WIDTH, (player.dst_rect.y + player.dst_rect.h) / MAP_TILE_HEIGHT); Uint8 tile_under_right_foot = ReadMapTile((player.dst_rect.x + player.dst_rect.w - 4) / MAP_TILE_WIDTH, (player.dst_rect.y + player.dst_rect.h) / MAP_TILE_HEIGHT); - bool i_am_above_platform = ((tile_under_left_foot = TILE_PLATFORM) || (tile_under_right_foot = TILE_PLATFORM)); - bool i_am_above_travesable = ((tile_under_left_foot = TILE_TRAVESABLE_PLATFORM) || (tile_under_right_foot = TILE_TRAVESABLE_PLATFORM)); + bool i_am_above_platform = ((tile_under_left_foot == TILE_PLATFORM) || (tile_under_right_foot == TILE_PLATFORM)); + bool i_am_above_travesable = ((tile_under_left_foot == TILE_TRAVESABLE_PLATFORM) || (tile_under_right_foot == TILE_TRAVESABLE_PLATFORM)); Uint8 tile_on_left_foot = ReadMapTile((player.dst_rect.x + 3) / MAP_TILE_WIDTH, (player.dst_rect.y + player.dst_rect.h - 1) / MAP_TILE_HEIGHT); Uint8 tile_on_right_foot = ReadMapTile((player.dst_rect.x + player.dst_rect.w - 4) / MAP_TILE_WIDTH, (player.dst_rect.y + player.dst_rect.h - 1) / MAP_TILE_HEIGHT); - bool i_am_on_background = ((tile_on_left_foot = TILE_BACKGROUND) && (tile_on_right_foot = TILE_BACKGROUND)); + bool i_am_on_background = ((tile_on_left_foot == TILE_BACKGROUND) && (tile_on_right_foot == TILE_BACKGROUND)); if (((i_am_above_platform) || (i_am_above_travesable)) && (i_am_on_background)) return true; @@ -984,7 +910,8 @@ void MoveActors() actor[i].direction = LEFT; // Colisi� amb el mapa, correcci� a l'ultim pixel bo i canvi de sentit - if ((ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) + if ((ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || + (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) { actor[i].dst_rect.x = actor[i].dst_rect.x - ((actor[i].dst_rect.x + actor[i].dst_rect.w) % MAP_TILE_WIDTH); actor[i].direction = LEFT; @@ -1000,7 +927,8 @@ void MoveActors() actor[i].direction = RIGHT; // Colisi� amb el mapa, correcci� a l'ultim pixel bo i canvi de sentit - if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || (ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) + if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || + (ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) { actor[i].dst_rect.x = actor[i].dst_rect.x + (MAP_TILE_WIDTH - (actor[i].dst_rect.x % MAP_TILE_WIDTH)); actor[i].direction = RIGHT; @@ -1016,7 +944,8 @@ void MoveActors() actor[i].direction = UP; // Colisi� amb el mapa, correcci� a l'ultim pixel bo i canvi de sentit - if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) + if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || + (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) { actor[i].dst_rect.y = actor[i].dst_rect.y - ((actor[i].dst_rect.y + actor[i].dst_rect.h) % MAP_TILE_WIDTH); actor[i].direction = UP; @@ -1032,7 +961,8 @@ void MoveActors() actor[i].direction = DOWN; // Colisi� amb el mapa, correcci� a l'ultim pixel bo i canvi de sentit - if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) + if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || + (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) { actor[i].dst_rect.y = actor[i].dst_rect.y + (MAP_TILE_WIDTH - (actor[i].dst_rect.y % MAP_TILE_WIDTH)); actor[i].direction = DOWN; @@ -1064,7 +994,8 @@ void MoveActors() actor[i].direction = LEFT; // Colisi� amb el mapa, correcci� a l'ultim pixel bo i canvi de sentit - if ((ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) + if ((ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || + (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) { actor[i].dst_rect.x = actor[i].dst_rect.x - ((actor[i].dst_rect.x + actor[i].dst_rect.w) % MAP_TILE_WIDTH); actor[i].direction = LEFT; @@ -1084,7 +1015,8 @@ void MoveActors() actor[i].direction = RIGHT; // Colisi� amb el mapa, correcci� a l'ultim pixel bo i canvi de sentit - if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || (ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) + if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || + (ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) { actor[i].dst_rect.x = actor[i].dst_rect.x + (MAP_TILE_WIDTH - (actor[i].dst_rect.x % MAP_TILE_WIDTH)); actor[i].direction = RIGHT; @@ -1123,7 +1055,8 @@ void MoveActors() actor[i].direction = LEFT; // Colisi� amb el mapa, correcci� a l'ultim pixel bo i canvi de sentit - if ((ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) + if ((ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || + (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) { actor[i].dst_rect.x = actor[i].dst_rect.x - ((actor[i].dst_rect.x + actor[i].dst_rect.w) % MAP_TILE_WIDTH); actor[i].direction = LEFT; @@ -1149,7 +1082,8 @@ void MoveActors() actor[i].direction = RIGHT; // Colisi� amb el mapa, correcci� a l'ultim pixel bo i canvi de sentit - if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || (ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) + if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || + (ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) { actor[i].dst_rect.x = actor[i].dst_rect.x + (MAP_TILE_WIDTH - (actor[i].dst_rect.x % MAP_TILE_WIDTH)); actor[i].direction = RIGHT; @@ -1183,7 +1117,8 @@ void MoveActors() actor[i].direction = LEFT; // Colisi� amb el mapa, correcci� al ultim pixel bo i canvi de sentit - if ((ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) + if ((ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || + (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) { actor[i].dst_rect.x = actor[i].dst_rect.x - ((actor[i].dst_rect.x + actor[i].dst_rect.w) % MAP_TILE_WIDTH); actor[i].direction = LEFT; @@ -1200,7 +1135,8 @@ void MoveActors() actor[i].direction = RIGHT; // Colisi� amb el mapa, correcci� al ultim pixel bo i canvi de sentit - if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || (ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) + if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || + (ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) { actor[i].dst_rect.x = actor[i].dst_rect.x + (MAP_TILE_WIDTH - (actor[i].dst_rect.x % MAP_TILE_WIDTH)); actor[i].direction = RIGHT; @@ -1217,7 +1153,8 @@ void MoveActors() actor[i].direction = UP; // Colisi� amb el mapa, correcci� al ultim pixel bo i canvi de sentit - if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) + if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || + (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) { actor[i].dst_rect.y = actor[i].dst_rect.y - ((actor[i].dst_rect.y + actor[i].dst_rect.h) % MAP_TILE_WIDTH); actor[i].direction = UP; @@ -1234,7 +1171,8 @@ void MoveActors() actor[i].direction = DOWN; // Colisi� amb el mapa, correcci� al ultim pixel bo i canvi de sentit - if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) + if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || + (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, actor[i].dst_rect.y / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) { actor[i].dst_rect.y = actor[i].dst_rect.y + (MAP_TILE_WIDTH - (actor[i].dst_rect.y % MAP_TILE_WIDTH)); actor[i].direction = DOWN; @@ -1278,7 +1216,8 @@ void MoveActors() } // Colisi� amb el mapa, correcci� al ultim pixel bo, transforma en KIND_DROP_SPLAT - if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) + if ((ReadMapTile(actor[i].dst_rect.x / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND) || + (ReadMapTile((actor[i].dst_rect.x + actor[i].dst_rect.w - 1) / MAP_TILE_WIDTH, (actor[i].dst_rect.y + actor[i].dst_rect.h - 1) / MAP_TILE_HEIGHT) != TILE_BACKGROUND)) { actor[i].dst_rect.y = actor[i].dst_rect.y - ((actor[i].dst_rect.y + actor[i].dst_rect.h) % MAP_TILE_WIDTH); actor[i].kind = KIND_DROP_SPLAT; @@ -1563,21 +1502,32 @@ void DrawHud() hud.num_dst_rect.x = 41; DrawSprite(hud.sprite, hud.num_src_rect, hud.num_dst_rect); + //i_am_on_background + Uint8 tile_on_left_foot = ReadMapTile((player.dst_rect.x + 3) / MAP_TILE_WIDTH, (player.dst_rect.y + player.dst_rect.h - 1) / MAP_TILE_HEIGHT); + Uint8 tile_on_right_foot = ReadMapTile((player.dst_rect.x + player.dst_rect.w - 4) / MAP_TILE_WIDTH, (player.dst_rect.y + player.dst_rect.h - 1) / MAP_TILE_HEIGHT); + bool i_am_on_background = ((tile_on_left_foot == TILE_BACKGROUND) && (tile_on_right_foot == TILE_BACKGROUND)); + if (i_am_on_background) + hud.num_src_rect.x = 1 * hud.num_src_rect.w; + else + hud.num_src_rect.x = 0 * hud.num_src_rect.w; + hud.num_dst_rect.x = 45; + DrawSprite(hud.sprite, hud.num_src_rect, hud.num_dst_rect); + // Pinta el numero de habitación // Centena hud.num_src_rect.x = (map.room / 100) * hud.num_src_rect.w; hud.num_dst_rect.y = 1; - hud.num_dst_rect.x = 49; + hud.num_dst_rect.x = 49 + 4; DrawSprite(hud.sprite, hud.num_src_rect, hud.num_dst_rect); // Decena hud.num_src_rect.x = ((map.room % 100) / 10) * hud.num_src_rect.w; - hud.num_dst_rect.x = 53; + hud.num_dst_rect.x = 53 + 4; DrawSprite(hud.sprite, hud.num_src_rect, hud.num_dst_rect); // Unidad hud.num_src_rect.x = (map.room % 10) * hud.num_src_rect.w; - hud.num_dst_rect.x = 57; + hud.num_dst_rect.x = 57 + 4; DrawSprite(hud.sprite, hud.num_src_rect, hud.num_dst_rect); } } @@ -1628,8 +1578,8 @@ void CheckPlayerCollisionWithMap() Uint8 tile_on_left_foot = ReadMapTile((player.dst_rect.x + 3) / MAP_TILE_WIDTH, (player.dst_rect.y + player.dst_rect.h - 1) / MAP_TILE_HEIGHT); Uint8 tile_on_right_foot = ReadMapTile((player.dst_rect.x + player.dst_rect.w - 4) / MAP_TILE_WIDTH, (player.dst_rect.y + player.dst_rect.h - 1) / MAP_TILE_HEIGHT); - bool i_am_on_platform = (tile_on_left_foot = TILE_PLATFORM) || (tile_on_right_foot = TILE_PLATFORM); - bool i_am_on_travesable = (tile_on_left_foot = TILE_TRAVESABLE_PLATFORM) || (tile_on_right_foot = TILE_TRAVESABLE_PLATFORM); + bool i_am_on_platform = (tile_on_left_foot == TILE_PLATFORM) || (tile_on_right_foot == TILE_PLATFORM); + bool i_am_on_travesable = (tile_on_left_foot == TILE_TRAVESABLE_PLATFORM) || (tile_on_right_foot == TILE_TRAVESABLE_PLATFORM); if ((player.was_on_background) && (player.speed_y > 0) && ((i_am_on_platform) || (i_am_on_travesable))) { @@ -1640,16 +1590,19 @@ void CheckPlayerCollisionWithMap() player.can_jump = true; } - player.was_on_background = ((tile_on_left_foot = TILE_BACKGROUND) && (tile_on_right_foot = TILE_BACKGROUND)); + player.was_on_background = ((tile_on_left_foot == TILE_BACKGROUND) && (tile_on_right_foot == TILE_BACKGROUND)); // Mirem si colisionem cap amunt i corregim - if ((ReadMapTile((player.dst_rect.x + 3) / MAP_TILE_WIDTH, player.dst_rect.y / MAP_TILE_HEIGHT) == TILE_PLATFORM) || (ReadMapTile((player.dst_rect.x + player.dst_rect.w - 4) / MAP_TILE_WIDTH, player.dst_rect.y / MAP_TILE_HEIGHT) == TILE_PLATFORM)) + if ((ReadMapTile((player.dst_rect.x + 3) / MAP_TILE_WIDTH, player.dst_rect.y / MAP_TILE_HEIGHT) == TILE_PLATFORM) || + (ReadMapTile((player.dst_rect.x + player.dst_rect.w - 4) / MAP_TILE_WIDTH, player.dst_rect.y / MAP_TILE_HEIGHT) == TILE_PLATFORM)) // Corregim la posicio player.dst_rect.y = player.dst_rect.y + (MAP_TILE_HEIGHT - (player.dst_rect.y % MAP_TILE_HEIGHT)); // Una vegada em permes la colisi� amunt o avall, al haver un marge de 3 pixels pot ser que estiguem dins d'una paret. S'ha de corregir aquest offset // Mirem les colisions laterals - if ((ReadMapTile(player.dst_rect.x / MAP_TILE_WIDTH, player.dst_rect.y / MAP_TILE_HEIGHT) == TILE_PLATFORM) || (ReadMapTile(player.dst_rect.x / MAP_TILE_WIDTH, (player.dst_rect.y + (player.dst_rect.h / 2)) / MAP_TILE_HEIGHT) == TILE_PLATFORM) || (ReadMapTile(player.dst_rect.x / MAP_TILE_WIDTH, (player.dst_rect.y + player.dst_rect.h - 1) / MAP_TILE_HEIGHT) == TILE_PLATFORM)) + if ((ReadMapTile(player.dst_rect.x / MAP_TILE_WIDTH, player.dst_rect.y / MAP_TILE_HEIGHT) == TILE_PLATFORM) || + (ReadMapTile(player.dst_rect.x / MAP_TILE_WIDTH, (player.dst_rect.y + (player.dst_rect.h / 2)) / MAP_TILE_HEIGHT) == TILE_PLATFORM) || + (ReadMapTile(player.dst_rect.x / MAP_TILE_WIDTH, (player.dst_rect.y + player.dst_rect.h - 1) / MAP_TILE_HEIGHT) == TILE_PLATFORM)) player.dst_rect.x = player.dst_rect.x + (MAP_TILE_WIDTH - (player.dst_rect.x % MAP_TILE_WIDTH)); if ((ReadMapTile((player.dst_rect.x + player.dst_rect.w - 1) / MAP_TILE_WIDTH, player.dst_rect.y / MAP_TILE_HEIGHT) == TILE_PLATFORM) || (ReadMapTile((player.dst_rect.x + player.dst_rect.w - 1) / MAP_TILE_WIDTH, (player.dst_rect.y + (player.dst_rect.h / 2)) / MAP_TILE_HEIGHT) == TILE_PLATFORM) || (ReadMapTile((player.dst_rect.x + player.dst_rect.w - 1) / MAP_TILE_WIDTH, (player.dst_rect.y + player.dst_rect.h - 1) / MAP_TILE_HEIGHT) == TILE_PLATFORM)) @@ -1922,9 +1875,12 @@ int main(int argc, char *args[]) break; case SDL_SCANCODE_G: + ++_GRAVITY %= 2; + break; + + case SDL_SCANCODE_H: player.lifes = 255; - _GRAVITY++; - _GRAVITY %= 2; + player.invulnerable = !player.invulnerable; break; case SDL_SCANCODE_M: @@ -1937,7 +1893,9 @@ int main(int argc, char *args[]) case SDL_SCANCODE_T: IniPlayer(); - LoadRoom(TEST_ROOM); + ++starting_room %= 4; + player.invulnerable = true; + LoadRoom(starting_rooms_to_test[starting_room]); break; case SDL_SCANCODE_Z: diff --git a/source/volcano.h b/source/volcano.h index d638279..83fc44b 100644 --- a/source/volcano.h +++ b/source/volcano.h @@ -72,6 +72,7 @@ struct Tplayer bool key[6]; // Indica las llaves que posee el jugador bool standing; // Si esta de pie (o quieto?) bool was_on_background; // Si viene de una zona atravesable + bool invulnerable; // Si es invulnerable int coins; // Cantidad de monedas int cooldown; // Tiempo de inhabilitación int jumpforce; // Cantidad de pixels a desplazarse y velocidad que pilla al saltar