• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps help for my game

oriz

Newbie
Hey i am making a game that you are a spaceship and enemys are falling on you so far i have made the spaceship shoot and the
enemy falling fron the top of the screen (i have already made that if the bullet hits the enemy you get points)

but i have one problem that im stuck on for 2 days already the problem is to detect spaceship and enemy hit (they hit each other)
when they hitting each other it works but also when they far away from each other..

the code of the hit check is

Code:
            if(invaders.getx0()-(iwidth/2)>=this.x-(pwidth/2)&&invaders.getx0()+iwidth<=this.x+pwidth&&invaders.gety0()+iheight>this.y&&invaders.gety0()<=this.y)
            {
                invaders.setbitmap(1);
                
            }
it checks if enemy 0 hitted the spaceship
iwidth is the enemy bitmap width
iheight is enemy bitmap height
pwidth is spaceship bitmap width
pheight is spaceship bitmap height

this.x and this.y is spaceship x and y
invaders.getx0 and invaders.gety0 is the enemy x and y

and invaders.setbitmap() is to set the life
please help me thanks
 
It's hard to help from here. To see what's going on, try to log all these values and see what happens, for instance
PHP:
Log.d('invader x is '+invaders.getx0()+', my x is '+this.x);/// ant all other values too
What does it display? Are all values correct?
 
Any news? I am worrying a bit, because I feel responsible for I advised you to develop this game :)
Do it, it shouldn't be something impossible. I am sure you will immediately see what is the problem.
 
Any news? I am worrying a bit, because I feel responsible for I advised you to develop this game :)
Do it, it shouldn't be something impossible. I am sure you will immediately see what is the problem.

I have made it!
The answer to this was that i made 2 rects the store the location and checked intersect
the game ia finished :)
 
Good for you!

Regarding different screen sizes - well, there is no universal answer. You need to detect the size on each device and resize your bitmaps according to the screen. In some apps it's easier to have one big bitmap and resize it, in other apps it's better to keep several sizes in app and use the closest one in particular case.
 
Back
Top Bottom