1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
22 # Square of the range to shoot at the player
23 fun range2
: Float do return 32.0*32.0
25 redef fun update
(dt
, world
)
29 var player
= world
.player
30 if is_alive
and player
!= null and player
.is_alive
and can_shoot
(world
) then
32 if player
.center
.dist2
(self.center
) < range2
then
33 aim_and_shoot
(world
, player
)
38 # Aim to shoot at `target`
39 fun aim_and_shoot
(world
: World, target
: Body)
41 # TODO aim forward of `moving` target
42 var angle
= self.center
.atan2
(target
.center
)
47 # Go to `target` using jetpack-like movement
48 fun go_to
(target
: Point3d[Float], displacement
: Float) do
51 if target
.x
< sc
.x
then
53 if inertia
.x
< -displacement
then inertia
.x
= -displacement
56 if inertia
.x
> displacement
then inertia
.x
= displacement
58 if target
.y
< sc
.y
then
60 if inertia
.y
< -displacement
then inertia
.y
= -displacement
63 if inertia
.y
> displacement
then inertia
.y
= displacement
68 redef class JetpackEnemy
69 redef fun update
(dt
, world
)
73 var player
= world
.player
74 if is_alive
and player
!= null and player
.is_alive
and can_shoot
(world
) then
76 var target
= player
.center
83 redef fun range2
do return 64.0*64.0