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 - The Illusionist Mirage

Pages: 1 ... 4 5 [6] 7 8
76
SFML projects / Re: AW: A very nice Pong clone using SFML - 2.1
« on: September 09, 2013, 11:19:15 am »
You might want to put it under something like libpng/zlib or MIT license. With GPL you restrict the use to GPL projects only.

Okay, thanks! :)

And did you by any chance see or run my game? Please tell me how it is. A lot of my real life friends say it sucks.

77
SFML projects / Re: A very nice Pong clone using SFML - 2.1
« on: September 09, 2013, 07:54:49 am »
Hey guys

Sorry for being really rude and not posting the source before.  :-[

Well I have created a repository on GitHub where you can find the source and the resources(images, fonts and sounds) used and what's amazing is it is fully documented!

Sorry, I wasn't able to download it before as I was busy.

I just tried it though and it runs fine, really smoothly actually, you have a nice remake on your hands!

I am glad you liked it since this is my first ever complete game project. :)

And one more thing I'd like to ask everyone - how to I license my program as open source, freely distributive and modifiable(probably under GPL I guess).

CHEERS! :)

78
SFML projects / Re: Created a Pong clone
« on: September 08, 2013, 02:47:53 pm »
I'd be very glad if you would first download and see if my game is running because it may contain glitches and bugs.
There are some people who can't do anything with a windows executable and therefore are asking for the source  ;)

What about you, did you run my game? I am insisting that someone run my game since in a lot of computers that I tried to run it, the game either didn't run or was very slow.

79
SFML projects / Re: Created a Pong clone
« on: September 08, 2013, 09:05:45 am »
The project looks nice, it would be cool if you uploaded the source code, so I could try it out.

Yeah, I would also like to see the source code please!

It looks like a nice remake and I'm curious how you did it, as I'm pretty new to SFML.

Thanks!


I'd be very glad if you would first download and see if my game is running because it may contain glitches and bugs. If there are indeed errors please report them to me, I'd fix them and then I'll definitely post the source. :)

CHEERS!

80
SFML projects / A very nice Pong clone using SFML - 2.1
« on: September 06, 2013, 08:14:36 pm »
Hello friends!

I just finished creating my first complete game using SFML 2.1 on windows using Code::Blocks 12.11(but game is cross platform, runs on mac and linux too). I am uploading it. Please do run it and tell me what you think of it .
I don't claim that my game is very exciting or anything like that. Hope you like it. :)
If it's not working, please let me know.

CHEERS!

Link to download (Windows only)

Here are a few screenshots:







A gameplay video:

81
General / Re: .exe not running on other computers
« on: September 03, 2013, 04:17:03 pm »
Do the other computers have the audio dlls? (libdnsfile and openal, forgot the exact names)

Yes, I copied the entire project folder to the other computer(including, images, fonts, dlls and project file). I have linked everything statically.

Don't construct SFML objects at global scope, especially resources. SFML has its own global objects, and these might not be initialized before yours (order is undefined and may change from one computer/compiler to another).

All I did is define some some classes(like game manger class, button class, etc.). As soon as I finish minimum and complete code, that can to be seen to point out flaws, I'll post it here.

82
General / .exe not running on other computers
« on: September 03, 2013, 05:23:11 am »
Hello

I made a game in sfml 2.0 using codeblocks and mingw 4.7.2. It runs fine in my computer but when I run it on other computers, it doesn't run. also, if I debug it on other computers, i get these:

#0 004565B6   sf::SoundBuffer::SoundBuffer(this=0x402b01) (C:\SFML-2.1\src\SFML\Audio\SoundBuffer.cpp:42)
#1 00402BBA   __static_initialization_and_destruction_0(__initialize_p=1, __priority=65535) (D:\CodeBlocks\SFML  2.0\Games\Pong_Final\main.cpp:41)
#2 00402C16   _GLOBAL__sub_I_WINDOW_CAPTION() (D:\CodeBlocks\SFML  2.0\Games\Pong_Final\main.cpp:219)
#3 0046225F   __do_global_ctors() (../mingw/gccmain.c:59)
#4 00401098   __mingw_CRTStartup() (../mingw/crt1.c:236)
#5 00401284   mainCRTStartup() (../mingw/crt1.c:264)


Also I get this message:

Program recieved SIGSEGV, segmentation fault.


Can anyone explain what's the problem?

Thanks

EDIT:

I just realized that if I recompile my code in another computer and then run .exe, it runs correctly. But without recompiling, it doesn't run.

83
Audio / Re: Playing sound
« on: September 01, 2013, 12:49:16 pm »
Use events (sf::Event::MouseButtonPressed) instead of real-time input (sf::Mouse::isButtonPressed()).

Yea, thanks, it worked beautifully. :)

And your position is wrong; use the sf::RenderWindow::map...() function to map correctly from pixel to world coordinates. Like this, your code won't break if you use a different view.

