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