Search Results

Search found 853 results on 35 pages for 'tile'.

Page 5/35 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Draw Bug 2D player Camera

    - by RedShft
    I have just implemented a 2D player camera for my game, everything works properly except the player on the screen jitters when it moves between tiles. What I mean by jitter, is that if the player is moving the camera updates the tileset to be drawn and if the player steps to the right, the camera snaps that way. The movement is not smooth. I'm guessing this is occurring because of how I implemented the function to calculate the current viewable area or how my draw function works. I'm not entirely sure how to fix this. This camera system was entirely of my own creation and a first attempt at that, so it's very possible this is not a great way of doing things. My camera class, pulls information from the current tileset and calculates the viewable area. Right now I am targettng a resolution of 800 by 600. So I try to fit the appropriate amount of tiles for that resolution. My camera class, after calculating the current viewable tileset relative to the players location, returns a slice of the original tileset to be drawn. This tileset slice is updated every frame according to the players position. This slice is then passed to the map class, which draws the tile on screen. //Map Draw Function //This draw function currently matches the GID of the tile to it's location on the //PNG file of the tileset and then draws this portion on the screen void Draw(SDL_Surface* background, int[] _tileSet) { enforce( tilesetImage != null, "Tileset is null!"); enforce( background != null, "BackGround is null!"); int i = 0; int j = 0; SDL_Rect DestR, SrcR; SrcR.x = 0; SrcR.y = 0; SrcR.h = 32; SrcR.w = 32; foreach(tile; _tileSet) { //This code is matching the current tiles ID to the tileset image SrcR.x = cast(short)(tileWidth * (tile >= 11 ? (tile - ((tile / 10) * 10) - 1) : tile - 1)); SrcR.y = cast(short)(tileHeight * (tile > 10 ? (tile / 10) : 0)); //Applying the tile to the surface SDL_BlitSurface( tilesetImage, &SrcR, background, &DestR ); //this keeps track of what column/row we are on i++; if ( i == mapWidth ) { i = 0; j++; } DestR.x = cast(short)(i * tileWidth); DestR.y = cast(short)(j * tileHeight); } } //Camera Class class Camera { private: //A rectangle representing the view area SDL_Rect viewArea; //In number of tiles int viewAreaWidth; int viewAreaHeight; //This is the x and y coordinate of the camera in MAP SPACE IN PIXELS vect2 cameraCoordinates; //The player location in map space IN PIXELS vect2 playerLocation; //This is the players location in screen space; vect2 playerScreenLoc; int playerTileCol; int playerTileRow; int cameraTileCol; int cameraTileRow; //The map is stored in a single array with the tile ids //this corresponds to the index of the starting and ending tile int cameraStartTile, cameraEndTile; //This is a slice of the current tile set int[] tileSetCopy; int mapWidth; int mapHeight; int tileWidth; int tileHeight; public: this() { this.viewAreaWidth = 25; this.viewAreaHeight = 19; this.cameraCoordinates = vect2(0, 0); this.playerLocation = vect2(0, 0); this.viewArea = SDL_Rect (0, 0, 0, 0); this.tileWidth = 32; this.tileHeight = 32; } void Init(vect2 playerPosition, ref int[] tileSet, int mapWidth, int mapHeight ) { playerLocation = playerPosition; this.mapWidth = mapWidth; this.mapHeight = mapHeight; CalculateCurrentCameraPosition( tileSet, playerPosition ); //writeln( "Tile Set Copy: ", tileSetCopy ); //writeln( "Orginal Tile Set: ", tileSet ); } void CalculateCurrentCameraPosition( ref int[] tileSet, vect2 playerPosition ) { playerLocation = playerPosition; playerTileCol = cast(int)((playerLocation.x / tileWidth) + 1); playerTileRow = cast(int)((playerLocation.y / tileHeight) + 1); //writeln( "Player Tile (Column, Row): ","(", playerTileCol, ", ", playerTileRow, ")"); cameraTileCol = playerTileCol - (viewAreaWidth / 2); cameraTileRow = playerTileRow - (viewAreaHeight / 2); CameraMapBoundsCheck(); //writeln( "Camera Tile Start (Column, Row): ","(", cameraTileCol, ", ", cameraTileRow, ")"); cameraStartTile = ( (cameraTileRow - 1) * mapWidth ) + cameraTileCol - 1; //writeln( "Camera Start Tile: ", cameraStartTile ); cameraEndTile = cameraStartTile + ( viewAreaWidth * viewAreaHeight ) * 2; //writeln( "Camera End Tile: ", cameraEndTile ); tileSetCopy = tileSet[cameraStartTile..cameraEndTile]; } vect2 CalculatePlayerScreenLocation() { cameraCoordinates.x = cast(float)(cameraTileCol * tileWidth); cameraCoordinates.y = cast(float)(cameraTileRow * tileHeight); playerScreenLoc = playerLocation - cameraCoordinates + vect2(32, 32);; //writeln( "Camera Coordinates: ", cameraCoordinates ); //writeln( "Player Location (Map Space): ", playerLocation ); //writeln( "Player Location (Screen Space): ", playerScreenLoc ); return playerScreenLoc; } void CameraMapBoundsCheck() { if( cameraTileCol < 1 ) cameraTileCol = 1; if( cameraTileRow < 1 ) cameraTileRow = 1; if( cameraTileCol + 24 > mapWidth ) cameraTileCol = mapWidth - 24; if( cameraTileRow + 19 > mapHeight ) cameraTileRow = mapHeight - 19; } ref int[] GetTileSet() { return tileSetCopy; } int GetViewWidth() { return viewAreaWidth; } }

    Read the article

  • Zelda-style top-down RPG. How to store tile and collision data?

    - by Delerat
    I'm looking to build a Zelda: LTTP style top-down RPG. I've read a lot on the subject and am currently going back and forth on a few solutions. I'm using C#, MonoGame, and Tiled. For my tile maps, these are the choices I can see in front of me: Store each tile as its own array. Each one having 3-4 layers, texture/animation, depth, flags, and maybe collision(depending on how I do it). I've read warning about memory issues going this route, and my biggest map will probably be 160x120 tiles. My average map however will be about 40x30. The number of tiles might cut in half if I decide to double my tile size, which is currently 16x16. This is the most appealing approach for me, as I feel like I would know how to save maps, make changes, and separate it into chunks for collision checks. Store the static parts of my tile map in multiple arrays acting as the different layers. Then I would just use entities for anything that wasn't static. All of the other tile data such as collisions, depth, etc., would be stored in their own layers as well I guess? This way just seems messy to me though. Regardless of which one I choose, I'm also unsure how to plan all of that other tile data. I could write a bunch of code that would know which integer represents what tile and it's data, but if I changed a tileset in Tiled and exported it again, all of those integers could potentially change and I'd have to adjust a whole bunch of code. My other issue is about how I could do collision. I want to at least support angled collision that slides you around the corners of objects like LTTP does, if not more oddball shapes as well. So do I: Store collision as a flag for binary collision. Could I get this to support angles? Would it be fine to store collision as an integer and have each number represent a certain angle of collision? Store a list of rectangles or other shapes and do collision that way? Sorry for the large two-part(three-part?) question. I felt like these needed to be asked together as I believe each choice influences the other.

    Read the article

  • LibGDX: transform Texture to TextureRegion

    - by FeRo2991
    I am creating a TowerDefence Game in LibGDX and am now trying to replace the old Tile with a new StaticTiledMapTile. But to create a StaticTiledMapTile I need a TextureRegion, not a Texture. Now I'm trying to create a TextureRegion, which contains the whole Texture, but it doesn't seem to work. It always appears distorted. I have tried the following: TextureRegion region = new TextureRegion(new Texture("someImg.png"), 0, 0, 32, 32); StaticTileMapTile tile = new StaticTiledMapTile(region); getLayer().getCell(x,y).setTile(tile); //setting the new tile In my opinion this should work (if the image, as it is, is 32px wide and 32px high).

    Read the article

  • Update tile notifcation with XML returned by web service

    - by tempid
    I have a Metro app in C# & XAML. The tile is updated periodically and I've used WebAPI to serve the tile notification XML. So far so good. I was then told that I cannot use WebAPI as the server that I was planning to host it on does not have .NET 4.5. No plans to install it anytime soon either. I had to change the WebAPI to a plain old Web service (.NET 3.5) which does the same thing - return tile notification XML. I've enabled HTTP-GET (I know, security concern) and was able to invoke the webservice like this - http://server/TileNotifications.asmx/[email protected] But ever since I made the switch, the tiles are not being updated. I've checked Fiddler and made sure the app is hitting the webservice and the XML is being returned correctly. But the tiles are not updated. If I replace it with the WebAPI, the tiles are updated. Do I need to do anything special with the web services? like decorating the web method with a custom attribute? Here's my web service code - [WebMethod] public XmlDocument GetTileData(string user) { // snip var xml = new XmlDocument(); xml.LoadXml(string.Format(@"<tile> <visual> <binding template='TileWideSmallImageAndText02'> <image id='1' src='http://server/images/{0}_wide.png'/> <text id='1'>Custom Field : {1}/text> <text id='2'>Custom Field : {2}</text> <text id='3'>Custom Field : {3}</text> </binding> <binding template='TileSquarePeekImageAndText01'> <image id='1' src='http://server/images/{0}_square.png'/> <text id='1'>Custom Field</text> <text id='2'>{1}</text> </binding> </visual> </tile>", value1, value2, value3, value4)); return xml; }

    Read the article

  • How would I go about updating my electronic circuit simulator's 'electricity'?

    - by liqwidice
    I have made an application which allows the user to place down wires, power sources, and inverters on a virtual circuit board. All connections between tiles are automatic, as shown here: As you can see in the last image, the updating of power throughout this grid is not yet functioning. I think I understand how to do this updating conceptually, but getting it to work in my program is appearing to be much more difficult than I first imagined. My source code can be found here. If you have any tips as to how to I might approach this monstrous task, please let me know. EDIT The goal here is to simply get a working application. Getting tiles to pass on power to their neighbors is quite easy, but the tricky part is getting wires to "unpower" after the removal of a power source. The size of the grid is just 18x18, so efficiency really isn't a factor, for those wondering.

    Read the article

  • Windows secure pinned website tile

    - by Stijn de Voogd
    I'm currently working on a pinned website tile for my website and instead of using a static XML file i'm linking the tile to a web api that returns user specific XML. My question is: Is it possible to secure this tile so that a user needs to be logged in before the data loads? The pinned website livetile doesn't send any security request headers/ cookies: - Http: Request, GET /v1/livetile/firsttile Command: GET + URI: /v1/livetile/firsttile ProtocolVersion: HTTP/1.1 UserAgent: Microsoft-WNS/6.3 Host: 192.168.14.109:2089 Cache-Control: no-cache HeaderEnd: CRLF Sidenote: Notice how it's not even sending an accept header even though it only wants xml. Info: http://msdn.microsoft.com/en-US/library/ie/dn455106 http://msdn.microsoft.com/en-us/library/ie/hh761491.aspx# Thanks in advance!

    Read the article

  • What should I use (controls, methods) to make a 2D tile based map editor?

    - by user1306322
    I'm making a 2d game where each tile is a square and it's viewed at straight angle, no skewing, no rotation, it's pretty simple. Two weeks ago I tried using DataGridView, but as the number of rows and columns increased, it became frustratingly slow, then I read how it should've happened to me earlier, because this control is not supposed to work with large number of cells, and I have at least 7500 cells in my smallest level, which made it unbearable to use. This is what I expect from my new editor: Most importantly, tile type. Tile images or their color codes are fine (seeing map as it is in-game is cool, but the faster, the better). Secondly, all tile parameters (in text, preferrably editable in a popup or sidebar). I'm using my own format, so I'm most probably not going to use third party product. Besides, I'm trying to learn how to do it myself.

    Read the article

  • Checking if an object is inside bounds of an isometric chunk

    - by gopgop
    How would I check if an object is inside the bounds of an isometric chunk? for example I have a player and I want to check if its inside the bounds of this isometric chunk. I draw the isometric chunk's tiles using OpenGL Quads. My first try was checking in a square pattern kind of thing: e = object; this = isometric chunk; if (e.getLocation().getX() < this.getLocation().getX()+World.CHUNK_WIDTH*World.TILE_WIDTH && e.getLocation().getX() > this.getLocation().getX()) { if (e.getLocation().getY() > this.getLocation().getY() && e.getLocation().getY() < this.getLocation().getY()+World.CHUNK_HEIGHT*World.TILE_HEIGHT) { return true; } } return false; What happens here is that it checks in a SQUARE around the chunk so not the real isometric bounds. Image example: (THE RED IS WHERE THE PROGRAM CHECKS THE BOUNDS) What I have now: Desired check: Ultimately I want to do the same for each tile in the chunk. EXTRA INFO: Till now what I had in my game is you could only move tile by tile but now I want them to move freely but I still need them to have a tile location so no matter where they are on the tile their tile location will be that certain tile. then when they are inside a different tile's bounding box then their tile location becomes the new tile. Same thing goes with chunks. the player does have an area but the area does not matter in this case. and as long as the X and Y are inside the bounding box then it should return true. they don't have to be completely on the tile.

    Read the article

  • Should I make the Cells in a Tiledmap as null when my player hits it

    - by Vishal Kumar
    I am making a Tile Based game using Libgdx. I took the idea from SuperKoalio platformer demo by Mario Zencher. When I wanted to implement Collectables in my game , I simply draw the coins using Tiled Map Editor. When my player hits that, I use to set that cell as null. Someday on this site suggested me not to do so... never use null. I agreed. What can be any other way. If I am using layer.setCell(x,y) to set the cell to any other cell... even if an transparent one .. my player seems to be stopped by an invisible object/hurdle. This is my code: for (Rectangle tile : tiles) { if (koalaRect.overlaps(tile)) { TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(1); try{ type = layer.getCell((int) tile.x, (int) tile.y).getTile().getProperties().get("tileType").toString(); } catch(Exception e){ System.out.print("Exception in Tiles Property"+e); type="nonbreakable"; } //Let us destroy this cell if(("award".equals(type))){ layer.setCell((int) tile.x, (int) tile.y, null); listener.coin(); score+=100; test = ""+layer.getCell(0, 0).getTile().getProperties().get("tileType"); } //DOING THIS GIVES A BAD EFFECT if(("killer".equals(type))){ //player.health--; //layer.setCell((int) tile.x, (int) tile.y, layer.getCell(20,0)); } // we actually reset the player y-position here // so it is just below/above the tile we collided with // this removes bouncing :) if (player.velocity.y > 0) { player.position.y = (tile.y - Player.height); } Is this a right approach? OR I should create separate Sprite Class called Coin.

    Read the article

  • Zelda-style Top-down RPG. Storing data for each tile type

    - by Delerat
    I'm creating a Zelda-style RPG using Tiled, C#, and MonoGame. When my code parses the .tmx file, it will get a number to associate with each tile type based off of their position in the tile sheet. If I ever need to change my sprite sheet, this number will change for many of the tiles. How can I guarantee that when I parse my .tmx file, I will be able to know exactly what tile type I'm getting so that I can associate the proper data with it(transparency, animated, collision, etc.)?

    Read the article

  • How can I improve my isometric tile-picking algorithm?

    - by Cypher
    I've spent the last few days researching isometric tile-picking algorithms (converting screen-coordinates to tile-coordinates), and have obviously found a lot of the math beyond my grasp. I have come fairly close and what I have is workable, but I would like to improve on this algorithm as it's a little off and seems to pick down and to the right of the mouse pointer. I've uploaded a video to help visualize the current implementation: http://youtu.be/EqwWcq1zuaM My isometric rendering algorithm is based on what is found at this stackoverflow question's answer, with the exception that my x and y axis' are inverted (x increased down-right, while y increased up-right). Here is where I am converting from screen to tiles: // these next few lines convert the mouse pointer position from screen // coordinates to tile-grid coordinates. cameraOffset captures the current // mouse location and takes into consideration the camera's position on screen. System.Drawing.Point cameraOffset = new System.Drawing.Point( 0, 0 ); cameraOffset.X = mouseLocation.X + (int)camera.Left; cameraOffset.Y = ( mouseLocation.Y + (int)camera.Top ); // the camera-aware mouse coordinates are then further converted in an attempt // to select only the "tile" portion of the grid tiles, instead of the entire // rectangle. this algorithm gets close, but could use improvement. mouseTileLocation.X = ( cameraOffset.X + 2 * cameraOffset.Y ) / Global.TileWidth; mouseTileLocation.Y = -( ( 2 * cameraOffset.Y - cameraOffset.X ) / Global.TileWidth ); Things to make note of: mouseLocation is a System.Drawing.Point that represents the screen coordinates of the mouse pointer. cameraOffset is the screen position of the mouse pointer that includes the position of the game camera. mouseTileLocation is a System.Drawing.Point that is supposed to represent the tile coordinates of the mouse pointer. If you check out the above link to youtube, you'll notice that the picking algorithm is off a bit. How can I improve on this?

    Read the article

  • How to determine if a 3D voxel-based room is sealed, efficiently

    - by NigelMan1010
    I've been having some issues with efficiently determining if large rooms are sealed in a voxel-based 3D rooms. I'm at a point where I have tried my hardest to solve the problem without asking for help, but not tried enough to give up, so I'm asking for help. To clarify, sealed being that there are no holes in the room. There are oxygen sealers, which check if the room is sealed, and seal depending on the oxygen input level. Right now, this is how I'm doing it: Starting at the block above the sealer tile (the vent is on the sealer's top face), recursively loop through in all 6 adjacent directions If the adjacent tile is a full, non-vacuum tile, continue through the loop If the adjacent tile is not full, or is a vacuum tile, check if it's adjacent blocks are, recursively. Each time a tile is checked, decrement a counter If the count hits zero, if the last block is adjacent to a vacuum tile, return that the area is unsealed If the count hits zero and the last block is not a vacuum tile, or the recursive loop ends (no vacuum tiles left) before the counter is zero, the area is sealed If the area is not sealed, run the loop again with some changes: Checking adjacent blocks for "breathable air" tile instead of a vacuum tile Instead of using a decrementing counter, continue until no adjacent "breathable air" tiles are found. Once loop is finished, set each checked block to a vacuum tile. Here's the code I'm using: http://pastebin.com/NimyKncC The problem: I'm running this check every 3 seconds, sometimes a sealer will have to loop through hundreds of blocks, and a large world with many oxygen sealers, these multiple recursive loops every few seconds can be very hard on the CPU. I was wondering if anyone with more experience with optimization can give me a hand, or at least point me in the right direction. Thanks a bunch.

    Read the article

  • In a 2D tile-based game, how should NPCs and tiles reference each other?

    - by lezebulon
    I'm making a tile engine for 2D games (seen from the top). Basically the world is composed of a grid of tiles. Now I want to put for instance NPCs that can move on the map. What do you think is best: 1) each tile has a pointer to the NPC that is on its tile, or a NULL pointer 2) having a list of NPCs, and they have the coordinates of the tile they are on. 3) something else? 1) is faster for collision detection but it would use much more memory space and it is slower to find all NPCs in a map. 2) is the opposite. thanks

    Read the article

  • How to create Button/Switch-Like Tile where you can step on it and change its value?

    - by aldroid16
    If the player step on Button-Tile when its true, it become false. If the player step on Button-Tile when its false, it become true. The problem is, when the player stand on (intersect) the Button-Tile, it will keep updating the condition. So, from true, it become false. Because its false and player intersect on it, it become true again. True-false-true-false and so on. I use ElapsedGameTime to make the updating process slower, and player can have a chance to change the Button to true or false. However, its not a solution I was looking for. Is there any other way to make it keep in False/True condition while the Player standing on it (The Button tile) ?

    Read the article

  • How to create Button/Switch-Like Tile where you can step on it and change its value?

    - by aldroid16
    If the player steps on a Button-Tile when its true, it becomes false. If the player steps on a Button-Tile when it is false, it becomes true. The problem is, when the player stands on (intersects) the Button-Tile, it will keep updating the condition. So, from true, it becomes false. Because its false and the player intersects it, it becomes true again. True-false-true-false and so on. I use ElapsedGameTime to make the updating process slower, and the player can have a chance to change the Button to true or false. However, it's not the solution I was looking for. Is there any other way to make it keep in False/True condition while the Player is standing on the Button tile?

    Read the article

  • tile a window with a hotkey on Ubuntu

    - by Eli Bendersky
    On Windows I use an AutoHotKey script to tile the active window to the left half of the screen, the right half, or a few other options. Does Ubuntu/Gnome have a program that would allow me to do that? If not, do you have an idea how to create this programmatically, or at least can point me to a resource?

    Read the article

  • Loudspeaker Tile in Windows 8

    - by lampa
    In the classical desktop I have the loudspeaker symbol, which I use to make the sound louder and quieter by using the mouse. On the modern UI Start Screen I can change it through the Charm-Bar and settings, but it is inconvenient. Is there some fast access to the loudspeaker for example through a tile? here is the screenshot of the usual loudspeaker: http://i.stack.imgur.com/O00af.png (I don't have enough rep to post the pic directly)

    Read the article

  • Tile map collision detection

    - by hero
    There are many topics like this, but none with concrete answers. I am drawing a tile-map in the traditional way (two for loops) and keeping my player centered except when the edges of the map is reached. How would I create collision detection? I need to know how to translate tile location in the array to screen coordinates I think.

    Read the article

  • display custome tile for missing tiles in google maps app

    - by Beans
    I am working with google maps in flash, and i would like to know how to serve up my own image tile for the "we have no imagery at this zoom level..." error. I dont want to serve up an entire map of images - just for the times when google has no image does the tile layer base dispatch an event? (i couldnt find any in the api) is there a method that can be overridden by extending the tilelayerbase class any help appreciated

    Read the article

  • A star algorithm implementation problems

    - by bryan226
    I’m having some trouble implementing the A* algorithm in a 2D tile based game. The problem is basically that the algorithm gets stuck when something gets in its direct way (e.g. walls) Note that it only allows Horizontal and Vertical movement. Here's a picture as it works fine across the map without something in its direct way: (Green tile = destination, Blue = In closed list, Green = in open list) This is what happens if I try to walk 'around' a wall: I calculate costs with the F = G + H formula: G = 1 Cost per Step H = 10 Cost per Step //Count how many tiles are between current-tile & destination-tile The functions: short c_astar::GuessH(short Startx,short Starty,short Destinationx,short Destinationy) { hgeVector Start, Destination; Start.x = Startx; Start.y = Starty; Destination.x = Destinationx; Destination.y = Destinationy; short a = 0; short b = 0; if(Start.x > Destination.x) a = Start.x - Destination.x; else a = Destination.x - Start.x; if(Start.y > Destination.y) b = Start.y - Destination.y; else b = Destination.y - Start.y; return (a+b)*10; } short c_astar::GuessG(short Startx,short Starty,short Currentx,short Currenty) { hgeVector Start, Destination; Start.x = Startx; Start.y = Starty; Destination.x = Currentx; Destination.y = Currenty; short a = 0; short b = 0; if(Start.x > Destination.x) a = Start.x - Destination.x; else a = Destination.x - Start.x; if(Start.y > Destination.y) b = Start.y - Destination.y; else b = Destination.y - Start.y; return (a+b); } At the end of the loop I check which tile is the cheapest to go according to its F value: Then some quick checks are done for each tile (UP,DOWN,LEFT,RIGHT): //...CX are holding the F value of the TILE specified // Info: C0 = Center (Current) // C1 = UP // C2 = DOWN // C3 = LEFT // C4 = RIGHT //Quick checks if(((C1 < C2) && (C1 < C3) && (C1 < C4))) { Current.y -= 1; bSimilar = false; if(DEBUG) hge->System_Log("C1 < ALL"); } //.. same for C2,C3 & C4 If there are multiple tiles with the same F value: It’s actually a switch for DOWNLEFT,UPRIGHT.. etc. Here’s one of it: case UPRIGHT: { //UP Temporary = Current; Temporary.y -= 1; bTileStatus[0] = IsTileWalkable(Temporary.x,Temporary.y); if(bTileStatus[0]) { //Proceed normal we are OK & walkable Tilex.Tile = map.at(Temporary.y).at(Temporary.x); //Search in lists if(SearchInClosedList(Tilex.Tile.ID,C0)) bFoundInClosedList[0] = true; if(SearchInOpenList(Tilex.Tile.ID,C0)) bFoundInOpenList[0] = true; //RIGHT Temporary = Current; Temporary.x += 1; bTileStatus[1] = IsTileWalkable(Temporary.x,Temporary.y); if(bTileStatus[1]) { //Proceed normal we are OK & walkable Tilex.Tile = map.at(Temporary.y).at(Temporary.x); //Search in lists if(SearchInClosedList(Tilex.Tile.ID,C0)) bFoundInClosedList[1] = true; if(SearchInOpenList(Tilex.Tile.ID,C0)) bFoundInOpenList[1] = true; //************************************************* // Purpose: ClosedList behavior //************************************************* if(bFoundInClosedList[0] && !bFoundInClosedList[1]) { //UP found in ClosedList. Go RIGHT return RIGHT; } if(!bFoundInClosedList[0] && bFoundInClosedList[1]) { //RIGHT found in ClosedList. Go UP return UP; } if(bFoundInClosedList[0] && bFoundInClosedList[1]) { //Both found in ClosedList. Random value switch(hge->Random_Int(8,9)) { case 8: return UP; break; case 9: return RIGHT; break; } } //************************************************* // Purpose: OpenList behavior //************************************************* if(bFoundInOpenList[0] && !bFoundInOpenList[1]) { //UP found in OpenList. Go RIGHT return RIGHT; } if(!bFoundInOpenList[0] && bFoundInOpenList[1]) { //RIGHT found in OpenList. Go UP return UP; } if(bFoundInOpenList[0] && bFoundInOpenList[1]) { //Both found in OpenList. Random value switch(hge->Random_Int(8,9)) { case 8: return UP; break; case 9: return RIGHT; break; } } } else if(!bTileStatus[1]) { //RIGHT is not walkable OR out of range //Choose UP return UP; } } else if(!bTileStatus[0]) { //UP is not walkable OR out of range //Fast check RIGHT Temporary = Current; Temporary.x += 1; bTileStatus[1] = IsTileWalkable(Temporary.x,Temporary.y); if(bTileStatus[1]) { return RIGHT; } else return FAILED; //Failed, no valid path found! } } break; A log for the second picture: (Cut down to ten passes, because it’s just repeating itself) ----------------------------------------------------- PASS: 1 | C1: 211 | C2: 191 | C3: 211 | C4: 191 DOWN + RIGHT SIMILAR Going DOWN ----------------------------------------------------- PASS: 2 | C1: 200 | C2: 182 | C3: 202 | C4: 182 DOWN + RIGHT SIMILAR Going DOWN ----------------------------------------------------- PASS: 3 | C1: 191 | C2: 193 | C3: 193 | C4: 173 C4 < ALL Tile(12.000000,6.000000) not walkable. MAX_F_VALUE set. ----------------------------------------------------- PASS: 4 | C1: 182 | C2: 184 | C3: 182 | C4: 999 UP + LEFT SIMILAR Going UP Tile(12.000000,5.000000) not walkable. MAX_F_VALUE set. ----------------------------------------------------- PASS: 5 | C1: 191 | C2: 173 | C3: 191 | C4: 999 C2 < ALL Tile(12.000000,6.000000) not walkable. MAX_F_VALUE set. ----------------------------------------------------- PASS: 6 | C1: 182 | C2: 184 | C3: 182 | C4: 999 UP + LEFT SIMILAR Going UP Tile(12.000000,5.000000) not walkable. MAX_F_VALUE set. ----------------------------------------------------- PASS: 7 | C1: 191 | C2: 173 | C3: 191 | C4: 999 C2 < ALL Tile(12.000000,6.000000) not walkable. MAX_F_VALUE set. ----------------------------------------------------- PASS: 8 | C1: 182 | C2: 184 | C3: 182 | C4: 999 UP + LEFT SIMILAR Going LEFT ----------------------------------------------------- PASS: 9 | C1: 191 | C2: 193 | C3: 193 | C4: 173 C4 < ALL Tile(12.000000,6.000000) not walkable. MAX_F_VALUE set. ----------------------------------------------------- PASS: 10 | C1: 182 | C2: 184 | C3: 182 | C4: 999 UP + LEFT SIMILAR Going LEFT ----------------------------------------------------- Its always going after the cheapest F value, which seems to be wrong. If someone could point me to the right direction I'd be thankful. Regards, bryan226

    Read the article

  • Tiling Windows on Mac

    - by Roberto Aloi
    What is your favourite free Tiling Window Manager for Mac? Open Source would be a plus, but it's not required. NOTE: I know about Expose', but it doesn't "tile" the windows as far as I know (but I would be glad to be corrected).

    Read the article

  • SDL_BlitSurface segmentation fault (surfaces aren't null)

    - by Trollkemada
    My app is crashing on SDL_BlitSurface() and i can't figure out why. I think it has something to do with my static object. If you read the code you'll why I think so. This happens when the limits of the map are reached, i.e. (iwidth || jheight). This is the code: Map.cpp (this render) Tile const * Map::getTyle(int i, int j) const { if (i >= 0 && j >= 0 && i < width && j < height) { return data[i][j]; } else { return &Tile::ERROR_TYLE; // This makes SDL_BlitSurface (called later) crash //return new Tile(TileType::ERROR); // This works with not problem (but is memory leak, of course) } } void Map::render(int x, int y, int width, int height) const { //DEBUG("(Rendering...) x: "<<x<<", y: "<<y<<", width: "<<width<<", height: "<<height); int firstI = x / TileType::PIXEL_PER_TILE; int firstJ = y / TileType::PIXEL_PER_TILE; int lastI = (x+width) / TileType::PIXEL_PER_TILE; int lastJ = (y+height) / TileType::PIXEL_PER_TILE; // The previous integer division rounds down when dealing with positive values, but it rounds up // negative values. This is a fix for that (We need those values always rounded down) if (firstI < 0) { firstI--; } if (firstJ < 0) { firstJ--; } const int firstX = x; const int firstY = y; SDL_Rect srcRect; SDL_Rect dstRect; for (int i=firstI; i <= lastI; i++) { for (int j=firstJ; j <= lastJ; j++) { if (i*TileType::PIXEL_PER_TILE < x) { srcRect.x = x % TileType::PIXEL_PER_TILE; srcRect.w = TileType::PIXEL_PER_TILE - (x % TileType::PIXEL_PER_TILE); dstRect.x = i*TileType::PIXEL_PER_TILE + (x % TileType::PIXEL_PER_TILE) - firstX; } else if (i*TileType::PIXEL_PER_TILE >= x + width) { srcRect.x = 0; srcRect.w = x % TileType::PIXEL_PER_TILE; dstRect.x = i*TileType::PIXEL_PER_TILE - firstX; } else { srcRect.x = 0; srcRect.w = TileType::PIXEL_PER_TILE; dstRect.x = i*TileType::PIXEL_PER_TILE - firstX; } if (j*TileType::PIXEL_PER_TILE < y) { srcRect.y = 0; srcRect.h = TileType::PIXEL_PER_TILE - (y % TileType::PIXEL_PER_TILE); dstRect.y = j*TileType::PIXEL_PER_TILE + (y % TileType::PIXEL_PER_TILE) - firstY; } else if (j*TileType::PIXEL_PER_TILE >= y + height) { srcRect.y = y % TileType::PIXEL_PER_TILE; srcRect.h = y % TileType::PIXEL_PER_TILE; dstRect.y = j*TileType::PIXEL_PER_TILE - firstY; } else { srcRect.y = 0; srcRect.h = TileType::PIXEL_PER_TILE; dstRect.y = j*TileType::PIXEL_PER_TILE - firstY; } SDL::YtoSDL(dstRect.y, srcRect.h); SDL_BlitSurface(getTyle(i,j)->getType()->getSurface(), &srcRect, SDL::getScreen(), &dstRect); // <-- Crash HERE /*DEBUG("i = "<<i<<", j = "<<j); DEBUG("srcRect.x = "<<srcRect.x<<", srcRect.y = "<<srcRect.y<<", srcRect.w = "<<srcRect.w<<", srcRect.h = "<<srcRect.h); DEBUG("dstRect.x = "<<dstRect.x<<", dstRect.y = "<<dstRect.y);*/ } } } Tile.h #ifndef TILE_H #define TILE_H #include "TileType.h" class Tile { private: TileType const * type; public: static const Tile ERROR_TYLE; Tile(TileType const * t); ~Tile(); TileType const * getType() const; }; #endif Tile.cpp #include "Tile.h" const Tile Tile::ERROR_TYLE(TileType::ERROR); Tile::Tile(TileType const * t) : type(t) {} Tile::~Tile() {} TileType const * Tile::getType() const { return type; } TileType.h #ifndef TILETYPE_H #define TILETYPE_H #include "SDL.h" #include "DEBUG.h" class TileType { protected: TileType(); ~TileType(); public: static const int PIXEL_PER_TILE = 30; static const TileType * ERROR; static const TileType * AIR; static const TileType * SOLID; virtual SDL_Surface * getSurface() const = 0; virtual bool isSolid(int x, int y) const = 0; }; #endif ErrorTyle.h #ifndef ERRORTILE_H #define ERRORTILE_H #include "TileType.h" class ErrorTile : public TileType { friend class TileType; private: ErrorTile(); mutable SDL_Surface * surface; static const char * FILE_PATH; public: SDL_Surface * getSurface() const; bool isSolid(int x, int y) const ; }; #endif ErrorTyle.cpp (The surface can't be loaded when building the object, because it is a static object and SDL_Init() needs to be called first) #include "ErrorTile.h" const char * ErrorTile::FILE_PATH = ("C:\\error.bmp"); ErrorTile::ErrorTile() : TileType(), surface(NULL) {} SDL_Surface * ErrorTile::getSurface() const { if (surface == NULL) { if (SDL::isOn()) { surface = SDL::loadAndOptimice(ErrorTile::FILE_PATH); if (surface->w != TileType::PIXEL_PER_TILE || surface->h != TileType::PIXEL_PER_TILE) { WARNING("Bad tile surface size"); } } else { ERROR("Trying to load a surface, but SDL is not on"); } } if (surface == NULL) { // This if doesn't get called, so surface != NULL ERROR("WTF? Can't load surface :\\"); } return surface; } bool ErrorTile::isSolid(int x, int y) const { return true; }

    Read the article

  • Smooth waypoint traversing

    - by TheBroodian
    There are a dozen ways I could word this question, but to keep my thoughts in line, I'm phrasing it in line with my problem at hand. So I'm creating a floating platform that I would like to be able to simply travel from one designated point to another, and then return back to the first, and just pass between the two in a straight line. However, just to make it a little more interesting, I want to add a few rules to the platform. I'm coding it to travel multiples of whole tile values of world data. So if the platform is not stationary, then it will travel at least one whole tile width or tile height. Within one tile length, I would like it to accelerate from a stop to a given max speed. Upon reaching one tile length's distance, I would like it to slow to a stop at given tile coordinate and then repeat the process in reverse. The first two parts aren't too difficult, essentially I'm having trouble with the third part. I would like the platform to stop exactly at a tile coordinate, but being as I'm working with acceleration, it would seem easy to simply begin applying acceleration in the opposite direction to a value storing the platform's current speed once it reaches one tile's length of distance (assuming that the tile is traveling more than one tile-length, but to keep things simple, let's just assume it is)- but then the question is what would the correct value be for acceleration to increment from to produce this effect? How would I find that value?

    Read the article

  • How'd they do it: Millions of tiles in Terraria

    - by William 'MindWorX' Mariager
    I've been working up a game engine similar to Terraria, mostly as a challenge, and while I've figured out most of it, I can't really seem to wrap my head around how they handle the millions of interactable/harvestable tiles the game has at one time. Creating around 500.000 tiles, that is 1/20th of what's possible in Terraria, in my engine causes the frame-rate to drop from 60 to around 20, even tho I'm still only rendering the tiles in view. Mind you, I'm not doing anything with the tiles, only keeping them in memory. Update: Code added to show how I do things. This is part of a class, which handles the tiles and draws them. I'm guessing the culprit is the "foreach" part, which iterates everything, even empty indexes. ... public void Draw(SpriteBatch spriteBatch, GameTime gameTime) { foreach (Tile tile in this.Tiles) { if (tile != null) { if (tile.Position.X < -this.Offset.X + 32) continue; if (tile.Position.X > -this.Offset.X + 1024 - 48) continue; if (tile.Position.Y < -this.Offset.Y + 32) continue; if (tile.Position.Y > -this.Offset.Y + 768 - 48) continue; tile.Draw(spriteBatch, gameTime); } } } ... Also here is the Tile.Draw method, which could also do with an update, as each Tile uses four calls to the SpriteBatch.Draw method. This is part of my autotiling system, which means drawing each corner depending on neighboring tiles. texture_* are Rectangles, are set once at level creation, not each update. ... public virtual void Draw(SpriteBatch spriteBatch, GameTime gameTime) { if (this.type == TileType.TileSet) { spriteBatch.Draw(this.texture, this.realm.Offset + this.Position, texture_tl, this.BlendColor); spriteBatch.Draw(this.texture, this.realm.Offset + this.Position + new Vector2(8, 0), texture_tr, this.BlendColor); spriteBatch.Draw(this.texture, this.realm.Offset + this.Position + new Vector2(0, 8), texture_bl, this.BlendColor); spriteBatch.Draw(this.texture, this.realm.Offset + this.Position + new Vector2(8, 8), texture_br, this.BlendColor); } } ... Any critique or suggestions to my code is welcome. Update: Solution added. Here's the final Level.Draw method. The Level.TileAt method simply checks the inputted values, to avoid OutOfRange exceptions. ... public void Draw(SpriteBatch spriteBatch, GameTime gameTime) { Int32 startx = (Int32)Math.Floor((-this.Offset.X - 32) / 16); Int32 endx = (Int32)Math.Ceiling((-this.Offset.X + 1024 + 32) / 16); Int32 starty = (Int32)Math.Floor((-this.Offset.Y - 32) / 16); Int32 endy = (Int32)Math.Ceiling((-this.Offset.Y + 768 + 32) / 16); for (Int32 x = startx; x < endx; x += 1) { for (Int32 y = starty; y < endy; y += 1) { Tile tile = this.TileAt(x, y); if (tile != null) tile.Draw(spriteBatch, gameTime); } } } ...

    Read the article

  • How can I determine the first visible tile in an isometric perspective?

    - by alekop
    I am trying to render the visible portion of a diamond-shaped isometric map. The "world" coordinate system is a 2D Cartesian system, with the coordinates increasing diagonally (in terms of the view coordinate system) along the axes. The "view" coordinates are simply mouse offsets relative to the upper left corner of the view. My rendering algorithm works by drawing diagonal spans, starting from the upper right corner of the view and moving diagonally to the right and down, advancing to the next row when it reaches the right view edge. When the rendering loop reaches the lower left corner, it stops. There are functions to convert a point from view coordinates to world coordinates and then to map coordinates. Everything works when rendering from tile 0,0, but as the view scrolls around the rendering needs to start from a different tile. I can't figure out how to determine which tile is closest to the upper right corner. At the moment I am simply converting the coordinates of the upper right corner to map coordinates. This works as long as the view origin (upper right corner) is inside the world, but when approaching the edges of the map the starting tile coordinate obviously become invalid. I guess this boils down to asking "how can I find the intersection between the world X axis and the view X axis?"

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >