Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Two Things in a single grid area  (Read 514 times)
0 Members and 1 Guest are viewing this topic.
Offline Soljaragz

Jr. Member
**

Posts: 55



« on: 2006-02-04 21: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 Kernel
*****

Posts: 3535


Got any cats?


« Reply #1 on: 2006-02-04 22: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!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Soljaragz

Jr. Member
**

Posts: 55



« Reply #2 on: 2006-02-04 22: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! Go get 'em!
Offline Soljaragz

Jr. Member
**

Posts: 55



« Reply #3 on: 2006-02-04 23: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 Kernel
*****

Posts: 3535


Got any cats?


« Reply #4 on: 2006-02-05 15: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!

http://wiki.java.net/bin/view/Games/JeffFAQ
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.118 seconds with 20 queries.