Arreglos y limpieza de código
This commit is contained in:
15
source/common/Makefile
Normal file
15
source/common/Makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
executable = jaildoctors_dilemma
|
||||
source = source/*.cpp source/common/*.cpp
|
||||
|
||||
windows:
|
||||
@echo off
|
||||
if not exist bin\ (mkdir bin)
|
||||
g++ $(source) -std=c++11 -Wall -O2 -lmingw32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o bin/$(executable).exe
|
||||
strip -s -R .comment -R .gnu.version bin/$(executable).exe --strip-unneeded
|
||||
macos:
|
||||
mkdir -p bin
|
||||
g++ $(source) -std=c++11 -Wall -O2 -lSDL2 -ffunction-sections -fdata-sections -o bin/$(executable)_macos
|
||||
linux:
|
||||
mkdir -p bin
|
||||
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o bin/$(executable)_linux
|
||||
strip -s -R .comment -R .gnu.version bin/$(executable)_linux --strip-unneeded
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "animatedsprite.h"
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(LTexture *texture, SDL_Renderer *renderer, std::string file, std::vector<std::string> *buffer)
|
||||
AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::string file, std::vector<std::string> *buffer)
|
||||
{
|
||||
// Copia los punteros
|
||||
setTexture(texture);
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "movingsprite.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifndef ANIMATEDSPRITE_H
|
||||
#define ANIMATEDSPRITE_H
|
||||
@@ -30,7 +30,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
AnimatedSprite(LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "", std::vector<std::string> *buffer = nullptr);
|
||||
AnimatedSprite(Texture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "", std::vector<std::string> *buffer = nullptr);
|
||||
|
||||
// Destructor
|
||||
~AnimatedSprite();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "../const.h"
|
||||
#include "menu.h"
|
||||
|
||||
// Constructor
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <vector>
|
||||
#include "sprite.h"
|
||||
#include "text.h"
|
||||
#include "asset.h"
|
||||
#include "input.h"
|
||||
#include "utils.h"
|
||||
#include "jail_audio.h"
|
||||
#include <sstream>
|
||||
#include "sprite.h"
|
||||
#include "text.h"
|
||||
#include "utils.h"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#ifndef MENU_H
|
||||
#define MENU_H
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#include "../const.h"
|
||||
#include "movingsprite.h"
|
||||
|
||||
// Constructor
|
||||
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, LTexture *texture, SDL_Renderer *renderer)
|
||||
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Copia los punteros
|
||||
this->texture = texture;
|
||||
@@ -51,11 +50,6 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vel
|
||||
currentFlip = SDL_FLIP_NONE;
|
||||
};
|
||||
|
||||
// Destructor
|
||||
MovingSprite::~MovingSprite()
|
||||
{
|
||||
}
|
||||
|
||||
// Reinicia todas las variables
|
||||
void MovingSprite::clear()
|
||||
{
|
||||
|
||||
@@ -35,10 +35,7 @@ protected:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr);
|
||||
|
||||
// Destructor
|
||||
~MovingSprite();
|
||||
MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr);
|
||||
|
||||
// Mueve el sprite
|
||||
void move();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#include "../const.h"
|
||||
#include "smartsprite.h"
|
||||
|
||||
// Constructor
|
||||
SmartSprite::SmartSprite(LTexture *texture, SDL_Renderer *renderer)
|
||||
SmartSprite::SmartSprite(Texture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Copia punteros
|
||||
setTexture(texture);
|
||||
@@ -12,11 +11,6 @@ SmartSprite::SmartSprite(LTexture *texture, SDL_Renderer *renderer)
|
||||
init();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
SmartSprite::~SmartSprite()
|
||||
{
|
||||
}
|
||||
|
||||
// Inicializa el objeto
|
||||
void SmartSprite::init()
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
class SmartSprite : public AnimatedSprite
|
||||
{
|
||||
private:
|
||||
// VAriables
|
||||
// Variables
|
||||
bool enabled; // Indica si esta habilitado
|
||||
bool onDestination; // Indica si está en el destino
|
||||
int destX; // Posicion de destino en el eje X
|
||||
@@ -28,10 +28,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
SmartSprite(LTexture *texture, SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~SmartSprite();
|
||||
SmartSprite(Texture *texture, SDL_Renderer *renderer);
|
||||
|
||||
// Inicializa el objeto
|
||||
void init();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "sprite.h"
|
||||
|
||||
// Constructor
|
||||
Sprite::Sprite(int x, int y, int w, int h, LTexture *texture, SDL_Renderer *renderer)
|
||||
Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Establece la posición X,Y del sprite
|
||||
this->x = x;
|
||||
@@ -24,7 +24,7 @@ Sprite::Sprite(int x, int y, int w, int h, LTexture *texture, SDL_Renderer *rend
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
Sprite::Sprite(SDL_Rect rect, LTexture *texture, SDL_Renderer *renderer)
|
||||
Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Establece la posición X,Y del sprite
|
||||
x = rect.x;
|
||||
@@ -137,13 +137,13 @@ void Sprite::setSpriteClip(int x, int y, int w, int h)
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
LTexture *Sprite::getTexture()
|
||||
Texture *Sprite::getTexture()
|
||||
{
|
||||
return texture;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setTexture(LTexture *texture)
|
||||
void Sprite::setTexture(Texture *texture)
|
||||
{
|
||||
this->texture = texture;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "ltexture.h"
|
||||
#include "texture.h"
|
||||
|
||||
#ifndef SPRITE_H
|
||||
#define SPRITE_H
|
||||
@@ -16,15 +16,15 @@ protected:
|
||||
int h; // Alto del sprite
|
||||
|
||||
SDL_Renderer *renderer; // Puntero al renderizador de la ventana
|
||||
LTexture *texture; // Textura donde estan todos los dibujos del sprite
|
||||
Texture *texture; // Textura donde estan todos los dibujos del sprite
|
||||
SDL_Rect spriteClip; // Rectangulo de origen de la textura que se dibujará en pantalla
|
||||
|
||||
bool enabled; // Indica si el sprite esta habilitado
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Sprite(int x = 0, int y = 0, int w = 0, int h = 0, LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr);
|
||||
Sprite(SDL_Rect rect, LTexture *texture, SDL_Renderer *renderer);
|
||||
Sprite(int x = 0, int y = 0, int w = 0, int h = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr);
|
||||
Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Sprite();
|
||||
@@ -69,10 +69,10 @@ public:
|
||||
void setSpriteClip(int x, int y, int w, int h);
|
||||
|
||||
// Obten el valor de la variable
|
||||
LTexture *getTexture();
|
||||
Texture *getTexture();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setTexture(LTexture *texture);
|
||||
void setTexture(Texture *texture);
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Renderer *getRenderer();
|
||||
|
||||
@@ -10,7 +10,7 @@ Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
|
||||
initOffsetFromFile(textFile);
|
||||
|
||||
// Crea los objetos
|
||||
texture = new LTexture(renderer, bitmapFile);
|
||||
texture = new Texture(renderer, bitmapFile);
|
||||
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ private:
|
||||
|
||||
// Objetos y punteros
|
||||
Sprite *sprite; // Objeto con los graficos para el texto
|
||||
LTexture *texture; // Textura con los bitmaps del texto
|
||||
Texture *texture; // Textura con los bitmaps del texto
|
||||
|
||||
// Variables
|
||||
int boxWidth; // Anchura de la caja de cada caracter en el png
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
#include "ltexture.h"
|
||||
#include "texture.h"
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
// Constructor
|
||||
LTexture::LTexture(SDL_Renderer *renderer, std::string path)
|
||||
Texture::Texture(SDL_Renderer *renderer, std::string path)
|
||||
{
|
||||
// Copia punteros
|
||||
this->renderer = renderer;
|
||||
@@ -23,14 +23,14 @@ LTexture::LTexture(SDL_Renderer *renderer, std::string path)
|
||||
}
|
||||
|
||||
// Destructor
|
||||
LTexture::~LTexture()
|
||||
Texture::~Texture()
|
||||
{
|
||||
// Libera memoria
|
||||
unload();
|
||||
}
|
||||
|
||||
// Carga una imagen desde un fichero
|
||||
bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
||||
bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
||||
{
|
||||
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
|
||||
int req_format = STBI_rgb_alpha;
|
||||
@@ -98,7 +98,7 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
||||
}
|
||||
|
||||
// Crea una textura en blanco
|
||||
bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess access)
|
||||
bool Texture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess access)
|
||||
{
|
||||
// Crea una textura sin inicializar
|
||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
||||
@@ -116,7 +116,7 @@ bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_Te
|
||||
}
|
||||
|
||||
// Libera la memoria de la textura
|
||||
void LTexture::unload()
|
||||
void Texture::unload()
|
||||
{
|
||||
// Libera la textura si existe
|
||||
if (texture != nullptr)
|
||||
@@ -129,25 +129,25 @@ void LTexture::unload()
|
||||
}
|
||||
|
||||
// Establece el color para la modulacion
|
||||
void LTexture::setColor(Uint8 red, Uint8 green, Uint8 blue)
|
||||
void Texture::setColor(Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
SDL_SetTextureColorMod(texture, red, green, blue);
|
||||
}
|
||||
|
||||
// Establece el blending
|
||||
void LTexture::setBlendMode(SDL_BlendMode blending)
|
||||
void Texture::setBlendMode(SDL_BlendMode blending)
|
||||
{
|
||||
SDL_SetTextureBlendMode(texture, blending);
|
||||
}
|
||||
|
||||
// Establece el alpha para la modulación
|
||||
void LTexture::setAlpha(Uint8 alpha)
|
||||
void Texture::setAlpha(Uint8 alpha)
|
||||
{
|
||||
SDL_SetTextureAlphaMod(texture, alpha);
|
||||
}
|
||||
|
||||
// Renderiza la textura en un punto específico
|
||||
void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
|
||||
void Texture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
|
||||
{
|
||||
// Establece el destino de renderizado en la pantalla
|
||||
SDL_Rect renderQuad = {x, y, width, height};
|
||||
@@ -167,25 +167,25 @@ void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, floa
|
||||
}
|
||||
|
||||
// Establece la textura como objetivo de renderizado
|
||||
void LTexture::setAsRenderTarget(SDL_Renderer *renderer)
|
||||
void Texture::setAsRenderTarget(SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_SetRenderTarget(renderer, texture);
|
||||
}
|
||||
|
||||
// Obtiene el ancho de la imagen
|
||||
int LTexture::getWidth()
|
||||
int Texture::getWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
// Obtiene el alto de la imagen
|
||||
int LTexture::getHeight()
|
||||
int Texture::getHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
// Recarga la textura
|
||||
bool LTexture::reLoad()
|
||||
bool Texture::reLoad()
|
||||
{
|
||||
return loadFromFile(path, renderer);
|
||||
}
|
||||
@@ -4,25 +4,27 @@
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#ifndef LTEXTURE_H
|
||||
#define LTEXTURE_H
|
||||
#ifndef TEXTURE_H
|
||||
#define TEXTURE_H
|
||||
|
||||
// Clase LTexture
|
||||
class LTexture
|
||||
class Texture
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Texture *texture; // La textura
|
||||
SDL_Renderer *renderer; // Renderizador donde dibujar la textura
|
||||
int width; // Ancho de la imagen
|
||||
int height; // Alto de la imagen
|
||||
std::string path; // Ruta de la imagen de la textura
|
||||
|
||||
// Variables
|
||||
int width; // Ancho de la imagen
|
||||
int height; // Alto de la imagen
|
||||
std::string path; // Ruta de la imagen de la textura
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
LTexture(SDL_Renderer *renderer, std::string path = "");
|
||||
Texture(SDL_Renderer *renderer, std::string path = "");
|
||||
|
||||
// Destructor
|
||||
~LTexture();
|
||||
~Texture();
|
||||
|
||||
// Carga una imagen desde un fichero
|
||||
bool loadFromFile(std::string path, SDL_Renderer *renderer);
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "ltexture.h"
|
||||
#include "texture.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "../const.h"
|
||||
#include "writer.h"
|
||||
|
||||
// Constructor
|
||||
@@ -22,11 +21,6 @@ Writer::Writer(Text *text)
|
||||
finished = false;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Writer::~Writer()
|
||||
{
|
||||
}
|
||||
|
||||
// Actualiza el objeto
|
||||
void Writer::update()
|
||||
{
|
||||
|
||||
@@ -32,9 +32,6 @@ public:
|
||||
// Constructor
|
||||
Writer(Text *text);
|
||||
|
||||
// Destructor
|
||||
~Writer();
|
||||
|
||||
// Actualiza el objeto
|
||||
void update();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user