Borrado todo el código y vuelta a empezar

This commit is contained in:
2022-08-11 09:19:49 +02:00
parent 1301ef6a27
commit 57ddf60c1b
24 changed files with 125 additions and 1336 deletions

10
source/actors.cpp Normal file
View File

@@ -0,0 +1,10 @@
#include "actors.h"
// Constructor
Actors::Actors()
{
}
Actors::~Actors()
{
}

20
source/actors.h Normal file
View File

@@ -0,0 +1,20 @@
#pragma once
#include <SDL2/SDL.h>
#ifndef ACTORS_H
#define ACTORS_H
class Actors
{
private:
public:
// Constructor
Actors();
// Destructor
~Actors();
};
#endif

View File

@@ -1,5 +1,5 @@
#pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "movingsprite.h"
#ifndef ANIMATEDSPRITE_H

View File

@@ -1,5 +1,5 @@
#pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include <string>
#include <vector>

View File

@@ -1,6 +1,4 @@
#pragma once
#include "ifdefs.h"
#include <string>
#ifndef CONST_H
#define CONST_H
@@ -20,335 +18,4 @@
#define GAMECANVAS_WIDTH 320
#define GAMECANVAS_HEIGHT 240
const Uint8 GAME_SPEED = 24; //16 = normal-rapido, 24 = normal. Cuanto mas pequeño, más rápido
const Uint8 UP = 0;
const Uint8 DOWN = 2;
const Uint8 RIGHT = 1;
const Uint8 LEFT = 3;
const Uint8 NONE = 4;
const Uint8 MAP_TILE_HEIGHT = 16;
const Uint8 MAP_TILE_WIDTH = 16;
const Uint8 ROOM_WIDTH_IN_TILES = 20;
const Uint8 ROOM_HEIGHT_IN_TILES = 14;
const Uint16 GAME_WINDOW_WIDTH = 320;
const Uint16 GAME_WINDOW_HEIGHT = 234;
const Uint8 TEST_ROOM = 118;
const Uint8 STARTING_ROOM = 161; //TEST_ROOM;
const Uint8 STARTING_PLAYER_TILE_X = 5;
const Uint8 STARTING_PLAYER_TILE_Y = 11;
const Uint8 ENEMY_HITBOX_REDUCTION = 4;
const Uint8 COOLDOWN_TIME = 50;
const Uint8 GRAVITY = 1;
const Uint8 MAX_SPEED_Y = 5;
const Uint8 BASE_SPEED = 1;
const Uint8 MAX_SPEED = 8;
const Uint8 RATIO_SPEED = 8;
const Uint8 DROP_TIMER = 100;
const Uint8 TOP_COLLISION = 0;
const Uint8 BOTTOM_COLLISION = 1;
const Uint8 LEFT_COLLISION = 2;
const Uint8 RIGHT_COLLISION = 3;
const Uint8 NO_COLLISION = 4;
const Uint8 MAX_ACTORS = 50;
const Uint8 KIND_FLYING_ENEMY = 0;
const Uint8 KIND_COIN = 1;
const Uint8 KIND_HEART = 2;
const Uint8 KIND_STATIC_ENEMY = 3;
const Uint8 KIND_MOBILE_PLATFORM = 4;
const Uint8 KIND_WALKING_ENEMY = 5;
const Uint8 KIND_DROP_GENERATOR = 6;
const Uint8 KIND_DROP_ENEMY = 7;
const Uint8 KIND_DROP_SPLAT = 8;
const Uint8 KIND_SPEED_ENEMY = 9;
const Uint8 KIND_KEY = 10;
const Uint8 KIND_LOCK = 11;
const Uint8 CODE_ENEMY_V1U = 208;
const Uint8 CODE_ENEMY_V2U = 209;
const Uint8 CODE_ENEMY_V3U = 210;
const Uint8 CODE_ENEMY_V1D = 211;
const Uint8 CODE_ENEMY_V2D = 212;
const Uint8 CODE_ENEMY_V3D = 213;
const Uint8 CODE_ENEMY_H1L = 214;
const Uint8 CODE_ENEMY_H2L = 215;
const Uint8 CODE_ENEMY_H3L = 216;
const Uint8 CODE_ENEMY_H1R = 217;
const Uint8 CODE_ENEMY_H2R = 218;
const Uint8 CODE_ENEMY_H3R = 219;
const Uint8 CODE_ENEMY_W1L = 224;
const Uint8 CODE_ENEMY_W2L = 225;
const Uint8 CODE_ENEMY_W3L = 226;
const Uint8 CODE_ENEMY_W1R = 227;
const Uint8 CODE_ENEMY_W2R = 228;
const Uint8 CODE_ENEMY_W3R = 229;
const Uint8 CODE_ENEMY_DRP = 230;
const Uint8 CODE_ENEMY_SPL = 231;
const Uint8 CODE_ENEMY_SPR = 232;
const Uint8 CODE_COIN = 240;
const Uint8 CODE_HEART = 241;
const Uint8 CODE_KEY_RED = 242;
const Uint8 CODE_LOCK_RED = 243;
const Uint8 CODE_KEY_BLUE = 244;
const Uint8 CODE_LOCK_BLUE = 245;
const Uint8 CODE_KEY_GREEN = 246;
const Uint8 CODE_LOCK_GREEN = 247;
const Uint8 CODE_KEY_YELLOW = 248;
const Uint8 CODE_LOCK_YELLOW = 249;
const Uint8 MAX_ANIMATED_TILES = 200;
const Uint8 TILE_BACKGROUND = 0;
const Uint8 TILE_PLATFORM = 1;
const Uint8 TILE_KILLING_PLATFORM = 2;
const Uint8 TILE_ACTOR = 3;
const Uint8 TILE_TRAVESABLE_PLATFORM = 4;
const Uint8 PLAYER_ANIMATION_STANDING_LEFT = 0;
const Uint8 PLAYER_ANIMATION_STANDING_RIGHT = 1;
const Uint8 PLAYER_ANIMATION_WALKING_LEFT = 2;
const Uint8 PLAYER_ANIMATION_WALKING_RIGHT = 3;
const Uint8 PLAYER_ANIMATION_JUMPING_LEFT = 4;
const Uint8 PLAYER_ANIMATION_JUMPING_RIGHT = 5;
const Uint8 PLAYER_ANIMATION_DYING_LEFT = 6;
const Uint8 PLAYER_ANIMATION_DYING_RIGHT = 7;
const Uint8 SECTION_MENU = 0;
const Uint8 SECTION_GAME = 1;
const Uint8 SECTION_QUIT = 2;
const Uint8 MENU_SECTION_MAIN = 0;
const Uint8 MENU_SECTION_CREDITS = 1;
const Uint8 MENU_SECTION_ANIMATION = 2;
const Uint8 ZONE_SURFACE = 0;
const Uint8 ZONE_VOLCANO = 1;
///////////////////////////////COFFEE CRISIS//////////////////////////////////////////////
// Tamaño de la pantalla que se muestra
const int VIEW_WIDTH = SCREEN_WIDTH * 3; // 960
const int VIEW_HEIGHT = SCREEN_HEIGHT * 3; // 720
// Cantidad de enteros a escribir en los ficheros de datos
const Uint8 TOTAL_SCORE_DATA = 3;
const Uint16 TOTAL_DEMO_DATA = 2000;
// Zona de juego
const int PLAY_AREA_TOP = (0 * BLOCK);
const int PLAY_AREA_BOTTOM = SCREEN_HEIGHT - (4 * BLOCK);
const int PLAY_AREA_LEFT = (0 * BLOCK);
const int PLAY_AREA_RIGHT = SCREEN_WIDTH - (0 * BLOCK);
const int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
const int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
const int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
const int PLAY_AREA_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2);
const int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
// Anclajes de pantalla
const int SCREEN_CENTER_X = SCREEN_WIDTH / 2;
const int SCREEN_FIRST_QUARTER_X = SCREEN_WIDTH / 4;
const int SCREEN_THIRD_QUARTER_X = (SCREEN_WIDTH / 4) * 3;
const int SCREEN_CENTER_Y = SCREEN_HEIGHT / 2;
const int SCREEN_FIRST_QUARTER_Y = SCREEN_HEIGHT / 4;
const int SCREEN_THIRD_QUARTER_Y = (SCREEN_HEIGHT / 4) * 3;
// Color transparente para los sprites
const Uint8 COLOR_KEY_R = 0xff;
const Uint8 COLOR_KEY_G = 0x00;
const Uint8 COLOR_KEY_B = 0xff;
// Opciones de menu
const int MENU_NO_OPTION = -1;
const int MENU_OPTION_START = 0;
const int MENU_OPTION_QUIT = 1;
const int MENU_OPTION_TOTAL = 2;
// Selector de menu
const int MENU_SELECTOR_BLACK = (BLOCK * 0);
const int MENU_SELECTOR_WHITE = (BLOCK * 1);
// Tipos de fondos para el menu
const int MENU_BACKGROUND_TRANSPARENT = 0;
const int MENU_BACKGROUND_SOLID = 1;
// Estados del jugador
const Uint8 PLAYER_STATUS_WALKING_LEFT = 0;
const Uint8 PLAYER_STATUS_WALKING_RIGHT = 1;
const Uint8 PLAYER_STATUS_WALKING_STOP = 2;
const Uint8 PLAYER_STATUS_FIRING_UP = 0;
const Uint8 PLAYER_STATUS_FIRING_LEFT = 1;
const Uint8 PLAYER_STATUS_FIRING_RIGHT = 2;
const Uint8 PLAYER_STATUS_FIRING_NO = 3;
const Uint8 PLAYER_ANIMATION_LEGS_WALKING_LEFT = 0;
const Uint8 PLAYER_ANIMATION_LEGS_WALKING_RIGHT = 1;
const Uint8 PLAYER_ANIMATION_LEGS_WALKING_STOP = 2;
const Uint8 PLAYER_ANIMATION_BODY_WALKING_LEFT = 0;
const Uint8 PLAYER_ANIMATION_BODY_FIRING_LEFT = 1;
const Uint8 PLAYER_ANIMATION_BODY_WALKING_RIGHT = 2;
const Uint8 PLAYER_ANIMATION_BODY_FIRING_RIGHT = 3;
const Uint8 PLAYER_ANIMATION_BODY_WALKING_STOP = 4;
const Uint8 PLAYER_ANIMATION_BODY_FIRING_UP = 5;
const Uint8 PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT = 6;
const Uint8 PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT = 7;
const Uint8 PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT = 8;
const Uint8 PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT = 9;
const Uint8 PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT = 10;
const Uint8 PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT = 11;
// Variables del jugador
const Uint16 PLAYER_INVULNERABLE_TIMER = 200;
// Estados del juego
const Uint8 GAME_SECTION_TITLE = 0;
const Uint8 GAME_SECTION_PLAYING = 1;
const Uint8 GAME_SECTION_QUIT = 2;
const Uint8 GAME_SECTION_GAME_OVER_SCREEN = 3;
const Uint8 GAME_SECTION_INTRO = 4;
const Uint8 GAME_SECTION_DEMO = 5;
const Uint8 GAME_SECTION_INSTRUCTIONS = 6;
const Uint8 GAME_SECTION_LOGO = 7;
const Uint8 GAME_SECTION_INIT = 8;
// Estados de cada elemento que pertenece a un evento
const Uint8 EVENT_WAITING = 1;
const Uint8 EVENT_RUNNING = 2;
const Uint8 EVENT_COMPLETED = 3;
// Cantidad de eventos de la intro
const Uint8 INTRO_TOTAL_BITMAPS = 6;
const Uint8 INTRO_TOTAL_TEXTS = 9;
const Uint8 INTRO_TOTAL_EVENTS = INTRO_TOTAL_BITMAPS + INTRO_TOTAL_TEXTS;
// Cantidad de eventos de la pantalla de titulo
const Uint8 TITLE_TOTAL_EVENTS = 2;
// Relaciones de Id con nomnbres
const Uint8 BITMAP0 = 0;
const Uint8 BITMAP1 = 1;
const Uint8 BITMAP2 = 2;
const Uint8 BITMAP3 = 3;
const Uint8 BITMAP4 = 4;
const Uint8 BITMAP5 = 5;
const Uint8 TEXT0 = 6;
const Uint8 TEXT1 = 7;
const Uint8 TEXT2 = 8;
const Uint8 TEXT3 = 9;
const Uint8 TEXT4 = 10;
const Uint8 TEXT5 = 11;
const Uint8 TEXT6 = 12;
const Uint8 TEXT7 = 13;
const Uint8 TEXT8 = 14;
// Anclajes para el marcador de puntos
const int SCORE_WORD_X = (SCREEN_WIDTH / 4) - ((5 * BLOCK) / 2);
const int SCORE_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 2;
const int SCORE_NUMBER_X = (SCREEN_WIDTH / 4) - ((6 * BLOCK) / 2);
const int SCORE_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
const int HISCORE_WORD_X = ((SCREEN_WIDTH / 4) * 3) - ((8 * BLOCK) / 2);
const int HISCORE_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 2;
const int HISCORE_NUMBER_X = ((SCREEN_WIDTH / 4) * 3) - ((6 * BLOCK) / 2);
const int HISCORE_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
const int MULTIPLIER_WORD_X = (SCREEN_WIDTH / 2) - ((4 * BLOCK) / 2);
const int MULTIPLIER_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 2;
const int MULTIPLIER_NUMBER_X = (SCREEN_WIDTH / 2) - ((3 * BLOCK) / 2);;
const int MULTIPLIER_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
// Ningun tipo
const Uint8 NO_KIND = 0;
// Tipos de globo
const Uint8 BALLOON_1 = 1;
const Uint8 BALLOON_2 = 2;
const Uint8 BALLOON_3 = 3;
const Uint8 BALLOON_4 = 4;
// Velocidad del globo
const float BALLON_VELX_POSITIVE = 0.7f;
const float BALLON_VELX_NEGATIVE = -0.7f;
// Indice para las animaciones de los globos
const Uint8 BALLOON_MOVING_ANIMATION = 0;
const Uint8 BALLOON_POP_ANIMATION = 1;
const Uint8 BALLOON_BORN_ANIMATION = 2;
// Cantidad posible de globos
const Uint8 MAX_BALLOONS = 75;
// Tipos de bala
const Uint8 BULLET_UP = 1;
const Uint8 BULLET_LEFT = 2;
const Uint8 BULLET_RIGHT = 3;
// Cantidad posible de globos
const Uint8 MAX_BULLETS = 50;
// Tipos de objetos
const Uint8 ITEM_POINTS_1_DISK = 1;
const Uint8 ITEM_POINTS_2_GAVINA = 2;
const Uint8 ITEM_POINTS_3_PACMAR = 3;
const Uint8 ITEM_CLOCK = 4;
const Uint8 ITEM_TNT = 5;
const Uint8 ITEM_COFFEE = 6;
// Cantidad de objetos simultaneos
const Uint8 MAX_ITEMS = 5;
// Valores para las variables asociadas a los objetos
const Uint8 REMAINING_EXPLOSIONS = 3;
const Uint8 REMAINING_EXPLOSIONS_TIMER = 50;
const Uint16 TIME_STOPPED_TIMER = 300;
// Estados de entrada
const Uint8 NO_INPUT = 0;
const Uint8 INPUT_UP = 1;
const Uint8 INPUT_DOWN = 2;
const Uint8 INPUT_LEFT = 3;
const Uint8 INPUT_RIGHT = 4;
const Uint8 INPUT_ACCEPT = 5;
const Uint8 INPUT_CANCEL = 6;
const Uint8 INPUT_FIRE_UP = 7;
const Uint8 INPUT_FIRE_LEFT = 8;
const Uint8 INPUT_FIRE_RIGHT = 9;
const Uint8 INPUT_PAUSE = 10;
// Zona muerta del mando analógico
const int JOYSTICK_DEAD_ZONE = 8000;
// Tipos de mensajes para el retorno de las funciones
const Uint8 MSG_OK = 0;
const Uint8 MSG_BULLET_OUT = 1;
// Tipos de texto
const Uint8 TEXT_FIXED = 0;
const Uint8 TEXT_VARIABLE = 1;
// Cantidad de elementos del vector de SmartSprites
const Uint8 MAX_SMART_SPRITES = 10;
// Contadores
const Uint16 TITLE_TIMER = 800;
const Uint8 STAGE_COUNTER = 200;
const Uint16 INSTRUCTIONS_COUNTER = 600;
const Uint16 DEATH_COUNTER = 350;
#endif

