Marshland Games has moved to http://www.marshlandgames.com/

This site will no longer be updated.

All games and text copyright © Kai Marshland 2012

Wednesday, April 11, 2012

Snowball game

It is playable, but collision detection is behaving very oddly. It does not seem to register collisions when they should happen, but says there was a collision at seemingly random times. The code looks like:

if ((o.vPos + (0.5 * o.getHeight()) + (0.5 * snowball.diameter) > 500) && (o.vPos < 500)){
if (((Math.abs(o.hPos) - (0.5 * o.getWidth())) < (0.5 * snowball.diameter)) &&
(Math.abs(o.hPos) - (0.5 * o.getWidth()) > (-0.5 * snowball.diameter))){
//do stuff

o is an obstacle. vPos and hPos stand for vertical and horizontal position. The snowball is located at 500 on the y-axis, and is at what functions as 0 on the x-axis. (in terms of pixels, this is actually 300)

No comments:

Post a Comment