Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (553)
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  
  blocks in a tile game  (Read 504 times)
0 Members and 1 Guest are viewing this topic.
Offline James van Dalen

Senior Newbie





« Posted 2013-05-02 14:27:03 »

Hi all,

What is the best way of implimenting blocks into a tile oriented game? blocks like fences, sign posts, chairs maybe and generally things that have unique data to each block. for example each sign post has unique text attached to each one. The way I have it implimented now is giving me trouble with the unique block.

I've got it implimented in the same way my tiles are, the tile class initiates all the tiles. Heres a code snippit of what I mean.
FROM Block.class
1  
2  
3  
4  
5  
6  
7  
public class Block{
   private static SpriteSheet spriteSheet = new SpriteSheet("/spriteSheets/block_sheet.png");

   public static Block[] blocks = new Block[256];
   public static Block empty = new blockVoid      (spriteSheet, 0xFF00FF00, 0);
   public static Block fence = new blockFence      (spriteSheet, 0xFFFF0000, 1);
   public static Block sign = new blockSign      (spriteSheet, 0xFF, 2);


this doesn't really allow for individual setup because if you change it there then it changes for all of the objects.

Thanks for the help,
James
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #1 - Posted 2013-05-02 17:09:03 »

It changes everything because your variables are static-read more here. Block spritesheet could be static if all blocks have the same unchanging spritesheet, but things like x/y should not be static. I don't really understand your code, however. An array of blocks within your block class, and three other blocks? "empty", "fence", and "sign" are not exactly descriptive variable names.
Offline Zhon

Junior Member


Medals: 4



« Reply #2 - Posted 2013-05-02 18:40:30 »

Have your world store 2 values in each tile position: id, metadata
id is the value to represent the block in that tile, metadata is to give it singularity.
Then have a single instance of each block to receive the metadata and tile position in order to administrate that tile through it's methods (metadata and tile positions should be used as parameters in the Blocks' methods.
For example, change the metadata of the tile x,y which represents a fence, to open/close it throught the Fence block instance's method.
But the sign is a problem here. A sign can hold a lot of text, it'd be hard to hold all those characters in a single integer (metadata), so you could create some kind of tile-entity for the sign to hold the text, or a class to hold sign's texts and access them via the sign's metadata?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline James van Dalen

Senior Newbie





« Reply #3 - Posted 2013-05-03 05:47:46 »

That doesn't sound like a bad idea, I might need to make a blockManager class then to determine which block it is and what action to take when the player uses that block... like it would see that the block is a fence and then it would run a use method to open or close the fence but only change the data on that instance of fence... I'll have to just try and see  Grin thanks for the help I'll let you know if I managed to get it working. I'm trying to keep it as simple as programmably possible.
Offline James van Dalen

Senior Newbie





« Reply #4 - Posted 2013-05-06 08:10:05 »

well that didn't work... and then it did work...

I removed "blocks" and just made the sign an entity and now everything is working as I wanted it too. Thanks Zhon for the help.
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.

CopyableCougar4 (24 views)
2014-08-22 19:31:30

atombrot (34 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (28 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (27 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (33 views)
2014-08-08 02:01:56

Norakomi (42 views)
2014-08-06 19:49:38
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!