I am making a pong clone and just need the mouse for navigating through menu and stuff. So do you really want that I should not use
MouseSprite.setPosition(sf::Vector2f(sf::Mouse::getPosition(Render_window_name)));

84
Audio / Playing sound
« on: September 01, 2013, 11:57:23 am »
Hello

I have made a custom mouse icon and I am using it through the methods -
Render_window_name.setMouseCursorVisible(false)
and
MouseSprite.setPosition(sf::Vector2f(sf::Mouse::getPosition(Render_window_name)));

I have also added a sound that is played everytime the user clicks the left button. Everything is smooth except that while I click the left button and hold it the sound keeps on playing. I want that it must be played only once when the left button is pressed, no matter for how much time I hold it.

How do I set up a sound using SFML so that it plays only once when the mouse is clicked.

Thanks

85
General / Re: Loading tile maps
« on: August 30, 2013, 03:37:03 pm »
External, so you can just edit the map and restart/reload instead of having to recompile every single time. ;)

Thanks! :D

86
General / Re: Loading tile maps
« on: August 30, 2013, 03:24:48 pm »
Thanks! Now I am clear about how stuff works using SFML.

BTW what do you suggesst is better - keeping tile maps in separate text files and using them through the fstream class objects or by declaring them in a sf::String?

Like:
#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>
.
.
.
int main()
{
     std::fstream tilemap("Tilemap.txt", ios::in);
     .
     .
     .
}
 

OR

#include <SFML/Graphics.hpp>

sf::String tilemap[10][10] =
{ "1 1 1 1 1 1 1 1 1 1",
  "1                 1",
  "1                 1",
  "1                 1",
  "1                 1",
  "1     #####       1",
  "1                 1",
  "1                 1",
  "1                 1",
  "1 1 1 1 1 1 1 1 1 1",
};
.
.
.
int main()
{
     .
     .
     .
}


 

87
General / [Solved]Loading tile maps
« on: August 28, 2013, 01:32:24 pm »
Hello

I downloaded a mario clone source from here : http://en.sfml-dev.org/forums/index.php?topic=12232.msg84944#msg84944

But I didn't understand the tile map loading part. Can anyone please explain it to me?

Thanks

88
General / Re: Need help in creating a game state manager class
« on: August 22, 2013, 12:39:52 pm »
The SFML Game Development book is pretty neat, especially since it was written for SFML from community members.

It includes a chapter about state stack handling. ;)


Yeah, I know. I saw the sample chapters at the PacktPub website and also the preview at safari books But no book store near me or in my state sells hard copies. And to get an e-book you need a credit card or PayPal etc, which I don't have. :(

But programming is my passion, I will learn, one way or the other. Maybe it'll take some time but one day I'll surely grab hold of C++ and then I can moonwalk with SFML. :)

89
General / Re: Need help in creating a game state manager class
« on: August 22, 2013, 11:59:50 am »
Quote from: Gobbles

Actually going through it some more, you should consider picking up a good C++ book and a good game dev book. Both will have a wealth of knowledge in learning this stuff.


Can you please suggest a game dev book for beginners. The ones I use for learning C++ are The complete C++ reference by Herbert Schildt and Learn C++ in 21 Days by Jesse Liberty & Bradley Jones.

But I didn't consult any game dev book until now.


Thanks

90
General / Re: Need help in creating a game state manager class
« on: August 21, 2013, 04:55:11 pm »
Ok. I'm done with coding. Here's my Paddle class, Ball class and Game state Manager class. Plese note that I haven't documented my code fully( or even partially). And one more thing I'd like to make clear - I am not a professional or brilliant programmer - I'm still learning. So if I have committed any laughable mistake or  made the code too long than necessary, please pardon me.

Paddle.h:
/** Paddle.h **/

#ifndef PADDLE_H
#define PADDLE_H

#include <SFML/Graphics.hpp>

class Paddle
{
    private:
        //sf::RectangleShape PaddleObject;

    public:
        sf::RectangleShape PaddleObject;

        Paddle();
        Paddle(sf::Vector2f PADDLE_OBJECT_SIZE, sf::Color PADDLE_OBJECT_COLOR,
               sf::Vector2f PADDLE_OBJECT_POSITION);
        ~Paddle();
};

#endif // PADDLE_H
 

Paddle.cpp
/** Paddle.cpp **/

#include "Paddle.h"

Paddle::Paddle()
{

}

Paddle::Paddle(sf::Vector2f PADDLE_OBJECT_SIZE, sf::Color PADDLE_OBJECT_COLOR,
               sf::Vector2f PADDLE_OBJECT_POSITION)
{
    PaddleObject;
    PaddleObject.setSize(PADDLE_OBJECT_SIZE);
    PaddleObject.setFillColor(PADDLE_OBJECT_COLOR);
    PaddleObject.setPosition(PADDLE_OBJECT_POSITION);
}

