Code Example

// CONTROLS

// Player 1 turns with A and D

// Player 2 turns With J and L

// The camera can be moved With the arrow keys and mouse

type duck is object3d with

action update

number score

end Type

type gamestate is abstract with

number nextbreadx

number nextbready

end type

action handling key_a

game.getduck(name="Player 1").rotation.y -= 1.5

end action

action handling key_d

game.getduck(name="Player 1").rotation.y += 1.5

end action

action handling key_j

game.getduck(name="Player 2").rotation.y -= 1.5

end action

action handling key_l

game.getduck(name="Player 2").rotation.y += 1.5

end action

action duck.update

if distance(position,game.getobject3d("Bread").position) < 2.5*scale.x then

game.getobject3d(name="Bread").position =<game.getgamestate(name="GameState").nextbreadx.tofloat(),10,game.getgamestate(name="GameState").nextbready.tofloat()>

game.getgamestate(name="GameState").nextbreadx = game.getgamestate(name="GameState").nextbreadx * 1001 % 811 - 400

game.getgamestate(name="GameState").nextbready = game.getgamestate(name="GameState").nextbready * 1001 % 811 - 200

scale = scale + <5,5,5>

speed = speed+1

score = score+1

if score > 7 then

if name.equals_ignore_case("Player 1") then

game.getduck("Player 2").position = <-1000000,1000000,-100000>

game.getduck("Player 2").speed = 0

else

game.getduck("Player 1").position = <-1000000,1000000,-100000>

game.getduck("Player 1").speed = 0

end if

end if

end if

end Action

action game.initialise

add object3d(mesh="20kdm2.bsp",archive="#map-20kdm2.zip",scale=<0,0,0>)

add object3d(mesh="#pond.3ds",position=<0,-40,100>,scale=<3,2,2>)

Add CameraFP(position=<0,1200,-600>,rotation=<60,0,0>)

add duck(name="Player 1",mesh="#duck.3ds",position=<200,0,200>,scale=<10,10,10>,speed=2,score=0)

add duck(name="Player 2",mesh="#duck.3ds",position=<-200,0,200>,scale=<10,10,10>,speed=2,score=0)

add object3d(name="Bread",mesh="#sphere.3ds",position=<0,10,400>,scale=<3,3,3>)

add gamestate(name="GameState",nextbreadx=200,nextbready=220)

end Action