public class Robot
extends java.lang.Object
import ch.aplu.raspisim.*;
public class Example
{
static
{
RobotContext.setStartPosition(100, 100);
RobotContext.setStartDirection(45);
}
public Example()
{
Robot robot = new Robot();
Gear gear = new Gear();
robot.addPart(gear);
gear.forward(5000);
robot.exit();
}
public static void main(String[] args)
{
new Example();
}
}
Modifier and Type | Field and Description |
---|---|
static java.awt.Point |
collisionCenter
Center of a circle to detect robot-obstacle collisions
(pixel coordinates relative to center of robot image, default: (-13, 0)).
|
static int |
collisionRadius
Radius of a circle to detect robot-obstacle collisions
(in pixels, default: 20).
|
Constructor and Description |
---|
Robot()
Creates a robot with its playground using defaults from RobotContext.
|
Modifier and Type | Method and Description |
---|---|
void |
addButtonListener(ButtonListener listener)
Registers a button listener that simulates the events
when one of the brick buttons is hit.
|
void |
addCollisionListener(CollisionListener listener)
Registers a robot-obtacle collision listener that fires
the collide callback when the circumcircle of the robot overlaps
with an obstacle.
|
void |
addObstacle(Obstacle obstacle,
int x,
int y)
Adds the given obstacle in the obstacle list and shows it at the given
location.
|
void |
addTarget(Target target,
int x,
int y)
Adds the given target in the target list and shows it at the given
location.
|
static void |
debug(java.lang.String msg) |
void |
exit()
Stops any motion and performs a cleanup of all parts.
|
static GameGrid |
getGameGrid()
Returns the instance reference of the GameGrid.
|
int |
getHitButtonID()
Returns the button ID of the button previously hit.
|
static Actor |
getRobot()
Returns the instance reference of the MyRobot actor.
|
static java.lang.String |
getVersion()
Returns the current library version.
|
boolean |
isAutonomous()
Returns always false.
|
boolean |
isButtonHit()
Returns true, if any of the buttons was hit.
|
boolean |
isConnected()
Returns the current state of the underlying GameGrid window.
|
boolean |
isDownHit()
Returns true, if the DOWN button was the last button hit since
the last call of this method.
|
boolean |
isEnterHit()
Returns true, if the ENTER button was the last button hit since
the last call of this method.
|
boolean |
isEscapeHit()
Returns true, if the ESCAPE button was the last button hit since
the last call of this method.
|
boolean |
isLeftHit()
Returns true, if the LEFT button was the last button hit since
the last call of this method.
|
boolean |
isRightHit()
Returns true, if the RIGHT button was the last button hit since
the last call of this method.
|
boolean |
isUpHit()
Returns true, if the UP button was the last button hit since
the last call of this method.
|
void |
playTone(double frequency,
double duration)
Plays a sine tone with given frequency and duration and maximum volume.
|
void |
playTone(double volume,
double frequency,
double duration,
boolean blocking)
Plays a sine tone with given frequency and duration.
|
void |
removeObstacle(Obstacle obstacle)
Removes the given obstacle from the obstacle list and hides it.
|
void |
removeTarget(Target target)
Removes the given target from the target list and hides it.
|
void |
reset()
Resets MyRobot to start location/direction.
|
public static java.awt.Point collisionCenter
public static int collisionRadius
public Robot()
public static GameGrid getGameGrid()
public boolean isConnected()
public static Actor getRobot()
public void exit()
public static java.lang.String getVersion()
public void reset()
public void addTarget(Target target, int x, int y)
target
- the target to addx
- the x location of the target centery
- the y location of the target centerpublic void removeTarget(Target target)
target
- the target to removepublic void addObstacle(Obstacle obstacle, int x, int y)
obstacle
- the obstacle to addx
- the x location of the target centery
- the y location of the target centerpublic void removeObstacle(Obstacle obstacle)
obstacle
- the obstacle to removepublic void addCollisionListener(CollisionListener listener)
listener
- the CollisionListener to registerpublic void addButtonListener(ButtonListener listener)
listener
- the ButtonListener to registerpublic boolean isButtonHit()
public int getHitButtonID()
public boolean isUpHit()
public boolean isDownHit()
public boolean isLeftHit()
public boolean isRightHit()
public boolean isEnterHit()
public boolean isEscapeHit()
public boolean isAutonomous()
public void playTone(double frequency, double duration)
frequency
- the frequency of the tone (in Hertz) (double rounded to int)duration
- the duration of the tone (in Millisec) (double rounded to int)public void playTone(double volume, double frequency, double duration, boolean blocking)
volume
- the sound volume (0..100) (double rounded to int)frequency
- the frequency of the tone (in Hertz) (double rounded to int)duration
- the duration of the tone (in Millisec) (double rounded to int)blocking
- if true, the methods blocks until the tone is finishedpublic static void debug(java.lang.String msg)