Paddle::~Paddle()
{

}
 

Ball.h:
/** Ball.h **/

#ifndef BALL_H
#define BALL_H

#include <SFML/Graphics.hpp>
#include "Paddle.h"

class Ball
{
    private:
       //sf::CircleShape BallObject;

    public:
        sf::CircleShape BallObject;
        Ball();
        Ball(float BALL_OBJECT_RADIUS, sf::Color BALL_OBJECT_COLOR,
             sf::Vector2f BALL_OBJECT_POSITION);
        ~Ball();
};

#endif // BALL_H
 

Ball.cpp:
/** Ball.cpp **/

#include "Ball.h"

Ball::Ball()
{

}

Ball::Ball(float BALL_OBJECT_RADIUS, sf::Color BALL_OBJECT_COLOR,
             sf::Vector2f BALL_OBJECT_POSITION)
{
    BallObject.setRadius(BALL_OBJECT_RADIUS);
    BallObject.setFillColor(BALL_OBJECT_COLOR);
    BallObject.setPosition(BALL_OBJECT_POSITION);
}

Ball::~Ball()
{

}
 

GameState.h:
/** GameState.h **/

#ifndef GAMESTATE_H_INCLUDED
#define GAMESTATE_H_INCLUDED

enum GameState{
    showingMainMenu,
    showingPlayMenu,
    showingOptionsMenu,
    showingHowToPlay,
    showingAbout,
    playingVsComputer,
    playingVsHuman,
    quitting
};

#endif // GAMESTATE_H_INCLUDED

 

GameStateManager.h:
/** GameStateManager.h **/

#ifndef GAMESTATEMANAGER_H
#define GAMESTATEMANAGER_H


#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <sstream>
#include "GameState.h"
//#include "Constants.h"
#include "Paddle.h"
#include "Ball.h"

class GameStateManager
{
    private:
       GameState CurrentState, PreviousState;
       Paddle Player_1, Player_2 ;
       Ball GameBall;

    public:

        //static Ball ball;
        //static Paddle player1, player2;

        GameStateManager();

        ~GameStateManager();

        void setGameState(GameState STATE);
        GameState getGameState();

        void showMainMenu(sf::RenderWindow &GAME_WINDOW);

        void showPlayMenu(sf::RenderWindow &GAME_WINDOW);

        void showOptionsMenu(sf::RenderWindow &GAME_WINDOW);

        void showHowToPlay(sf::RenderWindow &GAME_WINDOW);

        void showAbout(sf::RenderWindow &GAME_WINDOW);

        void playVsComputer(sf::RenderWindow &GAME_WINDOW, int GAME_WINDOW_WIDTH, int GAME_WINDOW_HEIGHT,
                            Paddle &PLAYER_1_PADDLE, Paddle &PLAYER_2_PADDLE, Ball &GAME_BALL);

        void playVsHuman(sf::RenderWindow &GAME_WINDOW,
                    int GAME_WINDOW_WIDTH, int GAME_WINDOW_HEIGHT);

        void quitGame(sf::RenderWindow &GAME_WINDOW);
};

#endif // GAMESTATEMANAGER_H
 

GameStateManager.cpp:
#include "GameStateManager.h"
#include <iostream>


GameStateManager::GameStateManager()
{
    CurrentState = showingMainMenu;
}

GameStateManager::~GameStateManager()
{
    //dtor
}

void GameStateManager::setGameState(GameState STATE)
{
    CurrentState = STATE;
}

GameState GameStateManager::getGameState()
{
    return CurrentState;
}


