Re: How to see if an object is part of a specific vector?
- From: Johan Poppe <jupweb@xxxxxxxxx>
- Date: Tue, 31 May 2005 04:24:00 +0200
caleb wrote:
1.
> for(int i=0; i<aliens.size(); i++) {
> Alien a = (Alien) aliens.elementAt(i);
2.
> if(a.contains(ufos)) {
> for(int z=0; z<ufos.size(); z++) {
> Ufo u = (Ufo) ufos.elementAt(i);
> d = u.getSizeX() /2;
> e = u.getSizeY() /2;
> }
> }
> else if(a.contains(smartAliens)) {
> for(int z=0; z<smartAliens.size(); z++) {
> SmartAlien s = (SmartAlien)
>smartAliens.elementAt(i);
> d = s.getSizeX() /2;
> e = s.getSizeY() /2;
> }
> }
Quite aside from the question you actually ask, this code ha a lot of
unnecessary things and I doubt it is doing what you intend it to do.
At the end of each of the inner loops, (and after you have fixed the
'contains' bug) d and e will contain the size of _the last_ element in
either the smartAliens vector or the ufos vector. Is that what you
want?
I am not quite sure I understand your thinking, but I _think_ you
should replace the whole if (ufos.contain(a)) .... else if ...
structure with these two lines:
d = a.getSizeX() /2;
e = a.getSizeY() /2;
Then you should make sure that the getSizeX and ...Y-methods returns
the correct values for the various types of aliens.
>I'm new to java(and programming in general) though so I
>don't know all of the lingo yet. Also if anyone had any good links to
>starting java game programmers that would be great.
If you are new to programming, you should start by just learning
programming and not focus too much on the "game" part just yet.
--
Johan Utne Poppe
.
- Follow-Ups:
- References:
- Prev by Date: Re: 2's complement
- Next by Date: Re: How to see if an object is part of a specific vector?
- Previous by thread: Re: How to see if an object is part of a specific vector?
- Next by thread: Re: How to see if an object is part of a specific vector?
- Index(es):