Ok, I think I've done well, But now I'm getting problems with compiling with my calling the functions, when I compile. I get:
f:\lester\cwp\lester\lester\main.cpp(63) : error C2065: 'Player' : undeclared identifier
f:\lester\cwp\lester\lester\main.cpp(63) : error C2228: left of '.setTexture' must have class/struct/union
type is ''unknown-type''
f:\lester\cwp\lester\lester\main.cpp(63) : error C2065: 'player_left' : undeclared identifier
f:\lester\cwp\lester\lester\main.cpp(64) : error C2065: 'Player' : undeclared identifier
f:\lester\cwp\lester\lester\main.cpp(64) : error C2228: left of '.move' must have class/struct/union
type is ''unknown-type''
f:\lester\cwp\lester\lester\main.cpp(68) : error C2065: 'Player' : undeclared identifier
f:\lester\cwp\lester\lester\main.cpp(68) : error C2228: left of '.setTexture' must have class/struct/union
type is ''unknown-type''
f:\lester\cwp\lester\lester\main.cpp(68) : error C2065: 'player_right' : undeclared identifier
f:\lester\cwp\lester\lester\main.cpp(69) : error C2065: 'Player' : undeclared identifier
f:\lester\cwp\lester\lester\main.cpp(69) : error C2228: left of '.move' must have class/struct/union
type is ''unknown-type''
f:\lester\cwp\lester\lester\main.cpp(73) : error C2065: 'Player' : undeclared identifier
f:\lester\cwp\lester\lester\main.cpp(73) : error C2228: left of '.setTexture' must have class/struct/union
type is ''unknown-type''
f:\lester\cwp\lester\lester\main.cpp(73) : error C2065: 'player_up' : undeclared identifier
f:\lester\cwp\lester\lester\main.cpp(74) : error C2065: 'Player' : undeclared identifier
f:\lester\cwp\lester\lester\main.cpp(74) : error C2228: left of '.move' must have class/struct/union
type is ''unknown-type''
f:\lester\cwp\lester\lester\main.cpp(78) : error C2065: 'Player' : undeclared identifier
f:\lester\cwp\lester\lester\main.cpp(78) : error C2228: left of '.setTexture' must have class/struct/union
type is ''unknown-type''
f:\lester\cwp\lester\lester\main.cpp(78) : error C2065: 'player_down' : undeclared identifier
f:\lester\cwp\lester\lester\main.cpp(79) : error C2065: 'Player' : undeclared identifier
f:\lester\cwp\lester\lester\main.cpp(79) : error C2228: left of '.move' must have class/struct/union
type is ''unknown-type''
f:\lester\cwp\lester\lester\main.cpp(89) : error C2065: 'window' : undeclared identifier
f:\lester\cwp\lester\lester\main.cpp(89) : error C2228: left of '.isOpen' must have class/struct/union
My Code Is:
#include <SFML/Graphics.hpp>
void viewControls()
{
sf::RenderWindow window(sf::VideoMode(800, 450), "Lester");
sf::View gameView;
gameView.reset(sf::FloatRect(200, 200, 300, 200));
sf::View minimapView;
minimapView.setCenter(sf::Vector2f(350, 300));
minimapView.setSize(sf::Vector2f(200, 200));
gameView.setViewport(sf::FloatRect(0, 0, 1, 1));
minimapView.setViewport(sf::FloatRect(0.75f, 0, 0.25f, 0.25f));
}
void gametextures()
{
//Game Textures
sf::Texture grass;
sf::Texture stone;
sf::Texture flower_Yellow;
sf::Texture flower_Red;
sf::Texture sand;
//Player Textures
sf::Texture player_left;
sf::Texture player_right;
sf::Texture player_down;
sf::Texture player_up;
//Load All Textures
grass.loadFromFile("grass.png");
stone.loadFromFile("stone.png");
flower_Yellow.loadFromFile("flower_yellow.png");
sand.loadFromFile("sand.png");
//Player Load
player_up.loadFromFile("char_u.png");
player_right.loadFromFile("char_r.png");
player_left.loadFromFile("char_l.png");
player_down.loadFromFile("char_d.png");
//Set Textures to a Sprite
sf::Sprite Grass(grass);
sf::Sprite Stone(stone);
sf::Sprite FlowerY(flower_Yellow);
sf::Sprite Sand(sand);
//Set Player Sprite
sf::Sprite Player(player_up);
}
void playermovement(){
gametextures();
float playerSpeed = 2.0f;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
Player.setTexture(player_left);
Player.move(playerSpeed - 0.1, 0);
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
Player.setTexture(player_right);
Player.move(playerSpeed + 0.1, 0);
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
Player.setTexture(player_up);
Player.move(0, playerSpeed - 0.1);
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
Player.setTexture(player_down);
Player.move(0, playerSpeed + 0.1);
}
}
int main()
{
viewControls();
gametextures();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
playermovement();
window.clear(sf::Color::Black);
window.draw(Player);
window.display();
}
return 0;
}
If you could spot anything that I have done wrong, please tell me.
Thanks