void GameStateManager::showMainMenu(sf::RenderWindow &GAME_WINDOW)
{
    GAME_WINDOW.clear(sf::Color(0, 0, 0));

    /** BACKGROUND IMAGE SPRITE **/
    sf::Texture BackgroundTexture;
    if(!BackgroundTexture.loadFromFile("background.png"))
        GAME_WINDOW.close();

    sf::Sprite BackgroundSprite;
    BackgroundSprite.setTexture(BackgroundTexture);

    /** MENU TITLE SPRITE */
    sf::Texture MenuTitle;
    if(!MenuTitle.loadFromFile("menutitle.png"))
        GAME_WINDOW.close();

    sf::Sprite MenuTitleSprite;
    MenuTitleSprite.setTexture(MenuTitle);
    MenuTitleSprite.setPosition(sf::Vector2f(265, 250));

    /** MENU BUTTON TEXTURE **/
    sf::Texture MenuTexture;
    if(!MenuTexture.loadFromFile("menu.png"))
        GAME_WINDOW.close();

    /** MENU BUTTONS **/

    // PLAY BUTTON
    sf::Sprite PlayButtonSprite;
    PlayButtonSprite.setTexture(MenuTexture);
    PlayButtonSprite.setTextureRect(sf::IntRect(0, 7, 100, 35));
    PlayButtonSprite.setPosition(sf::Vector2f(305, 350));

    // OPTIONS BUTTON
    sf::Sprite OptionsButtonSprite;
    OptionsButtonSprite.setTexture(MenuTexture);
    OptionsButtonSprite.setTextureRect(sf::IntRect(0, 40, 170, 25));
    OptionsButtonSprite.setPosition(sf::Vector2f(305, 385));

    // HOW TO PLAY BUTTON
    sf::Sprite HowToPlayButtonSprite;
    HowToPlayButtonSprite.setTexture(MenuTexture);
    HowToPlayButtonSprite.setTextureRect(sf::IntRect(0, 70, 256, 25));
    HowToPlayButtonSprite.setPosition(sf::Vector2f(305, 415));

    // ABOUT BUTTON
    sf::Sprite AboutButtonSprite;
    AboutButtonSprite.setTexture(MenuTexture);
    AboutButtonSprite.setTextureRect(sf::IntRect(0, 100, 130, 25));
    AboutButtonSprite.setPosition(sf::Vector2f(305, 447));

    // QUIT BUTTON
    sf::Sprite QuitButtonSprite;
    QuitButtonSprite.setTexture(MenuTexture);
    QuitButtonSprite.setTextureRect(sf::IntRect(0, 130, 95, 30));
    QuitButtonSprite.setPosition(sf::Vector2f(305, 475));


    sf::Vector2i MousePosition = sf::Mouse::getPosition(GAME_WINDOW);
    std::cout << MousePosition.x << ", " << MousePosition.y << std::endl;   // omit this later

    if(MousePosition.x > 308 && MousePosition.x < 435 && MousePosition.y > 351 && MousePosition.y < 370)
    {
        PlayButtonSprite.setTextureRect(sf::IntRect(105, 7, 135, 35));

        OptionsButtonSprite.setTextureRect(sf::IntRect(0, 40, 170, 25));
        HowToPlayButtonSprite.setTextureRect(sf::IntRect(0, 70, 256, 25));
        AboutButtonSprite.setTextureRect(sf::IntRect(0, 100, 130, 25));
        QuitButtonSprite.setTextureRect(sf::IntRect(0, 130, 95, 30));

        if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
        {
            //CurrentState = showingPlayMenu;
            setGameState(showingPlayMenu);
        }
    }

    if(MousePosition.x > 307 && MousePosition.x < 510 && MousePosition.y > 385 && MousePosition.y < 405)
    {
        OptionsButtonSprite.setTextureRect(sf::IntRect(170, 40, 210, 25));

        PlayButtonSprite.setTextureRect(sf::IntRect(0, 7, 100, 35));
        HowToPlayButtonSprite.setTextureRect(sf::IntRect(0, 70, 256, 25));
        AboutButtonSprite.setTextureRect(sf::IntRect(0, 100, 130, 25));
        QuitButtonSprite.setTextureRect(sf::IntRect(0, 130, 95, 30));

        if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
        {
//            CurrentState = showingOptionsMenu;
        }
    }

    if(MousePosition.x > 307 && MousePosition.x < 598 && MousePosition.y > 415 && MousePosition.y < 434)
    {
        HowToPlayButtonSprite.setTextureRect(sf::IntRect(260, 70, 560, 25));

        PlayButtonSprite.setTextureRect(sf::IntRect(0, 7, 100, 35));
        OptionsButtonSprite.setTextureRect(sf::IntRect(0, 40, 170, 25));
        AboutButtonSprite.setTextureRect(sf::IntRect(0, 100, 130, 25));
        QuitButtonSprite.setTextureRect(sf::IntRect(0, 130, 95, 30));

        if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
        {
//            CurrentState = showingHowToPlay;
        }
    }

    if(MousePosition.x > 306 && MousePosition.x < 474 && MousePosition.y > 450 && MousePosition.y < 466)
    {
        AboutButtonSprite.setTextureRect(sf::IntRect(135, 100, 175, 25));

        PlayButtonSprite.setTextureRect(sf::IntRect(0, 7, 100, 35));
        OptionsButtonSprite.setTextureRect(sf::IntRect(0, 40, 170, 25));
        HowToPlayButtonSprite.setTextureRect(sf::IntRect(0, 70, 256, 25));
        QuitButtonSprite.setTextureRect(sf::IntRect(0, 130, 95, 30));

        if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
        {
//            CurrentState = showingAbout;
        }
    }

    if(MousePosition.x > 310 && MousePosition.x < 435 && MousePosition.y > 478 && MousePosition.y < 502)
    {
        QuitButtonSprite.setTextureRect(sf::IntRect(100, 130, 135, 30));

        PlayButtonSprite.setTextureRect(sf::IntRect(0, 7, 100, 35));
        OptionsButtonSprite.setTextureRect(sf::IntRect(0, 40, 170, 25));
        HowToPlayButtonSprite.setTextureRect(sf::IntRect(0, 70, 256, 25));
        AboutButtonSprite.setTextureRect(sf::IntRect(0, 100, 130, 25));

        if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
        {
            PreviousState = CurrentState;
            CurrentState = quitting;
        }
    }

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
    {
        PreviousState = CurrentState;
        CurrentState = quitting;
    }

    GAME_WINDOW.draw(BackgroundSprite);
    GAME_WINDOW.draw(MenuTitleSprite);
    GAME_WINDOW.draw(PlayButtonSprite);
    GAME_WINDOW.draw(OptionsButtonSprite);
    GAME_WINDOW.draw(HowToPlayButtonSprite);
    GAME_WINDOW.draw(AboutButtonSprite);
    GAME_WINDOW.draw(QuitButtonSprite);
}

