Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 1006 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 gamedev.net and checking under the articles/tile based graphics sections.
Offline JuddMan

Senior Member


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
1  
2  
3  
4  
5  
6  
7  
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)
        this.food = f;

etc...


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 »

hello.

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 :-)

thankyou.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (28 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (74 views)
2014-09-10 06:39:09

Tekkerue (37 views)
2014-09-09 02:24:56

mitcheeb (57 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (28 views)
2014-09-07 01:12:14

Longarmx (34 views)
2014-09-07 01:11:22

Longarmx (34 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!