Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
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  
  Resizeable 2d grid  (Read 990 times)
0 Members and 1 Guest are viewing this topic.
Offline iamsteveholmes

Senior Newbie





« Posted 2006-02-15 00:06:44 »

Hello All!
Any idea how to create a grid that could be resized by the user?  Preferably by dragging with the mouse.  Here is the app I'm trying to produce:

http://www.java-gaming.org/forums/index.php?topic=12472.0

I figure this is probably simple stuff but me being a total n00b I figure I should ask for advice first.
Offline Mr_Light

Senior Member




shiny.


« Reply #1 - Posted 2006-02-15 01:38:15 »

*zip* I was almost writing a book on data structures here.

lets keep it short. figure out your use case how often you would change the grid. notice how dragging the mouse has little impact on the data structure you chose since you should separate the model from the UI.

a grid is interesting term, ask yourself this am I useing the tiles or the intersections of the grid?

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline iamsteveholmes

Senior Newbie





« Reply #2 - Posted 2006-02-15 02:15:43 »

Mr_Light,

Let me see if I can explain the use case.  The user will either start with an imported image of a map or a blank slate that they can draw on.  The grid should be placed over it as a representation of distance, etc.  So for example in most games one tile (square) will represent 5'.

So figures will have to be dragged and dropped to the various parts of the grid.  Here is the problem about intersections and tiles.  Sometimes a figure will be the size of one tile and sometimes by four (or more) depending on the size so the middle would be an intersection.  Also, certain effects are based on the radius around an intersection.  For instance, an effect might be a 20' radius and so would be four tiles in all directions around an intersection (I hope this makes sense to people).

At the same time it seems that all the figures, effects, etc could be represented by a certain number of tiles, so I'm open to suggestions.

If you didn't know I was a N00b you should know by now.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline iamsteveholmes

Senior Newbie





« Reply #3 - Posted 2006-02-15 02:32:21 »

I should also mention that this isn't the traditional tiles (that I've mostly read about) where each tile is a graphical object that is put together to form a map.  The map would be an imported image or one drawn by the user.  The grid would need to be resized to the specifications of the map.

The figures and such that would be placed on the grid (or on the tiles) would need to resize also to the size of the grid.  So for instance if a figure is supposed to be the size of 2x2 tiles then the figure would resize with the grid.

I think that point can be tackled later....
Thanks!
Offline Ask_Hjorth_Larsen

Junior Member




Java games rock!


« Reply #4 - Posted 2006-02-15 14:07:08 »

First, I'd create a Grid class or something similar. Now, since you have lots of stuff at each point, you'll probably need a kind of List at each tile. If only one thing can be at one point, just let it have a Thing instead. Now, the Grid should have a number of properties: resolution (the constant size in pixels of each tile which I assume is quadratic), width and height (which measure how many pixels there are on each side.

If the user resizes, which is obviously a completely separate problem from how to make a grid, you just need to adjust the resolution. If the resolution is a floating point number then you can resize rather smoothly. Done!
Offline Mr_Light

Senior Member




shiny.


« Reply #5 - Posted 2006-02-15 16:33:52 »

the way I read it your grid is not so much resizable as it is of unkown size.

I might read it wrong, but after you actually start doing somehting with the grid, it doesn't change size anymore.

wenn the user is figuring out the size it might look like theres a grid but there is actually not(the way I would implent it) only a grid is drawn. wenn the user figures it is of good size(you might actually already know the size in advance since you know the size of the image) and resolution. he "finishes" and then you actually create the underlaying datastructure. this way a simple array could work.


//off topic
bringing up the 'tiles'-tiles, it might actually be wise to create the tiles out of the picture at the same point you create the array. the reason to use tiles is that you can surfise with only redrawing that tile, and since I supect the tiles will have some kind of poin on them.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline iamsteveholmes

Senior Newbie





« Reply #6 - Posted 2006-02-15 21:24:04 »

Mr Larsen,
Okay so each tile will hold information about what is on it?  That makes alot of sense to me.  It is possible a couple of objects could be on one tile at a time although this would not happen often.  In addition to the length of the lines (height and width of each square) I would also like the user to be able to modify the size of the lines.  I know that should just be one more simple parameter.  I'll try coding that up tonight and see how far I get.

Offline iamsteveholmes

Senior Newbie





« Reply #7 - Posted 2006-02-15 21:29:34 »

Mr Light,
Not sure whether they will need to modify it after they have set it the first time.  I suspect they will just to get it right.  The grid is the actual playing board but the image in the background represents where the figures/effects are at so it is important that the user has a fair amount of flexibility to play around with the grid until it "snaps on" to the background image. 

Also, I don't really want to go down the road of allowing the users to modify the background images greatly.  I will provide some drawing tools so they can create an extra layer if they want to make simple modifications.  Imagine the background image is a dungeon, the dungeon itself won't change much except some objects like chairs, tables etc which could either be drawn on seperate layer.  Want to keep it really simple at least at first.

In some cases the player will not import an image at all but will simply put a grid down and make a simple sketch of the battlefield.
Offline Mr_Light

Senior Member




shiny.


« Reply #8 - Posted 2006-02-15 23:11:11 »

yes so before "snapping on" you can surfice with a grapical representation of a grid. after "snapping on" create the datastructure after which it doesn't change. thus a simple Object[][]/matrix would surfice. if the thing does have to change they can rerun the "wizard".


It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
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.

xsi3rr4x (25 views)
2014-04-15 18:08:23

BurntPizza (20 views)
2014-04-15 03:46:01

UprightPath (36 views)
2014-04-14 17:39:50

UprightPath (18 views)
2014-04-14 17:35:47

Porlus (34 views)
2014-04-14 15:48:38

tom_mai78101 (60 views)
2014-04-10 04:04:31

BurntPizza (118 views)
2014-04-08 23:06:04

tom_mai78101 (218 views)
2014-04-05 13:34:39

trollwarrior1 (185 views)
2014-04-04 12:06:45

CJLetsGame (192 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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!