void GameStateManager::showPlayMenu(sf::RenderWindow &GAME_WINDOW)
{
    GAME_WINDOW.clear(sf::Color(0, 0, 0));

    /** BACKGROUND IMAGE SPRITE **/
    sf::Texture BackgroundTexture;
    if(!BackgroundTexture.loadFromFile("background.png"))
        GAME_WINDOW.close();

    sf::Sprite BackgroundSprite;
    BackgroundSprite.setTexture(BackgroundTexture);

    /** PLAY MENU TEXTURE **/
    sf::Texture MenuTexture;
    if(!MenuTexture.loadFromFile("menu.png"))
        GAME_WINDOW.close();

    /** PLAY MENU TITLE **/

    sf::Sprite PlayMenuTitle;
    PlayMenuTitle.setTexture(MenuTexture);
    PlayMenuTitle.setTextureRect(sf::IntRect(0, 7, 100, 35));
    PlayMenuTitle.setPosition(sf::Vector2f(330, 300));

    /** PLAY MENU BUTTON SPRITES **/
    // PLAYING VS COMPUTER BUTTON
    sf::Sprite PlayVSComputerButton;
    PlayVSComputerButton.setTexture(MenuTexture);
    PlayVSComputerButton.setTextureRect(sf::IntRect(0, 165, 370, 25));    // Fill these later
    PlayVSComputerButton.setPosition(sf::Vector2f(210, 380));            // Fill these later

    // PLAYING VS HUMAN BUTTON
    sf::Sprite PlayVShumanButton;
    PlayVShumanButton.setTexture(MenuTexture);
    PlayVShumanButton.setTextureRect(sf::IntRect(0, 195, 300, 30));    // Fill these later
    PlayVShumanButton.setPosition(sf::Vector2f(240, 430));            // Fill these later

    // BACK BUTTON SPRITE
    sf::Sprite BackButtonSprite;
    BackButtonSprite.setTexture(MenuTexture);
    BackButtonSprite.setTextureRect(sf::IntRect(6, 326, 90, 21));
    BackButtonSprite.setPosition(sf::Vector2f(335, 500));


    sf::Vector2i MousePosition = sf::Mouse::getPosition(GAME_WINDOW);
    std::cout << MousePosition.x << ", " << MousePosition.y << std::endl;   // omit this later

    if(MousePosition.x > 215 && MousePosition.x < 570 && MousePosition.y > 380 && MousePosition.y < 402) // 215, 570, 380, 402
    {
        PlayVSComputerButton.setTextureRect(sf::IntRect(370, 165, 410, 25));
        PlayVShumanButton.setTextureRect(sf::IntRect(0, 195, 300, 30));

        if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
        {
            CurrentState = playingVsComputer;
        }
    }
    if(MousePosition.x > 245 && MousePosition.x < 534 && MousePosition.y > 432 && MousePosition.y < 454) // 215, 570, 380, 402
    {
        PlayVShumanButton.setTextureRect(sf::IntRect(305, 195, 340, 30));
        PlayVSComputerButton.setTextureRect(sf::IntRect(0, 165, 370, 25));

        if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
        {
            CurrentState = playingVsHuman;
        }
    }

    if(MousePosition.x > 336 && MousePosition.x < 420 && MousePosition.y > 501 && MousePosition.y < 517)
    {
        //ShowMenu(sf::RenderWindow &GAME_WINDOW);
        BackButtonSprite.setTextureRect(sf::IntRect(105, 326, 125, 25));

        PlayVShumanButton.setTextureRect(sf::IntRect(0, 195, 300, 30));
        PlayVSComputerButton.setTextureRect(sf::IntRect(0, 165, 370, 25));

        if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
        {
            CurrentState = showingMainMenu;
        }
    }

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
    {
        PreviousState = CurrentState;
        CurrentState = quitting;
    }

    GAME_WINDOW.draw(BackgroundSprite);
    GAME_WINDOW.draw(PlayMenuTitle);
    GAME_WINDOW.draw(PlayVSComputerButton);
    GAME_WINDOW.draw(PlayVShumanButton);
    GAME_WINDOW.draw(BackButtonSprite);
}

