Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.


Messages - twigz

Pages: [1]
1
General discussions / Can somebody help me understand this code?
« on: July 16, 2011, 05:33:01 am »
Oh ok then, Sorry I'm kinda new to the forum didn't know.

To be honest i'm lost with the entire paddle class.

1)
Code: [Select]
Paddle(const Player& play) :
      player(play)

2)
Code: [Select]
rect.SetPosition(ScreenWidth - 10,  rect.GetPosition().y);
   


3)
Code: [Select]
void Move(const sf::RenderWindow& win)

4
Code: [Select]
)const float delta = Speed * win.GetFrameTime();
      //Collision with walls
      if(rect.GetPosition().y < 0)
         rect.SetPosition(rect.GetPosition().x, 0);
      if(rect.GetPosition().y > ScreenHeight - 100)
         rect.SetPosition(rect.GetPosition().x, ScreenHeight - 100);


5)
Code: [Select]
sf::Vector2f Position() const
   {
      return rect.GetPosition();
   }
private:
   sf::Shape rect;
   Player player;
   enum { Speed = 200 };
};

Those are the parts where i'm lost, I'm going back and fort by the tutorial section, but i still can't seem to understand their use right in this program.

Can u help me to understand those parts.[/quote]

2
General discussions / Can somebody help me understand this code?
« on: July 16, 2011, 04:48:04 am »
This code is from somebody's Pong game. I do not own it, I just want to understand it, as it has no comments explaining to me about it.

So if any one can explain it to me a bit, it would be much appreciated.
Thank You.

Here is the code.


Code: [Select]
//Pong game yet to finish
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

const int ScreenWidth  = 550;
const int ScreenHeight = 450;

enum Player {Player1, Player2, Computer};

class Paddle
{
public:
Paddle(const Player& play) :
player(play), rect(sf::Shape::Rectangle(0,0,10,100, sf::Color(200,200,200)))
{
rect.SetPosition(0, (ScreenHeight / 2) -  50);
if(player == Player2 || player == Computer)
rect.SetPosition(ScreenWidth - 10,  rect.GetPosition().y);
}
void Move(const sf::RenderWindow& win)
{
const float delta = Speed * win.GetFrameTime();
//Collision with walls
if(rect.GetPosition().y < 0)
rect.SetPosition(rect.GetPosition().x, 0);
if(rect.GetPosition().y > ScreenHeight - 100)
rect.SetPosition(rect.GetPosition().x, ScreenHeight - 100);

switch(player)
{
case Player1:
if(win.GetInput().IsKeyDown(sf::Key::Down)) rect.Move(0,  delta);
if(win.GetInput().IsKeyDown(sf::Key::Up))   rect.Move(0, -delta);
break;
case Player2:
if(win.GetInput().IsKeyDown(sf::Key::S)) rect.Move(0,  delta);
if(win.GetInput().IsKeyDown(sf::Key::W)) rect.Move(0, -delta);
break;
case Computer:
break;
}
}
void Draw(sf::RenderWindow& win) const
{
win.Draw(rect);
}
sf::Vector2f Position() const
{
return rect.GetPosition();
}
private:
sf::Shape rect;
Player player;
enum { Speed = 200 };
};
class Ball
{
public:
Ball(): circle(sf::Shape::Circle(ScreenWidth / 2,
ScreenHeight / 2, 10, sf::Color(200,200,200)))
{
}
void Draw(sf::RenderWindow& window)
{
window.Draw(circle);
//The differente between the position and width
//float diX =  circle.GetPosition().x + ScreenWidth / 2;
//float diY =  circle.GetPosition().y + ScreenHeight / 2;
}

private:
sf::Shape circle;
};
int main()
{
sf::RenderWindow window(sf::VideoMode(ScreenWidth,ScreenHeight), "Pong Game");

Paddle player1(Player1);
Paddle player2(Player2);
Ball ball;

while(window.IsOpened())
{
sf::Event event;
while(window.GetEvent (event))
if(event.Type == sf::Event::Closed)
window.Close();

if(window.GetInput().IsKeyDown(sf::Key::Escape))
window.Close();

window.Clear(sf::Color(100,100,100));

player1.Move(window);
player2.Move(window);

ball.Draw(window);
player1.Draw(window);
player2.Draw(window);

window.Display();
}
}

3
Thanks a million, i never noticed that it had a game tutorial in here. I'm going to work on That and see what new things i can learn.

Umm, u said that a pong game is simple, but i'm not even sure how i can start making it, i would really like to make a pong game, so is there any tutorials on making a pong game for SFML?

Thanks once again.

oh and one more thing, before i can start with the making of games.
I have to be familiar with object oriented programming right?

4
Hello, I'm new to sfml , went through the tutorials until the sound tuts. I'm understanding it piece by piece, but i was wondering how will i be able to start making games using this library.

If you can refer me to simple games tutorials or a way i can start, that will be much appreciated.

Thanks in Advance.

Pages: [1]
anything