1 package simworldobjects;
2
3 import interfaces.*;
4 import main.*;
5
6
11 public class SimLightSensor extends SimSensor
12 {
13 private SimRCX robot;
14 private double xOffset, zOffset;
15 private int currentValue;
16 private int previousValue;
17
18
25 public SimLightSensor(SimRCX r, double xOffset, double zOffset, char loc)
26 {
27 robot=r;
28 initSimSensor(r,xOffset,zOffset,4.0,4.0,4.0,"sensorLight", loc);
29 this.xOffset=xOffset;
30 this.zOffset=zOffset;
31 currentValue=0;
32 previousValue=0;
33 }
34
35
40 public int getValue()
41 {
42 BasicSimWorld world= (BasicSimWorld)robot.getWorld();
43 return LightSensorColorLibrary.getValue(world.getColorUnderLightSensor(this));
44 }
45
46
51 public double getXOffset()
52 {
53 return xOffset;
54 }
55
56
61 public double getZOffset()
62 {
63 return zOffset;
64 }
65
66
69 public int getPreviousValue(){
70 return this.previousValue;
71 }
72
73
76 public int getCurrentValue(){
77 BasicSimWorld world= (BasicSimWorld)robot.getWorld();
78 previousValue = currentValue;
79 currentValue = LightSensorColorLibrary.getValue(world.getColorUnderLightSensor(this));
80 return this.currentValue;
81 }
82 }
83