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 - Demian

Pages: [1] 2
1
General / Multiple new commands with pointer(s)
« on: May 17, 2010, 11:43:45 am »
Thank you all : D

I will definitely post the game later in the project forum as a open source : D
Ah, it's working well.

2
General / Multiple new commands with pointer(s)
« on: May 15, 2010, 04:46:28 pm »
Quote from: "Hiura"
Why using pointers ?

You want to display a certain amount of boxes according to the score, right ?
Create a class to manage this.
Code: [Select]
(pseudocode)
class SCORE-BOXES
  int score
  setScore(int)
  display/render/...
  /*internal stuffs*/
With some inheritance (sf::Drawable) you can display you "SCORE-BOXES" the same way you display a sf::Sprite.


Hey thanks : D
Sometimes I have to think more about it.
Is the member Score now the condition for how many boxes should be displayed ?

And I didn't mention that I want a collision function.
Would it be right if it looks like that?

Code: [Select]
class Score-Boxes
{
int collision(sf::Sprite &Sprite)

//...
sf::sprite sprite_one;
sf::sprite sprite_two;
sf::sprite sprite_three;
sf::sprite sprite_four;
}



in the main.cpp it would look like this:

Code: [Select]

for (int i = 0;i < count of Sprites;i++)
{
      if (i == 0)
      collision(sprite_one)
      else
      if (i == 1)
      collision(sprite_two)
// and so on ?
}

3
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

4
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.


5
Window / Text box in SFML ?
« on: April 19, 2010, 05:50:35 pm »
Quote from: "Walker"
SFML doesn't include anything like that. Windows message box would work, but I would recommend using Qt for cross-platform goodness :)

There is also some sort of GUI thing in the wiki I believe, but I haven't looked into it.

EDIT: Come to think of it, you could just make a new window. Make your own buttons etc. Probably could even encase this in a class and have it return whatever based on which button was pressed, sort of like windows MessageBox.  :wink:


I just want to add a textbox in order to take Input from the keyboard.
It should to be something like EDITTEXT from windows.h

6
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 ?

7
General / No executable ?
« on: April 17, 2010, 03:37:09 pm »
Quote from: "Ashenwraith"

I think I might know your prob which is not clearly explained in the tutorial if you are new.

When you set up your linking and everything you can set it up for your project instead of compiler to make sure everything is correct.

Make sure you create a new project, then at the top menu go to Project>>Build Options

Click Release on the left, set all options again, but make sure the Policy: drop menu is 'Use target options only'

After setting all options go back to the menu at the top Build>>Select Target>>Release

Now try Build>>Build and Run and if successful your exe should be in my_project_folder/bin/release

It won't run without a copy of the dlls used in the same folder.

Also, make sure to save your project and close after these steps because if code::blocks crashes you will lose all your settings (even compiler/editor/etc).


Thanks but this doesn't  seem to work.
I figured out  that the problem is probably related to the code I wrote.
When I remove FS_STATES.cpp and Game_Board.h from the project it works(Plus the Menue(App) Command in main.cpp)
Could you all look at my code and tell me if there's anything wrong with it, please?

===========
EDIT:

I think I figured out the problem.
I defined the Window_State in the .h  instead of declaring it.(I know, you can't define variables in .h files)
Everything works.

I have a last question.
I declare an integer in file a.h and define it in b.cpp and use it in another file c.cpp.
(The function is written in c.cpp and used by b.cpp)
I compile it and it works...how can c.cpp work without the definition of the integer?

Thank you all for the help . )

8
General / No executable ?
« on: April 16, 2010, 03:56:58 pm »
Quote from: "Laurent"
You forgot to define SFML_DYNAMIC, as explained in the tutorial.


Still the same ; (

9
General / No executable ?
« on: April 16, 2010, 02:56:48 pm »
Oh the build log seems to be very interesting.
While building it this appears in the log :

Code: [Select]


-------------- Build: Debug in SFMLTEST ---------------

Linking executable: bin\Debug\SFMLTEST.exe
Info: resolving vtable for sf::Spriteby linking to __imp___ZTVN2sf6SpriteE (auto-import)
obj\Debug\FS_STATES.o: In function `_ZNSt8_Rb_treeIPN2sf11ResourcePtrINS0_5ImageEEES4_St9_IdentityIS4_ESt4lessIS4_ESaIS4_EE11_M_put_nodeEPSt13_Rb_tree_nodeIS4_E':
C:/Programme/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_construct.h:(.data+0x0): multiple definition of `_Window_State'
obj\Debug\main.o:C:/Programme/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_construct.h:(.data+0x0): first defined here
C:\Programme\CodeBlocks\MinGW\bin\ld.exe: warning: auto-importing has been activated without --enable-auto-import specified on the command line.
This should work unless it involves constant data structures referencing symbols from auto-imported DLLs.collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 1 warnings

 


I don't understand this.
I was able to build and run it, but afterwards I created the FS_STATES.cpp and Game_Board.h and added it to the Project this happened

10
General / No executable ?
« on: April 16, 2010, 02:42:00 pm »
@Mindiell
No I'm linking the standard libs to compile it :
-lsfml-system
-lsfml-window
-lsfml-graphics

@Coolhome
I'm using code blocks.

In the project options it say :
Output filename : "bin\Debug\SFMLTEST.exe"

@Osbios
I didn't know about that.
I used to build my codes without this and it worked.

@Walker
I did that two times ...it doesn't work after it either

@panithadrum
I will have a look at it

11
General / No executable ?
« on: April 15, 2010, 10:01:23 pm »
Quote from: "Ashenwraith"
It should be in your bin/debug or bin/release folder


Yeah I know, but there is no exe ; (
Could it be that I changed something to say the compiler not to build anything.
It's because when i try to use the "build and run" button it always says "It seems that the code isn't build yet.Build it now?"
Then I say yes, it's compiling and there it goes again...no exe and no running it.

12
Graphics / sf::string Text using as sprintf?
« on: April 15, 2010, 06:02:19 pm »
Thank you all.
All tips are working : D

13
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 : )

14
Graphics / sf::string Text using as sprintf?
« on: April 10, 2010, 04:01:42 pm »
Thank you all.

Now it works as it should be.
Another thing, I don't get the boost::format to work.

Are there any special Header to be included?

15
Graphics / sf::string Text using as sprintf?
« on: April 09, 2010, 11:29:57 pm »
ok, I changed my code but it doesn't show up on the window :

Code: [Select]


int main()
{

//...
std::stringstream stream;


   while (App.IsOpened())
   {

        //...

        App.Display();

        stream << 2;


        std::string string;


        stream >> string;


        std::cout << string << std::endl;



   }

    return EXIT_SUCCESS;
}




I thought I have to convert it like this...somehow it doesn't show up either ; (
Code: [Select]


int main()
{
//...

std::stringstream stream;

sf::String Text;
Text.SetText("Nothing yet");
Text.SetFont(MyFont);
Text.SetSize(50);

//...

while (App.IsOpened())
   {

        //...


        stream << 2;


        std::string string;


        stream >> string;

        Text.SetText(string);

        App.Draw(Text);
        App.Display();


   }

    return EXIT_SUCCESS;
}






EDIT :

Hey, i have to apologize.
it worked!

But if I write it like this :
Code: [Select]

//...
        stream << "Something else";

        std::string string;

        stream >> string;
        Hello.SetText(string);


        // Clear screen
        App.Clear();

        // Display sprite in our window
        App.Draw(Sprite);



        App.Draw(Hello);

        // Display window contents on screen
        App.Display();
//...


The text appears like this "else Something"

Pages: [1] 2