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.


Topics - Demian

Pages: [1]
1
General / Multiple new commands with pointer(s)
« on: May 15, 2010, 02:54:59 am »
Hey

I have a fight with sprite-pointers.
I want to display multiple Sprites using pointers depending on score-condition.
Something like that:
If your score points are above 100 create one "box".
If your score points are above 200 create two "box" and so on.

My solution so far :
Code: [Select]

/// Game - Class  ///////////////////////////

//... Here somewhere I define the pointer

sf::Sprite *ptrSprite;

// end Game - Class

int Game_run()
{
//...

if (Score >= 100 )
{
                if (ptrSprite == 0)
                {
                // Create the new sprite
                ptrSprite = new sf::Sprite(IMG_Plop);

                // Set the position in y-axis and it's velocity to random.
                // I don't know if it's alright, but I have more than one rand because it
                // appears to me that the y is always quite the same or it is close by the last number.
                short int randY=rand() % 480 + 1;
                randY=rand() % 480 + 1;
                randY=rand() % 480 + 1;
                randY=rand() % 480 + 1;
                randY=rand() % 480 + 1;

                ptrSprite->SetPosition(810, randY);

                // Set a random velocity between -50 and -200.
                ptrSpriteVelocity = rand() % 200;
                ptrSpriteVelocity -= 200;

                }
}

// Below is the delete command

if (Score > 100 && ptrSprite != 0)
         {
             ptrSprite->Move(ptrSpriteVelocity * ElapsedTime,0);
             // If the Sprite reaches the end delete it.
             if (ptrSprite->GetPosition().x < -10)
             {
                 delete ptrSprite;
                 ptrSprite = 0;
             }
         }


return 0 ;

}


I don't know how to do this.
My only idea is to make this for each pointer I define, so that this code appears as often as the number of pointers plus the condition of points.
But this wouldn't be a clear and well code.

Thanks : D

2
SFML projects / SFML - Collision Demo
« on: May 08, 2010, 03:13:37 pm »
Hi : D

I started to play around with the collision and to benefit the most from it
I decided to begin a new project and post it here.
The finished program should help beginners to start with collision in 2D.
(I'm thinking about supporting this with some pictures oder pdf's)

My program has two features so far :
    -You can switch between collision or noclip
    -You can activate gravity
