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])

Recommended Answers

All 4 Replies

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

What is the exact problem you are trying to solve?

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.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.