A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Tile map without tiles?

  1. #1
    Junior Member
    Join Date
    Jun 2008
    Posts
    4

    Question Tile map without tiles?

    First off, I want to say thanks to the flash-kit community. You all have been a great help to flash developers/designers.

    Now to my question. Is is possible to impliment tile based system but never actually draw tiles? Actually, I know it is possible but I have not been able to figure it out.

    I am creating a tile based tower defense game. I have different maps that the player can use. These maps are tile based but i don't draw them dynamically. I have a movie clip of a graphic i use for my map. I have an array of 0s and 1s to store where it will be okay to build towers. (0s are okay, 1s are occupied space.) So my array looks like this:

    Code:
    MapData = [
    	[0,0,0,0,0,0,0,0,1,1,0,1,1,0,0],
    	[0,1,1,1,1,1,1,1,1,1,0,1,1,0,0],
    	[0,1,1,1,1,1,1,1,1,1,0,1,1,0,0],
    	[0,1,1,0,0,0,0,0,0,0,0,1,1,0,0],
    	[0,1,1,1,1,1,1,1,1,1,0,1,1,0,0],
    	[0,1,1,1,1,1,1,1,1,1,0,1,1,0,0],
    	[0,0,0,0,0,0,0,0,1,1,0,1,1,0,0],
    	[0,1,1,1,1,1,1,0,1,1,0,1,1,0,0],
    	[0,1,1,1,1,1,1,0,1,1,0,1,1,0,0],
    	[0,1,1,0,0,1,1,1,1,1,0,1,1,0,0],
    	[0,1,1,0,0,1,1,1,1,1,0,1,1,0,0],
    	[0,1,1,0,0,0,0,0,0,0,0,1,1,0,0],
    	[0,1,1,1,1,1,1,1,1,1,1,1,1,0,0],
    	[0,1,1,1,1,1,1,1,1,1,1,1,1,0,0]
    	];
    When the player clicks on an icon of a tower and places his tower in an unoccupied space, i want it to snap to the coordinating grid tile and replace the 0 with a 1 in the array. That way the next time we try to place a tower that space is occupied.

    Any help as to how this can be accomplished would be a great help. If I am going about this all wrong, it would be appreciated if you would say how it could be done more efficiently.

    Thanks

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    If it were me, I'd store the tower object inside that array instead of ones & zeros, so if you check and it comes back null, you know you can put something in there, otherwise you can directly access the tower at that position.

    Otherwise you'll need to start doing the math to figure out what range of pixels is going to correlate to a given point in your array...it should be something like Math.floor(tower.x/map.width)

  3. #3
    Junior Member
    Join Date
    Jun 2008
    Posts
    4
    So i should store the actual tower or a reference to the tower in the array? Wouldn't this cause some big memory issues?

    So what you're saying is i should store a reference to the tower at Mapdata[x][y]. where x and y are the tile positions on my grid. Then when i check if a tile is occupied I just check to see if it returns null. I could see how this would work.

    Could you give me some example code?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center