Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

215 Neutral

About Scottehy

  • Rank

Personal Information

  • Interests
  1. Alright, so I have been looking at a few open source 2D tile engines. And found a fair few different ways of how they had implemented their designs. The difference with mine though, is I want pure grid based movement to void AABB collision etc. So objects are just shifting what cell they are in, so they can be looked up easy.    The couple that stuck out the most to me were:   This implementation uses less memory, but for npc to npc interaction etc, you would have to loop through each NPC to check if it's in the tile you're interacting with. Unless you imlemented a form of quad-tree/bucketlist to break them all apart so you're only scanning small slices within the chunk.  class MapChunk {     bool[,]       layerCollison     Tile[,]       layerTile     List<Objects> non-interactable     List<Objects> interactable      List<NPC>     npcs }   Then there is this implementation which was sort of like what I was doing. Except it's the map chunk that holds pointers to what's in each cell. With the lists holding the actual objects. This will use more memory, but the actual execution of interaction would be a lot faster. class MapChunk {     bool[,]       layerCollison     Tile[,]       layerTile     Objects[,]    layer-non-interactable // Pointers to objects     Objects[,]    layer-interactable     // Pointers to objects     NPC[,]        layer-npcs             // Pointers to objects       List<Objects> non-interactable     List<Objects> interactable      List<NPC>     npcs }   I do want to avoid using AABB/QuadTrees etc if possible. But if you guys think it would be more appropriate for some reason. Please do explain why. If my objects weren't all grid locked and needed to collide with the tiles/objects/npcs, I could see the point. I'm just trying to work out what would be the best design to go with. Before I move onto a more solid build.    Cheers :)
  2. Seeming as it was only a prototype rewriting was no issue. I've ended up splitting everything up though.So it is far more modular :) -- Thanks for your input buddy.   I just need to work out the best way for stitching the grid all together, as in the threaded loading and unloading.
  3. I'd be changing it in the future, it's for simplicity and readability at the moment :) But you're absolutely right.   That's the issue, why the tile needs to know wherever it holds something or not? A tile is a tile, a pure logical seperation in the map. Holding "just a refernece" doesn't make it any more valid.  The first rule that you should follow is try to reduce coupling between different logics. When you have something that "must know everything" it soons turn into a god class or just a class with too much knowledge about different systems. This makes harder to implement new features or replace existing systems. For A* you'll need to know something, but if you want a different AI system? You'd have to hardcode properties all over again.    I'm going to look at some other tile engines, see how they do things. Seeming as I want to make it much more large scale.
  4. If you have a specific case that fits this, its fine :)   Well but how do you actually build the tilemap? Do you really have to type WOODWALL_TOPLEFT in the specific cell to select this tile (I'm using you have or plan on having an editor)? I don't know how exactly your tilemaps are laid out but for anything more than like 20 tiles per screen, this sounds like an enormous pain. Might not be an issue with the design, but if you plan on making a content-heavy game with lots of different locations, you are going to spend a huge ton of time remembering and typing in repeated names of tiles, unless you have the proper toolset to automate this.   This is more why I was saying, here is the prototype/implementation on how I'm doing it. Who has some advice for me on how I should do it. I did it this way after researching and reading a few tutorials I found on tile engines.   I have an artist that is giving me for example, a texture with X floor tiles, X wall tiles, X npc frames, then a text file that contains #WOODWALL_TOPLEFT, #location(x, y, width, height) #framecount if there are more than 1 frames (npc walking etc). This is all parsed through a custom loader that sets it all up for me. Thus allowing me to call a string key of WOODWALL_TOPLEFT in the dictionary. 
  5. @Alberth - That's how I was thinking of implementing it, I just wasn't sure if it was over or under kill.    @WoopsASword - The cell itself only contains pointers to objects. As in the active solid object in it. So for physical updates, they're handled outside the cell. The cell just happens to have access to what's in it for interaction purposes. I tried to lock everything to the grid though, for the sake of voiding real collision. The player/npc though is actually separate from the cell. What I have at the moment is more of a prototype, more the reason to see how others would do it and their thoughts. As for drawing textures, they're all stored on a single texture / tile map. I have a dictionary that holds info about about what part of that texture to draw / animate.    Changing code / scrapping code / rewriting code is no issue, I'm just working out what will fit best before I add actual gameplay mechanics. I just want to make sure I'm heading in the right direction.    ---   @Juliean - There can be more than one Node in a cell, they're designed to be able to look at more than a single object. As for your guard and door example. In games like this I've played. They usually have 2 guards, or a guard that's scripted to quickly move in front of the player to block them. The game has no fast action or movement though, so projectiles and spawned objects have no issues fighting for room on the grid. I have pathfinding already in place as well, working fine with no issues. I do have all my level textures contained in a single texture. The string is just the key in the dictionary to pull out a certain texture. Etc "WOODWALL_TOPLEFT" would return me the source rectangle of the section I'm looking for, on my tilemap texture.
  6. Hey Guys!   So I've resumed programming again after a long break. Due to other work. I started working on a Tile Engine this time, and the game is starting to become larger. So I'm wondering how I should change my design and data storage.   I'll delve right in and make it as simple as possible, I'm using C# with Monogame for everything.   So right now the design works like such, and of course is working. I get no lag or issues so far, interactions between objects are all fine.   I have a Grid at the moment that is 200 by 200 of a class called Cell. Each cell is 32x32 pixels big. The grid is stored as a 2D array[,].  Cell contains: A pointer to a Node class, which can be an NPC, Player, Furniture etc A base layer, Floor/Wall etc which are enums and a string, the string is a key for pulling textures from my TextureManager Dictionary A bool for checking if this tile is occupied or not. This helped for A* path finding etc The actual NPCs are contained in just a plain old c# List<NPC> etc. Same with furniture and other objects that aren't a base Wall or Floor. The reason I separated all this is so when I iterate through a cell, I can render all of that cells objects. So for example, in my drawing call. I iterate through only the cells we can see on screen. Then do a Draw call to the floor. I then iterate again and draw from top to bottom, the wall, npc's/player and furniture etc. This way the tiles that are taller than 32 pixels render correctly and don't overlap objects incorrectly. But this isn't the issue, I know I could just use a depthlayer in my spritebatch draw call to fix up it's z ordering.   The view is like an oldschool pokemon / zelda game. Where the characters are 1.5 tiles in height (32x48), and the walls are 2 tiles in height (32x64) etc. So these have no issue in size, due to I can just consider them a single tile.    So the first issue I run into now, is objects that are bigger than a single tile (not just the texture) but rather say a table that is 3x2 tiles in size. Seeming as I was storing an objects pointer in each cell, it allowed for very simple collision, (if I want to move right, is the cell.occupied etc). How should I go about this, should I store it to a pointer in the cell still, and just mark the extra 5 tiles it would take up as occupied? Or should I store it in all 6 cells for collision/interaction sake, but mark 5 of them not to update/draw.   Or should I be totally redesigning how larger items are stored? And totally revamp my array[,] / List<objects>. This is where I'm wondering if I should be using a Dictionary for objects as well, and make they key a Point, so I can just type in a cell location technically to get the object out that way? I'm sure there is a much simpler way or design for this, so I'd love to hear some thoughts.       This part might look a bit of a mess, just trying to get what's in my head down into words.   The next thing is about expanding the map. I'm asking this now as it will relate to the above in how I change my data storage. I want to go on the same sort of design as a pokemon game. Where you have a large map that is loaded in chunks (each chunk on the world map with be same same size), and when you enter a building you're technically just loading a single chunk.   I don't have an issue with how to do this as much, but more so what should I be storing it all in? Should each chunk be stored in a text file, for example a simple drawn map where 0 = floor, 1 = wall, 2 bench and so forth (during editing stages). Which is then loaded into an 2D[x, y] size array.    Said Array would be stored in a 2x2 array that loads 4 maps at once, providing you were in a corner of a a map etc.    Another question I have about the above though, is when changing chunks, should I be wrapping everything position? So we're always in more of a local location design.   Any thoughts and comments would be much appreciated. Or links to some well designed tile engines. I've read through far to many tutorials but most of them seem to fall short of something fantastic.   Cheers, Scott.
  7. Scottehy

    Newton's laws help

    I was thinking of doing this, but wondering the best way to do it. Possibly lerp the velocity vector to vector.zero if the player isn't accelerating. Or should i just be applying counter thrust in the opposite direction the player is traveling? Both would probably end up doing the same, but i imagine lerping might be smoother. I'd test it now but im at work heh.
  8. Scottehy

    Newton's laws help

    I noticed the divide by zero was happening when the screen would go fully black. Thus the normalizing causing the issue, due to retro being zero. How exactly does the above cause the rocket to be more responsive though? Unless I'm implementing your math wrong. I find when I begin to turn I lose most of my velocity exceptionally quick. But that was with a retroforce of 5 etc, where as 1 feels a lot nicer, except I'm still drifting a lot like before. Either the values I'm using are way off, or I'm not implementing it correctly to be able to do a smooth 180 turn etc, and still keep majority of my velocity. float rocket_boost = 0.0f; if (Global.Instance.IsDown(Keys.W)) rocket_boost = 2000.0f; Vector2 force = direction * rocket_boost; mass = 10.0f; Vector2 acceleration = force / mass; velocity += acceleration * DT; Vector2 desired = direction * velocity.Length(); float retroForce = 5.0f; Vector2 retro = desired - velocity; retro.Normalize(); float retroLength = retro.LengthSquared(); if (retroLength > 0) { retro /= (float)Math.Sqrt(retroLength); retro *= retroForce; velocity += retro; } position += velocity * DT; Thanks so much for the help you're providing though. I can't believe how much more there is to moving objects than I've previously done. When ever I've implemented movement before, it has been nothing remotely detailed in comparison.
  9. Scottehy

    [Greenlight] Slap Village

    Simple and to the point, I've never been a fan of point and click games. Then I watched your trailer, I was instantly draw to the fantastic graphics and animation of the characters. And to top it off the mini-games looked a blast and really sold it for me. You got a yes vote from me, look forward to it hopefully being Greenlit. Goodluck!
  10. Scottehy

    Grid, Quadtree or something else?

      My grid works fine, it's indexed and only uses/displays the cells that are on the screen. The issue was more about having 500 objects in a cell (stress testing), and getting a framerate drop. So I just decided to decrease the size of a cell, which in turn removed the collision lag. It is why I was wondering if I should of used a quadtree inside of each cell etc.
  11. Scottehy

    Newton's laws help

    Are you finding your ship is 'drifitng' more than you would like when turning? If that's the case you need to sort of retro thrust to slow you down. With planes you have air resistance doing the job and with cars it is the friction between the road and the wheels but in space you have nothing so you need to provide that counter force to stop you drifting.   In your code you have a 'direction' variable which I am assuming is the direction of the ship and presumably else where when you wish to rotate/turn you rotate that direction. What you need to do is have another variable 'desired velocity', which is just direction*maxspeed (or you could just make it the same magnitude as your current velocity). You then need to work out a vector from your current velocity to your desired velocity: desired = direction*magnitudeOf(velocity) retro = normalize(desired-velocity) * retroForce That may take some tweeking as my vector math is a bit rusty but it should provide a counter force that reduces velocity in the direction you are drifting. There are probably some issues with it though. You could limit the direction retro thrust can be applied too.     I'm a little confused with what you wrote. My ship is drifting to much in X direction, so I do need something to slow it down. I've tried a couple of forms of the math you posted but keep ending up with NaNs (not a number) at random points. Mostly when I try to normalize the resto vector. I'm confusing myself now   I been trying something like this with no luck: float rocket_boost = 0.0f; if (Global.Instance.IsDown(Keys.W)) rocket_boost = 2000.0f; Vector2 force = direction * rocket_boost; mass = 10.0f; Vector2 acceleration = force / mass; velocity += acceleration * DT; Vector2 desired = direction * velocity.Length(); float retroForce = 10.0f; Vector2 retro = desired - velocity; retro.Normalize(); retro *= retroForce; velocity += retro; position += velocity * DT; EDIT:   It seems to function decent with something like this, but is this what you had intended? float rocket_boost = 0.0f; if (Global.Instance.IsDown(Keys.W)) rocket_boost = 2000.0f; Vector2 force = direction * rocket_boost; mass = 10.0f; Vector2 acceleration = force / mass; velocity += acceleration * DT; Vector2 desired = direction * velocity.Length(); Vector2 retro = desired - velocity; velocity += retro; position += velocity * DT;
  12. Scottehy

    Newton's laws help

    sergamer1, what you've said makes much more sense related to deltatime. I understand deltatime fine, I was just unsure the reasoning in applying it twice to the movement calculation, but I can see why now.      In this case, would rocket_boost be a constant number though? Or should It be something I increment from 0 to a max value. For argument sake of my understanding, lets say it's a constant value of 2,000. public void Accelerate(float DT) { float rocket_boost = 2000.0f; Vector2 force = direction * rocket_boost; mass = 10.0f; Vector2 acceleration = force / mass; velocity += acceleration * DT; position += velocity * DT; } That works fine and starts to accelerate nicely. However it does take a few seconds to really kick in. But once it does, I feel locked to the direction I'm traveling for far to long. So how can I change my direction faster in this instance? Not exactly a sharp turn, but being able to fully change direction in a second or two, so it has a smooth turn?   Thanks so much for the help though guys, it's greatly appreciated :)
  13. Scottehy

    Newton's laws help

      So if I try something like that, with a constant force of say 10,000 on an object with a mass of 100. I end up moving like a couple of pixels per second~ float power = 10000.0f; Vector2 force = direction * power; mass = 100.0f; Vector2 acceleration = force / mass; Vector2 velocity = acceleration * DT; position += velocity * DT; How come we're applying the time between frames twice per update? Sorry, I'm a little confused, either that or I'm implementing what you posted wrong   Whoops, I was resetting velocity every frame. It works now though. Should power be a constant though, I'm just curious what sort of values I should be using.
  14. Scottehy

    Newton's laws help

    Hey guys, just trying to work out exactly how to apply Newton's laws of motion etc, to a Spaceship. I've made games where I've faked it all before, however this time I want to use something a bit more realistic. But to also include another object hitting said spaceship and changing it's direction, plus also having a stars gravity pull it as well etc.   So what I presume this should look like is something like this for basic movement; public void MoveInDirection(float deltaTime) { float power = ?; Vector2 force = direction * power; float mass = 1000.0f; // 1000kg in this case Vector2 acceleration = force / mass; Vector2 velocity = acceleration * deltaTime; position += velocity; } Now the part I'm a little confused with, is where I should be adding my delta/elapsed time. Should I only be adding it to the velocity, not at all or somewhere else to simulate the movement? And as for power, what sort of input would I need to give it to move a 1,000kg object etc.   As the power input, I presume it needs something else behind it, as in, to generate it from 0 up to a max power. So we don't just instantly go max speed. So some form of coefficient with a limiter etc?   And lastly if I have say a projectile hit the ship. I presume I should be doing something like adding that projectiles force by doing this to the previous function in the post: Vector2 force = direction * power; force += projectileForce * projectilePower; To the previous function in the post. So that way we incorporate another objects force to our own. But then slowly dampen it till it's effect wears off etc.   Any lastly how would I add in gravity to this function, so I can have this object being slowly pulled to the gravity's source.   I should know all this stuff, but after not programming or doing math for a couple of years, I can't believe how rusty I feel in some areas    Cheers, Scott
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!