Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
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  
  Two Things in a single grid area  (Read 1043 times)
0 Members and 1 Guest are viewing this topic.
Offline Soljaragz

Junior Devvie

« Posted 2006-02-05 02:35:58 »

Every object/enemy in my game are in a big [][] array, and then all the items are put in a [] array, and all the enemies are put in a different [] array,

I ve done the collision for my regular attack and ranged attack, and it works fine, but the problem is i haven't animated the enemies yet,so they are just sitting there waiting to be attacked

because of that, no two enemies are in the same grid, so i can do collision quite easily

but enemies have to move lol.......................
 my main character class has a column number int  that is basically what column he is in, and my enemies has the same thing,

so there is two ways ii think i can do collision

1. have a loop that goes through the entire enemyList and checks each enemie's column number to see if it is the same as the characters, or if it is one in front of it (if character facing left, then check for the current column and one behind it).

2. make a ArrayList  that can hold several enemies, and make an ARRAY OF ARRAYLISTS for  the entire level, and then each time an enemy moves, put him in the corresponding array index,
 then when i test for collision, I just test my character's current col position against the current array index, and go through the entire arrayList to test (if !arrayList.isEmpty())

so which way would be faster or is there something better>?
Offline Jeff

JGO Coder

Got any cats?

« Reply #1 - Posted 2006-02-05 03:01:44 »

So why exactly are you not using objects to represent your data such as the contents of a cell?

This isnt BASIC.  This is OOP?

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!
Offline Soljaragz

Junior Devvie

« Reply #2 - Posted 2006-02-05 03:07:58 »

ugh, i have an element class and a enemy class that extends element...................and a level class that process all that.....

so i should make a class that holds everything instead of using arrayS?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Soljaragz

Junior Devvie

« Reply #3 - Posted 2006-02-05 04:28:51 »

disregarding me using objects or arrays, what is the best way to do what i said in the first post
Offline Jeff

JGO Coder

Got any cats?

« Reply #4 - Posted 2006-02-05 20:07:02 »

For any sigfnificant number of objects, storing them by location and just checking those in the right lcoation for collision will be faster then checking them all.

This is called a "bucket" in the genreal sense.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

bilznatch (28 views)
2015-08-04 11:03:17

SHC (44 views)
2015-08-01 03:58:20

Jesse (25 views)
2015-07-29 04:35:27

Riven (48 views)
2015-07-27 16:38:00

Riven (26 views)
2015-07-27 15:35:20

Riven (28 views)
2015-07-27 12:26:13

Riven (19 views)
2015-07-27 12:23:39

BurntPizza (42 views)
2015-07-25 00:14:37

BurntPizza (56 views)
2015-07-24 22:06:39

BurntPizza (35 views)
2015-07-24 06:06:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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!