View File

@@ -1,464 +0,0 @@
#include "const.h"
#include "director.h"
#include <iostream>
const Uint8 *keystates;
// Constructor
Director::Director(std::string path)
{
// Arranca SDL y crea la ventana
initSDL();
// Crea todos los objetos del juego
eventHandler = new SDL_Event();
screen = new Screen(window, renderer);
asset = new Asset(path.substr(0, path.find_last_of("\\/")));
setFileList();
// Inicializa todas las variables
section = NONE;
gameControllerFound = false;
for (int i = 0; i < 360; i++)
sen[i] = sin(i * 3.14 / 180);
for (int i = 0; i < TOTAL_SCORE_DATA; i++)
scoreData[i] = 0;
initOptions();
initGame();
quit = false;
}
Director::~Director()
{
quitGame();
// Borra todos los objetos del juego
delete eventHandler;
eventHandler = nullptr;
// delete text.white;
// text.white = nullptr;
delete screen;
screen = nullptr;
delete asset;
asset = nullptr;
// Destruye la ventana
SDL_DestroyRenderer(renderer);
SDL_DestroyTexture(backbuffer);
SDL_DestroyWindow(window);
backbuffer = nullptr;
renderer = nullptr;
window = nullptr;
// Sal del subsistema SDL
SDL_Quit();
}
// Inicializa las variables de las opciones
void Director::initOptions()
{
options.fullScreenMode = 0;
options.fullScreenModePrevious = 0;
options.windowSize = 0;
options.windowSizePrevious = 0;
}
// Inicializa las variables y crea los objetos del juego
void Director::initGame()
{
// Variables
game.score = 0;
game.section = 0;
game.paused = false;
game.ticks = 0;
game.ticksSpeed = GAME_SPEED;
game.counter = 0;
// Player
player = new Player(renderer, asset);
// Map
map = new Map(renderer, asset->get("volcano.map"), asset);
}
// Destruye los objetos del juego
void Director::quitGame()
{
// Player
delete player;
player = nullptr;
// Map
delete map;
map = nullptr;
}
// Arranca SDL y crea la ventana
bool Director::initSDL()
{
// Indicador de inicialización
bool success = true;
// Inicializa SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_HAPTIC) < 0)
{
printf("SDL could not initialize!\nSDL Error: %s\n", SDL_GetError());
success = false;
}
else
{
// Establece el filtro de la textura a nearest
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"))
{
printf("Warning: Nearest texture filtering not enabled!\n");
}
// Inicializa jail_audio
JA_Init(48000, AUDIO_S16, 2);
// Comprueba si hay algun mando conectado
if (SDL_NumJoysticks() < 1)
{
printf("Warning: No joysticks connected!\n");
gameControllerFound = false;
}
else
{
// Carga el mando
gameController = SDL_JoystickOpen(0);
gameControllerFound = true;
if (gameController == NULL)
{
printf("Warning: Unable to open game controller!\nSDL Error: %s\n", SDL_GetError());
gameControllerFound = false;
}
else
{
printf("%i joysticks were found.\n", SDL_NumJoysticks());
std::cout << SDL_JoystickNumButtons(gameController) << " buttons\n";
// Get controller haptic device
controllerHaptic = SDL_HapticOpenFromJoystick(gameController);
if (controllerHaptic == NULL)
{
printf("Warning: Controller does not support haptics!\nSDL Error: %s\n", SDL_GetError());
}
else
{
printf("Haptics detected\n");
// Get initialize rumble
if (SDL_HapticRumbleInit(controllerHaptic) < 0)
{
printf("Warning: Unable to initialize rumble!\nSDL Error: %s\n", SDL_GetError());
}
}
}
}
// Crea la ventana
window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, VIEW_WIDTH, VIEW_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
if (window == NULL)
{
printf("Window could not be created!\nSDL Error: %s\n", SDL_GetError());
success = false;
}
else
{
// Crea un renderizador para la ventana con vsync
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (renderer == NULL)
{
printf("Renderer could not be created!\nSDL Error: %s\n", SDL_GetError());
success = false;
}
else
{
// Inicializa el color de renderizado
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
// Establece el tamaño del buffer de renderizado
SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
// Establece el modo de mezcla
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
}
// Crea un backbuffer para el renderizador
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
if (backbuffer == NULL)
{
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
success = false;
}
}
}
printf("\n");
return success;
}
// Crea el indice de ficheros de recursos
bool Director::setFileList()
{
// Ficheros binarios
asset->add("/data/volcano.map", data);
asset->add("/data/config.bin", data, false);
// Texturas
asset->add("/media/gfx/actors.png", bitmap);
asset->add("/media/gfx/bg_surface.png", bitmap);
asset->add("/media/gfx/filter.png", bitmap);
asset->add("/media/gfx/hud.png", bitmap);
asset->add("/media/gfx/menu_animation.png", bitmap);
asset->add("/media/gfx/menu.png", bitmap);
asset->add("/media/gfx/player.png", bitmap);
asset->add("/media/gfx/tiles_surface.png", bitmap);
asset->add("/media/gfx/tiles_volcano.png", bitmap);
// Sonidos
asset->add("/media/sound/sound_player_coin.wav", sound);
asset->add("/media/sound/sound_player_death.wav", sound);
asset->add("/media/sound/sound_drop_enemy.wav", sound);
asset->add("/media/sound/sound_drop_splat.wav", sound);
asset->add("/media/sound/sound_player_jump.wav", sound);
asset->add("/media/sound/sound_menu_logo.wav", sound);
asset->add("/media/sound/sound_menu_start.wav", sound);
// Musicas
asset->add("/media/music/music_menu.ogg", music);
asset->add("/media/music/music_surface.ogg", music);
asset->add("/media/music/music_volcano.ogg", music);
return asset->check();
}
// Carga el fichero de configuración
bool Director::loadConfig()
{
// Indicador de éxito en la carga
bool success = true;
const std::string p = asset->get("config.bin").c_str();
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
// Abre el fichero con la configuracion de las opciones para leer en binario
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b");
// El fichero no existe
if (file == NULL)
{
printf("Warning: Unable to open %s file\n", filename.c_str());
// Crea el fichero para escribir
file = SDL_RWFromFile(p.c_str(), "w+b");
if (file != NULL)
{
printf("New file (%s) created!\n", filename.c_str());
// Inicializa los datos
options.fullScreenMode = 0;
SDL_RWwrite(file, &options.fullScreenMode, sizeof(options.fullScreenMode), 1);
options.windowSize = 3;
SDL_RWwrite(file, &options.windowSize, sizeof(options.windowSize), 1);
// Cierra el fichero
SDL_RWclose(file);
}
else
{
printf("Error: Unable to create file %s\n", filename.c_str());
success = false;
}
}
// El fichero existe
else
{
// Carga los datos
printf("Reading file %s\n", filename.c_str());
SDL_RWread(file, &options.fullScreenMode, sizeof(options.fullScreenMode), 1);
SDL_SetWindowFullscreen(window, options.fullScreenMode);
SDL_RWread(file, &options.windowSize, sizeof(options.windowSize), 1);
SDL_SetWindowSize(window, SCREEN_WIDTH * options.windowSize, SCREEN_HEIGHT * options.windowSize);
// Cierra el fichero
SDL_RWclose(file);
}
printf("\n");
return success;
}
// Guarda el fichero de configuración
bool Director::saveConfig()
{
// Indicador de éxito en la carga
bool success = true;
const std::string p = asset->get("config.bin");
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
// Abre el fichero de puntuación para escribir
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b");
if (file != NULL)
{
// Guardamos los datos
SDL_RWwrite(file, &options.fullScreenMode, sizeof(Uint32), 1);
SDL_RWwrite(file, &options.windowSize, sizeof(Uint8), 1);
printf("Writing file %s\n", filename.c_str());
// Cerramos el fichero
SDL_RWclose(file);
}
else
{
printf("Error: Unable to save %s file! %s\n", filename.c_str(), SDL_GetError());
}
return success;
}
// Obtiene el valor de la variable
Uint8 Director::getGameSection()
{
return game.section;
}
// Establece el valor de la variable
void Director::changeGameSection(_section sectionPrevious, _section sectionNext)
{
switch (sectionPrevious)
{
case GAME:
quitGame();
break;
default:
break;
}
switch (sectionNext)
{
case GAME:
initGame();
break;
default:
break;
}
game.section = sectionNext;
}
// Cambia el valor de la variable de modo de pantalla completa
void Director::changeFullScreenMode()
{
switch (options.fullScreenMode)
{
case 0:
options.fullScreenMode = SDL_WINDOW_FULLSCREEN;
break;
case SDL_WINDOW_FULLSCREEN:
options.fullScreenMode = SDL_WINDOW_FULLSCREEN_DESKTOP;
break;
case SDL_WINDOW_FULLSCREEN_DESKTOP:
options.fullScreenMode = 0;
break;
default:
options.fullScreenMode = 0;
break;
}
}
// Comprueba si hay que salir
bool Director::isRunning()
{
return !quit;
}
// Bucle para el logo del juego
void Director::runLogo()
{
}
// Bucle para la intro del juego
void Director::runIntro()
{
}
// Bucle para el titulo del juego
void Director::runTitle()
{
}
// Bucle para el juego
void Director::runGame()
{
// Actualiza la lógica del juego
updateGame();
// Pinta la sección de juego
renderGame();
}
// Actualiza la lógica del juego
void Director::updateGame()
{
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - game.ticks > game.ticksSpeed)
{
// Actualiza el contador de ticks
game.ticks = SDL_GetTicks();
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(eventHandler) != 0)
{
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
quit = true;
break;
}
}
game.counter++;
map->update();
player->update();
}
}
// Pinta la sección de juego
void Director::renderGame()
{
// Prepara para empezar a dibujar el frame
screen->start();
// Limpia la pantalla
screen->clean();
// Dibuja los objetos
map->render();
player->render();
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
// Bucle principal
void Director::run()
{
while (isRunning())
{
runGame();
}
}

View File

@@ -1,134 +0,0 @@
#pragma once
#include "ifdefs.h"
#include "sprite.h"
#include "movingsprite.h"
#include "player.h"
#include "map.h"
#include "text.h"
#include "const.h"
#include "jail_audio.h"
#include "utils.h"
#include "screen.h"
#include "asset.h"
#include <math.h>
#ifndef GAME_H
#define GAME_H
// director
class Director
{
private:
struct _text // Objetos de texto
{
Text *white;
};
struct _options // Variables relacionadas con las opciones del juego
{
Uint32 fullScreenMode; // Guarda el valor elegido para el modo de pantalla completa
Uint32 fullScreenModePrevious; // Guarda el valor previo del modo de pantalla completa
Uint8 windowSize; // Guarda el valor elegido para el tamaño de la ventana
Uint8 windowSizePrevious; // Guarda el valor previo del tamaño de la ventana
};
struct _game // Variables para el control del juego
{
Uint32 score; // Puntuación actual
Uint8 section; // Indicador para el bucle principal
bool paused; // Idica si el juego está en pausa
Uint32 ticks; // Contador de ticks para ajustar la velocidad del juego
Uint8 ticksSpeed; // Velocidad a la que se repite el bucle de juego
Uint32 counter; // Contador para el juego
};
SDL_Window *window; // La ventana de la aplicación
SDL_Renderer *renderer; // El renderizador donde se dibuja todo
SDL_Event *eventHandler; // Manejador de eventos
SDL_Texture *backbuffer; // Texturas
SDL_Joystick *gameController; // Manejador para el mando 1
SDL_Haptic *controllerHaptic; // Manejador para la vibración del mando
_game game; // Contiene las variables de la sección de juego
_options options; // Contiene todas las opciones del programa
_text text; // Variable con los objetos texto
bool gameControllerFound; // Indica si se ha encontrado algun mando conectado
double sen[360]; // Vector con los valores del seno para 360 grados
Player *player; // El jugador
Map *map; // El mapa del juego
Screen *screen; // Objeto para pintar en pantalla
Asset *asset; // Objeto con todos los ficheros de recursos
Uint32 scoreData[TOTAL_SCORE_DATA]; // Datos del fichero de puntuación
enum _section // Lista con todas las secciones en las que se divide el programa
{
GAME,
TITLE,
QUIT,
NONE
};
_section section; // Seccion actual del programa
bool quit; // Indica si hay que terminar el programa
// Inicializa las variables de las opciones
void initOptions();
// Inicializa las variables y crea los objetos del juego
void initGame();
// Destruye los objetos del juego
void quitGame();
// Arranca SDL y crea la ventana
bool initSDL();
// Crea el indice de ficheros de recursos
bool setFileList();
// Carga el fichero de configuración
bool loadConfig();
// Guarda el fichero de configuración
bool saveConfig();
// Obtiene el valor de la variable
Uint8 getGameSection();
// Establece el valor de la variable
void changeGameSection(_section sectionPrevious, _section sectionNext);
// Cambia el valor de la variable de modo de pantalla completa
void changeFullScreenMode();
// Comprueba si hay que salir
bool isRunning();
// Bucle para el logo del juego
void runLogo();
// Bucle para la intro del juego
void runIntro();
// Bucle para el titulo del juego
void runTitle();
// Bucle para el juego
void runGame();
// Pinta la sección de juego
void renderGame();
// Actualiza la lógica del juego
void updateGame();
public:
// Constructor
Director(std::string _path);
// Destructor
~Director();
// Bucle principal
void run();
};
#endif

10
source/game.cpp Normal file
View File

@@ -0,0 +1,10 @@
#include "game.h"
// Constructor
Game::Game()
{
}
Game::~Game()
{
}

20
source/game.h Normal file
View File

@@ -0,0 +1,20 @@
#pragma once
#include <SDL2/SDL.h>
#ifndef GAME_H
#define GAME_H
class Game
{
private:
public:
// Constructor
Game();
// Destructor
~Game();
};
#endif

View File

@@ -1 +0,0 @@
#include <SDL2/SDL.h>

View File

@@ -1,5 +1,5 @@
#pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED };
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED };

View File

@@ -1,5 +1,5 @@
#pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include <stdio.h>
#include <string>

View File

@@ -12,12 +12,10 @@ Repres un 14 de febrer de 2021
*/
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include <time.h>
#include <stdio.h>
#include <string>
#include "const.h"
#include "director.h"
#include "prog.h"
int main(int argc, char *args[])
{
@@ -25,13 +23,13 @@ int main(int argc, char *args[])
srand(time(nullptr));
// Crea el objeto director
Director *director = new Director(args[0]);
Prog *prog = new Prog(args[0]);
// Bucle principal
director->run();
prog->run();
// Libera todos los recursos y cierra SDL
delete director;
delete prog;
printf("Shutting down the game...\n");
return 0;

View File

@@ -1,224 +1,12 @@
#include "const.h"
#include "map.h"
// Constructor
Map::Map(SDL_Renderer *renderer, std::string file, Asset *asset)
Map::Map()
{
this->asset = asset;
this->renderer = renderer;
texture_tile = new LTexture();
texture_actor = new LTexture();
texture_bg = new LTexture();
loadTextureFromFile(texture_tile, asset->get("tiles_volcano.png"), renderer);
loadTextureFromFile(texture_actor, asset->get("actors.png"), renderer);
loadTextureFromFile(texture_bg, asset->get("bg_surface.png"), renderer);
sprite_tile = new AnimatedSprite(texture_tile, renderer);
sprite_actor = new AnimatedSprite(texture_actor, renderer);
const SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
background = new Sprite(rect, texture_bg, renderer);
music = JA_LoadMusic(asset->get("music_surface.ogg").c_str());
src_rect = {0, 0, 0, 0};
dst_rect = {0, 0, 0, 0};
w = 0;
h = 0;
room = 0;
loadFromFile(file);
}
// Destructor
Map::~Map()
{
texture_tile->unload();
delete texture_tile;
texture_tile = nullptr;
texture_actor->unload();
delete texture_actor;
texture_actor = nullptr;
texture_bg->unload();
delete texture_bg;
texture_bg = nullptr;
delete sprite_tile;
sprite_tile = nullptr;
delete sprite_actor;
sprite_actor = nullptr;
delete background;
background = nullptr;
delete[] tile;
delete[] actor;
JA_DeleteMusic(music);
}
// Carga el mapa a partir de un fichero
void Map::loadFromFile(std::string path)
{
std::string filename = path.substr(path.find_last_of("\\/") + 1);
SDL_RWops *file = SDL_RWFromFile(path.c_str(), "r+b");
Uint8 *w;
Uint8 *h;
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, &w, sizeof(Uint8), 1);
SDL_RWread(file, &h, sizeof(Uint8), 1);
long size = (*w) * (*h);
tile = new Uint8[size];
actor = new Uint8[size];
for (long i = 0; i < size; i++)
SDL_RWread(file, &tile[i], sizeof(Uint8), 1);
for (long i = 0; i < size; i++)
SDL_RWread(file, &actor[i], sizeof(Uint8), 1);
SDL_RWclose(file);
}
}
// Actualiza todas las variables
void Map::update()
{
background->setPosX(0);
background->setPosY(0);
}
// Dibuja el objeto
void Map::render()
{
background->render();
}
// Obtiene el valor del tile de la habitación actual
Uint8 Map::getTile(int x, int y)
{
const long room_x = (room % 12) * ROOM_WIDTH_IN_TILES;
const long room_y = (room / 12) * ROOM_HEIGHT_IN_TILES;
return tile[(room_x + x) + (room_y + y) * w];
}
// Obtiene el tipo de tile segun su ubicación en la textura
Uint8 Map::readMapTile(Uint8 x, Uint8 y)
{
const Uint8 tile = getTile(x, y);
if (tile >= 0 && tile <= 63)
{
return TILE_BACKGROUND;
}
else if (tile >= 64 && tile <= 143)
{
return TILE_PLATFORM;
}
else if (tile >= 144 && tile <= 175)
{
return TILE_TRAVESABLE_PLATFORM;
}
else if (tile >= 176 && tile <= 207)
{
return TILE_KILLING_PLATFORM;
}
else if (tile >= 208 && tile <= 255)
{
return TILE_ACTOR;
}
else
{
return 0;
}
}
// Obtiene el valor del actor en esa ubicación
Uint8 Map::getActor(Uint8 x, Uint8 y)
{
long room_x = (room % 12) * ROOM_WIDTH_IN_TILES;
long room_y = (room / 12) * ROOM_HEIGHT_IN_TILES;
return actor[(room_x + x) + (room_y + y) * w];
}
// Establece el valor del actor en esa ubicación
void Map::setActor(Uint8 x, Uint8 y, Uint8 valor)
{
long room_x = (room % 12) * ROOM_WIDTH_IN_TILES;
long room_y = (room / 12) * ROOM_HEIGHT_IN_TILES;
actor[(room_x + x) + (room_y + y) * w] = valor;
}
// Carga las texturas del mapa en función de la zona
void Map::setMapGFX(Uint8 zone)
{
switch (zone)
{
case ZONE_SURFACE:
loadTextureFromFile(texture_tile, asset->get("tiles_surface.png").c_str(), renderer);
loadTextureFromFile(texture_bg, asset->get("bg_surface.png").c_str(), renderer);
break;
case ZONE_VOLCANO:
loadTextureFromFile(texture_tile, asset->get("tiles_volcano.png").c_str(), renderer);
loadTextureFromFile(texture_bg, asset->get("bg_surface.png").c_str(), renderer);
break;
}
}
// Carga las musica del juego en función de la zona
void Map::setMapMusic(Uint8 zone)
{
switch (zone)
{
case ZONE_SURFACE:
music = JA_LoadMusic(asset->get("music_surface.ogg").c_str());
break;
case ZONE_VOLCANO:
music = JA_LoadMusic(asset->get("music_volcano.ogg").c_str());
break;
}
}
// Comprueba si se ha cambiado de zona
bool Map::checkZoneChange(int room)
{
Uint8 _zone = 0;
if ((room >= 0) && (room <= 23))
_zone = ZONE_SURFACE;
else if ((room >= 24) && (room <= 255))
_zone = ZONE_VOLCANO;
if (_zone == zone)
return false;
else
return true;
}
// Cambia la zona del mapa
void Map::setZone(int room)
{
if ((room >= 0) && (room <= 23))
zone = ZONE_SURFACE;
else if ((room >= 24) && (room <= 255))
zone = ZONE_VOLCANO;
setMapGFX(zone);
setMapMusic(zone);
JA_PlayMusic(music, -1);
}

