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

Pages: [1]
1
I've got it solved now using recursion. Thanks guys  :)

2
If you need speed you could do a geometric approach..........................

Thank you for the descriptive answer. However, I must admit that I do not have the faintest idea on how to actually go about implementing that. Mathematics has not been my strong point. Can you please provide a small example of this?


If I understand what you want, what you need is a flood fill algorithm

You start at the player position, and collect all its non-occupied adjacent cells (there should be max 4).................

Thanks for the idea. I have looked into wiki and have tried different ways of implementing this. But I still can't seem to get it to work correctly.


Once again, thank you both for your help. I cannot even fathom how a geometric approach to this would be. So I've went and redone the function several times trying to  to implement a recursive function akin to what a flood fill algorithm may be like (except of course, mine doesn't work). My current code follows this logic (or at least I think it does!)

(click to show/hide)

My actual code is
(click to show/hide)

This sorts of works...
(click to show/hide)

But not perfectly.
(click to show/hide)

Actually it doesn't work at all.
(click to show/hide)

Inconsistent too.
(click to show/hide)

Is there something wrong with my underlying code logic or am I making some major mistakes in coding? Or both? I feel like I have difficulties with trying to come up with the a working algorithm  :-\ Is there something very obvious that I am missing?

3
Hi,

I'm still quite a newb when it comes to C++ (or programming in general) and SFML so this is a project more for my personal learning and interest than anything else.

I've been stumped for a while now on how to implement a way to properly determine the possible movements in a turn-based grid game.

At first, I've implemented possible movements to be something like this:

(click to show/hide)

Basically what happens is that when you click the banana button (just testing for now), the possible grids you can click on to move to gets filled with the colour yellow. After you click on one of those grids, the grids will stop showing and the sprite on the left will move to that grid (always x first, then y; I don't intend to make diagonal movements possible for now; also note that the sprite on the right doesn't do anything other than occupy a grid at the moment). Once the sprite finishes the movement, the banana button will appear again.

I threw in a check so that you cannot move to a grid already occupied by another entity and thought it was fine until I realised that while you cannot move to an occupied grid, you can still move through them:

(click to show/hide)

However, before I start working on trying to make it so it moves around the occupied grids instead of right through them, I needed to make sure the possible grid movement being shown is correct. There shouldn't be a yellow grid on the right of the non-moving stick entity since it would take more than 3 grids to get there (that is if you dont move through him or diagonally).

I've been stumped on this for a long time, tried multiple different ways to implement this logic but I cannot come up with anything that works properly or consistently. I've tried to write nests and nests of IF statements instead of using loops , but it got way too messy to manage and I feel that there has to be an easier way.

Eventually, I've stripped it all down to movement in a straight line. If the grid is blocked, further grids beyond no longer gets shown:

(click to show/hide)

This works fine, but obviously I want to also display grids beyond just a straight line. What would be a simple solution to implement this logic?

For reference, below are my current code for implementing the grids. I apologise in advance if they lack clarity, since I'm still quite a newb and may adopt practices and conventions that are not optimal. However, I've inserted comments and tried to explain what I did.

(click to show/hide)

Thanks for anyone who can help me this.

-Sine

Pages: [1]
anything