Jump to content
  • Advertisement
Sign in to follow this  
ShyAngel

combining array with image

This topic is 2851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!