So I'm working on a agent based simulation and I'm going to use a 2D array which could be 500x5000 or 1000x1000. The actual simulation will consist of walls which make up rooms. The problem I don't want to manually insert each wall because this could take very long.
Is there a way where I can create a simple 2D image of a map and have the program read this image and insert the walls into the 2D array based on the image.
Regards
Related
Im trying to make make a heatmap using WeightedLatLng. Right now it shows an increase in "intensity" for high values or for multiple lower values close together.
I want to be able to only take in to account the values of the weights, not the sum of different points.
Anyway you can create custom Ground Overlay or Tile Overlay with your own algorithm for heatmap. As start point for heatmap creation you can use for example AndroidHeatMap project of tredpath.
I have a 2D array for a game of a 9x9 board for Gomoku. I want to scan the board as quickly and efficiently as possible to find pieces. I need to check if their is a row/col/diagonal of X amount of whites/blacks.
Is the best way just to use a for-loop or is there a better way?
Thanks
This usually depends on the game, how many pieces there are vs cells on the board. If your game had a 1000x1000 board and only 10 pieces it would be terrible to use a nested loop to find them (sparse array). It would be better to track the board pieces using a dedicated structure like a list or hashmap.
But in your case a nested loop + 2d array is a good solution. The 2d array also has the benefit of quick random access.
I'm just starting with game development and decided to make a 2048 clone using LibGDX to learn the basics.
I started to implement it using a simple 2D array and it works, but the problem is that there aren't any animations. So, for example if there's a tile that is at position [0][0] and after the user swipes the screen it has to move to [0][3], that transition occurs instantly (since I'm basically just updating my 2D array and re-rendering the tiles).
I was told this kind of board game-like UI is the perfect scenario to use Scene2D. I can very easily implement the basic 4x4 grid using Actors, but my question is, how do I correctly manage what is essentially a 2D structure using a Scene2D?
I already have the algorithms to handle where to move the tiles if the user swipes the board (left, right, top, down) and update a 2D array, but it feels like if I'm using a Scene2D, using this secondary 2D array data structure is overkill.
Right now my approach is:
Create a 2D array and Scene2D with my tiles
When user swipes, update the 2D array with the new position of the tiles
Iterate over the actors in the Scene2D and compare it with the tiles I have in my updated 2D array. If there have been changes, animate them (basic transition from the tile's original position to it's final position)
I just felslike I have unnecessary steps and also and unnecessary data structure here.
What would be the correct way to handle this sort of scenario?
Appreciate helpful advices, thanks!
Are you putting your tiles in a TableLayout? Just drawing it over won't work, as you have discovered.
To animate it you will need to define a MoveAction.
MoveToAction moveAction = new MoveToAction();
moveAction.setPosition(300f, 0f);
moveAction.setDuration(10f);
myActor.addAction(moveAction);
Example copied from:
http://www.gamefromscratch.com/post/2013/12/09/LibGDX-Tutorial-9-Scene2D-Part-2-Actions.aspx
I am not sure how this can be implemented if you are using TableLayout though.
I have built a JPanel which is painted based on a 2D array of data which the user can draw on.
I'm wondering if it is possible to somehow allow the user to upload a background picture, then set the size of the array based on the image to allow them to draw over it by filling in array cells. Then of course, rubbing out the colour in a cell should get back the original segement of the image.
Is this at all possible? I haven't found anything? I have the array at the moment and drawing using a MouseMotionListener but can't seem to find a way to set the 2D array size based on an image and then display it behind the 2d array.
I'm wondering if it is possible to somehow allow the user to upload a background picture, then set the size of the array based on the image to allow them to draw over it by filling in array cells. Then of course, rubbing out the colour in a cell should get back the original segement of the image.
Yes this is definitely possible. The key as in all programming is to break down a big problem into little steps and then try to solve each small step, one at a time.
Is this at all possible? I haven't found anything?
Your question is much too broad to find a complete or even partial solution by searching online. Again you can find solutions for each individual step, but you first have to create your steps. Once this is accomplished then it will be easy to find tutorials and solutions for each step that you may be stuck on.
I have the array at the moment and drawing using a MouseMotionListener but can't seem to find a way to set the 2D array size based on an image and then display it behind the 2d array.
Show us what you have and where you're stuck. We'll need code. And please note, the more specific your question, usually the better and more specific will be our answers. Your current question is in a nut-shell "is this possible", and the answer is of course "yes", but short of that, I'm not sure what else to say without knowing more about where in particular you may be stuck.
I am well into creating my 2d remake of minecraft in java. I know it can be done well, orange451 on youtube inspired me to try and make this. I have all blocks on the map loading from text files, and when the game loads, it adds all of the blocks from the text files to an ArrayList. I created an algorithm for calculating the index of the block your cursor is on in the game, and added a MouseListener so that when i clicked it would replace the block with an air block (basically destroying the block). To replace the block in the ArrayList, I used the ArrayList set(index, obj) method. In theory, it should be working correctly, and it in a way does. The only problem is that it also creates a black space in the map a few blocks away. This is extremly frustrating, especially since I have come so far. ADDITIONAL INFO: I need a method that will replace the object in the ArrayList, or a better way to do it because my collision detection method also uses the ArrayList to detect a blocks position. PLEASE HELP ME! I cant post images but its setting the block to the air texture but creating a black square (a gap in the arraylist mabey?) near it. Because theres too much code to post, heres the source code for the whole project: Blockworld 2D Source
You're struggling with this because an ArrayList of objects that know their coordinate is an insane way to represent this 2d structure. It's unordered - you could reverse or shuffle your ArrayList and it would paint the same. It has O(N) update, as you have to search the ArrayList for an object of the appropriate coordinate before you can replace it. It can have more than one object with the same coordinate. It can be in a state where visible coordinates do not have corresponding objects at all -- which is what you've encountered, here.
PLEASE HELP ME
OK. Start with a two dimensional array (array, not ArrayList) of byte. Which allows you 256 kinds of block, and which allows your players to dig without constantly allocating memory with your new AirBlock(0, 0) madness. To draw the world, iterate over visible coordinates and map bytes to Bitmap or like.
Also: a 2d Minecraft already exists. It's called Terraria.