Hi i would like to build a c++ game with SFML graphic library
now i see sprites can move using floats ( sprite.move(+x,+y) )

how do i connect between the graph ( configured by a matrix ) and the graphic library?
since the graphic library uses floats and set positions how do i tell which spot is
the graph[0][0] location? and how much do i need to move when i press RIGHT in order
to get to graph[0][1]?

simple explanation would be great just need to understand and i will write the code
thank you!

have so far:
graph[20][20] size with all cells = true ( can move anywhere)
need help :
configuring each player to a right location depending on the graph
(i read a game map from a file. if first char is X i want X image to be
displayed on the screen but on the graph it will be on graph[0][0])

5 Years
Discussion Span
Last Post by Despairy

It depends on the size of each cell in the graph. For example, if graph[0][0] is a rectangle of size 1 unit, then when the user presses right, you can move the sprite one unit to the right, and it would now be in graph[0][1]. And similary, if the user presses down, assuming he started at graph[0][0], you can move him one unit down, and now be in the location of graph[1][0] and so on


The graph is configures as bool graph[20][20]
if you can move to next cell or not.
from what you are saying it seems like this way isnt good.
should i change the graph cells to a different struct?
eventualy i need each cell to hold a different class. like a player / wall / etc...

how do you suggest i do that?
thank you


i was offered to use translate function of the library which shd show me
a x/y coordinates as on a matrix instead of the (something like) mouse position
ill try to use it but you are welcome to post other ideas.

*problem is i have a grid and if i put a penguin on 0.0 = top left edge of screen
and i write that the penguin is on x=0/ y=0 on a matrix i created.

now on each right button click i need to move it using x++, and i dont know how
to move it accordingly on the grid.


This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.