• Post Reply Bookmark Topic Watch Topic
  • New Topic

Considrin' Lemmings

 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a game like Lemmings, every pixel (or at least 2x2-ish pixel block) is either full, or not-full. Is the best way to implement this a monserously large 2d boolean array? (maybe bytes, I might want to have more than just full/not-full)
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think an array of booleans will probably end up using one 32-bit word for each bit. Which may be acceptable - but offhand I'd probably look at using an array of BitSets, which internally represent a row of booleans using an array of longs (64 booleans per long). Or you might roll your own implementation similar to BitSet, perhaps with additional methods.
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A common practice seems to be favoring a single dimension array over a 2 dimension array and doing access with:

array[row*col]

I'm working on a game that requires pixel level accuracy for display and colision detection. I use an array of ints that is width*height in size(ints for me because I need color data for each pixel).
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how would that work, Steven? I don't want my value at (2,12) to be the sane as (4,6).
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops, sorry. the array access is actually

array[row*col + col]
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry again, I need to think before I post. It's

array[row*width + col]

although I went back to look at my game code, and I found that I switched to using a BufferedImage to store the information.
 
Henry Wong
author
Sheriff
Posts: 22530
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is checking the actual pixels the best way detect collision? I would think it is better to just store info -- location of the lemmings, direction of travel, type, etc. And then use algorithms to detect collisions.

This was the preferred way decades ago (using sprites collision detection). And with the number of gaming algorithm books skyrocketting in the last few years (which discuss and build on this), there should be an algorithm that should work.

Henry
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry:

I must confess that I don't follow. How would an algorithm (I'm not really sure of what nature algorithm you're talking) be easier than just testing location vs. the map? You'd need to store the entire map anyway.
 
Henry Wong
author
Sheriff
Posts: 22530
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nick George:
I must confess that I don't follow. How would an algorithm (I'm not really sure of what nature algorithm you're talking) be easier than just testing location vs. the map? You'd need to store the entire map anyway.


Nick,

Search your nearest graphics book, or the internet, for sprites. Or to be specific, collision detection of sprites. Basically, given any two bitmap patterns, there is a fast mathamatical formula to determine whether they will collide, before actually drawing them.

With this, you only need to store the pixels for the individual lemmings and their locations. You don't need to store -- what could be a huge -- copy of the pixels on the screen.

Henry
 
Zbyszek Cyktor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry, You seem to have missed the point. In a game like Lemmings the application needs to keep information about changes in terrain, which can be demolished in unpredictable ways - it can not be implemented by using sprites.
Using individual bits instead of boolean values seems to be the most economic way, as previous posters suggested.

Of course it's perfectly fine and natural to use sprites for game characters.

Zbyszek
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!