View File

@@ -1,9 +1,4 @@
#pragma once
#include "animatedsprite.h"
#include "asset.h"
#include "jail_audio.h"
#include "utils.h"
#ifndef MAP_H
#define MAP_H
@@ -11,64 +6,13 @@
class Map
{
private:
SDL_Renderer *renderer; // El renderizador donde se dibuja todo
LTexture *texture_tile; // Textura con los gráficos de los tiles
LTexture *texture_actor; // Textura con los gráficos de los actores
LTexture *texture_bg; // Textura con los gráficos de fondo
Asset *asset; // Objeto con los ficheros de recursos
AnimatedSprite *sprite_tile; // Sprite de los tiles del mapa
AnimatedSprite *sprite_actor; // Sprite de los actores
Sprite *background; // Fondo de la pantalla
SDL_Rect src_rect; // Ni puta idea
SDL_Rect dst_rect; // Ni puta idea
Uint8 *tile; // Vector con los tiles
Uint8 *actor; // Vector con los acores
Uint8 w; // Anchura en habitaciones del mapa
Uint8 h; // Altura en habitaciones del mapa
Uint8 room; // Habitación actual del mapa
std::string mapfile; // Ruta con el fichero del mapa
JA_Music music; // La musica del mapa
Uint8 zone; // Zona del mapa
public:
// Constructor
Map(SDL_Renderer *renderer, std::string file, Asset *asset);
Map();
// Destructor
~Map();
// Carga el mapa a partir de un fichero
void loadFromFile(std::string file);
// Actualiza todas las variables
void update();
// Dibuja el objeto
void render();
// Obtiene el valor del tile de la habitación actual
Uint8 getTile(int x, int y);
// Obtiene el tipo de tile segun su ubicación en la textura
Uint8 readMapTile(Uint8 x, Uint8 y);
// Obtiene el valor del actor en esa ubicación
Uint8 getActor(Uint8 x, Uint8 y);
// Establece el valor del actor en esa ubicación
void setActor(Uint8 x, Uint8 y, Uint8 valor);
// Carga las texturas del mapa en función de la zona
void setMapGFX(Uint8 zone);
// Carga las musica del juego en función de la zona
void setMapMusic(Uint8 zone);
// Comprueba si se ha cambiado de zona
bool checkZoneChange(int room);
// Cambia la zona del mapa
void setZone(int room);
};
#endif

View File

@@ -1,5 +1,5 @@
#pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "sprite.h"
#ifndef MOVINGSPRITE_H

View File

@@ -1,70 +1,21 @@
#include "const.h"
#include "player.h"
// Constructor
Player::Player(SDL_Renderer *renderer, Asset *asset)
Player::Player()
{
this->asset = asset;
texture = new LTexture();
loadTextureFromFile(texture, asset->get("player.png"), renderer);
sprite = new AnimatedSprite(texture, renderer);
rect = {0, 0, 16, 24};
sprite->setSpriteClip(rect);
sound_coin = JA_LoadSound(asset->get("sound_player_coin.wav").c_str());
sound_death = JA_LoadSound(asset->get("sound_player_death.wav").c_str());
sound_jump = JA_LoadSound(asset->get("sound_player_jump.wav").c_str());
// Inicializa todas las variables
can_jump = false;
enabled = false;
jump_pressed_before = false;
jump_pressed_now = false;
for (Uint8 i = 0; i < 6; i++)
key[i] = false;
standing = false;
was_on_background = false;
coins = 0;
cooldown = 0;
jumpforce = 0;
respawn_x = 0;
respawn_y = 0;
speed_x = 0;
speed_y = 0;
active_animation = 0;
direction = 0;
lifes = 0;
respawn_direction = 0;
}
// Destructor
Player::~Player()
{
texture->unload();
delete texture;
texture = nullptr;
delete sprite;
sprite = nullptr;
JA_DeleteSound(sound_coin);
JA_DeleteSound(sound_death);
JA_DeleteSound(sound_jump);
}
// Actualiza todas las variables
void Player::update()
{
sprite->setPosX(rect.x);
sprite->setPosY(rect.y);
}
// Dibuja el objeto
void Player::render()
{
sprite->render();
}