void GameStateManager::showOptionsMenu(sf::RenderWindow &GAME_WINDOW)
{

    GAME_WINDOW.clear(sf::Color(0, 0, 0));



    //GAME_WINDOW.draw();

}

// I'll write these functions later
/*void GameStateManager::showHowToPlay(sf::RenderWindow &GAME_WINDOW);
void GameStateManager::showAbout(sf::RenderWindow &GAME_WINDOW);*/



void playVsComputer(sf::RenderWindow &GAME_WINDOW, int GAME_WINDOW_WIDTH, int GAME_WINDOW_HEIGHT,
                            Paddle &PLAYER_1_PADDLE, Paddle &PLAYER_2_PADDLE, Ball &GAME_BALL)
{
    GAME_WINDOW.clear(sf::Color(0, 0,0));

    sf::RectangleShape top(sf::Vector2f(800, 30));
    sf::RectangleShape bottom(sf::Vector2f(800, 30));
    sf::RectangleShape left(sf::Vector2f(30, 600));
    sf::RectangleShape right(sf::Vector2f(30, 600));
    sf::RectangleShape separationLine(sf::Vector2f(5, 540));

    top.setFillColor(sf::Color::Green);
    bottom.setFillColor(sf::Color::Green);
    left.setFillColor(sf::Color::Green);
    right.setFillColor(sf::Color::Green);
    separationLine.setFillColor(sf::Color::Green);

    top.setPosition(0, 0);
    bottom.setPosition(0, 570);
    left.setPosition(0,0);
    right.setPosition(770, 0);
    separationLine.setPosition(GAME_WINDOW_WIDTH / 2 - separationLine.getSize().x, 30);

    sf::Vector2<float> ballSpeed(0.2, 0.2);

    float paddlespeedY = 450.0f;

    float currentTime = 0.0;
    float previousTime = 0.0;
    float deltaTime = 0.0;
    sf::Clock Clock;

    sf::Font gameFont;
    if(!gameFont.loadFromFile("BankGothic.ttf"))
        GAME_WINDOW.close();

    sf::Text score("0   0", gameFont, 50);
    score.setColor(sf::Color(44, 127, 255));
    score.setPosition(sf::Vector2f(GAME_WINDOW_WIDTH/2 - 68, 20)) ;

    unsigned int player1_Score = 0, player2_Score = 0;

    sf::SoundBuffer paddleHit;
    if(!paddleHit.loadFromFile("paddlehit.wav"))
        GAME_WINDOW.close();

    sf::Sound sound_PaddleHit;
    sound_PaddleHit.setBuffer(paddleHit);

    sf::SoundBuffer scoreUpdate;
    if(!scoreUpdate.loadFromFile("scoreupdate.wav"))
        GAME_WINDOW.close();

    sf::Sound sound_ScoreUpdate;
    sound_ScoreUpdate.setBuffer(scoreUpdate);

    bool pressSpace= false;
    int spaceCounter = 0;

    sf::FloatRect player1_Rect = PLAYER_1_PADDLE.PaddleObject.getGlobalBounds();
    sf::FloatRect player2_Rect = PLAYER_1_PADDLE.PaddleObject.getGlobalBounds();
    sf::FloatRect topRect = top.getGlobalBounds();
    sf::FloatRect bottomRect = bottom.getGlobalBounds();
    sf::FloatRect leftRect = left.getGlobalBounds();
    sf::FloatRect rightRect = right.getGlobalBounds();

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
        PLAYER_1_PADDLE.PaddleObject.move(0, - (paddlespeedY * deltaTime));

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
        PLAYER_1_PADDLE.PaddleObject.move(0, paddlespeedY * deltaTime);

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && spaceCounter == 0)
    {
        pressSpace = true;
        spaceCounter = 1;
    }

    sf::Vector2i MousePosition = sf::Mouse::getPosition(GAME_WINDOW);
    std::cout << MousePosition.x << ", " << MousePosition.y << std::endl;

    if (GAME_BALL.BallObject.getPosition().y < PLAYER_2_PADDLE.PaddleObject.getPosition().y)
        PLAYER_2_PADDLE.PaddleObject.move(0, - paddlespeedY / 2000);
    else if(GAME_BALL.BallObject.getPosition().y +  2 * GAME_BALL.BallObject.getRadius() >
            PLAYER_2_PADDLE.PaddleObject.getPosition().y + PLAYER_2_PADDLE.PaddleObject.getSize().y)
        PLAYER_2_PADDLE.PaddleObject.move(0, paddlespeedY / 2000);

    if(PLAYER_1_PADDLE.PaddleObject.getGlobalBounds().intersects(topRect))
    {
        PLAYER_1_PADDLE.PaddleObject.setPosition(PLAYER_1_PADDLE.PaddleObject.getPosition().x,
                                                 top.getPosition().y + 30);
    }

    if(PLAYER_1_PADDLE.PaddleObject.getGlobalBounds().intersects(bottomRect))
    {
        PLAYER_1_PADDLE.PaddleObject.setPosition(PLAYER_1_PADDLE.PaddleObject.getPosition().x,
                            bottom.getPosition().y - PLAYER_1_PADDLE.PaddleObject.getSize().y - 0);
    }

    if(PLAYER_2_PADDLE.PaddleObject.getGlobalBounds().intersects(topRect))
    {
        PLAYER_2_PADDLE.PaddleObject.setPosition(PLAYER_2_PADDLE.PaddleObject.getPosition().x,
                                                 top.getPosition().y + 30);
    }
    if(PLAYER_2_PADDLE.PaddleObject.getGlobalBounds().intersects(bottomRect))
    {
        PLAYER_2_PADDLE.PaddleObject.setPosition(PLAYER_2_PADDLE.PaddleObject.getPosition().x,
                                bottom.getPosition().y - PLAYER_2_PADDLE.PaddleObject.getSize().y - 0);
    }

    if(GAME_BALL.BallObject.getGlobalBounds().intersects(player1_Rect))
    {
        sound_PaddleHit.play();
        sf::FloatRect p = PLAYER_2_PADDLE.PaddleObject.getGlobalBounds();
        sf::FloatRect b = GAME_BALL.BallObject.getGlobalBounds();
        ballSpeed.x = - ballSpeed.x;
        ballSpeed.y = (b.top + b.height / 2 - p.top - p.height / 2) / 100;
    }

    if(GAME_BALL.BallObject.getGlobalBounds().intersects(player2_Rect))
    {
        sound_PaddleHit.play();
        sf::FloatRect p = PLAYER_2_PADDLE.PaddleObject.getGlobalBounds();
        sf::FloatRect b = GAME_BALL.BallObject.getGlobalBounds();
        ballSpeed.x = - ballSpeed.x;
        ballSpeed.y = (b.top + b.height / 2 - p.top - p.height / 2) / 1000;
    }

    if(GAME_BALL.BallObject.getGlobalBounds().intersects(bottomRect))
    {
        ballSpeed.y = -ballSpeed.y;
    }

    if(GAME_BALL.BallObject.getGlobalBounds().intersects(topRect))
    {
        ballSpeed.y = -ballSpeed.y;
    }

    if(GAME_BALL.BallObject.getGlobalBounds().intersects(leftRect))
    {
        sound_ScoreUpdate.play();
        player2_Score++;
        std::stringstream Player_score;
        Player_score << player1_Score << "   " << player2_Score;
        score.setString(Player_score.str());
        GAME_BALL.BallObject.setPosition(sf::Vector2f(GAME_WINDOW_WIDTH / 2 - 5, GAME_WINDOW_HEIGHT / 2 - 5));
        PLAYER_2_PADDLE.PaddleObject.setPosition(sf::Vector2f(
                PLAYER_2_PADDLE.PaddleObject.getPosition().x, GAME_WINDOW_HEIGHT / 2 - 5));
        pressSpace = false;
        spaceCounter = 0;
        ballSpeed.x = 0.2;
        ballSpeed.y = 0.2;
    }

    if(GAME_BALL.BallObject.getGlobalBounds().intersects(rightRect))
    {
        sound_ScoreUpdate.play();
        player1_Score++;
        std::stringstream Player_score;
        Player_score << player1_Score << "   " << player2_Score;
        score.setString(Player_score.str());
        GAME_BALL.BallObject.setPosition(sf::Vector2f(GAME_WINDOW_WIDTH / 2 - 5, GAME_WINDOW_HEIGHT / 2 - 5));
        PLAYER_1_PADDLE.PaddleObject.setPosition(sf::Vector2f(
                PLAYER_2_PADDLE.PaddleObject.getPosition().x, GAME_WINDOW_HEIGHT / 2 - 5));
        pressSpace = false;
        spaceCounter = 0;
        ballSpeed.x = 0.2;
        ballSpeed.y = 0.2;
    }

    if(pressSpace && spaceCounter == 0)
        GAME_BALL.BallObject.move(ballSpeed.x, ballSpeed.y);

    if(player1_Score >= 10)
        score.setPosition(sf::Vector2f(GAME_WINDOW_WIDTH / 2 - 100, 20));

    else if(player1_Score < 10)
        score.setPosition(sf::Vector2f(GAME_WINDOW_WIDTH / 2 - 68, 20)) ;

    GAME_WINDOW.draw(top);
    GAME_WINDOW.draw(bottom);
    GAME_WINDOW.draw(left);
    GAME_WINDOW.draw(right);
    GAME_WINDOW.draw(separationLine);
    GAME_WINDOW.draw(PLAYER_1_PADDLE.PaddleObject);
    GAME_WINDOW.draw(PLAYER_2_PADDLE.PaddleObject);
    GAME_WINDOW.draw(GAME_BALL.BallObject);
    GAME_WINDOW.draw(score);

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
        GAME_WINDOW.close();


}

