(Just to be clear I'm asking for guideance not for someone to program this whole thing(unless they want to XD))
Hi, I'm currently trying to make a game for android in which you can build a map out of blocks(there are several types but we'll just use walls here).
The map is going to be 100x20 blocks, in which the players can put any of the blocks available inside in any order, and it's going to be stored as a text file "Let's call it "mapFile""(this part I've already solved) in which 0's would be nothing and 1's would be walls.
Now, the problem is that when you start playing the map, the game will have to load all the blocks to make the obstacles, but I want it to do it in a specific way (mainly to make the game go smoother and doesn't have to check 2000 blocks every update):
-make groups of blocks(lines, squares, rectangles) as 1 obstacle so there os only 1 collision detection in a large amount of blocks(the difficult part is to divide a complex shape in the best way)
-divide the map into 5x5 chunks so it doesn't have to check every obstacle in order to see if it should be drawn(it would just draw the chunk in which the player is in and the ones surrounding it)
The output from this should be a 4 levels array(or something similar):
Array[Ychunk][Xchunk][obstacle][x,y,xBlocks,yBlocks,type]
(Type is just the num of the block in the map(in this case it's 1 because it's the number for wall in my app)
For now the game has:
-An array with all the obstacles info (x,y,xBlocks,yBlocks,type)
-Only updates obstacles if they are a small distance from the player(still has to check them all)
-Only draws obstacles that are inside the window(also has to check them all)
Firstly, You don't need an array with all the map info, what you need is a 2D array of tiles. The tile object will contain all the info like the image, isSolid, etc.
Secondly, You will always have the player visible, so that acts as your anchor, Only show the tiles around your player and render that to the screen. Its makes no sense to render the tiles that will not be rendered on the screen e.g., If the player is at the center and the screen renders 5x5 tiles then +/- 2 tiles of the player tile. Same goes for checking if the tile is visible No, need to check all
Lastly, Again you don't need to check the player collision with all the obstacles, only need to check collision with the tile that the player is going to move on.
Hope it helps.
Related
I have a floor plan on which the walls are black, the doors are orange and the target is red. What I want is to make an app where given a specific point on the image, the route to the target is calculated and displayed. I already have a routing method, but it is in matlab and each position and object is defined in the code and it doesn't use an image. What I would like to know is how to scan the image to identify the walls, the doors and the target by color in order to apply the routing method and then display the route over the image of the map (I guess I should use drawable for that).
This are some steps to implement a pathfinding algorithmm from an image.
Upload your image
Apply a color detection HSV(in the real life is most easy control the
light changes with this format) algorithm to obtain the objects
separately.
Make a new binary Matrix with 1 for your floor and 0 to the
obstacles.
Apply to that binary Matrix an Occupancy grid algorithm(this reduce
your matrix because in the pathfinding algorithm you need
processing).
and now ur path finding algorithm. I recommend use the diijistrak or A star algorithm, in this two cases
you need construct an adjacency matrix.
The graph theory will help you to understand better.Good Luck!!
You can work in processing IDE for rapid prototipyng and migrate all the processing IDE core to eclipse, you need implement the PApplet class in your eclipse project, and can compile your app to Android.
I would use somekind of occupancy grid/map where each grid cell = one pixel (or possibly a small collection of pixels like 2x2 3x3, etc) And just do k-means clustering on the image. There are a few choices for k
k=2
you have walls is one group (the black lines)
everything else is considered opened space (this assumes doors can be opened).
You will need to know where the red point is located, but it doens't need to be visible in your map. It is just another open space in your map. that your program internally knows is the endpoint.
k=4
a group for everything black=walls(occupied), orange=doors(may or may not look like occupied cells depending on whether or not they can be opened),red=target(unoccupied), white=open space(unoccupied).
In both cases you can generate labels for your clusters and use those in your map. I'm not sure what exactly your path finding algorithm is, but typically the goal is to minimize some cost function, and as such you assign a extremely high cost to walls (so they will never be crossed), possibly assign a medium cost to doors (in case they can't be opened). Just some ideas, good luck
I took a look on those 2 project that I found in here:
AndEngineJb2dJson
AndEngineRubeLoaderExtension
As some of you know I'm developing a rolling scene based game
I'm loading all the entities from a XML file and create them in the Loading Scene
recently I increase the game width , and by doing so , in the whole level I have about 500 entities (instead of 250+-)
But this cause a performance problems , the game is "Lagging" \ "jumping" and everything move slow.
My question is , if those Rube Loaders support performance issues , do some improvement
or its just like the normal andengine loader , that I need to manually load each entity in the XML \ JSON
Does anyone develop a rolling scene based game with the same amount +- of entities and tell me what it the correct way to implement it?
Thanks
As you don't really provide much detail about your specific implementation I will just provide you with a generic way of handling a game of this type.
First, you need to define an "active" area for your game world - this would be the area of the world that needs to be simulated (i.e. the entities in this area will move and interact with the world).
Your world layout might look something like this:
In this example your world is the grey block and extends beyond the screen boundaries (which is the black frame). The red frame indicates the active area - notice that it extends beyond the size of the display, but does not cover the entire world. The size of this area will depend on your specific implementation/needs.
The active area will generally move along with your player and hence can easily be represented as distance from player (in two directions).
The basic idea is that the entities (in blue) are only simulated while they are inside the active area. All entities to the right of the active area should be inactive until they enter it, at which point their simulation can start - for this reason, the active area should extend some amount to the right of the display area so that entities have some initial time to run their simulation before being displayed. Once the entities leave the active area (to the left) they can stop their simulation - and be removed if needed.
So in the example image:
E1 is has already gone through the active area and is no longer needed (it can be disabled/removed)
E2 is active and visible (currently displayed)
E3 is active but not visible yet
E4 and E5 is not active yet and will only become active once they enter the active area as the player gets closer to them
As for how to handle the entities, that depends on the size of the world, the number of entities, etc.
One way is to create/load the entities once they enter the active area - in which case it should extend far enough to the right of the display so that they have enough time to be created/loaded before entering the display area. This is the best approach for large worlds where there may be thousands of entities. In this case you may also need some kind of subdivision for your world so that you can exclude large amounts of entities from processing without checking each one - a array of fixed sized "blocks", each containing the entities that are within it, would work fine in most cases for a simple 2D side-scroller.
Another approach is to load all objects at the start and only perform simulation updates (such as physics, movement, collision detection) for them once they enter the active area. This approach works great for smaller worlds and provides an easier implementation.
I'd like to create a custom map. It should be or look like one picture, but according to the part of which the user clicks, it should move the user to a different location (i.e. start a different activity). I've seen it done in several games but I don't know how to do it myself.
The part of the picture should have non-geometrical borders (obviously it would be easily done with many square images). Sadly, I don't even know what term describes what I want to do so I wasn't able to find any helpful tutorials or discussed topics.
Example:
Picture: http://i236.photobucket.com/albums/ff40/iathen/mapEx.png
If the user touches the purple slide, (s)he should be leaded to activity_1
If the user touches the blue slide, (s)he should be leaded to activity_2
If the user touches the green slide, (s)he should be leaded to activity_3
In my experience there are 2 main (most used) ways to achieve this.
The first (my favorite):
Get the data from a PNG
You should write multiple layers to a canvas. These layers constitute your "zones" (blue, green, purple in the image). To obtain the data of these areas, you get it from PNGs (with transparencies off course) to write the canvas with whatever you want. You must store the values where there can be a tap from the user (non-transparent areas). Notice that this values can be scaled up/down depending on the map size, screen resolution, map dimensions, etc.
Once you've written the layers to the canvas you should check for a match of the user tap and the stored areas you have. You should take into consideration here the order in which the user tap is processed in your code. For instance, in your image, the purple layer is on top so it must be processed first, the blue as second, and the green as the last one. This way you can have an "island" inside a bigger area.
The second way:
Generate the boundaries programmaticaly
I think this solution is self-explanatory. The only I've faced with this variant is that when the surfaces boundaries get messy, it's really complicated to generate the proper equations.
EDIT:
Using the first approach you can employ multiple PNGs to load data or use a single PNG with data coded into the bytes (i.e. RGB values). It's up to you to decide which one to implement.
Hope it helps!
Since a touchscreen itself isn't very accurate, your collision detection for the buttons doesn't need to be either. It would be a waste of time to try to make a complicated collision detection algorithm to detect a touch within those weird shapes.
Since you are making a game, I assume you know how to handle custom touch events, as well as canvas (at least). There are many ways to do what you want, but in the specific example image you linked is kind of a special case.
You could create a giant bounding circle around the three blobs, and then check if the user touched within the bounds of the circle (ie check if the distance from the touch to the center of the circle is less than or equal to the radius). Once you determine that it is, you could check which section of the circle it falls into by splitting it up into 3 equal sections. Requires some math, but shouldn't be that complicated.
It wouldn't be a perfect solution, but it should be good enough. Although, you might have to change the buttons a little so they aren't so stretched out horizontally, otherwise a bounding circle wouldn't be ideal.
Personally, in my games I always have "nodes" that represent the visual elements of the game, such as buttons. Instead of using a large image like you are doing, I would create separate images for each button, and then check their collisions with touch events independently. That way I could have each button check with their own individual bounding circles, or, if absolutely necessary, I could even have custom algorithms for each individual button.
These aren't perfect solutions. If you do want a pixel-perfect solution, you'll need to implement some polygon collision detection algorithms
One thing to consider is screen size and ratio. The only constants you should use are for percentages.
I am looking at creating a 2D birdseye view of a map where the user is basically working their way through it.
Is there a way that I can create the whole map in 1 go and store it somewhere, then simply only display a certain section of that map during game play?
e.g map size =100 x 100 but user can only ever see 5x5 (which is zoomed-in to use up 70% of the screen).
It might use too much memory if you store the whole 100x100 map as a bitmap/texture in memory and only display a certain part. I think you'll be more happy if you divide it into chunks of e.g. 5x5 and cache these chunks (only those that are visible and drawn right now). When the user moves and gets to a new chunk, you just draw the 5x5 tiles on a bitmap/texture and cache it for as long as it's visible (and unchanged).
I'm trying to figure out the best way to store map objects on a 2d side scrolling game.
For example, in the game Doodle Jump, how do the platforms you jump on get stored?
I've had a few thoughts about how it is possibly done..
Are the platforms stored in a string or other object that defines where each platform is going to be placed? For example if I defined a string like 0,10,5,8,6,2,3,4,2,..... and so on, I could interpret those as x-coordinates of each game piece in the game. I guess the problem with this is that could potentially be A LOT of game pieces to define. The game appears to be endless, so pre-defining the map seems like a bad idea.
I also thought that maybe the pieces are just random. So whenever the map calls for a new map piece, it randomly gets an x-coordinate. I thought this seemed pretty feasible but when playing DoodleJump it doesn't appear that they are all random.
Does anyone have any idea on how these map objects could be stored to lead me in the right direction?
Thanks!
I'm thinking an array of incremental height coordinates and their respective width coordinates (1d or 2d array). Incremental because of not letting the coordinates get to big.
You can use the screensize to know which platforms to calculate screen coordinates for. When the jumping object reaches a certain screenheight threshold, shift the camera with it, calculating new screen coordinates, omitting platforms that fall off screen and adding platforms that come within view.
You could generate the array beforehand using an algorithm with some randomness with a min/max constraint on coordinate distance. When using ints, you could generate a pretty big array before getting into trouble I guess.
Or generate it real-time using the same seed for the random function, so it will generate the same array every time and you can keep going indefinitely
You could use a random number generator with a fixed seed per level so users get the same level every time. The random numbers can select from an array of appropriate values. (I've used this successfully in an android game.)
A lot of platform games store the static map platforms (that is, the parts of the map that cannot be manipulated/destroyed - the floor tiles in Mario Bros., for example) as either predefined map. This can be done using an array of values or an alphamap image.
If you use the array method, use bytes (unsigned char's) instead of int's.