I'm trying to write rts-like-tile-based game using Tiled and slick2d.
I don't know how to handle a multi-tile objects, like buildings, how to create, keep and e.g. move them.
One solution would be to create a layer in tiled where the tiles are used as "markers" for your game code. These "markers" are never drawn. Instead, when you initialize your game, go through the the tiled map and every time a corresponding marker is found add a "new Building()" to some kind of EntityManager class. This way you can write the code for the class Building yourself, and instead of it being completely static tile you can move it around like you would any other entity. This also lets you make these buildings any arbitrary size independently of any tile sizes.
Related
For example I currently have a Player object that contains it's textures/animations and how to render these (I'd consider this as the view). Player also has an update() method which controls where the player is going to move, if it's going to lose health etc. (controller). Finally Player also has all it's attributes like runspeed, health, max health, inventory items etc.
The Player class is starting to look very cluttered and unorganized and serializing the complete Player class isn't really possible, so I made a separate PlayerState class which basically contains all it's attributes that could be changed while playing (This could actually be turned into the PlayerModel). I was wondering if it would be a good idea to split the Player up using a MVC pattern. I would have a Player, PlayerController and PlayerRenderer. Serializing the Player would be easy and it would be easier to keep the rendering separate from the updating and make sure rendering only happens when everything for the next frame has been updated.
This seemed like a good idea, however then I would also want to do this for GameMap. A GameMapRenderer that renders the map and it's textures to the screen. A GameMap model that contains what animals and hostiles are in the map and other various attributes the map might have. And of course a controller that controls everything that happens in that map.
I could go even further and say a Pig may need a model since it has attributes that can change, a renderer to render it's texture and a controller to control movement etc. but this seems a bit excessive. However, I don't like only implementing the MVC pattern to the player and then ignoring it for other classes like Pig. But the way I'm working currently is very badly structured imo and it's frustrating to work with.
I'm currently making a 2D side-scroller game, in which the main character has to go through tubes (game objects as Actors) to score. I know how to move the game objects (using act under the render method of each actor), but how do I move the main character so it goes through individual tubes? I'm trying to make it move automatically by forcing it to go through a sequence of x,y coordinates, but is there another way for this work?
If you don't want to specify coordinates step by step why not use Box2d physics engine build in LibGdx. By setting tube bounds you may easily limit player character motion.
Advantages:
Good performance
You are not responsible for collision logic
Easy to implement, and keep implementation clean: http://programmersweb.blogspot.com/2012/07/simple-libgdx-box2d-bouncing-ball.html
Editor to create bodies and levels in visual manner.
I have a large tmx map which I made in Tiled. I am using libgdx to render the tmx map. I would like to know how can I render specific tiles. For example I have a 100x100 tile/tmx map. Player entity spawns in 10,30 (x,y) I only want to render around the location of the player entity (or for any entity, and control the seeing distance within the respective entity class). How can I use libgdx to selectively render like this? I tried setting rendering bounds to camera but not working like I want.
I want to be able to zoom in/out of overall map (which would look dark/completely blacked out) except for the parts where an entity sprite is located. Looking to maintain the fog of war around the entity sprite.. and multiple entities.
Should I pass renderer into the entity constructor? multiple cameras? How can I do a layered effect where i have another 100x100 blacked out tilemap on top of the actual map and have it so the alpha around entities is 0? (bear in mind im using tmx maps)
I'm not really sure if this is the place to be asking this but I was trying to use the program Tiled but I'm not sure where to start. I have looked at its documentations but it's not that useful as I already have some experience in using a tiled editor in a game engine (GameMaker), but I'm working straight up Java for this project.
How does the Tiled object layer work? Does it allow me to place enemies in the tiled editor that would show up and actually move in the game or are they just static images like a tile?
Also if it does allow what I programed for the enemy how do I use it?
Tiled allows you to edit layers of tiles and items. There's tile layers which represent a 2D grid of images, and item layers which are just polygons with properties.
After you create a map, its up to you to do something with that data. Tiled is not like GameMaker. All Tiled does is allow you to read, write, and edit data.
I recommend you use LIBGDX as a game engine, and Tiled to create your maps. LIBGDX has support for loading and rendering tiled maps.
To create enemies, you'd place some polygons, add attributes to these polygons, and create enemies based on these properties when parsing the Tiled map in your game.
I'm working on a 2d top down game in pure Java and until now I've got a noise mapping system that works with chunks of tiles (and entities) just like Minecraft.
The way I store tiles is by creating a int[s * s] array, where s is the size (in tiles) that a side of the chunk has. Then, I have a static array of Tiles which contains each of the possible tiles in the game, indexed with an integer. Those are the integers stored in the int[s * s] in each chunk. Now, I want to be able to overlay tiles, such as invisible spawn tiles, walls, trees and transition tiles (like when grass changes to sand: there should be a border of grass over the sand, which would be a new tile).
The problem is that only one integer can be stored in each coordinate of the chunk. Another way to do it would be to put actual instances of the tiles inside the chunks and make the overlaying tiles point to the ones directly below them (like a stack), but I think that's kind of a bad approach. Another approach which I tested was to make an array of Lists of tiles, that was also really bad.
Which would be a good way to accomplish this?
Typically you would separate the storage for tiles and objects.
You would have an int [w*h] or similar for the tiles themselves,
which would only allow one tile per square.
Separately, you could have a ArrayList [w*h] which stores a list of
entities in each square. This array would contain null for empty
squares, so the extra storage cost for the majority of squares (that
have no entities in them) is minimal.
There are other approaches of course, but this has the advantage that it is both simple and pretty efficient.
Only real downside is that you will have to write separate code for handling tiles and entities - but since you usually handle tiles and entities differently anyway then this is unlikely to be a big problem.