View File

@@ -1,9 +1,4 @@
#pragma once
#include "animatedsprite.h"
#include "asset.h"
#include "jail_audio.h"
#include "utils.h"
#ifndef PLAYER_H
#define PLAYER_H
@@ -11,35 +6,10 @@
class Player
{
private:
bool can_jump; // Si puede saltar
bool enabled; // Si está habilitado
bool jump_pressed_before; // Si se ha pulsado el botón de salto previamente
bool jump_pressed_now; // Si se acaba de pulsar el salto
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
int coins; // Cantidad de monedas
int cooldown; // Tiempo de inhabilitación
int jumpforce; // Cantidad de pixels a desplazarse y velocidad que pilla al saltar
int respawn_x; // Coordenadas para revivir
int respawn_y; // Coordenades para revivir
int speed_x; // Cantidad de pixeles a desplazarse
int speed_y; // Cantidad de pixels a desplazarse
JA_Sound sound_coin; // Sonido al coger monedas
JA_Sound sound_death; // Sonido al morir
JA_Sound sound_jump; // Sonido al saltar
SDL_Rect rect; // Rectangulo con la posición del jugador
AnimatedSprite *sprite; // Sprite con los graficos y animaciones
Asset *asset; // Objeto con los ficheros de recursos
LTexture *texture; // Objeto con los gráficos del jugador
Uint8 active_animation; // Animación activa
Uint8 direction; // Sentido del desplazamiento
Uint8 lifes; // Cantidad de vidas
Uint8 respawn_direction; // Dirección para revivir
public:
// Constructor
Player(SDL_Renderer *renderer, Asset *asset);
Player();
// Destructor
~Player();

12
source/prog.cpp Normal file
View File

@@ -0,0 +1,12 @@
#include "prog.h"
// Constructor
Prog::Prog(std::string executablePath)
{
asset = new Asset(executablePath);
}
Prog::~Prog()
{
delete asset;
}

25
source/prog.h Normal file
View File

@@ -0,0 +1,25 @@
#pragma once
#include <SDL2/SDL.h>
#include <string>
#include "asset.h"
#ifndef PROG_H
#define PROG_H
class Prog
{
private:
Asset *asset;
public:
// Constructor
Prog(std::string executablePath);
// Destructor
~Prog();
// Bucle principal
void run();
};
#endif

View File

@@ -1,20 +1,19 @@
#include "screen.h"
#include "const.h"
// Constructor
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, int scr_w, int scr_h, int gc_w, int gc_h)
{
// Inicializa variables
mWindow = window;
mRenderer = renderer;
mScreenWidth = SCREEN_WIDTH;
mScreenHeight = SCREEN_HEIGHT;
mGameCanvasWidth = GAMECANVAS_WIDTH;
mGameCanvasHeight = GAMECANVAS_HEIGHT;
mGameCanvasPosX = (SCREEN_WIDTH - GAMECANVAS_WIDTH) / 2;
mGameCanvasPosY = (SCREEN_HEIGHT - GAMECANVAS_HEIGHT) / 2;
mScreenWidth = scr_w;
mScreenHeight = scr_h;
mGameCanvasWidth = gc_w;
mGameCanvasHeight = gc_h;
mGameCanvasPosX = (scr_w - gc_w) / 2;
mGameCanvasPosY = (scr_h - gc_h) / 2;
mDest = {mGameCanvasPosX, mGameCanvasPosY, mGameCanvasWidth, mGameCanvasHeight};
mBorderColor = {0x27, 0x27, 0x36};
// Crea la textura donde se dibujan los graficos del juego
@@ -52,11 +51,8 @@ void Screen::blit()
SDL_SetRenderDrawColor(mRenderer, mBorderColor.r, mBorderColor.g, mBorderColor.b, 0xFF);
SDL_RenderClear(mRenderer);
// Rectangulo de destino donde se dibujarà la textura con el juego
SDL_Rect dest = {mGameCanvasPosX, mGameCanvasPosY, mGameCanvasWidth, mGameCanvasHeight};
// Copia la textura de juego en el renderizador en la posición adecuada
SDL_RenderCopy(mRenderer, mGameCanvas, NULL, &dest);
SDL_RenderCopy(mRenderer, mGameCanvas, NULL, &mDest);
// Muestra por pantalla el renderizador
SDL_RenderPresent(mRenderer);

View File

@@ -1,5 +1,5 @@
#pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "utils.h"
#ifndef SCREEN_H
@@ -20,11 +20,12 @@ private:
int mGameCanvasPosX; // Posicion en el eje X donde se dibujará la textura del juego dentro de la pantalla
int mGameCanvasPosY; // Posicion en el eje Y donde se dibujará la textura del juego dentro de la pantalla
SDL_Rect mDest; // Rectangulo de destino donde se dibujarà la textura con el juego
color_t mBorderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
public:
// Constructor
Screen(SDL_Window *windows, SDL_Renderer *renderer);
Screen(SDL_Window *windows, SDL_Renderer *renderer, int scr_w = 0, int scr_h = 0, int gc_w = 0, int gc_h = 0);
// Destructor
~Screen();

View File

@@ -1,5 +1,5 @@
#pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "ltexture.h"
#ifndef SPRITE_H

View File

@@ -1,15 +1,11 @@
#pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "ltexture.h"
#include <string>
#ifndef UTILS_H
#define UTILS_H
#define DIFFICULTY_EASY 0
#define DIFFICULTY_NORMAL 1
#define DIFFICULTY_HARD 2
// Estructura para definir un circulo
struct circle_t
{
@@ -33,30 +29,10 @@ struct section_t
Uint8 subsection;
};
// Estructura para mapear el teclado usado en la demo
struct demoKeys_t
{
Uint8 left;
Uint8 right;
Uint8 noInput;
Uint8 fire;
Uint8 fireLeft;
Uint8 fireRight;
};
// Estructura para albergar métodos de control
struct input_t
{
int id; // Identificador en el vector de mandos
std::string name; // Nombre del dispositivo
Uint8 deviceType; // Tipo de dispositivo (teclado o mando)
};
// Estructura con todas las opciones de configuración del programa
struct options_t
{
Uint8 difficulty; // Dificultad del juego
input_t input[2]; // Modo de control (teclado o mando)
Uint8 language; // Idioma usado en el juego
Uint32 fullScreenMode; // Contiene el valor del modo de pantalla completa
Uint8 windowSize; // Contiene el valor del tamaño de la ventana