Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 26 Jun 2012
Offline Last Active Apr 22 2013 06:44 AM

#4996995 Top Down TBS Tile Selection Help

Posted by on 03 November 2012 - 04:31 PM

here a quick example I wrote up. the code is java but the idea is the same

package example;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.*;
import javax.swing.*;

public class Main implements MouseListener
    private final static int SCREEN_WIDTH = 640;
    private final static int SCREEN_HEIGHT = 480;
    private final static int tile_size = 32;
    private int map[][];
    private int mousex, mousey;
    private JFrame frame;
    private JPanel panel;
    public Main()
	    map = new int[SCREEN_WIDTH / tile_size][SCREEN_HEIGHT / tile_size];
	    frame = new JFrame();
	    panel = new JPanel();
	    frame.setSize(new Dimension(640,480));
	    int k = 0;
	    for(int i = 0; i < map.length; i++)
		    for(int j = 0; j < map[i].length; j++)
			    map[i][j] = k;
    public static void main(String[] args)
	    Main main = new Main();
    public void mouseClicked(MouseEvent e)
	    System.out.println(map[e.getX() / tile_size][e.getY() / tile_size]);
    public void mousePressed(MouseEvent e) {
    public void mouseReleased(MouseEvent e) {
    public void mouseEntered(MouseEvent e) {
    public void mouseExited(MouseEvent e) {

#4996992 Top Down TBS Tile Selection Help

Posted by on 03 November 2012 - 04:18 PM

say you have a map array which is 32x32 (tiles of size 32x32 not a whole picture)

and say your screen size was 640x460

this gives you a total number of tiles x:20 y:15

20 x15 = 300 tiles

this means that we can do very easy mouse translation.

when you click the mouse. get the mouse x and y location of the click/

then do something like

int tile = map[ (int)mouseX / 32][(int)mouseY / 32]

so to show an example of this. imagine your screen 640x480 and imagine we click at mouse location 450 150

450 / 32 = 14
150 / 32 = 4

so now we have our tile 14 across and 4 down which would select tile 56.

as for making the tile brighter im not sure

#4988674 Basic Questions on animating tile based games & frameworks/engines

Posted by on 10 October 2012 - 05:29 AM

Okay. The simplest way to do a tiled map with textures (images) is simple
You have your width of your window and the height of the window (say 640x480)
and then you want to assign a tile size. this will be the size you want the 'environment' to be (not the characters or enemies etc) so trees,grass all that stuff.
I usually pick either 16x16, 32x32 or 64x64 for my tiles. Then (if we are not using slick and tiled maps) we do the following below.
static final int WIDTH = 640;
static final int HEIGHT =480;
int tileSize = 32;
int map[][] map;
Random rand = new Random();
public void init()
	 map = new int[WIDTH / tileSize][HEIGHT / tileSize]
	 for(int i = 0; int i < map.length; i++)
		  for(int j = 0; j < map[i].length; j++)
			  map[i][j] = rand.nextInt(2);
we create a 2D array for our map (just like a matrix) and the size is basically how many tiles across and down your map is. So 640 / 32 = 20. 480 / 32 = 15. (you can obviously create your own maps and load them in from a text or something but That's too much detail for the moment.
after that all you have to do if loop through the code. if the element at index i,j = 0 we draw nothing (or a default tile) and if the element at index i,j = 1 we draw something interesting
for(int i = 0; int i < map.length; i++)
		  for(int j = 0; j < map[i].length; j++)
						 g.drawImage('your default tile',i*32,j*32);
						 g.drawImage('your interesting tile',i*32,j*32);
						 g.drawImage('default tile',i*32,j*32);
and this will draw out your tile map. after which you draw your player after you draw you map, so that the player is rendered on top of the map and not behind. then when you want to move a player between somewhere on the map. you can just to tile movement (eg move it by a tile at a time rather than pixels at a time)
The slick2D way is a lot easier in my opinion though.
If you make a 2D map using Tiled map editor. you can load and display the map very quickly like this
import org.newdawn.slick.*;
public class Game extends BasicGame
	 private TiledMap map;
	 public Game()
		  super("This is where you put the title");
		  map = new TiledMap("location")   //and some other parameters I can't remember off the top of my head. Check the javadock for slick
    public static void main(String[] args)
		  AppGameContainer gc = new AppGameContainer(new Game());
public void init(GameContainer container) throws SlickException

public void update(GameContainer container, int delta) throws SlickException

public void render(GameContainer container, Graphics g) throws SlickException

Simples ;). and you can still do your gird movement and stuff the same way.
Sorry if this is a long winded explanation. if something is unclear just ask. hope this helps

#4988500 Basic Questions on animating tile based games & frameworks/engines

Posted by on 09 October 2012 - 03:38 PM

Oh yeah Slick2D is up to date. You just need to download the Nightly build (as that's always the most recent update)

I'm just a bit confused as to why you have a grid of buttons. Do you want to select characters with the mouse or whatever and have them move to that point (animating while moving?)

If so there are easy ways of doing this. Also you can used Tiled editor to make your tiled maps and loads them into java with the Slick2D methods

#4988467 Integer multiplication, division

Posted by on 09 October 2012 - 02:18 PM

Actually, you're running out of precision in that operation. -255 * 409 is -104,295, but int16_t only has 16 bits of storage, which means it can only store values in the range −32,768 to 32,767. So what happens? Your intermediate result gets chomped down to 16 bits *before* the divide happens, and the end result is a weird value due to overflow.

What should you do about it? Use a bigger data type.

Could you please elaborate on that? What exactly is the factor that causes the calculation to be processed in 16-bit? Shouldn't the program detect that its running out of precision and automatically use a bigger (i.e. 32-bit) temporary buffer?

Which variables exactly should be increase in size?
EDIT: Is there a way to increase the temporary buffer size without changing the variable data types?

That's not how it works. Yes there is something that causes the calculation to be processed in 16-bit...its the fact you told it that your values are all 16 bit signed integers. when you get an overflow, instead of crashing your program. The value gets wrapped around. so when you reach the max value, it goes back to 0 and starts counting up again.

Is there a reason you chose int16_t or did you copy it from somewhere. Like I said change it to int32_t or higher and see the results

#4988464 Basic Questions on animating tile based games & frameworks/engines

Posted by on 09 October 2012 - 02:09 PM

If you are using Java + Netbeans have you had a look at Slick2D.

I've used it for many 2d tile based game project. It has support for tiled maps and makes animation easy.
If you wan't more info you should have a look at it and you can send me a message or something. or ask more questions here.

#4988460 Integer multiplication, division

Posted by on 09 October 2012 - 01:57 PM

I think you have found your answer from most of these replies. If you don't believe them then change them to int64_t and see the result

#4988111 IDE most comparable to VS

Posted by on 08 October 2012 - 02:45 PM

Dude InteliJ . it's just like visual studio for java. it's crazy

#4985993 wolfenstein 3D (How To)

Posted by on 02 October 2012 - 02:24 AM

caldiar I just wanted to say thanks for the quick detailed reply.


#4980865 All from scratch

Posted by on 17 September 2012 - 07:22 AM

I wonder if film-making forums get posts from people that don't know anything about film-making but want to make a movie like Iron Man 2, and want to know where to start.

There is nothing wrong with having ambition and a goal, even if it is unrealistic. As long as you keep taking the stepping stones to get there.

But its good to ask people, because then your goal is put in perspective.

#4978991 Timer vs. thread.sleep();

Posted by on 11 September 2012 - 12:32 PM

Sleep should only be used as a way to preserve the battery on mobile devices (Which tend to behave far better when sleeping aswell).

This is not totally true. I will give you a quote from the book 'killer game programming in java'

"sleep() causes the animation thread to stop executing, which frees up the CPU for other taks, such as garbage collection by the JVM. without a period of sleep, the GamePanel thread could hog all the CPU time"

I mainly sleep to keep a constant FPS, there are many ways to do this, but the amount of time Thread.sleep() should sleep for, should not be a constant number, that's probably why you had that laggy feeling effect.

This book is a good one and I would recommend it.

#4977498 Question about Macbook Pro and game development

Posted by on 06 September 2012 - 11:28 PM

While the specs on a Macbook Pro are all right, and they are pretty much regarded as media editing laptops (Photoshop and so on) I think the price is totally out of proportion. I just asked a similar kind of question to games dev in the lounge forums because i wanted a decent laptop for going abroad to study.

Take a look at it and see what you think, some of the comments may still be relevant.


If you need any more information, just ask. That's what the community are here for.

#4971061 Help! I'm trying to make a game.

Posted by on 19 August 2012 - 04:20 AM

The problem with the answer you are looking for is that all languages are good in their own way, even for making games. Sometimes people totally miss that the concepts of programming are more important than the language choice for learning.

Go with whatever you feel the most comfortable.

With C# and XNA you already have a pretty nice framework and plenty of tutorials that will help you in making your game. Next to XNA there are probably some more other viable options that will help you make your game. Perhaps Unity3D is something you want to look into.

With C++ you have a bit more choice I think (I'm not that deep into what is out there for C#, so I might be wrong) there are plenty of engines/frameworks out there that will let you focus on the gameplay part instead of the rendering part.

So basically, see what fits you best in your goal. If you are still new to either of those 2 languages, compare differences, see what is out there that might help you in your development. All of that has already been answered more than once on this forum alone, so do some digging here and see what has been said over the past time.

Good luck! Posted Image

I think this answer is pretty good IMO.

But I'll try and be a little constructive.

If you are really serious about getting into games development and see it as something you would definitely want to get a job in when you are older.
Think about C++, its today's industry standard, however, it is a very intensive language. so learn the concepts and basic ideas before trying make games straight away, you will just stress out and fail.

The other thing is about your age, you are quite young, so the industry standard might change by the time you are 20 or something. That said, knowing the principles of programming is better than focusing on a language, it means you can pick up any language that happens to come along.

If you want to just dive right into games programming however, without having to worry to much about other stuff. Yes c# and XNA is a good place to go.

#4964847 first time game design, which language would you recommend?

Posted by on 31 July 2012 - 07:17 AM

bustout65. Let us know what programming experience you have and we can point you in the right direction, as GameMaker might be the right step for you. But maybe something more advanced is at your level.

#4964586 Comparing strings

Posted by on 30 July 2012 - 01:30 PM

I'm not sure if this has anything to do with what you're looking for because im not amazing with C++

but in my text game i have something like

cin >> response;

do stuff
do other stuff