Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (512)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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 879 times)
0 Members and 1 Guest are viewing this topic.
Offline Soljaragz

Junior Duke





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

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

Junior Duke





« 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 Duke





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

http://wiki.java.net/bin/view/Games/JeffFAQ
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.

Longarmx (50 views)
2014-10-17 03:59:02

Norakomi (39 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (36 views)
2014-10-15 16:18:58

TehJavaDev (66 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (55 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!