How to make a GUI to display my game? - java

I have already coded a game which is played on a 2D grid. Now I just need to make a GUI to display it.
Each cell in my grid has an attribute that goes along with an image. For instance, if cell (0, 0) is water, I want to display an image of water in that pixel. I have already made images for each attribute (e.g. image of a character, water, land, etc.). I just don't know how to make the GUI.
It's a simple 2d map where each pixel (cell) is a specific texture/character/item. I also would like the character to move around, that is it.
Any resources or help would be appreciated. I've tried searching for a tutorial but they all seem so complicated and use Color to fill in their map instead of images.
Thanks.

Here's a 2D platformer that makes use of a simple thread, drawing, gamestates, etc. Although you might not need the full extent of everything it has, you might find interest in the main thread logic, etc. I believe he has a link to the source code in the comments. YouTube

Related

How do I make 2d- Flashlight effect in Processing 3

For reference the effect I'm going for is this:
I'm working in Processing 3, NOT p5.js.
I've looked around processing forums, but i can't find anything that works in the current version or doesn't use PGraphics and a mask which from what I've read can be expensive to use.
My current ideas and implementations have resulted to drawing shapes around the player and filling the gaps in with a circles with no fill that has a large stroke weight.
Does anyone know of any methods to easily and inexpensively draw a black background over everything except a small circular area?
If this is the wrong place to ask this question just send me on my way I guess, but please be nice. Thank you:)
You could create an image (or PGraphics) that consists of mostly black, with a transparent circle in it. This is called image masking or alpha compositing. Doing a Google image search for "alpha composite" returns a bunch of the images I'm talking about.
Anyway, after you have the image, it's just a matter of drawing it on top of your scene wherever the player is. You might also use the PImage#mask() function. More info can be found in the reference.

java 2d graphics array over an image

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.

Drawing a simple game board in Android

I have some C# experience, but im completly new to java. So i have some questions for someone with more experience.
I would like to draw a simple game board of for example 10x10 grey boxes. So i figured a 2d array might be useful:
int gameBoard[][] = new int[10][10];
For each board i would like to draw a grey rectangle, and place it it some control to be rendered on the device.
I suppose this can be done with an instance of Paint and Canvas
And this is where im stuck at the moment. What controls are best suited for this? Any help is much appreciated.
Take a look at this link, it explains very clearly the differences between canvas, paint and bitmap and finishes with an example of an app that draws a colored rectangle and displays it in an ImageView. Hope it can be useful.
Better use GridView or TableView for the box structure. Further , if you will wand something to crawl over boxes, it will be another activity on the deskboard one. There you'll maybe use bitmaps. THis way you will save heaps of time.
I would probably go with the TableLayout, which I guess is what Gangnus meant with TableView
There is a tutorial for TableLayout here:
http://developer.android.com/resources/tutorials/views/hello-tablelayout.html
In your case you would put 10 views in each of 10 rows. You can chose to create them in the xml file or from the java file.

Java detection of images on a screen

I'm trying to take an ongoing chess game and use image recognition to automatically transcribe it into a list of chess moves (1. e4 e5 2. Nf3 Nc6), automatically.
Given a 2D layout of the board and pieces, and standard images for each of the pieces, how would I go about in Java doing this?
Thanks!
I would imagine that depending on the set being played with, given a top down view of the board, it might prove difficult to distinguish between the different pieces.
Rather than relying on image recognition to determine which pieces are which, it would almost certainly be easier to simply track the pieces throughout the course of the game. You already know exactly where they started from, so after each turn it should be possible to deduce which square is now empty that wasn't previously empty, and which square is now occupied that wasn't previously occupied. This makes your image analysis much simpler as you're just determining whether each square on the board is empty or not.
Well if you have an image for each piece than just follow and save(using some arrays) all the moves. But first show us some code on what you have. More info.
For image classification in JAVA you can try Rapidminer and IMMI extension for image mining:
http://spl.utko.feec.vutbr.cz/en/component/content/article/46-image-processing-extension-for-rapidminer-5
For this purpose you should extract global features from images and than train some classifier (e.g. SVM). Another approach might be training Viola-Jones detector.

android opengl game

I'm trying to develop a 2D game to android using opengl.
I know how to print images on the screen and animate them. But in my game I have a map and a want to zoom in and out and scroll the map. But I can't figure out the best way of doing it.
Can anybody help me?
I don't have any api examples but I did games design at college so I'll give my two bits.
The method you use will depend on your map style, size, functionality and format.
For example if you are looking for a very static non changing map, use a simple picture image. You can use the API frame for a picture view, enabling you to zoom in and out as you do in the gallery and to scroll on zoomed images, or in this case, zoom locations on your map.
Alternatively, if your map is based off a tiling system, a good example of this is the original Pokémon and Legend of Zelda games from the old game boy, then each area stores a tile 'thumbnail' for itself as a bitmap. These are then put into their appropriate locations on a grid depending on what areas are discovered.
This is the probably the most flexible way to build your map as you are not relying on a set bitmap for the entirety your map meaning it can change its look efficiently; you can build it as desired to show areas of choice (useful for if the map only reveals places the gamer has covered) and it also means you can do tile based overlay:
ie - if a certain area should contain treasure, theres a treasure icon overlayed on that tiles x,y position on the map grid.
I used the tiling option in my game projects from college and it made everything else map related easier. It also made the map side of things smaller storage wise.
The simplest approach would be to just call glTranslatef(-scrollX,-scrollY,0) followed by glScalef(zoom,zoom,zoom) before you render your map.

Categories

Resources