/**
*
*/
package svet.co;
import com.evelopers.unimod.runtime.ControlledObject;
import com.evelopers.unimod.runtime.context.StateMachineContext;
public class TrafficEngine implements ControlledObject {
public static boolean h_up, h_down, c_left, c_right, hurry, stopping;
public static int yup, ydown, xleft, xright;
/**
*
* @unimod.action.descr Add bottom human
*/
public void z011(StateMachineContext context) {
System.out.println("New human came from the bottom of the screen");
h_up=true;
DrawingWindows.sl.repaint(220, 145, 320, 460);
}
/**
*
* @unimod.action.descr Add top human
*/
public void z012(StateMachineContext context) {
System.out.println("New human came from the top of the screen");
h_down=true;
DrawingWindows.sl.repaint(220, 145, 320, 460);
}
/**
*
* @unimod.action.descr Add left car
*/
public void z021(StateMachineContext context) {
System.out.println("New car arrived from the left side of the road");
c_right = true;
DrawingWindows.sl.repaint();
}
/**
*
* @unimod.action.descr Add right car
*/
public void z022(StateMachineContext context) {
System.out.println("New car arrived from the right side of the road");
c_left = true;
DrawingWindows.sl.repaint();
}
/**
*
* @unimod.action.descr Humans step
*/
public void z3(StateMachineContext context) {
if (h_up || h_down) {
byte v = 2;
if (hurry)
v = 4;
if (h_up)
yup += v;
if (h_down)
ydown += v;
if (yup > 265) {
h_up = false;
yup = 0;
}
if (ydown > 265) {
h_down = false;
ydown = 0;
}
DrawingWindows.sl.repaint();
}
}
/**
* @unimod.action.descr Humans are beginning to make hurry
*/
public void z4(StateMachineContext context) {
hurry = true;
}
/**
*
* @unimod.action.descr Humans run
*/
public void z5(StateMachineContext context) {
if (h_up || h_down) {
if (h_up)
yup += 6;
if (h_down)
ydown += 6;
if (yup > 265) {
h_up = false;
yup = 0;
}
if (ydown > 265) {
h_down = false;
ydown = 0;
}
DrawingWindows.sl.repaint();
}
}
/**
* @unimod.action.descr Humans stop
*/
public void z6(StateMachineContext context) {
h_up = false;
h_down = false;
hurry = false;
yup = 0;
ydown = 0;
}
/**
*
* @unimod.action.descr Cars drive
*/
public void z7(StateMachineContext context) {
if (c_left || c_right) {
// byte v = 2;
// if (hurry) v=4;
if (c_left)
xleft += 5;
if (c_right)
xright += 5;
if (xright >= 410) {
c_right = false;
xright = 0;
}
if (xleft >= 410) {
c_left = false;
xleft = 0;
}
DrawingWindows.sl.repaint();
}
}
/**
*
* @unimod.action.descr Cars drive and stop
*/
public void z8(StateMachineContext context) {
if (c_left || c_right) {
if (stopping) {
if (c_left) {
if (xleft <= 100)
xleft = Math.min(xleft + 10, 100);
if (xleft > 100)
xleft += 10;
}
if (c_right) {
if (xright <= 100)
xright = Math.min(xright + 10, 100);
if (xright > 100)
xright += 10;
}
} else {
if (c_left)
xleft += 5;
if (c_right)
xright += 5;
}
if (xright >= 410) {
c_right = false;
xright = 0;
}
if (xleft >= 410) {
c_left = false;
xleft = 0;
}
DrawingWindows.sl.repaint();
}
}
/**
* @unimod.action.descr Cars are beginning to make hurry
*/
public void z9(StateMachineContext context) {
stopping = true;
}
/**
* @unimod.action.descr Cars stop
*/
public void z10(StateMachineContext context) {
stopping = false;
}
/**
* @unimod.action.descr humans are hurrying
*/
public boolean x1(StateMachineContext context) {
return TrafficEngine.hurry;
}
}
|