Professional Documents
Culture Documents
WARS
resources
textura _fondo
rect
rect
_bazooka rect
resources.rc
#include <iostream>
#include<SDL.h>
#include"window.h"
#include"rect.h"
#include"text.h"
#include<Windows.h>
#include<Mmsystem.h>
#include "window.h"
#include<SDL_image.h>
#include<iostream>
#include<SDL_ttf.h>
SDL_Renderer*window::_renderer=nullptr;
window::window(const std::string &title, int _width, int _height):
_title(title),_width(_width), _height(_height)
{
_closed = !init();
}
window::~window()
{
SDL_DestroyRenderer(_renderer);
SDL_DestroyWindow(_window);
TTF_Quit();
IMG_Quit();
SDL_Quit();
bool window::init()
{
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
{
std::cerr << "ERROR AL INICIAR SDL\n";
return false;
}
if (IMG_Init(IMG_INIT_PNG) != IMG_INIT_PNG)
{
std::cerr<<"FALLO AL INICIAR LAS TEXTURAS DESDE IMAGEN.\n";
return false;
}
if (TTF_Init() == -1)
{
std::cerr << "FALLO AL INICIAR LAS TTF.\n";
return false;
}
_window = SDL_CreateWindow(
_title.c_str(),
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
_width, _height,
0
);
if (_window == nullptr)
{
std::cerr << "FALLO AL CREAR LA VENTANA.\n";
return false;
}
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
{
_closed = true;
break;
}
default:
{
break;
}
}
}
}
#include<string>
#include<SDL.h>
class window {
public:
window(const std::string &title, int _width, int _height);
~window();
void pollEvents(SDL_Event &event);
void clear()const;
inline bool isClosed() const { return _closed; }
private:
bool init();
private:
std::string _title;
int _width=800;
int _height=600;
public:
static SDL_Renderer*_renderer;
};
#pragma once
#include"window.h"
class rect{
public:
rect( int w, int h, int x, int y, int r, int g, int b, int a);
rect(int w, int h, int x, int y, const std::string &image_path);
~rect();
void draw()const;
void pollEvents(SDL_Event &event);
private:
int _w, _h;
int _x, _y;
int _r, _g, _b, _a;
SDL_Texture*_bazooka_texture = nullptr;
};
#include"rect.h"
#include<SDL_image.h>
#include<iostream>
#include<Windows.h>
#include<Mmsystem.h>
#pragma comment(lib, "Winmm.lib"
PlaySound(TEXT("E:\\ORDENADOR TORRE\\UNIVERSIDAD\\3º\\INFORMÁTICA
INDUSTRIAL\\TRABAJO\\TRABAJO\\TEXTURES_PROJECT\\TEXTURES_C++\\TEXTURES_C++\\res\\SOUND\\EFFECTS\\WALKING.wav"), NULL, SND_FILENAME | SND_ASYNC);
_x = _x - 50;
break;
case (SDLK_RIGHT):
PlaySound(TEXT("E:\\ORDENADOR TORRE\\UNIVERSIDAD\\3º\\INFORMÁTICA
INDUSTRIAL\\TRABAJO\\TRABAJO\\TEXTURES_PROJECT\\TEXTURES_C++\\TEXTURES_C++\\res\\SOUND\\EFFECTS\\WALKING.wav"), NULL, SND_FILENAME | SND_ASYNC);
_x = _x + 50;
break;
case (SDLK_UP):
PlaySound(TEXT("E:\\ORDENADOR TORRE\\UNIVERSIDAD\\3º\\INFORMÁTICA
INDUSTRIAL\\TRABAJO\\TRABAJO\\TEXTURES_PROJECT\\TEXTURES_C++\\TEXTURES_C++\\res\\SOUND\\EFFECTS\\WALKING.wav"), NULL, SND_FILENAME | SND_ASYNC);
_y = _y - 50;
break;
case (SDLK_DOWN):
PlaySound(TEXT("E:\\ORDENADOR TORRE\\UNIVERSIDAD\\3º\\INFORMÁTICA
INDUSTRIAL\\TRABAJO\\TRABAJO\\TEXTURES_PROJECT\\TEXTURES_C++\\TEXTURES_C++\\res\\SOUND\\EFFECTS\\WALKING.wav"), NULL, SND_FILENAME | SND_ASYNC);
_y = _y + 50;
break;
case(SDLK_ESCAPE):
break;
}
}
if (event.type == SDL_MOUSEMOTION)
{
_x = event.motion.x;
_y = event.motion.y;
if (event.type == SDL_KEYDOWN)
{
switch (event.key.keysym.sym)
{
case SDL_MOUSEBUTTONDOWN:
{
_x = _x;
_y = _y;
break;
}
default:
break;
}
}
}
}
#include"text.h"
#include<iostream>
#include"window.h"
text::text(SDL_Renderer *_renderer, const std::string &font_path,
int font_size,
const std::string &message_text,
const SDL_Color &color)
{
text_texture = loadFont(_renderer,font_path, font_size, message_text, color);
SDL_QueryTexture(text_texture, nullptr, nullptr,&_text_rect.w, &_text_rect.h);
}
SDL_Texture *text::loadFont(SDL_Renderer *_renderer,const std::string &font_path, int font_size, const std::string &message_text, const SDL_Color
&color)
{
TTF_Font *font = TTF_OpenFont(font_path.c_str(), font_size);
if (!font)
{
std::cerr << "FALLO AL CARGAR FUENTE.\n";
}
auto text_surface = TTF_RenderText_Solid(font, message_text.c_str(),color);
if (!text_surface)
{
std::cerr << "FALLO AL CREAR SUPERFICIE PARA FUENTE.\n";
}
auto text_texture = SDL_CreateTextureFromSurface(_renderer, text_surface);
if (!text_texture)
{
std::cerr << "FALLO AL CREAR TEXTURA.\n";
}
SDL_FreeSurface(text_surface);
return text_texture;
}
#pragma once
#include<SDL_ttf.h>
#include<SDL.h>
#include<string>
class text
{
public:
text(SDL_Renderer *_renderer, const std::string &font_path, int font_size, const std::string &message_text, const SDL_Color &color);
void display(int x, int y, SDL_Renderer *_renderer)const;
static SDL_Texture *loadFont(SDL_Renderer *_renderer, const std::string &font_path, int font_size, const std::string &message_text,
const SDL_Color &color);
private:
SDL_Texture*text_texture = nullptr;
mutable SDL_Rect _text_rect;
};