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 (844)
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 1678 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
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,
Offline Jimmt
« League of Dukes »

JGO Kernel

Medals: 167
Projects: 5
Exp: 6 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 Devvie

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  

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

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

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

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

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

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

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

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

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

Solater (177 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!