ja pinta el logo en tamany 1:1
moguda la logica del main a la classe Logo
This commit is contained in:
BIN
jailgames.gif
BIN
jailgames.gif
Binary file not shown.
|
Before Width: | Height: | Size: 478 B After Width: | Height: | Size: 98 B |
78
source/logo.cpp
Normal file
78
source/logo.cpp
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
#include "logo.h"
|
||||||
|
|
||||||
|
#include "screen.h"
|
||||||
|
#include "mouse.h"
|
||||||
|
#include "surface.h"
|
||||||
|
#include "s_sprite.h"
|
||||||
|
|
||||||
|
Logo::Logo()
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
Logo::~Logo()
|
||||||
|
{
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logo::init()
|
||||||
|
{
|
||||||
|
Screen::get()->init();
|
||||||
|
logo_surface = std::make_shared<Surface>("jailgames.gif");
|
||||||
|
logo_sprite = std::make_unique<SSprite>(logo_surface);
|
||||||
|
logo_sprite->setPosition(
|
||||||
|
(options.game.width - logo_sprite->getWidth()) / 2,
|
||||||
|
(options.game.height- logo_sprite->getHeight()) / 2);
|
||||||
|
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Logo start");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logo::close()
|
||||||
|
{
|
||||||
|
Screen::get()->destroy();
|
||||||
|
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nBye!");
|
||||||
|
SDL_Quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logo::checkEvents()
|
||||||
|
{
|
||||||
|
SDL_Event event;
|
||||||
|
while (SDL_PollEvent(&event))
|
||||||
|
{
|
||||||
|
switch (event.type)
|
||||||
|
{
|
||||||
|
case SDL_EVENT_QUIT:
|
||||||
|
running = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mouse::handleEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logo::update()
|
||||||
|
{
|
||||||
|
if (SDL_GetTicks() - ticks > options.game.speed)
|
||||||
|
{
|
||||||
|
ticks = SDL_GetTicks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logo::render()
|
||||||
|
{
|
||||||
|
Screen::get()->start();
|
||||||
|
logo_sprite->render();
|
||||||
|
Screen::get()->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Logo::run()
|
||||||
|
{
|
||||||
|
while (running)
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
checkEvents();
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
27
source/logo.h
Normal file
27
source/logo.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
#include <memory>
|
||||||
|
#include "surface.h"
|
||||||
|
#include "s_sprite.h"
|
||||||
|
|
||||||
|
class Logo
|
||||||
|
{
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool running = true;
|
||||||
|
Uint64 ticks = 0;
|
||||||
|
std::shared_ptr<Surface> logo_surface = nullptr;
|
||||||
|
std::unique_ptr<SSprite> logo_sprite = nullptr;
|
||||||
|
|
||||||
|
void init();
|
||||||
|
void close();
|
||||||
|
void checkEvents();
|
||||||
|
void update();
|
||||||
|
void render();
|
||||||
|
|
||||||
|
public:
|
||||||
|
Logo();
|
||||||
|
~Logo();
|
||||||
|
int run();
|
||||||
|
};
|
||||||
@@ -1,75 +1,12 @@
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "screen.h"
|
#include "logo.h"
|
||||||
#include "mouse.h"
|
|
||||||
#include "surface.h"
|
|
||||||
#include "s_sprite.h"
|
|
||||||
|
|
||||||
bool running = true;
|
|
||||||
Uint64 ticks = 0;
|
|
||||||
std::shared_ptr<Surface> logo_surface = nullptr;
|
|
||||||
std::unique_ptr<SSprite> logo_sprite = nullptr;
|
|
||||||
|
|
||||||
void init()
|
|
||||||
{
|
|
||||||
Screen::get()->init();
|
|
||||||
logo_surface = std::make_shared<Surface>("jailgames.gif");
|
|
||||||
logo_sprite = std::make_unique<SSprite>(logo_surface);
|
|
||||||
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Logo start");
|
|
||||||
}
|
|
||||||
|
|
||||||
void close()
|
|
||||||
{
|
|
||||||
Screen::get()->destroy();
|
|
||||||
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nBye!");
|
|
||||||
SDL_Quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
void checkEvents()
|
|
||||||
{
|
|
||||||
SDL_Event event;
|
|
||||||
while (SDL_PollEvent(&event))
|
|
||||||
{
|
|
||||||
switch (event.type)
|
|
||||||
{
|
|
||||||
case SDL_EVENT_QUIT:
|
|
||||||
running = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Mouse::handleEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void update()
|
|
||||||
{
|
|
||||||
if (SDL_GetTicks() - ticks > options.game.speed)
|
|
||||||
{
|
|
||||||
ticks = SDL_GetTicks();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void render()
|
|
||||||
{
|
|
||||||
Screen::get()->start();
|
|
||||||
|
|
||||||
logo_sprite->render();
|
|
||||||
|
|
||||||
Screen::get()->render();
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
init();
|
// Crea el objeto Logo
|
||||||
|
auto logo = std::make_unique<Logo>();
|
||||||
|
|
||||||
while (running)
|
// Bucle principal
|
||||||
{
|
return logo->run();
|
||||||
update();
|
|
||||||
checkEvents();
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
|
|
||||||
close();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ Screen::Screen()
|
|||||||
std::cerr << "Error: game_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
std::cerr << "Error: game_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SDL_SetTextureScaleMode(game_texture_, options.video.scale_mode);
|
||||||
|
|
||||||
// Crea la surface donde se dibujan los graficos del juego
|
// Crea la surface donde se dibujan los graficos del juego
|
||||||
game_surface_ = std::make_shared<Surface>(options.game.width, options.game.height);
|
game_surface_ = std::make_shared<Surface>(options.game.width, options.game.height);
|
||||||
|
|||||||
@@ -494,7 +494,7 @@ void Surface::copyToTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||||||
int pitch = 0;
|
int pitch = 0;
|
||||||
|
|
||||||
// Bloquea la textura para modificar los píxeles directamente
|
// Bloquea la textura para modificar los píxeles directamente
|
||||||
if (SDL_LockTexture(texture, nullptr, reinterpret_cast<void **>(&pixels), &pitch) != 0)
|
if (!SDL_LockTexture(texture, nullptr, reinterpret_cast<void **>(&pixels), &pitch))
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Failed to lock texture: " + std::string(SDL_GetError()));
|
throw std::runtime_error("Failed to lock texture: " + std::string(SDL_GetError()));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user