private void deploySprite(DeploymentParams deployment, long elapsedTime) { // get the camera bounds Rectangle cameraBounds = kernel.getCameraBounds(); // get a random lane boolean south = (MathUtils.randomBoolean()); south = true; Vector lanes = (south) ? southLanes : northLanes; // get a random path PointPath path = (PointPath)lanes.elementAt( MathUtils.randomBoolean() ? 0 : 1); // get coordinates from camera based on lane direction int x1 = cameraBounds.x; int y1 = (south) ? cameraBounds.y : cameraBounds.y+cameraBounds.height; int x2 = cameraBounds.x+cameraBounds.width; int y2 = y1; // get point index int pointIdx = path.findIntersectionPoint(x1, y1, x2, y2, 0); if (pointIdx==-1) { return; } Point frontPoint = path.getPoint(pointIdx); Point behindPoint = path.getPoint(pointIdx-1); // get lane intersection with camera edge Line.intersectionPoint( x1, y1, x2, y2, frontPoint.x, frontPoint.y, behindPoint.x, behindPoint.y, dummyPoint ); // create sprite Sprite sprite = deployment.descriptor.createSprite(); dummyPoint.x -= (sprite.getBounds().width/2); dummyPoint.y -= (sprite.getBounds().height/2); // create deployment pair SpritePathPair pair = new SpritePathPair(); pair.fromPoint = new Point(dummyPoint); pair.path = path; pair.sprite = sprite; pair.toPoint = frontPoint; pair.toPointIndex = pointIdx; pair.lastTime = elapsedTime; // position the sprite sprite.getBounds().x = dummyPoint.x - (sprite.getBounds().width / 2); sprite.getBounds().y = dummyPoint.y - (sprite.getBounds().height / 2); // calculate velocity int maxVel = (int)MathFP.toLong(deployment.maxVelocity_f); int minVel = (int)MathFP.toLong(deployment.minVelocity_f); long velocity_f = MathFP.toFP(MathUtils.randomInt(maxVel-minVel)+minVel); // calculate direction long direction_f = Point.directionTweenPoints_f( pair.fromPoint.x, pair.fromPoint.y, pair.toPoint.x, pair.toPoint.y ); // set velocity and direction sprite.setVelocity_f(velocity_f); sprite.setDirection_f(direction_f); kernel.addRenderer(sprite); // add to deployment deployment.sprites.addElement(pair); handler.spriteDeployed(sprite); //#debug System.out.println("Added sprite at: "+ sprite.getBounds().x+","+sprite.getBounds().y+ " In direction: "+MathFP.toString(sprite.getDirection_f())+ " with velocity: "+MathFP.toString(sprite.getVelocity_f())); }