This is the Game.cpp
[spoiler]
#include <iostream>
#include "Game.h"
using namespace std;
using namespace sf;
zombie::zombie():ventana(VideoMode(800, 600),"Game") {
}
int zombie::inicia(){
ventana.setFramerateLimit(60);
ventana.setKeyRepeatEnabled(true);
ventana.setVerticalSyncEnabled(true);
if (!hero_texture.loadFromFile("hero.png")){
return 1;
}
hero_texture.setSmooth(true);
hero_texture.setRepeated(true);
hero_sprite.setTexture(hero_texture);
hero_sprite.setPosition(400, 400);
if (!lalala.openFromFile("music.ogg")){
cout << "error" <<endl;
return -1;
}
lalala.setVolume(100);
}
void zombie::evento_i() {
//Eventos de la ventana
while(ventana.pollEvent(evento)){
if (evento.type == Event::Closed){
lel = false;
}
}
//Eventos del heroe
if(Keyboard::isKeyPressed(Keyboard::Up)){
UP = true;
}
if(Keyboard::isKeyPressed(Keyboard::Down)){
DOWN = true;
}
if(Keyboard::isKeyPressed(Keyboard::Left)){
LEFT = true;
}
if(Keyboard::isKeyPressed(Keyboard::Right)){
RIGHT = true;
}
if (Keyboard::isKeyPressed(Keyboard::S)){
SOUND = true;
}
}
void zombie::update() {
Vector2f movimiento_heroe(0.f,0.f);
float velocidad_heroe = 3.f;
if (UP){
movimiento_heroe.y-= 1.f * velocidad_heroe;
UP = false;
}
if (DOWN){
movimiento_heroe.y= 1.f * velocidad_heroe;
DOWN = false;
}
if (LEFT){
movimiento_heroe.x-= 1.f * velocidad_heroe;
LEFT = false;
}
if (RIGHT){
movimiento_heroe.x= 1.f * velocidad_heroe;
RIGHT = false;
}
hero_sprite.move(movimiento_heroe);
if(SOUND){
music.play();
}
}
void zombie::render() {
lalala.play();
ventana.clear(Color::Blue);
ventana.draw(hero_sprite);
ventana.display();
}
void zombie::clear(){
ventana.close();
}
void zombie::corre(){
inicia();
while(lel){
evento_i();
update();
render();
}
clear();
}
[/spoiler]
#ifndef GAME_H
#define GAME_H
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
using namespace sf;
class zombie {
private:
RenderWindow ventana;
Event evento;
sf::Music music;
bool isPLay =false;
bool lel = true;
int mouse_x,mouse_y;
Texture hero_texture ;
Sprite hero_sprite;
bool UP = false;
bool DOWN = false;
bool LEFT = false;
bool RIGHT = false;
float recept_veloc;
Music lalala;
bool SOUND = false;
private:
int inicia();
void evento_i();
void update();
void render();
void clear();
public:
zombie();
void corre();
};
#endif // GAME_H
The variables are in spanish xP
I'm using the tutorials of the SFML 2.1 page
I'm doing bad? xD