Compare commits
4 Commits
7dbddd5524
...
2ec242b2c9
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ec242b2c9 | |||
| d993a6def4 | |||
| 5913d7548a | |||
| 84f3952232 |
BIN
data/gfx/controllers/controllers.png
Normal file
BIN
data/gfx/controllers/controllers.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -1,7 +1,7 @@
|
|||||||
#include "bullet.h"
|
#include "bullet.h"
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include <memory> // for std::unique_ptr
|
#include <memory> // for std::unique_ptr
|
||||||
|
|
||||||
// Constantes evaluables en tiempo de compilación
|
// Constantes evaluables en tiempo de compilación
|
||||||
constexpr int BULLET_WIDTH = 12;
|
constexpr int BULLET_WIDTH = 12;
|
||||||
@@ -11,12 +11,13 @@ constexpr int BULLET_VELX_LEFT = -2;
|
|||||||
constexpr int BULLET_VELX_RIGHT = 2;
|
constexpr int BULLET_VELX_RIGHT = 2;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Bullet::Bullet(int x, int y, BulletType kind, bool poweredUp, int owner, SDL_Rect* playArea, Texture* texture)
|
Bullet::Bullet(int x, int y, BulletType kind, bool poweredUp, int owner, SDL_Rect *playArea, Texture *texture)
|
||||||
: posX(x), posY(y), width(BULLET_WIDTH), height(BULLET_HEIGHT), velX(0), velY(BULLET_VELY),
|
: posX(x), posY(y), width(BULLET_WIDTH), height(BULLET_HEIGHT), velX(0), velY(BULLET_VELY),
|
||||||
kind(kind), owner(owner), playArea(playArea),
|
kind(kind), owner(owner), playArea(playArea),
|
||||||
sprite(std::unique_ptr<Sprite>(new Sprite(SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT}, texture))) // Crear manualmente el std::unique_ptr
|
sprite(std::unique_ptr<Sprite>(new Sprite(SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT}, texture))) // Crear manualmente el std::unique_ptr
|
||||||
{
|
{
|
||||||
velX = (kind == BulletType::LEFT) ? BULLET_VELX_LEFT : (kind == BulletType::RIGHT) ? BULLET_VELX_RIGHT : 0;
|
velX = (kind == BulletType::LEFT) ? BULLET_VELX_LEFT : (kind == BulletType::RIGHT) ? BULLET_VELX_RIGHT
|
||||||
|
: 0;
|
||||||
|
|
||||||
auto spriteOffset = poweredUp ? 3 : 0;
|
auto spriteOffset = poweredUp ? 3 : 0;
|
||||||
auto kindIndex = static_cast<int>(kind);
|
auto kindIndex = static_cast<int>(kind);
|
||||||
@@ -27,20 +28,24 @@ Bullet::Bullet(int x, int y, BulletType kind, bool poweredUp, int owner, SDL_Rec
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Implementación de render (llama al render del sprite)
|
// Implementación de render (llama al render del sprite)
|
||||||
void Bullet::render() {
|
void Bullet::render()
|
||||||
|
{
|
||||||
sprite->render();
|
sprite->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementación del movimiento usando BulletMoveStatus
|
// Implementación del movimiento usando BulletMoveStatus
|
||||||
BulletMoveStatus Bullet::move() {
|
BulletMoveStatus Bullet::move()
|
||||||
|
{
|
||||||
posX += velX;
|
posX += velX;
|
||||||
if (posX < param.game.playArea.rect.x - width || posX > playArea->w) {
|
if (posX < param.game.playArea.rect.x - width || posX > playArea->w)
|
||||||
|
{
|
||||||
disable();
|
disable();
|
||||||
return BulletMoveStatus::OUT;
|
return BulletMoveStatus::OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
posY += velY;
|
posY += velY;
|
||||||
if (posY < param.game.playArea.rect.y - height) {
|
if (posY < param.game.playArea.rect.y - height)
|
||||||
|
{
|
||||||
disable();
|
disable();
|
||||||
return BulletMoveStatus::OUT;
|
return BulletMoveStatus::OUT;
|
||||||
}
|
}
|
||||||
@@ -52,47 +57,58 @@ BulletMoveStatus Bullet::move() {
|
|||||||
return BulletMoveStatus::OK;
|
return BulletMoveStatus::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Bullet::isEnabled() const {
|
bool Bullet::isEnabled() const
|
||||||
|
{
|
||||||
return kind != BulletType::NULL_TYPE;
|
return kind != BulletType::NULL_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bullet::disable() {
|
void Bullet::disable()
|
||||||
|
{
|
||||||
kind = BulletType::NULL_TYPE;
|
kind = BulletType::NULL_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Bullet::getPosX() const {
|
int Bullet::getPosX() const
|
||||||
|
{
|
||||||
return posX;
|
return posX;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Bullet::getPosY() const {
|
int Bullet::getPosY() const
|
||||||
|
{
|
||||||
return posY;
|
return posY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bullet::setPosX(int x) {
|
void Bullet::setPosX(int x)
|
||||||
|
{
|
||||||
posX = x;
|
posX = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bullet::setPosY(int y) {
|
void Bullet::setPosY(int y)
|
||||||
|
{
|
||||||
posY = y;
|
posY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Bullet::getVelY() const {
|
int Bullet::getVelY() const
|
||||||
|
{
|
||||||
return velY;
|
return velY;
|
||||||
}
|
}
|
||||||
|
|
||||||
BulletType Bullet::getKind() const {
|
BulletType Bullet::getKind() const
|
||||||
|
{
|
||||||
return kind;
|
return kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Bullet::getOwner() const {
|
int Bullet::getOwner() const
|
||||||
|
{
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
circle_t& Bullet::getCollider() {
|
circle_t &Bullet::getCollider()
|
||||||
|
{
|
||||||
return collider;
|
return collider;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bullet::shiftColliders() {
|
void Bullet::shiftColliders()
|
||||||
|
{
|
||||||
collider.x = posX + collider.r;
|
collider.x = posX + collider.r;
|
||||||
collider.y = posY + collider.r;
|
collider.y = posY + collider.r;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound
|
#include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound
|
||||||
#include "logo.h" // for Logo
|
#include "logo.h" // for Logo
|
||||||
#include "manage_hiscore_table.h" // for ManageHiScoreTable
|
#include "manage_hiscore_table.h" // for ManageHiScoreTable
|
||||||
|
#include "on_screen_help.h" // for OnScreenHelp
|
||||||
#include "options.h" // for options, loadOptionsFile, saveO...
|
#include "options.h" // for options, loadOptionsFile, saveO...
|
||||||
#include "param.h" // for param, loadParamsFromFile
|
#include "param.h" // for param, loadParamsFromFile
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
@@ -34,7 +35,7 @@
|
|||||||
#include "utils.h" // for music_file_t, sound_file_t, opt...
|
#include "utils.h" // for music_file_t, sound_file_t, opt...
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <pwd.h> // for getpwuid, passwd
|
#include <pwd.h> // for getpwuid, passwd
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -101,6 +102,8 @@ Director::Director(int argc, char *argv[])
|
|||||||
Screen::init(window, renderer);
|
Screen::init(window, renderer);
|
||||||
screen = Screen::get();
|
screen = Screen::get();
|
||||||
|
|
||||||
|
OnScreenHelp::init();
|
||||||
|
|
||||||
// Carga los sonidos del juego
|
// Carga los sonidos del juego
|
||||||
loadSounds();
|
loadSounds();
|
||||||
|
|
||||||
@@ -115,6 +118,7 @@ Director::~Director()
|
|||||||
Asset::destroy();
|
Asset::destroy();
|
||||||
Input::destroy();
|
Input::destroy();
|
||||||
Screen::destroy();
|
Screen::destroy();
|
||||||
|
OnScreenHelp::destroy();
|
||||||
|
|
||||||
deleteSounds();
|
deleteSounds();
|
||||||
deleteMusics();
|
deleteMusics();
|
||||||
|
|||||||
@@ -789,7 +789,7 @@ void Game::deployEnemyFormation()
|
|||||||
createPowerBall();
|
createPowerBall();
|
||||||
|
|
||||||
// Da un poco de margen para que se creen mas enemigos
|
// Da un poco de margen para que se creen mas enemigos
|
||||||
enemyDeployCounter = 50;
|
enemyDeployCounter = 300;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -2642,11 +2642,6 @@ void Game::checkEvents()
|
|||||||
{
|
{
|
||||||
switch (eventHandler->key.keysym.sym)
|
switch (eventHandler->key.keysym.sym)
|
||||||
{
|
{
|
||||||
// CREA UN SPRITE DE 1000 PUNTOS
|
|
||||||
case SDLK_h:
|
|
||||||
createItemScoreSprite(param.game.width / 2, param.game.width / 2, n1000Sprite);
|
|
||||||
break;
|
|
||||||
|
|
||||||
// CREA UNA POWERBALL
|
// CREA UNA POWERBALL
|
||||||
case SDLK_1:
|
case SDLK_1:
|
||||||
createPowerBall();
|
createPowerBall();
|
||||||
|
|||||||
32
source/on_screen_help.cpp
Normal file
32
source/on_screen_help.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include "on_screen_help.h"
|
||||||
|
|
||||||
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
|
OnScreenHelp *OnScreenHelp::onScreenHelp = nullptr;
|
||||||
|
|
||||||
|
// [SINGLETON] Crearemos el objeto onScreenHelp con esta función estática
|
||||||
|
void OnScreenHelp::init()
|
||||||
|
{
|
||||||
|
OnScreenHelp::onScreenHelp = new OnScreenHelp();
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto onScreenHelp con esta función estática
|
||||||
|
void OnScreenHelp::destroy()
|
||||||
|
{
|
||||||
|
delete OnScreenHelp::onScreenHelp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto onScreenHelp y podemos trabajar con él
|
||||||
|
OnScreenHelp *OnScreenHelp::get()
|
||||||
|
{
|
||||||
|
return OnScreenHelp::onScreenHelp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
OnScreenHelp::OnScreenHelp()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
OnScreenHelp::~OnScreenHelp()
|
||||||
|
{
|
||||||
|
}
|
||||||
48
source/on_screen_help.h
Normal file
48
source/on_screen_help.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
class Screen;
|
||||||
|
class Asset;
|
||||||
|
class Input;
|
||||||
|
class Texture;
|
||||||
|
class Sprite;
|
||||||
|
|
||||||
|
enum class OnScreenHelpStatus
|
||||||
|
{
|
||||||
|
hidden,
|
||||||
|
showing,
|
||||||
|
entering,
|
||||||
|
exitting,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Classe on_screen_help
|
||||||
|
class OnScreenHelp
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// [SINGLETON] Objeto screen privado para Don Melitón
|
||||||
|
static OnScreenHelp *onScreenHelp;
|
||||||
|
|
||||||
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
|
Asset *asset; // Objeto con los ficheros de recursos
|
||||||
|
Input *input; // Objeto pata gestionar la entrada
|
||||||
|
|
||||||
|
SDL_Texture *texture; // Textura donde dibujar
|
||||||
|
|
||||||
|
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos screen desde fuera
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
OnScreenHelp();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~OnScreenHelp();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||||
|
static void init();
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||||
|
static void destroy();
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
||||||
|
static OnScreenHelp *get();
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user