Class QuantumObject

java.lang.Object
  extended by Actor
      extended by QuantumObject
Direct Known Subclasses:
Collectible, Missile, Spaceship

public class QuantumObject
extends Actor

Anything that can move around in space and interact (fluctuate, collide, "hit") with other quantum objects. All moving objects in this game have classes derived from QuantumObject. Unlike in real physics, QuantumObjects have an intrinsic speed that causes them to move around (implemented in act()). They may choose to fall off the screen when reaching the border. Special coding magic enables it to have real dynamic method dispatch so that collisions with different classes of quantum objects can be implemented.


Field Summary
protected  boolean destroysOnNextTurn
          Can be set to us by any caller within a given game turn.
protected  boolean disappear
          Whether the quantum object should fall off the world (i.
protected  Vector mantissa
          Contains the mantissa that remains from speed calculations (since Greenfoot only allows it to do pixel-based movements).
protected  Vector speed
           
 
Constructor Summary
QuantumObject()
           
 
Method Summary
 void act()
          A day in the life of a quantum object: 1.
 boolean getDestroysOnNextTurn()
           
 Vector getSpeed()
           
 boolean hit(Actor actor)
          hit.
 void move()
          move.
 void setDestroysOnNextTurn(boolean destroys)
           
 void setSpeed(Vector someSpeed)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

speed

protected Vector speed

mantissa

protected Vector mantissa
Contains the mantissa that remains from speed calculations (since Greenfoot only allows it to do pixel-based movements).

See Also:
move()

disappear

protected boolean disappear
Whether the quantum object should fall off the world (i. e. be destroyed) when reaching the edge.


destroysOnNextTurn

protected boolean destroysOnNextTurn
Can be set to us by any caller within a given game turn. The next time this.act() is called after setting, this object destroys itself.

Constructor Detail

QuantumObject

public QuantumObject()
Method Detail

act

public void act()
A day in the life of a quantum object: 1. Maybe commit suicide (i. e. destroys itself when destroysOnNextTurn is true) 2. Do quantum object interactions with intersecting objects 3. -- Err... are you missing point 3?


setSpeed

public void setSpeed(Vector someSpeed)

getSpeed

public Vector getSpeed()

setDestroysOnNextTurn

public void setDestroysOnNextTurn(boolean destroys)

getDestroysOnNextTurn

public boolean getDestroysOnNextTurn()

move

public void move()
move. Cause the quantum object to move around based on its speed. Fun fact: speed values can also be non-integer. Because Greenfoot only allows for pixel-based movement, the mantissa of the speed vector is kept seperately and summed up with the mantissa from the previous turn. That way, e. g. a vertical speed of 2.2 causes the quantum object to move 2 pixels every game turn, and 3 pixels every 5th turn, because after each 5 turns the .2 mantissae have added up to 1.

See Also:
mantissa

hit

public boolean hit(Actor actor)
hit. Base method hit(Actor). Uses java.lang.reflect to dynamically find out which hit() method of the quantum object to invoke based on which actual class "actor" has. Dynamic dispatch comes true!

Parameters:
actor - The object we are interacting with
Returns:
boolean. True if this quantum object should survive, false otherwise.