Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/single_player_map/scripts/spaceship.lua @ 4056

Last change on this file since 4056 was 4056, checked in by snellen, 18 years ago

spaceship.lua implemented

File size: 2.4 KB
Line 
1-- Get objects from orxonox
2thisscript:addObject("Claw", "spaceshipclaw")
3thisscript:addObject("RepairStation", "repair")
4thisscript:addObject("FPSPlayer", "Player")
5thisscript:addObject("SpaceShip", "spaceship")
6thisscript:addObject("SpaceShip", "spaceship2")
7
8-- Global Variables
9playerEnteredSpaceShip = false
10playerReachedTrigger = false
11spaceshipOnPad = false
12spaceshipLaunchReady = false
13
14
15-- Returns the distance between (x1,x2,x3) and (y1,y2,y3)
16function dist( x1,x2,x3, y1,y2,y3 )
17
18return math.sqrt( (x1-y1)^2 + (x2-y2)^2 + (x3-y3)^2 )
19
20end
21
22
23
24function observePlayer()
25
26playerEnteredSpaceShip = spaceship:hasPlayer()
27
28playerX = Player:getAbsCoorX()
29playerY = Player:getAbsCoorY()
30playerZ = Player:getAbsCoorZ()
31
32if dist( playerX,playerY,playerZ,167.361526,29,483.163818 ) < 60 then
33playerReachedTrigger = true
34end
35
36end
37
38
39positionReached = false
40spaceShipReleased = false
41function moveToLaunchSite(timestep)
42
43if not positionReached then
44dx = 1 * timestep
45dy = 0 * timestep
46dz = 1* timestep
47end
48
49if not spaceShipReleased and positionReached then 
50dx = 0 * timestep
51dy = -1 * timestep
52dz = 0 * timestep
53end
54
55if positionReached and spaceShipReleased then
56dx = 0 * timestep
57dy = 1 * timestep
58dz = 0 * timestep
59end
60
61
62if spaceshipOnPad then
63
64if not spaceShipReleased then
65spaceshipclaw:playAnimation(1,1)
66spaceShipReleased = true
67end
68
69if clawY > 100 then
70spaceshipLaunchReady = true
71end
72
73end
74
75
76-- set new coordinates
77clawX = claw:getAbsCoorX()
78clawY = claw:getAbsCoorY()
79clawZ = claw:getAbsCoorZ()
80
81claw:setAbsCoor(clawX + dx, clawY + dy, clawZ + dz)
82
83
84
85if dist( clawX,clawY,clawZ,167.361526,29,483.163818 ) < 60 then
86positionReached = true
87end
88
89
90if dist( clawX,clawY,clawZ,167.361526,29,483.163818 ) < 60 then
91spaceshipOnPad = true
92end
93
94
95end  --observePlayer
96
97hoverPosReached = false
98function launchSpaceShip(timestep)
99
100if not hoverPosReached then
101dx = 0 * timestep
102dy = 1 * timestep
103dz = 0 * timestep
104else
105dx = 1 * timestep
106dy = 0 * timestep
107dz = 1 * timestep
108end
109
110spaceshipX = spaceship:getAbsCoorX()
111spaceshipY = spaceship:getAbsCoorY()
112spaceshipZ = spaceship:getAbsCoorZ()
113
114spaceship:setAbsCoor(spaceshipX + dx, spaceshipY + dy, spaceshipZ + dz)
115
116if spaceshipY > 50 then
117hoverPosReached = true
118end
119
120end
121
122
123function tick(timestep)
124--io.write("Spaceship called \n")
125observePlayer()
126
127if playerReachedTrigger then
128moveToLaunchSite(timestep)
129end
130
131if spaceshipLaunchReady then
132launchSpaceShip(timestep)
133end
134
135
136return false
137end
Note: See TracBrowser for help on using the repository browser.