Tile-based map and A-star help?

I am working on a tower defense type game. A while ago I posted asking about maze logic and was kindly directed towards A-star pathfinding. It is perfect. I understand the concept and it makes sense. Now the problem I am having is how to do the tile-based map? I'm having a hard time wrapping my head around it. I just want to do a straight square map comprised of squares. I realize a 2D Array would probably be the best way just such as:
int[][] map = new int[100][100]
where there would be 100 x 100 tiles. I can then populate the array with numbers ie 0 = walkable, 1 = unwalkable. I can have my A* algorithm return the set of tiles to move to.
My problem is that I don't want my game to be in pixels and I'm having a hard time understanding how to make the game appear tile based and large enough to be playable? ie. 1 tile = 30x30 pixels. If we are looking at it in terms of model and view, I understand the model part, but I am having a hard time translating to the view? How do I create a tile based view so that the user can only place towers on a tile(the mouse click location could be any point inside the tile)? Also, how would I keep the enemy units moving smoothly between tiles and not just jumping to the center of each tile?
I got some great advice last time and any more advice or points in a good direction would be greatly appreciated.

The reason to distribute your maze into nodes (tiles) is that pathfinding is slow, so you want to eliminate any notion of screen dimensions (pixels, inches, etc.) from A*. For all purposes, your maze is 100x100 pixels; any given object can choose between 100 horizontal and 100 vertical values.
how would I keep the enemy units moving smoothly between tiles and not just jumping to the center of each tile?Although your units may only have 100x100 nodes to consider, you can still animate them walking between each adjacent node on the path. Remember that the pathfinding (per tier) will occur before anything actually moves.
Still, this could look funny with only 100 nodes per axis. Units should use the shortest path that’s visible to them, and turning several degrees at each node will look choppy. So. I list three potential solutions here:
• Increase the number of nodes (the “accuracy”). Speed may be an issue.
• Use path smoothing algorithm. I haven’t seen your circumstance, but I would generally recommend this.
• Use multi-tiered/hierarchical pathfinding. This is probably more complex to implement.
Note that although the second and third options are distinct, they may coincide (some smoothing algorithms use multiple tiers). Googling for ‘pathfinding smoothing’ returned many results; this one in particular looked useful: [Toward More Realistic Pathfinding|http://www.gamasutra.com/features/20010314/pinter_01.htm]
How do I create a tile based view so that the user can only place towers on a tile(the mouse click location could be any point inside the tile)?If objects can be placed at arbitrary points, then A* needs to deem nodes impassable (your array’s 1) based on the objects placed in them. You have to be careful here and decide whether entire nodes should be ignored based on tower’s partial presence; for instance:
|====|====|====|====|====|
|====|====|====|===+|+++=|
|====|====|====|===+|+++=|
|====|====|====|====|====|
|0~0=|====|====|====|====|pixels: = ; node dividers: | (and line breaks for vertical) ; tower: +
The tower only covers ¼ of the node at (3, 3); should you eliminate it? Five solutions are obvious:
• Ignore any node with any chunk of a tower in it.
• Ignore any node entirely covered by a tower.
• Ignore any node whose center is covered by a tower. This won’t work with multi-tiered pathfinding.
• Ignore any node that has a tower covering any point the units are required to pass through. This will work with multi-tiered pathfinding.
• Using multi-tiered pathfinding, consider only consider the sub-nodes that aren’t covered by a tower.
I realize a 2D Array would probably be the best way just such as
int[][] map = new int[100][100]
For starters, if only want two values—passable and impassible—then a boolean would be better. But I would recommend against this. I’d bet you could write some OO code specific to your situation. You might want to use terrain costs, where nodes exist that A* would prefer over others.
I hope I answered some of your questions. Let me know if you have more—or if I didn’t.
Good luck.
—Douglas

Similar Messages

  • Best way to do a tile-based map

    Hello everybody-
    This should be a simple thing but I just can't get it to work. I'm making a tile-based top-down online rpg (application, not applet), and I pretty much have most of it done except I can't get the map to display and scroll right. i will admit that java graphics isn't really my thing, but i just can't get it. Its been so frustrating that i actually quite develpment on my game and quit for awhile, but i decided to try again. What I have is an array if images that make up the map, and then i manipulate the array depending where the character is so i only draw the tiles necessary. what i want to do is to combine all the tiles i need for the particular position, draw that image to the screen (so i don't have to draw each tile individually to the screen). then i could move that large image depending where the character moved, and add tiles to it depending on which way the character moves. I just can't get it to work however. I've looked at double-bufferning posts and that gave me some ideas, but not enough for my particular situation. if anybody has any experience in this i would be more than greatful. thank you

    I know exactly what you are talking about, I had your problem a while back when I was doing mobile phone games.
    To reduce the number of cell draws needed, cells were only drawn when at the edges of the view area. (all other cells were maintained from the previously drawn frame.)
    It gets pretty complicated, but it will work - stick with it.
    I would post some code - but I don't have it anymore - and it was pretty specific to J2ME MIDP API (java mobile phone).
    p.s. When I did it, I had to include several additional optimisation, these made it incredibly complex :(
    I will try to describe it, but without pictures, It will probably be in vain. (don't worry if you don't understand it :P)
    here is the summary of the logic :-
    the backbuffer had dimensions SCREEN_WIDTH+CELL_WIDTH*2, SCREEN_HEIGHT+CELL_HEIGHT*2 (I effectively had a border that was CELL_WIDTH wide, and CELL_HEIGHT tall.)
    this meant new cells only had to be drawn every time the view area passed over a cell boundary.
    however, doing this, meant it was super smooth until it hit a cell boundary, at which point it had to draw all the cells in the newly exposed column and/or row - which caused a jerk.
    To get around this, I devised a speculative rendering, where by the next column/row was pre-rendered over a series of game frames.
    (each column/row had its own buffer into which the pre-rendering was done)
    On average 2-4 times as many edge cells had to be rendered than needed, but, because the camera moved slowly, this could be distributed over approx. 10 game frames.
    By distributing the rendering of the edge cells over a number of game frames, I hoped to remove the jerk experienced as the camera crossed a cell boundary.
    The system worked... ish... but I never finished it :(
    basically, these were crazy optimisations that were only necessary because I was developing for mobile phones.
    On mobile phones the speed of rendering is relative to the number of draw calls, NOT the actual area of the screen being repainted.
    e.g.
    fillRect(0,0,50,50)
    fillRect(0,50,50,50)
    will take almost twice as long as
    fillRect(0,0,100,100)
    even though you are only painting 1/2 the area.

  • Smooth walking on tile based map system

    Hello,
    I am developing a small game which requires the use of a map system. I chose to make that map system work upon a tile-based system. At the moment, each tile is 32x32, and I contain 24x20 tiles on my map.
    A walking system is also required for this game I'm developing, so I ran into some issues with making the loaded sprite walk "smoothly". At the moment, it jumps from tile to tile in order to walk. This makes it seem very unrealistic. I have tried many different ways to make the walking "smoother", but it requires me to change my tile's size in order to accommodate the sprite's size. This would not be an issue if I only used the same sprite in the game, but since I load different sprites which contain different measurements, I do not know how to make my walking system accommodate all of the sprites in order to make the walking realistic.
    I am not requesting any code whatsoever, simply ideas.
    Thank you

    If your image is opaque, then it may draw the edges around itself, but wouldn't this be a problem wether it were completely contained within a tile or not? If the image has transparency, then it doesn't matter if it's drawn as a rectangle, it would still appear to be contained only by its outline.
    If you're using a back-buffer (which I highly recommend if there is going to be animation or movement onscreen), then you may need to specify the type for the BufferedImage that you use as a buffer, I always use TYPE_INT_ARGB to make sure I have Alpha values (transparency).

  • Upgrading from snow leapord to mavericks, i couldn't opened app store, messenger, ibook,FaceTime, maps and other. please help

    upgrading from snow leapord to mavericks, i couldn't opened app store, messenger, ibook,FaceTime, maps and other. please help

    Try booting into the Safe Mode using your normal account.  Disconnect all peripherals except those needed for the test. Shut down the computer and then power it back up after waiting 10 seconds. Immediately after hearing the startup chime, hold down the shift key and continue to hold it until the gray Apple icon and a progress bar appear. The boot up is significantly slower than normal. This will reset some caches, forces a directory check, and disables all startup and login items, among other things. When you reboot normally, the initial reboot may be slower than normal. If the system operates normally, there may be 3rd party applications which are causing a problem. Try deleting/disabling the third party applications after a restart by using the application un-installer. For each disable/delete, you will need to restart if you don't do them all at once.
    Safe Mode
    Safe Mode - About
    If that doesn't work, do a backup. Boot to the Recovery Volume (command - R on a restart or hold down the option key during a restart and select Recovery Volume). Run Disk Utility Verify/Repair and Repair Permissions until you get no errors. Then reinstall the OS.
    OS X Recovery
    OS X Recovery (2)

  • RPG Tile Based Map Programming

    Does anybody have any experience in this area? I have an online rpg type game that I'm working on and its going fine, the only problem is that the map scrolls too slow so your character moves too slowly. For my map I simply extended a JPanel. For every tile the character moves(one tile = 32 pixels) the screen is redrawn 8 times (each redraw basically moves the whole screen 4 pixels in the desired direction) in this way the screen moves very smoothly and character animation is smooth, but it is also pretty slow. Can anybody offer any suggestions? I would love to talk with people who have done this type of thing before becuase it is my first stab at it. thanks.

    the reason your drawing is slow, is because you are redrawing every cell, every frame. This is unnecessary, as you can reuse the cells you drew in the previous frame, by simply shifting them by the appropriate amount.
    let me clarify:
    I will use some real numbers to demonstrate the optimisation.
    screenWidth=800, screenHeight=640, cellWidth=32, cellHeight=32;
    scrollSpeed=8; // << the number of frames it takes to move by 1 complete cell
    just to render the background, your current approach calls drawImage this many times every frame
    (screenWidth/cellWidth+1)*(screenHeight/cellHeight+1)
    e.g. (800/32 +1)*(640/32+1) = 546 cell redraws/frame
    There are several approaches you can use to fix this, all require the use of a cellBuffer to cache the previously drawn cells.
    1) draw the cellBuffer onto itself, and redraw all the cells that have become corrupt.
    Approach will require (screenWidth/cellWidth+1)+(screenHeight/cellHeight+1) cell redraws
    e.g. 800/32+1 +640/32+1 = 47 cell redraws/frame
    2) have an oversized cellBuffer (with dimensions of screenWidth+cellWidth*2 by screenHeight+cellHeight*2).
    With this method, redraw of exposed cells is only necessary every time you cross a cell boundary, not every frame rendered.
    Assuming you are moving at a constant 4 pixels/frame as you describe in your question, that will mean
    e.g. 800/32+1 +640/32+1 = 47 cell redraws every 8th frame (an average of 5.9 celldraws/frame)
    This method has the lowest number of celldraws per frame. However, because you draw all newly exposed cells, in 1 go, you end up with choppy scrolling.
    3) This method attempts to solve the problem of choppy scrolling, by using predictive edge cell drawing, and distributing the cell rendering over multiple frames. (giving a more consistant frame rate)
    using this method, requires you to have 4 additional buffers (1 for each edge of the screen)
    into these buffers, the predicted cells will be cached.
    This algorithm has 2 important factors deciding its efficiency, if the viewport scrolls quickly, its efficiency will drop massively.
    The accuracy to which you can predict which edge buffer to fill up first also greatly influences the algorithms efficiency - therefor it is better suited to use in an environment where the direction of scrolling doesn't change rapidly.
    Best case performance is ((screenWidth/cellWidth+1)+(screenHeight/cellHeight+1))/scrollSpeed (assumes you are moving in both axis, if only moving in 1 axis, the performance would be even better)
    e.g. ((800/32+1)+ (640/32+1))/8= 5.9 cells/frame
    Worst case performance is ((screenWidth/cellWidth+1)*2 + (screenHeight/cellHeight+1)*2) /scrollSpeed
    e.g. ((800/32+1)*2 + (640/32+1)*2)/8 = 52+42/8 = 11.8 cells/frame.
    So, as long as you scroll at a constant 1 cell every 8 frames, this algorithm will give you a performance per frame of between
    5.9 and 11.8 cells/frame.
    As you can see, even the simple method highlighted in method 1) is approx. 9 times faster than your current method.
    and, if the choppy scrolling of method 2), or the limitations imposed by method 3) are acceptable for your implementation, you can get an algorithm that will run approx. 50-100 times faster than your current method.

  • Tile Based Collision Detection

    I am following Tonypa's Tile Based Tutorials and I have to
    say, they are great. He covers everything needed, except for one
    thing I am troubled on - Refering to Tutorial 9,
    http://www.tonypa.pri.ee/tbw/tut09.html,
    Stupid Enemy, instead of an enemy I want to make this a NPC who
    walks around in a village. So what do I do to make it so that I, or
    the char, doesn't walk right over the enemy/NPC? I am trying to
    develop an RPG, and it would look silly to have the character walk
    on top of the NPC. Can someone provided a snippet on how to make a
    collision detection with the NPC and not walk on top/under the NPC?
    One last favor to ask: What if I want to talk to the NPC if I
    am within a half tile? Would anyone be willing to share info on how
    this as well?
    Thanks a bunch in advance

    Ok, let me see if I get the read correct here: you have your scenery objects as tiles and when moving your players/NPC's through the scenery you are not scrolling the background as you go, but when you get to s certain point you want to scroll the tiles of the background also, so you can have new scenery cycle in as needed an still have the tiled background objects and new tiled background objects work for collision detection.
    If my take on your project is correct, then you have to make your tiles addressed with relative addressing formulas as you'll probably need to do with your sprites also.
    So the way this will go is that you have to make an offset and add them into your formula based on your character position. Then based on your character position you can choose to scroll your tiles left, right, up, down or what ever you choose to support. As a tile falls fully off the screen, you can dispose of it or cycle back through depending on how you implement your background.

  • Google maps and google help not loading anymore! help!

    Google maps and google help aren't loading since I've updated firefox. Works in Chrome no problem. Tried everything listed here: https://support.mozilla.com/en-US/kb/Error%20loading%20web%20sites, re-installed flash, cleared cache, etc... what am I missing?

    Anyone have any ideas?

  • Policy Based Routing and IP Helper

    Can anyone help with an issue i am having with PBR and an IP Helper.  I cannot get devices in the VLAN with the associated SVI to get DHCP addresses, there is no DHCP server in the VLAN so an IP Helper is used but whenever i enable PBR on the SVI, DHCP stops working.  The switch is a 6506 Catalyst running Version 12.2(17d)SXB11 of IOS
    The SVI config for the VLAN is as below
    ip address 10.2.60.254 255.255.255.0
    ip helper-address 10.10.80.200
    ip helper-address 10.10.80.201
    ip policy route-map ACPBR
    no ip igmp snooping explicit-tracking
    no ipv6 mld snooping explicit-tracking
    no ipv6 mld snooping
    a route map configured as follows
    route-map ACPBR permit 10
    match ip address ACPBR_ACL
    set ip default next-hop 10.99.1.252
    route-map ACPBR permit 20
    set default interface Null0
    and an access list as follows
    ip access-list extended ACPBR_ACL
    deny udp any any eq bootps log
    permit ip 10.2.60.0 0.0.0.255 any
    So any DHCP traffic should hit the deny command and drop back to the normal routing process, at least thats my understanding.  The logs on the 6506 even show the DENY being hit, see below
    list ACPBR_ACL denied udp 0.0.0.0(68) -> 255.255.255.255(67), 1 packet
    Can anyone advise why this may be happening, if i add the PBR to the SVI DHCP stops working, if i remove it then it starts working so it is definately PBR doing something.
    Thanks
    Ryan

    Ryan,
    The deny line in your ACL merely causes the DHCP traffic to be not processed in the ACPBR block 10. However, for this traffic, the processing of the route-map continues to block 20 with the set default interface Null0 command. This could be the cause of the drops you are seeing. Remember, the permit/deny in ACL here only select packets to be dealt with in the particular route-map block. However, it is the permit/deny in the route-map block header that determines whether the packet is going to be PBR-ed or normally routed.
    Assuming you want to keep the DHCP traffic to be normally routed, one of ways of doing that would be:
    ip access-list extended ACPBR_ACL deny udp any any eq bootps log permit ip 10.2.60.0 0.0.0.255 any!ip access-list extended ACPBR_DHCP permit udp any any eq bootps!route-map ACPBR permit 10 match ip address ACPBR_ACL set ip default next-hop 10.99.1.252!route-map ACPBR deny 15 match ip address ACPBR_DHCP!route-map ACPBR permit 20 set default interface Null0
    This configuration causes the DHCP traffic to be processed in block 15, and because of the deny action in the block header, the traffic should fall back to normal routing.
    While I am somewhat surprised that the PBR would affect broadcasts (it should not, and perhaps it affects only a part of the DHCP communication that does happen to be unicasted), I believe this modification of your config is worth trying.
    Best regards,
    Peter

  • Help me please : Serious problems with collection-mapping, list-mapping and map-mappi

    Hi everybody;
    I have serious problems with list-mapping, collection-mapping and map-mapping.
    Acording to specifications and requirements in a system I am working on it is needed to
    get a "list" of values or an indivudual value.I am working with ORACLE 9i Database,
    ORACLE 9i AS and ORACLE 9i JDEVELOPER.
    I tried to map a master-detail relationship in an entity-bean, using list-mapping.
    And this was very useful in order to get a "list" of details, ...but, when I wanted
    to get a single value I have some problems with persistence, something about "saving a state"
    despite I just want to get the value of a single detail.
    I decided to change it to map-mapping and the problem related with a single detail
    worked successfully, but I can get access to the whole bunch of details.
    May anyone of you help me with that?
    I am very confused I do not know what to do.
    Have any of you a solution for that problem?
    Thank you very much.

    Have you tried a restore in iTunes?

  • Album ratings and clear stars are ruining my playlists. Help turn them off.

    I understand that if you give an album an album rating, it will give all unrated songs on that album clear stars based on the album rating. Because of this, I have not rated any of my albums, since all of my playlists are based off of the song ratings.
    All of a sudden, now when I rate a single song, it puts clear stars in the album rating column, and ALSO assigns clear stars for all of the unrated tracks on that album. It is ruining all of my playlists.
    Is there any way to turn off the album ratings, or turn off the clear stars, or do something to get rid of this, rather than going through manually and adjusting each song individually?

    Is there anyway to make itunes recognize the difference between clear stars and filled stars when making smart playlists? This may work to make things work for me.
    If you use "album rating" field in your playlist, it will use the clear stars that appear in that column. If you use "rating" field in your playlist, it should ignore the clear stars that appear in the "album rating" column.
    As for an example of how things are not working right now, I have a playlist that is just unrated music, so that if I feel like rating some of the newer songs I added in, I can just load that playlist, and everything in there has no ratings. Now, some of the albums that are mostly unrated are not showing up in that playlist, because instead of all of the unrated songs being blank, they all have clear stars next to them.
    When you say "unrated music", what precisely is the rule you use? When I set up a playlist with the rule "Rating is less than '1 star'", even albums with clear stars in the "album rating" field show up (as long as the individual track doesn't bear a rating, obviously). But when I change that rule to say "Album rating is less than '1 star'", then as soon as I rate one song, the entire album is removed from the playlist.
    And just to make sure I am being very clear on this, I have NOT used the album rating at all, those stars are clear as well.
    Ok, I think this may answer some of the questions in my previous post. I infer that you are seeing clear stars in the "rating" column, not just the "album rating" column. Can you confirm this? If that's the case, then this is truly a mystery. I was hoping the problem was an innocent confusion between the "album rating" and the "rating" columns.

  • Hi plz help me here .. I update my macbook air running with Mac 10.8.5 to yosemite and it will take too long to shut down and when stars it will like its gonig update?

    Hi plz help me here .. I update my macbook air running with Mac 10.8.5 to yosemite and it will take too long to shut down and when stars it will like its gonig update?

    More information would be helpful.

  • I have a Mac OS X 10.7 and want to be able to open Microsoft based WMV and MPG video. Can someone help me find a proper download?

    I have a Mac OS X 10.7 and want to be able to open Microsoft based WMV and MPG video. Can someone help me find a proper download?

    go out and gather together all players you can run on Lion:
    MpegstreamClip, with QuickTime pro as the engine you can open and export just about anything.
    Flip4Mac, buy it and you can convert and export to wmv. Usefull if you must have wmvs in PowerPoint.
    Perian
    VLC
    Divx for Mac
    Elgato h264 Turbo if you want to create h264 fast.

  • I have created several templates and they look great in live view, however they look like crap when actually tried to set up a webpage based on the template. Help!

    I have created sevedral templates and they look great in the live view, however they look like plain HTML text when I try to create a webpage based on the template. HELP!

    This forum is about the Cloud as a delivery process, not about using individual programs
    If you start at the Forums Index https://forums.adobe.com/welcome
    You will be able to select a forum for the specific Adobe product(s) you use
    Click the "down arrow" symbol on the right (where it says All communities) to open the drop down list and scroll

  • I enabled 3d in google maps, and it now crashes firefox everytime I open maps. HELP!!

    I have a mac, and I was using google maps. I was trying to find the views of the actual buildings on the maps, and clicked on the 3D option in the lower left corner. That caused an immediate crash of firefox and has done so everytime I try to open google maps. The window isn't open long enough for me to try and unclick that option. Please tell me how to get my google maps back! thanks

    Thank you, thank you, thank you!
    I couldn't tell which of the many cookies was the offender, so I had to clear them all...which I know is going to mean I lost some convenience, but it was worth it. For future reference, is there a way to know which cookie is causing the problem?

  • I was google mapping and my ipad bacame hung. Can neither exit nor switch off. need help!

    I was google mapping and my ipad hang. Can neither exit nor switch off. Any advice on what's gone wrong?

    Try a restart:
    To restart (reboot) Press and Hold the Home and Power buttons until the Apple Logo appears, about 10 seconds.

Maybe you are looking for