16
General discussions / Re: SFML 2.0 RC
« on: May 03, 2012, 12:31:48 am »
Actually i found that to be true too...that exact line of code seemed to slow down my computer
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.
#include "Manager.h"
#include "engine.h"
Manager cManager;
void Manager::Update()
{
this -> iter = this -> entities.begin();
Object object;
while (this -> iter != this -> entities.end())
{
object = *iter;
cEngine.cWindow.Draw(object.Sprite);
iter++;
}
}
void Manager::Add(Object object)
{
this -> entities.push_back(object);
}
#include "Game.h"
#include "Manager.h"
#include "engine.h"
Game cGame;
void Game::Game_Init()
{
Character player;
player.Create("ball.bmp", 200, 200, 45, 45);
cManager.Add(player);
}
void Game::Game_Run()
{
cEngine.cWindow.Clear();
cManager.Update();
cEngine.cWindow.Display();
}
#include "Object.h"
#include "engine.h"
int Character::Create(std::string filename, float x, float y, int width, int height)
{
if (!this -> Image.LoadFromFile(filename.c_str()))
{
return 0;
}
this -> Image.CreateMaskFromColor(sf::Color(255, 0, 255));
this -> Sprite.SetImage(this -> Image);
this -> Sprite.Resize(width, height);
this -> Sprite.SetPosition(x, y);
this -> PosX = this -> Sprite.GetPosition().x;
this -> PosY = this -> Sprite.GetPosition().y;
this -> Rect.Left = this -> PosX;
this -> Rect.Top = this -> PosY;
this -> Rect.Width = width;
this -> Rect.Height = height;
return 1;
}
#include "EntityManager.h"
void System::Init()
{
engine = new System();
engine -> SetWindow(800, 600, "Test");
Entity player;
player.Load("test.png", 100, 100);
manager.Add(player);
}
void System::Run()
{
sf::Event ev;
while (engine -> window -> IsOpened())
{
engine -> window -> PollEvent(ev);
engine -> window -> Clear();
manager.Update();
engine -> window -> Display();
}
}
#include "System.h"
void System::SetScreenDim(int width, int height)
{
this -> SCREENW = width;
this -> SCREENH = height;
}
void System::SetTitle(std::string title)
{
this -> Title = title;
}
void System::SetWindow(int width, int height, std::string title)
{
this -> SCREENW = width;
this -> SCREENH = height;
this -> window = new sf::RenderWindow(sf::VideoMode(width, height), title.c_str());
}
#include "EntityManager.h"
#include "System.h"
void Manager::Update()
{
Entity entity;
std::list<Entity>::iterator iter = eList.begin();
while (iter != eList.end())
{
entity = *iter;
entity.GetSprite().SetPosition(entity.GetX(), entity.GetY());
engine -> window -> Draw(entity.GetSprite());
iter++;
}
}
void Manager::Add(Entity entity)
{
eList.push_back(entity);
}
#include "Entity.h"
void Entity::Load(std::string filename, float x, float y)
{
this -> Filename = filename;
this -> Image.LoadFromFile(this -> Filename.c_str());
this -> Sprite.SetImage(this -> Image);
this -> posx = x;
this -> posy = y;
}
void Entity::Update()
{
this -> Sprite.SetPosition(this -> posx, this -> posy);
}
[/code]
sf::RenderWindow System::SetWindow(int width, int height, std::string title)
{
sf::RenderWindow *ref = new sf::RenderWindow();
sf::RenderWindow w(sf::VideoMode(width, height), title.c_str());
ref = &w;
return *ref;
}
void System::Init()
{
engine = new System();
window = new sf::RenderWindow();
engine -> window = &engine -> SetWindow(800, 600, "Test");
}
#include <SFML/Graphics.hpp>
#include <cstdlib>
int main()
{
sf::RenderWindow game(sf::VideoMode(1000, 700, 32), "Pong!");
//Images/Loading
sf::Image Ball;
sf::Image LeftPaddle;
sf::Image RightPaddle;
sf::Image Background;
sf::Image Gameover;
LeftPaddle.LoadFromFile("Leftpaddle.png");
RightPaddle.LoadFromFile("Rightpaddle.png");
Ball.LoadFromFile("PongBall.png");
Background.LoadFromFile("background.png");
Gameover.LoadFromFile("gameover.png");
//Sprites
sf::Sprite leftpaddle;
sf::Sprite rightpaddle;
sf::Sprite ball;
sf::Sprite background;
sf::Sprite gameover;
ball.SetImage(Ball);
leftpaddle.SetImage(LeftPaddle);
rightpaddle.SetImage(RightPaddle);
background.SetImage(Background);
gameover.SetImage(Gameover);
Ball.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
LeftPaddle.CreateMaskFromColor(sf::Color(255, 255, 255, 255));
RightPaddle.CreateMaskFromColor(sf::Color(255, 255, 255, 255));
ball.SetPosition(500, 350);
leftpaddle.SetPosition(0, 250);
rightpaddle.SetPosition(1000 - RightPaddle.GetWidth(), 250);
background.SetPosition(250, 200);
//Ball Movement
float move_x = -1.5;
float move_y = 0;
sf::Event close;
while (game.IsOpened())
{
game.GetEvent(close);
if (close.Type == sf::Event::Closed)
{
game.Close();
}
if (game.GetInput().IsKeyDown(sf::Key::Escape))
{
game.Close();
}
//Collision for everything
float ballX = ball.GetPosition().x;
float ballY = ball.GetPosition().y;
float leftPaddleX = leftpaddle.GetPosition().x;
float leftPaddleY = leftpaddle.GetPosition().y;
float rightPaddleX = rightpaddle.GetPosition().x;
float rightPaddleY = rightpaddle.GetPosition().y;
sf::IntRect ballcollision = ball.GetSubRect();
sf::IntRect leftPaddleCol = leftpaddle.GetSubRect();
sf::IntRect rightPaddleCol = rightpaddle.GetSubRect();
ballcollision.Offset(ballX, ballY);
leftPaddleCol.Offset(leftPaddleX, leftPaddleY);
rightPaddleCol.Offset(rightPaddleX, rightPaddleY);
//Ball Movement
ball.Move(move_x, move_y);
//Left Paddle Controls
if (game.GetInput().IsKeyDown(sf::Key::W))
{
leftpaddle.Move(0, -1);
}
if (game.GetInput().IsKeyDown(sf::Key::S))
{
leftpaddle.Move(0, 1);
}
//Right Paddle Controls
if (game.GetInput().IsKeyDown(sf::Key::Up))
{
rightpaddle.Move(0, -1);
}
if (game.GetInput().IsKeyDown(sf::Key::Down))
{
rightpaddle.Move(0, 1);
}
//Left Paddle Collision
if (leftPaddleCol.Top < 0)
{
leftpaddle.SetY(0);
}
if (leftPaddleCol.Bottom > 700)
{
leftpaddle.SetY(700 - LeftPaddle.GetHeight());
}
//Right Paddle Collision
if (rightPaddleCol.Top < 0)
{
rightpaddle.SetY(0);
}
if (rightPaddleCol.Bottom > 700)
{
rightpaddle.SetY(700 - RightPaddle.GetHeight());
}
//Ball Collision
if (ballcollision.Intersects(leftPaddleCol) && move_x < 0.0f)
{
move_x = -move_x;
move_y = move_y == 0.0f ? -1.5 : move_y;
}
if (ballcollision.Intersects(rightPaddleCol) && move_x > 0.0f)
{
move_x = -move_x;
move_y = move_y == 0.0f ? -1.5 : move_y;
}
if (ballcollision.Bottom > 700)
{
move_y = -1.5;
}
if (ballcollision.Top < 0)
{
move_y = 1.5;
}
if (ballcollision.Left < 0)
{
gameover.SetPosition(250, 200);
game.Draw(gameover);
game.Display();
sf::Sleep(3);
return EXIT_SUCCESS;
}
if (ballcollision.Right > 1000)
{
gameover.SetPosition(250, 200);
game.Draw(gameover);
game.Display();
sf::Sleep(3);
return EXIT_SUCCESS;
}
game.Clear();
game.Draw(background);
game.Draw(ball);
game.Draw(leftpaddle);
game.Draw(rightpaddle);
game.Display();
}
return EXIT_SUCCESS;
}
'Paki Pong.exe': Loaded 'C:\Users\Danielle\Documents\Visual Studio 2010\Projects\Paki Pong\Release\Paki Pong.exe', Symbols loaded.
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Users\Danielle\Documents\Visual Studio 2010\Projects\Paki Pong\sfml-system.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4974_none_50940634bcb759cb\msvcp90.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4974_none_50940634bcb759cb\msvcr90.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Users\Danielle\Documents\Visual Studio 2010\Projects\Paki Pong\sfml-window.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\opengl32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\glu32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\ddraw.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\dciman32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\setupapi.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Users\Danielle\Documents\Visual Studio 2010\Projects\Paki Pong\sfml-graphics.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\msvcp100.dll', Symbols loaded.
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\msvcr100.dll', Symbols loaded.
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Program Files (x86)\Common Files\Motive\McciContextHook_DSR.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\shell32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Program Files (x86)\Common Files\microsoft shared\ink\tiptsf.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\atioglxx.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\ws2_32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\nsi.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\atiadlxy.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\wintrust.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\crypt32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\msasn1.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\clbcatq.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\oleacc.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\dinput.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\hid.dll', Cannot find or open the PDB file
First-chance exception at 0x70760149 in Paki Pong.exe: 0xC0000005: Access violation reading location 0x64646170.
A buffer overrun has occurred in Paki Pong.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.
For more details please see Help topic 'How to debug Buffer Overrun Issues'.
The program '[1216] Paki Pong.exe: Native' has exited with code 0 (0x0).