i have an array that used to store tower data, if no tower then it store 0 and if there is tower it store 1.
how do i combine it with screen, example arr [0][0] is placed on x0.y0 to xn.yn on the screen. i still don't get it. i've been thingking about tileset but is there another option since i'm looking the easiest way to implement it :). here is my map
"http://img291.imageshack.us/img291/6050/playbg.png"
i'm using SDL
combining array with image
well i want to add tower in that map, to make sure player don't make tower at the same place i think i'll use array to mark place in map if there is a tower it won't build again it that place. but i don't know how to combine those array with my map to so there wont be a collision between towers
Looks like you don't understand tiles yet. Let me explain how you should do this.
Okay, you will have a .txt file of some sort, which holds something like this:
0 0 0 0 1 0
0 1 0 0 0 1
Etc...
Each of these numbers represents a point on your grid, so the top left will be in [0][0] in your array, one to the right will be in [0][1] etc..
Now, every frame you will loop through this array something like this:
loopX = 0;
loopY = 0;
While ( loopX < screen_width/tile_width )
{
While ( loopY < screen_height/tile_height )
{
Draw( loopX * tile_width, loopY * tile_height, src, dest );
}
}
In which tile_size will be the width/height of your image.
If you wish more explanation, feel free to ask. I am just typing this on my mobile, which is a pain.
P.s. I made a tower defence game myself, which isn't awesome but it should explain it to you. If you wish, I can try to find the source and upload it for you. Just tell me :)
Okay, you will have a .txt file of some sort, which holds something like this:
0 0 0 0 1 0
0 1 0 0 0 1
Etc...
Each of these numbers represents a point on your grid, so the top left will be in [0][0] in your array, one to the right will be in [0][1] etc..
Now, every frame you will loop through this array something like this:
loopX = 0;
loopY = 0;
While ( loopX < screen_width/tile_width )
{
While ( loopY < screen_height/tile_height )
{
Draw( loopX * tile_width, loopY * tile_height, src, dest );
}
}
In which tile_size will be the width/height of your image.
If you wish more explanation, feel free to ask. I am just typing this on my mobile, which is a pain.
P.s. I made a tower defence game myself, which isn't awesome but it should explain it to you. If you wish, I can try to find the source and upload it for you. Just tell me :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement