how a simple level editor is made?

Started by
12 comments, last by graveyard filla 20 years, 1 month ago
Don´t know how you can get mouse coords with SDL but I´m pretty sure it´s easy thing to do..

about collision and things.. I just described in my last post how I did them.. I don´t know what do you mean by saying "regular tile based collision detection"..

Advertisement
Use SDL_GetMouseState(int x, int y) function to get the mouse coordinates.

"If you are not willing to try, you will never succeed!"

Grellin
"If you are not willing to try, you will never succeed!"GrellinC++ Game Programming
mkk could you describe better how you found what tile the user clicked on? i see you divide by 46 and 23... is this your tile width/height?
FTA, my 2D futuristic action MMORPG
graveyard filla: Yes, 46 and 23 are the width and height of my tiles..

So to get the right tile.. first you have to decrease the number of pixels that are there before the gameboard itself.. In my editor there 170 pixels on x and 140 on y before the gameboard.

Example: The mouse is on bottom left corner of game board, let´s say it´s values are, x: 192, y: 150.

Here´s a pic.

Now we start to calculate numbers..

first we take off these extra pixels before game board (170 on x and 140 on y):

x = 192-170
x = 22

y = 150-140
y = 10

then we divide these numbers by width/height of the block:

x = 22/46 (width = 46)
x = 0,47826086956521739130434782608696
(but because x is integer type of variable, decimal numbers
are not considered and x will be zero)
x = 0

y = 10/23 (height = 23)
y = 0,43478260869565217391304347826087 (and y is also integer..)
y = 0

and now we have x = 0, y = 0 and we can put stuff to
first place in the array (and that´s the tile where the mouse is pointing):

gameBoard[x][y] = tile;


[edited by - Mkk on March 22, 2004 5:37:04 AM]

This topic is closed to new replies.

Advertisement