1
Graphics / Re: Strange Title Bar Text
« on: April 07, 2012, 10:41:28 pm »
*facepalm*, that fixed it, thanks to both of you!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
App(sf::VideoMode(ScreenWidth, ScreenHeight, 32),
std::string("Snake"), sf::Style::Close),
App(sf::VideoMode(ScreenWidth, ScreenHeight, 32), std::string(), sf::Style::Close)
For some reason the titlebar text looks like this: http://imageshack.us/photo/my-images/11/photour.png/#define LASTNODE nodes[nodes.size()-1]
Snake::Node *Snake::AddNode()
{
Node *NewNode;
switch (LASTNODE->GetDirection()) {
case Node::LEFT:
// 10 is the width and height of each node, I'm just currently too lazy to replace it
// with a const
NewNode = new Node(LASTNODE->GetShape().GetPosition().x+10,
LASTNODE->GetShape().GetPosition().y,
LASTNODE->GetShape().GetPosition().x+20,
LASTNODE->GetShape().GetPosition().y+10);
nodes.push_back(NewNode);
NewNode->SetDirection(Node::LEFT);
break;
case Node::RIGHT:
NewNode = new Node(LASTNODE->GetShape().GetPosition().x-10,
LASTNODE->GetShape().GetPosition().y,
LASTNODE->GetShape().GetPosition().x-20,
LASTNODE->GetShape().GetPosition().y-10);
nodes.push_back(NewNode);
NewNode->SetDirection(Node::RIGHT);
break;
case Node::UP:
NewNode = new Node(LASTNODE->GetShape().GetPosition().x,
LASTNODE->GetShape().GetPosition().y+10,
LASTNODE->GetShape().GetPosition().x+10,
LASTNODE->GetShape().GetPosition().y+20);
nodes.push_back(NewNode);
NewNode->SetDirection(Node::UP);
break;
case Node::DOWN:
NewNode = new Node(LASTNODE->GetShape().GetPosition().x,
LASTNODE->GetShape().GetPosition().y-10,
LASTNODE->GetShape().GetPosition().x+10,
LASTNODE->GetShape().GetPosition().y-20);
nodes.push_back(NewNode);
NewNode->SetDirection(Node::DOWN);
break;
}
return NewNode;
}
Node Constructor:Snake::Node::Node(float x1, float y1, float x2, float y2)
: shape(sf::Shape::Rectangle(x1, y1, x2, y2, sf::Color(100, 100, 100)))
{ }
Node Interface (which is nested in the Snake class) class Node {
public:
enum Direction { LEFT, RIGHT, UP, DOWN };
Node(float, float, float, float); // constructor
void Update(sf::RenderWindow &App, sf::Event &Event);
Direction GetDirection() const { return direction; }
sf::Shape &GetShape() const { return shape; }
void SetDirection(Node::Direction direc) { direction = direc; }
private:
sf::Shape shape;
void Move(float ElapsedTime);
// Direction
Direction direction;
void Direction(sf::RenderWindow&, sf::Event&);
};
enum Direction { left, right, up, down };
class CMove
{
public:
CMove(sf::Shape& obj)
: object(&obj)
{ }
void WalkLeft() // walk left
{
dir = left;
Walk(dir);
}
void WalkRight() // walk right
{
dir = right;
Walk(dir);
}
void WalkUp() // walk up
{
dir = up;
Walk(dir);
}
void WalkDown() // walk down
{
dir = down;
Walk(dir);
}
private:
Direction dir; // the direction to move in
sf::Shape* object; // pointer to the object to move
void Walk(Direction dir) const; // move the object
};
// move the player in the direction specified in dir
void CMove::Walk(Direction dir) const
{
switch(dir)
{
case left:
object->Move(-5, 0);
case right:
object->Move(5, 0);
case up:
object->Move(0, -5);
case down:
object->Move(0, 5);
}
return;
}
#include<SFML/Graphics.hpp>
#include<iostream>
#include "Move.h"
void handleMovement(const sf::Input& Input, CMove* Move) // handle movement of player
{
bool leftKey = Input.IsKeyDown(sf::Key::Left);
bool rightKey = Input.IsKeyDown( sf::Key::Right);
bool upKey = Input.IsKeyDown(sf::Key::Up);
bool downKey = Input.IsKeyDown(sf::Key::Down);
if(leftKey)
Move->WalkLeft();
if(rightKey)
Move->WalkRight();
if(upKey)
Move->WalkUp();
if(downKey)
Move->WalkDown();
}
int main(void)
{
sf::RenderWindow App(sf::VideoMode(800, 640, 32), "SFML Window");
App.SetFramerateLimit(60);
sf::Shape rect = sf::Shape::Rectangle(300, 300, 350, 350, sf::Color(200, 200, 200));
CMove Move(rect);
CMove* pMove = &Move;
while(App.IsOpened())
{
sf::Event Event;
const sf::Input& Input = App.GetInput();
while(App.GetEvent(Event))
{
// handle movement
handleMovement(Input, pMove);
if(Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear();
App.Draw(rect);
App.Display();
}
return EXIT_SUCCESS;
}
#include<SFML/Graphics.hpp>
#include<iostream>
#include "Move.h"
void handleMovement(sf::Shape& object, const sf::Input& Input)
{
CMove Move(object);
bool leftKey = Input.IsKeyDown(sf::Key::Left);
bool rightKey = Input.IsKeyDown( sf::Key::Right);
bool upKey = Input.IsKeyDown(sf::Key::Up);
bool downKey = Input.IsKeyDown(sf::Key::Down);
if(leftKey)
Move.WalkLeft();
if(rightKey)
Move.WalkRight();
if(upKey)
Move.WalkUp();
if(downKey)
Move.WalkDown();
}
int main(void)
{
sf::RenderWindow App(sf::VideoMode(800, 640, 32), "SFML Window");
App.SetFramerateLimit(60);
sf::Shape rect = sf::Shape::Rectangle(300, 300, 350, 350, sf::Color(200, 200, 200));
while(App.IsOpened())
{
sf::Event Event;
const sf::Input& Input = App.GetInput();
while(App.GetEvent(Event))
{
// handle movement
handleMovement(rect, Input);
if(Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear();
App.Draw(rect);
App.Display();
}
return EXIT_SUCCESS;
}
#pragma once
#include<SFML/Graphics.hpp>
enum Direction { up, down, left, right };
class CMove
{
public:
CMove(sf::Shape& obj)
: object(&obj)
{ }
void WalkLeft() // walk left
{
dir = left;
Walk(dir);
}
void WalkRight() // walk right
{
dir = right;
Walk(dir);
}
void WalkUp() // walk up
{
dir = up;
Walk(dir);
}
void WalkDown() // walk down
{
dir = down;
Walk(dir);
}
private:
Direction dir; // the direction to move in
sf::Shape* object; // pointer to the object to move
void Walk(Direction Dir) const; // move the object
};
// move the player in the direction specified in dir
void CMove::Walk(Direction dir) const
{
switch(dir)
{
case up:
object->Move(0, -2);
case down:
object->Move(0, 2);
case left:
object->Move(2, 0);
case right:
object->Move(-2, 0);
}
return;
}