( I know there isn't  much of code in there yet, but consider that it should help beginners to understand collision.)

As shown down on the picture you see there are two blocks or rectangles.
The white block has a constant position and it can't be changed in no way(later it will be, because I want the collision to be able to operate with circles, triangle and etc)
The red, transparent, block is controlled by you.
(Later it should be possible to change it's form either)
You can change it's properties such as size and position, like I said a option for the form is going to be build later.
The collision feature keeps you from entering the white block.
You can't enter it from any side.
But, if I activate the gravity and disable it before I reach the ground( or the top line of the white block), the collision for the upper and lower side of the white block doesn't work, at all.
I can't figure out why, though the left and right side of the white block can't be entered furthermore.


Here is the project with all files.(documented and excuse me for not using classes and using globals, I will clean up the code later : D)
http://ul.to/9syuf7

Thank you and of course Laurent , too  ; D

EDIT :
Here you can find the picture to the demo.


3
Window / Text box in SFML ?
« on: April 18, 2010, 03:57:04 pm »
Is it possible to code an text box with SFML or do I have to use the headers from the OS as windows.h ?

4
General / No executable ?
« on: April 15, 2010, 06:00:11 pm »
Hey

I am trying to build some code for my game, but everytime I try to compile it my compiler doesn't create a .exe data.
It's really simple so far:

main.cpp
Code: [Select]

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

#include <sstream> // String stream library
#include <iostream>

#include "Game_Board.h"


int main()
{

    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");


    Menue(App);         //Before App.IsOpened() we go visit the Menue

    sf::Image Image;
    sf::Sprite Sprite(Image);


    while (App.IsOpened())
    {

        sf::Event Event;
        while (App.GetEvent(Event))
        {

            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        App.Clear();

        App.Draw(Sprite);


        App.Display();
    }

    return EXIT_SUCCESS;
}


FS_STATES.cpp
Code: [Select]

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

#include "Game_Board.h"

int Menue(sf::RenderWindow &App)
{
    Window_State = FS_Menue;    // Window state is set to Menue
    App.Clear();                // Clear the whole Window


    sf::Image IMG_Buttons;      // Create the Image for all buttons

    // After load it's Image in case it fails return back with (!=) 0
    if (!IMG_Buttons.LoadFromFile("Buttons.bmp")
    return EXIT_FAILURE;


    sf::Sprite Button_Start(IMG_Buttons);       // Create the Sprite for Button : Start
    Button_Start.SetPosition(325.f, 150.f);     // Change it's Position

    // Start the Menue loop as long as the Window state contains FS_Menue
    while (Window_State == FS_Menue)
    {
        // Create a Event for the Menue (to handle buttons, clicks etc.)
        sf::Event Menue_Event;
        while (App.GetEvent(Event))         //Event loop for events
        {

            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        App.Clear();

        App.Draw(Button_Start);

        App.Display();
    }

    return EXIT_SUCCESS ;

}



Game_Board.h
Code: [Select]

#ifndef BOARD
#define BOARD

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

#define BOARD_Y_SIZE        //Can be changed    (5-20)
#define BOARD_X_SIZE        //Can be changed    (5-20)


enum Token
{
    Empty,
    Red,
    Blue,
};

// And these, the outline types of the tokens
enum Outline
{
    Normal,
    Highlight
};

// Returned when trying to place a token in a column
//
enum Move
{
    Placed,
    Full,
    EndOfGame

};

// Enum for all possible Window states.
// This Programm just uses Menue, Game, Init and Pause
enum WindowState
{
    FS_Menue,
    FS_Pause,
    FS_Game,
    FS_Init
};

// This template allows you to add a varible to a string in order to print out
template <typename T>
std::string str(const T& x)
{
    std::ostringstream oss;
    oss << x;

    return oss.str();
}

int Window_State = FS_Init; //Holds the state info for the window , starts with "FS_Init"

int Menue(sf::RenderWindow &App);



Compiler post :
Code: [Select]

1. ||Info: resolving vtable for sf::Spriteby linking to __imp___ZTVN2sf6SpriteE |
obj\Debug\FS_STATES.o
2.||In function `_ZNSt8_Rb_treeIPN2sf11ResourcePtrINS0_5ImageEEES4_St9_IdentityIS4_ESt4lessIS4_ESaIS4_EE11_M_put_nodeEPSt13_Rb_tree_nodeIS4_E':|
3.||warning: auto-importing has been activated without --enable-auto-import specified on the command line.|
||=== Build finished: 0 errors, 1 warnings ===|



Thanks to you all : )

5
Graphics / sf::string Text using as sprintf?
« on: April 09, 2010, 10:22:04 pm »
Hello

I want to use the sf::string class to print a variable, just as printf and sprintf in DOS.
I tried something like this:

Code: [Select]

//...
sf::Image Image;
    sf::Font MyFont;
    if (!Image.LoadFromFile("Bubbles.png") ||
        !MyFont.LoadFromFile("arial.ttf", 50))
           return EXIT_FAILURE;

    sf::String Hello;
    Hello.SetText("Pos y : %f Pos x : %f " ,Posy, Posx);
    Hello.SetFont(MyFont);
    Hello.SetColor(sf::Color(0, 128, 128));
    Hello.SetPosition(100.f, 100.f);
    Hello.SetRotation(15.f);
    Hello.SetSize(50.f);


The coordinates ought to show the point of the picture, but it didnt work.
I figured out "SetText" can only contain a naked text without variables.
Code: [Select]
C:\...\main.cpp|34|error: no matching function for call to `sf::String::SetText(float&)'|

Now I wonder if there is any way to pass out a variable to the window with SFML.
In case I ignored something in the tuts don't be mean to me, please!
(I really was searching for the answer!)

Thank you : )

Pages: [1]