// I'll write this function later
/*void GameStateManager::playVsHuman(sf::RenderWindow &GAME_WINDOW, int GAME_WINDOW_WIDTH, int GAME_WINDOW_HEIGHT)
{

}*/


void GameStateManager::quitGame(sf::RenderWindow &GAME_WINDOW)
{
    sf::Texture quitmsg;
    if(!quitmsg.loadFromFile("quitmessage.png"))
        GAME_WINDOW.close();

    sf::Sprite QuitMsgSprite;
    QuitMsgSprite.setTexture(quitmsg);
    QuitMsgSprite.setTextureRect(sf::IntRect(0, 2, 622, 184));
    QuitMsgSprite.setPosition(sf::Vector2f(85, 200));

    sf::Vector2i MousePosition = sf::Mouse::getPosition(GAME_WINDOW);

    if(MousePosition.x > 240 && MousePosition.x < 388 && MousePosition.y > 309 && MousePosition.y < 363)
    {
        QuitMsgSprite.setTextureRect(sf::IntRect(2, 198, 622, 184));

        if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
            GAME_WINDOW.close();
    }

    if(MousePosition.x > 395 && MousePosition.x < 542 && MousePosition.y > 309 && MousePosition.y < 363)
    {
        QuitMsgSprite.setTextureRect(sf::IntRect(2, 394, 622, 184));

        if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
            CurrentState = PreviousState;
    }

    if(MousePosition.x > 677 && MousePosition.x < 696 && MousePosition.y > 208 && MousePosition.y < 228)
    {
        if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
            CurrentState = PreviousState;
    }

    GAME_WINDOW.draw(QuitMsgSprite);
}
 


