Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
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  
  Pixel based 2d destructible terrain?  (Read 1291 times)
0 Members and 1 Guest are viewing this topic.
Offline nerb
« Posted 2013-02-25 09:55:14 »

Hi  Smiley,

First off, I should say thankyou! Over the years I have often browsed JGO for answers to my questions or to fill in time, albeit have never signed up until now.

I'm toying with the idea of creating a lemmings-esque game, with pixel based destructible terrain. I've had a good googling and have some idea about how I will accomplish this. However I'd like to run my thoughts past the JGO community to see if I am on the right track, or if there is a better way.

Essentially I will use a foreground image that forms the terrain (plus a background image). This would likely be accompanied by a byte array holding destructability & collision information for each pixel.

Should pixels be destroyed (by explosions, digging etc.), then I will set the alpha byte of each affected pixel to 0x00 using BufferedImage.setRGB(), followed by updating the byte array, and then render the images.

Does this sound reasonable and efficient? Or would you guys go about this differently?

Thanks very much,
nerb.
Offline RobinB

JGO Knight


Medals: 37
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #1 - Posted 2013-02-25 10:30:10 »

That way works, but is really slow, remember you also have to check collisions with the terrain.
Best way is to use an quad tree like this:
Offline Damocles
« Reply #2 - Posted 2013-02-25 10:45:27 »

The approach to directly detect collisions and alter terrain on an (Image)array
was used in the original Lemmings on the Amiga.
Thus the method should not slow down a modern PC that much.

It depends more on the resolution of your terrain (how many pixels is 1 lemming?)
if you need an optimization like a quad-tree.


Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nerb
« Reply #3 - Posted 2013-02-25 11:17:49 »

Quad tree is food for thought. At this stage I'm thinking of sticking to low-res maps. Although I guess there would be lots of contiguous empty areas or flat platforms. Using quadtree may reduce the need to inspect 60 or so pixels per 'lemming' per update. Although as you mentioned Damocles, it shouldn't take a big toll on modern hardware. Nonetheless, I intend to design it to run as lean as possible.

Cheers.
Offline Rorkien
« Reply #4 - Posted 2013-02-25 18:48:34 »

I think that getting the pixel-array and editing it would be easier and faster than using setRGB

And this might be some help: http://www.mojang.com/notch/j4k2k6/miners4k/
Offline relminator
« Reply #5 - Posted 2013-02-26 16:08:48 »

Quad tree is food for thought. At this stage I'm thinking of sticking to low-res maps. Although I guess there would be lots of contiguous empty areas or flat platforms. Using quadtree may reduce the need to inspect 60 or so pixels per 'lemming' per update. Although as you mentioned Damocles, it shouldn't take a big toll on modern hardware. Nonetheless, I intend to design it to run as lean as possible.

Cheers.

A quadtree(or octree for that matter) is not that hard to make. 

http://rel.phatcode.net/mytutes/octreetute/octree_tute.zip


However, for a lemmings game with less than 20 units, a pixel perfect detection would not hurt your FPS.  I know of a Lerio-like game that runs full speed on the 66 mhz NDS.  So  don't do premature optimizations until you get a hit on your FPS.
Offline nerb
« Reply #6 - Posted 2013-03-01 06:08:49 »

Cheers all.

I think that getting the pixel-array and editing it would be easier and faster than using setRGB

And this might be some help: http://www.mojang.com/notch/j4k2k6/miners4k/

That link is absolute gold Rorkien, thanks very much. Had to do some further reading on the pixel-array approach, but definitely sounds like the way to go. Calls to get/setRGB() appear to be relatively expensive. (This is new to me, I'm learning as I go!).

nerb.
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 (35 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (199 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

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
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!