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

Author Topic: help with puzzle game  (Read 1302 times)

0 Members and 1 Guest are viewing this topic.

MadTrial

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
help with puzzle game
« on: December 01, 2012, 05:32:44 pm »
Hi, i'm new with sfml, and i'm getting some problem in my first game, hope there is someone to help me.

I'm going to create some kind of puzzle games, but the game not going as i wanted, there's something wrong in my code, when i click on my sprite, it's moved to different possition as i want, but don't know why its going back to the same position after some milisecond, but when i delete "Area[temp]=Area[GetMouseClick()];" its moved, but its only worked when we click the sprite that hasn't clicked before. [note : it's only happen when the empty space is at right bottom corner]

this is my code :
            if (GetMouseClick() && moveAble(GetMouseClick()))
            {
                temp=0;
                while (!isAreaEmpty(temp))
                    ++temp;
                piece[Area[GetMouseClick()]].SetPosition(GetCord(temp));
                Area[temp]=Area[GetMouseClick()];
                Area[GetMouseClick()]=0;
            }
        }

 

there is no error appears on my compiler, and i'm using SFML 1.6 on Code::Blocks 10.05
Quote
sorry for my bad english :)

« Last Edit: December 01, 2012, 06:54:58 pm by MadTrial »

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: help with puzzle game
« Reply #1 on: December 01, 2012, 05:56:36 pm »
First read this: http://en.sfml-dev.org/forums/index.php?topic=5559.0

You should as well use SFML 2.0 and not 1.6, it hasn't been touched in two years and it has bad bugs, not to mention it lacks useful things such as renderTexture, Vertex and VertexArray.

You have no problem with rendering and other parts of your code that are there, so you should remove that part of the code and only post the code of where you think the problem is. It makes it easier for everyone, either you find out what was wrong on your own (it happens more often than you think) or you make us read less and find a faster answer.

Quote
When i click on my sprite, it's moved to different possition as i want, but don't know why its going back to the same position after some milisecond, but when i delete "Area[temp]=Area[GetMouseClick()];" its moved, but its only worked when we click the sprite that hasn't clicked before. [note : it's only happen when the empty space is at right bottom corner]

Area[temp]=Area[GetMouseClick()];

When the loop goes on it's next iteration it resets the position to an already existing one, so it's expected that your sprite reappears after this. Removing it should be the first step to take (and you have already done so it appears).

Other than that you need to explain your problem better, maybe a screenshot will help understand further, because saying there's an empty space doesn't say much, as we don't know with full detail what you want or what's the idea you have on your mind.

Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

MadTrial

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: help with puzzle game
« Reply #2 on: December 01, 2012, 07:13:19 pm »
thanks for your reply, i have just modify my post :)

here is my screenshoot.


when i click (hold) box numb 3 or 7, it's moved to the empty one(grey box), but when i release my click, thats box (3or 7) goes back to the first position.
it's only happen when the empty one in that position.

did you understand? if you dont, you may download the debug file here : https://dl.dropbox.com/u/26863830/forum/Debug.rar
it's explain everything.

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: help with puzzle game
« Reply #3 on: December 03, 2012, 05:25:13 am »
I downloaded the debug file and got what was wrong with it. You set new positions in a rather odd way.

Quote
if (GetMouseClick() && moveAble(GetMouseClick()))
            {
                temp=0;
                while (!isAreaEmpty(temp))
                    ++temp;
                piece[Area[GetMouseClick()]].SetPosition(GetCord(temp));
                Area[temp]=Area[GetMouseClick()];
                Area[GetMouseClick()]=0;
            }

The logic sample here shows that you do some crazy things with positions and vectors.  Your error is on the logic part and not something SFML related. Since your mini-game handles fixed positions (nine in this case), you should have a "NumberedTile" class that has a position, sprite and the corresponding functions to make it work and a "GameMaster" class that is in charge of managing how each tile gets on it's correct position.

The event MouseClick should execute a single function that moves the sprite (through GameMaster) only once when the given tile was clicked. The code is hard to follow because if I remember well all was in main(). And the logic did some unclear stuff with arrays, even for simple things like these it's better to have some structure, it gives your code ease of use and fixing errors.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

 

anything