And here's main.cpp:
#include <SFML/Graphics.hpp>
#include "GameState.h"
#include "GameStateManager.h"
#include "Constants.h"
#include "Paddle.h"
#include "Ball.h"
#include <iostream>

int main()
{
    sf::RenderWindow GameWindow(sf::VideoMode(GAME_WINDOW_WIDTH, GAME_WINDOW_HEIGHT,
            GAME_WINDOW_BPP), GAME_WINDOW_CAPTION, sf::Style::Close);

    GameStateManager g_SManager;

    sf::Vector2f Player1_Size = sf::Vector2f(10, 60);
    sf::Color Player1_Color = sf::Color::Red;
    sf::Vector2f Player1_Position = sf::Vector2f(40, 260);

    sf::Vector2f Player2_Size = sf::Vector2f(10, 60);
    sf::Color Player2_Color = sf::Color::Red;
    sf::Vector2f Player2_Position = sf::Vector2f(750, 200);

    Paddle Player1(Player1_Size, Player1_Color, Player1_Position);
    Paddle Player2(Player2_Size, Player2_Color, Player2_Position);

    const float Ball_Radius = 5.0f;
    sf::Color Ball_Color = sf::Color::White;
    sf::Vector2f Ball_Position = sf::Vector2f(GAME_WINDOW_WIDTH / 2 - 5,
                            GAME_WINDOW_HEIGHT / 2 - 5);

    Ball GameBall(Ball_Radius, Ball_Color, Ball_Position);

    while(GameWindow.isOpen())
    {
        sf::Event GameEvent;
        while(GameWindow.pollEvent(GameEvent))
        {
            switch(GameEvent.type)
            {
                case sf::Event::Closed:
                    GameWindow.close();
                    break;
            }
        }

        switch(g_SManager.getGameState())
        {
        case showingMainMenu:
            g_SManager.showMainMenu(GameWindow);
            break;
        case showingPlayMenu:
            g_SManager.showPlayMenu(GameWindow);
            break;
        case quitting:
            g_SManager.quitGame(GameWindow);
            break;
        case playingVsComputer:
            g_SManager.playVsComputer(GameWindow, GAME_WINDOW_WIDTH, GAME_WINDOW_HEIGHT,
                                          Player1, Player2, GameBall);
            break;
        }
        GameWindow.display();
    }

    return EXIT_SUCCESS;
}

 


But this produces an error:
Undefined reference to void playVsComputer(sf::RenderWindow & , int, int , Paddle &, Paddle &, Ball &)

I really don't know what is going wrong  :-[ :(

EDIT:
To all forum members who are reading this post :
After rectification of errors in my code, I'll remove this post. Once my code is complete, I'll post it in the Projects sub forum. If this condition of mine is violating any forum rules, please personal message me stating so.

Pages: 1 ... 4 5 [6] 7 8