Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (843)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  a different tile technique  (Read 1686 times)
0 Members and 1 Guest are viewing this topic.
Offline projectmmporg

Junior Newbie

Java games rock!

« Posted 2005-02-13 21:00:13 »

hello everyone.

 i have been reading these forums for a while on game development and would like to ask you all a question  Grin

I would like to try something new, but have not found any information on the topic for java. this is what i want :-

1) create a screen of tiles (easy)
2) give each tile a name that the java program can  identify (cant do)
3) apply attributes to the tiles

the intended outcome will be related to resources, that is each tile will have a different number of resources. using co-ordinates i cant figure out how to do this (i can make tiles but i cant give them a name). i could use panels or buttons but i dont want outline visable.

can anyone give suggestions for this method?

an example of this method is as follows.

object name   food value   wood value    iron value

Tile1               5                   0                    0
Tile2               5                   0                    0
Tile3               0                   5                    0
Tile4               0                   0                    5

in the above example it is greatly simplified and consists of only 4 tiles. i believe that giving a tile an identifier will allow me to use algorithms to randomly generate different attributes for the tiles.
 Refering back to using buttons or panels - i can give these two objects attributes, because they have an identifier eg jpanel1 jpanel2 etc. i have not been able to get rid of outlines or apply art to them tho.

thank you in advance for any help/articles/webpages that are relavent.
Offline bsmith2

Senior Newbie

All about the iso

« Reply #1 - Posted 2005-02-13 23:01:01 »

All you need is a map class that holds the information you want:

public class Map {
int sizeX; // map size
int sizeY; // map size

int[][] tileID; // tile id you use to lookup what tile to draw

string[][] description; // this is your tile description
int[][] food; // stores the food value
int[][] wood; // etc
int [][] iron; // etc


And maybe I'm misunderstanding what you're asking, but you shouldn't be trying to draw tiles using buttons or jpanels.  Assuming that youre using Java2d you should be loading Image objects through ImageIO. After you have some tiles loaded you could then draw them to your jpanel or jframe.

It sounds like you should start with getting a handle on how a tile based structure works. I'd recommend going to and checking under the articles/tile based graphics sections.
Offline JuddMan

Senior Devvie

Medals: 1

Your Ad Here

« Reply #2 - Posted 2005-02-13 23:54:43 »

alternately just make a Tile class that holds this info...

it sounds like you are using Swing (JLabels?) to do your game. Just do something like
Tile extends JLabel{
   int food = 0, iron = 0, wood = 0;
   String name = null;
   public Tile(int f, int i, int w, String n, ImageIcon icon)
        super(icon) = f;


while using Swing can work for low action games, you might want to look at building it from the ground up and doing your own rendering.

however, i suppose you might want to have the mouselistener and tool tips and all that stuff for your tiles as well, which could be convenient for a game like that where clicking on a tile will bring up info in the bottom.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline projectmmporg

Junior Newbie

Java games rock!

« Reply #3 - Posted 2005-02-14 02:05:57 »


firstly, thankyou both of you for replying to my question. they look like they will help me get what i want. im not able to try it out and integrat it into what i have at the moment, but i will do soon.
One of you said you were a buit unsure of my references to jpanels and the such. well i used jpanels as a dummy, just to see what i could do if a "tile" had a name.
Using my example of 4 tiles only, i call them tile1,tile2,tile3,tile4. each tile will have the food/wood/ore attributes but also the attribute picture.
a simple algorithm to be used (this is not written in java in this explanation) is using statements eg if..else.

1) tile1 will have a randomly generated number between one and five for each resource. if there are two fives, they are rerolled.
2) the highest number will dictate the type of terrain the tile is on. if there is a "five" then the other two attributes are changed to zero. ( a mixture of numbers eg 3 3 4 gives the attribute - rough)
3) so a "five" in food will class the tile as "grass". With the tile identified as "grass", the appropriate image is used on the tile.
4) the state of the first tile will dictate the state of the other tiles - this means if tile1 is "grass" then tile2 cannot be grass ( ie 5 food ), so tile2 has a "zero" for grass and so on.

i hope to use this to randomly generate different tiles. my use of jpanels was only because it was the only way that i knew of to actually give a tile an identifier. i do not intend to use them. i am aware that this theory is similar to turn based games, such as civilization, but i want to try to implement it into a different type of game. there is information out on the web, but 99% of it is visual basic or c++ ( i want java  Grin). the algorithms are not a problem , i just need to be able to assign those 3 values and be able to assign the appropriate picture to each one. hopefully the suggestions you gave me will allow me to do this :-)

Pages: [1]
  ignore  |  Print  

EgonOlsen (37 views)
2018-06-10 19:43:48

EgonOlsen (20 views)
2018-06-10 19:43:44

EgonOlsen (39 views)
2018-06-10 19:43:20

DesertCoockie (186 views)
2018-05-13 18:23:11

nelsongames (122 views)
2018-04-24 18:15:36

nelsongames (121 views)
2018-04-24 18:14:32

ivj94 (861 views)
2018-03-24 14:47:39

ivj94 (122 views)
2018-03-24 14:46:31

ivj94 (758 views)
2018-03-24 14:43:53

Solater (139 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!