1
General / App doesn't start VS2012 / help in change 1 line from 2.0 -> 1.6
« on: June 02, 2013, 03:17:18 pm »
Hi!
I've managed to get the whole Breakout's code. I made some cosmetic changes. There are 0 errors, everything is compiling and when I want to run it a new window is opening and nothing happens.
I'm using SFML 2.0, Windows 7 x64, Visual Studio 2012 and then I thought maybe changing code to 1.6 would be a good move to make it run properly, but I have problems in this line.
Maybe you can check if this code is compiling and running on your PCs.
This it the code:
I've managed to get the whole Breakout's code. I made some cosmetic changes. There are 0 errors, everything is compiling and when I want to run it a new window is opening and nothing happens.
I'm using SFML 2.0, Windows 7 x64, Visual Studio 2012 and then I thought maybe changing code to 1.6 would be a good move to make it run properly, but I have problems in this line.
void draw(sf::RenderWindow & App) { App.Draw(sf::Shape::Rectangle(x,y,x+30,y+3,sf::Color(255,255,255))); }
Maybe you can check if this code is compiling and running on your PCs.
This it the code:
#include <stdafx.h>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
/*
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <ctime>
#include <cstdio>
*/
struct Colors
{
int r;
int g;
int b;
void przypisz(int q, int w, int e){
r = q;
g = w;
b = e;
}
};
class cBrick
{
private:
Colors colors[5];
float x;
float y;
int color;
bool active;
public:
cBrick(){
x = y = color = 0;
active = false;
colors[0].przypisz(0, 0, 255);
colors[1].przypisz(0, 255, 0);
colors[2].przypisz(255, 0, 0);
colors[3].przypisz(255, 106, 0);
colors[4].przypisz(255, 255, 0);
};
void set(float xx, float yy, int ccolor) { x = xx; y = yy; color = ccolor; active = true; }
void destroy() { active = false; }
void draw(sf::RenderWindow & App) { App.Draw(sf::Shape::Rectangle(x+1,y+1,x+29,y+9,sf::Color(colors[color].r,colors[color].g,colors[color].b))); }
float xVal() { return x; }
float yVal() { return y; }
bool isActive() { return active; }
~cBrick() {}
};
class cPaddle
{
private:
float x;
float y;
int dir;
public:
cPaddle() { x = 132.5; y = 147; dir = 0; }
void draw(sf::RenderWindow & App) { App.Draw(sf::Shape::Rectangle(x,y,x+30,y+3,sf::Color(255,255,255))); }
void set(float xx) { x = xx; }
float xVal() { return x; }
float yVal() { return y; }
int dirVal() { return dir; }
void setDir(int ddir) { dir = ddir; }
~cPaddle() {}
};
class cBall
{
private:
float x;
float y;
int dir;
public:
cBall() { x = 146.5; y = 143.5; dir = 1; }
void draw(sf::RenderWindow & App) { App.Draw(sf::Shape::Circle(x,y,3.5,sf::Color(0,255,255))); }
void move()
{
switch(dir)
{
case 1:
y--;
x++;
break;
case 2:
y++;
x++;
break;
case 3:
y++;
x--;
break;
case 4:
y--;
x--;
break;
}
}
bool collision(cPaddle & paddle, cBrick bricks[])
{
if(y >= 150)
return true;
if(x >= 296.5)
if(dir == 1)
dir = 4;
else
dir = 3;
if(x <= 3.5)
if(dir == 4)
dir = 1;
else
dir = 2;
if(y <= 3.5)
if(dir == 1)
dir = 2;
else
dir = 3;
if(x >= paddle.xVal() && x <= paddle.xVal()+30 && y >=147 && y <= 150)
if(paddle.dirVal() == 1)
dir = 1;
else if(paddle.dirVal() == 2)
dir = 4;
else
if(dir == 2)
dir = 1;
else
dir = 4;
int i = 0;
while(i < 50)
{
if(bricks[i].isActive())
if(x+3.5 > bricks[i].xVal()
&& x-3.5 < bricks[i].xVal()+30
&& y+3.5 > bricks[i].yVal()
&& y-3.5 < bricks[i].yVal()+10)
{
bricks[i].destroy();
if(dir == 1)
dir = 2;
else if(dir == 2)
dir = 1;
if(dir == 3)
dir = 4;
else if(dir == 4)
dir = 3;
}
i++;
}
return false;
}
~cBall() {}
};
int main()
{
sf::RenderWindow App(sf::VideoMode(480,320,32),"Breakout");
cBrick bricks[50];
cPaddle paddle;
cBall ball;
for(int i=0, num = 0;i < 5;i++)
for(int m=0;m < 10;m++)
bricks[num++].set(m*30,i*10,i);
while(App.IsOpened())
{
sf::Event Event;
while(App.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed)
App.Close();
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
if(paddle.xVal() < App.GetInput().GetMouseX())
paddle.setDir(1);
else if(paddle.xVal() > App.GetInput().GetMouseX())
paddle.setDir(2);
else
paddle.setDir(0);
paddle.set(App.GetInput().GetMouseX());
}
ball.move();
if(ball.collision(paddle,bricks))
{
for(int i=0, num = 0;i < 5;i++)
for(int m=0;m < 10;m++)
bricks[num++].set(m*30,i*10,i);
paddle = cPaddle();
ball = cBall();
}
App.Clear();
for(int i=0;i<50;i++)
if(bricks[i].isActive())
bricks[i].draw(App);
paddle.draw(App);
ball.draw(App);
App.Display();
sf::Sleep(0.01);
}
return 0;
}
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
/*
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <ctime>
#include <cstdio>
*/
struct Colors
{
int r;
int g;
int b;
void przypisz(int q, int w, int e){
r = q;
g = w;
b = e;
}
};
class cBrick
{
private:
Colors colors[5];
float x;
float y;
int color;
bool active;
public:
cBrick(){
x = y = color = 0;
active = false;
colors[0].przypisz(0, 0, 255);
colors[1].przypisz(0, 255, 0);
colors[2].przypisz(255, 0, 0);
colors[3].przypisz(255, 106, 0);
colors[4].przypisz(255, 255, 0);
};
void set(float xx, float yy, int ccolor) { x = xx; y = yy; color = ccolor; active = true; }
void destroy() { active = false; }
void draw(sf::RenderWindow & App) { App.Draw(sf::Shape::Rectangle(x+1,y+1,x+29,y+9,sf::Color(colors[color].r,colors[color].g,colors[color].b))); }
float xVal() { return x; }
float yVal() { return y; }
bool isActive() { return active; }
~cBrick() {}
};
class cPaddle
{
private:
float x;
float y;
int dir;
public:
cPaddle() { x = 132.5; y = 147; dir = 0; }
void draw(sf::RenderWindow & App) { App.Draw(sf::Shape::Rectangle(x,y,x+30,y+3,sf::Color(255,255,255))); }
void set(float xx) { x = xx; }
float xVal() { return x; }
float yVal() { return y; }
int dirVal() { return dir; }
void setDir(int ddir) { dir = ddir; }
~cPaddle() {}
};
class cBall
{
private:
float x;
float y;
int dir;
public:
cBall() { x = 146.5; y = 143.5; dir = 1; }
void draw(sf::RenderWindow & App) { App.Draw(sf::Shape::Circle(x,y,3.5,sf::Color(0,255,255))); }
void move()
{
switch(dir)
{
case 1:
y--;
x++;
break;
case 2:
y++;
x++;
break;
case 3:
y++;
x--;
break;
case 4:
y--;
x--;
break;
}
}
bool collision(cPaddle & paddle, cBrick bricks[])
{
if(y >= 150)
return true;
if(x >= 296.5)
if(dir == 1)
dir = 4;
else
dir = 3;
if(x <= 3.5)
if(dir == 4)
dir = 1;
else
dir = 2;
if(y <= 3.5)
if(dir == 1)
dir = 2;
else
dir = 3;
if(x >= paddle.xVal() && x <= paddle.xVal()+30 && y >=147 && y <= 150)
if(paddle.dirVal() == 1)
dir = 1;
else if(paddle.dirVal() == 2)
dir = 4;
else
if(dir == 2)
dir = 1;
else
dir = 4;
int i = 0;
while(i < 50)
{
if(bricks[i].isActive())
if(x+3.5 > bricks[i].xVal()
&& x-3.5 < bricks[i].xVal()+30
&& y+3.5 > bricks[i].yVal()
&& y-3.5 < bricks[i].yVal()+10)
{
bricks[i].destroy();
if(dir == 1)
dir = 2;
else if(dir == 2)
dir = 1;
if(dir == 3)
dir = 4;
else if(dir == 4)
dir = 3;
}
i++;
}
return false;
}
~cBall() {}
};
int main()
{
sf::RenderWindow App(sf::VideoMode(480,320,32),"Breakout");
cBrick bricks[50];
cPaddle paddle;
cBall ball;
for(int i=0, num = 0;i < 5;i++)
for(int m=0;m < 10;m++)
bricks[num++].set(m*30,i*10,i);
while(App.IsOpened())
{
sf::Event Event;
while(App.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed)
App.Close();
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
if(paddle.xVal() < App.GetInput().GetMouseX())
paddle.setDir(1);
else if(paddle.xVal() > App.GetInput().GetMouseX())
paddle.setDir(2);
else
paddle.setDir(0);
paddle.set(App.GetInput().GetMouseX());
}
ball.move();
if(ball.collision(paddle,bricks))
{
for(int i=0, num = 0;i < 5;i++)
for(int m=0;m < 10;m++)
bricks[num++].set(m*30,i*10,i);
paddle = cPaddle();
ball = cBall();
}
App.Clear();
for(int i=0;i<50;i++)
if(bricks[i].isActive())
bricks[i].draw(App);
paddle.draw(App);
ball.draw(App);
App.Display();
sf::Sleep(0.01);
}
return 0;
}