Grundlagen der Programmierung 2 SS 2005 - Datei Hole.java
import java.lang.Math; import gamelet.*; public class Hole extends Actor { Hole(Gamelet theGamelet) { super(theGamelet); setImage(getGamelet().getImage("hole.gif")); setCurrentFrame(0); setXPos(Gamelet.randBetween(0.0, getGamelet().getWidth() - getWidth())); setYPos(Gamelet .randBetween(0.0, getGamelet().getHeight() - getHeight())); setXVelocity(0); setYVelocity(0); setWrapAround(false); } protected void collideWithActor(Actor other) { // Compute Distance of center points. double centerx = getXPos() + 0.5 * getWidth(); double centery = getYPos() + 0.5 * getHeight(); double otherx = other.getXPos() + 0.5 * other.getWidth(); double othery = other.getYPos() + 0.5 * other.getHeight(); double distance = Math.sqrt((otherx - centerx) * (otherx - centerx) + (othery - centery) * (othery - centery)); double radius = 0.5 * getWidth(); if (distance < radius) { getGamelet().removeActor(other); } } }
Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 22.04.2005