]> git.llucax.com Git - z.facultad/75.68/celdas.git/blob - trunk/src/breve/Demo-myvehicle-4wheels.tz
ahora gira :)
[z.facultad/75.68/celdas.git] / trunk / src / breve / Demo-myvehicle-4wheels.tz
1
2 @use Celdas.
3
4 Controller DemoController.
5
6 CeldasVehicle : MyVehicle {
7
8         + variables:
9                 sensor (object).
10                 flWheel, frWheel, blWheel, brWheel (object).
11
12         + to init at location = (0, 0, 0) (vector):
13
14                 self move to location.
15
16                 blWheel = (self add-wheel at (2, 0, -1.5)).
17                 brWheel = (self add-wheel at (2, 0, 1.5)).
18                 blWheel = (self add-wheel at (-2, 0, -1.5)).
19                 brWheel = (self add-wheel at (-2, 0, 1.5)).
20
21                 #blWheel set-velocity to 15.0.
22                 #brWheel set-velocity to 15.0.
23
24                 sensor = (self add-sensor at (2.0, .4, 0)).
25
26         + to set-global-velocity to velocity (float):
27
28                 brWheel set-velocity to velocity.
29                 frWheel set-velocity to velocity.
30                 blWheel set-velocity to velocity.
31                 flWheel set-velocity to velocity.
32
33         + to get-global-velocity:
34
35                 return ((brWheel get-velocity) + (frWheel get-velocity)
36                         + (blWheel get-velocity) + (flWheel set-velocity)) / 4.
37
38         + to turn-right with-velocity velocity (float):
39
40                 brWheel set-velocity to velocity.
41                 frWheel set-velocity to velocity.
42                 blWheel set-velocity to -velocity.
43                 flWheel set-velocity to -velocity.
44
45         + to turn-left with-velocity velocity (float):
46
47                 blWheel set-velocity to velocity.
48                 flWheel set-velocity to velocity.
49                 brWheel set-velocity to -velocity.
50                 frWheel set-velocity to -velocity.
51
52         + to get-sensor-value:
53
54                 return (sensor get-sensor-value).
55
56 }
57
58 CeldasControl : DemoController {
59         + variables:
60                 vehicle (object).
61
62                 n (int).
63
64         + to init:
65                 for n=0, n<10, n++:
66                         new CeldasObstacle init at-location (20 * sin(n * 6.28 / 10), 1, 20 * cos(n * 6.28 / 10)).
67
68                 vehicle = new MyVehicle.
69                 self watch item vehicle.
70
71         + to post-iterate:
72                 value (float).
73                         
74                 value = vehicle get-sensor-value.
75
76                 if value < 1:       vehicle set-global-velocity to ((vehicle get-global-velocity) + 1).
77                 else if value > 10: vehicle set-global-velocity to ((vehicle get-global-velocity) - 1).
78
79                 print value.
80
81 }