Permalink
Browse files

improve ai

  • Loading branch information...
1 parent 7f14086 commit 4010fa15892ee192c3353e55550de9b260453093 @leafo committed Dec 17, 2012
Showing with 33 additions and 8 deletions.
  1. +22 −8 enemies.moon
  2. +4 −0 guns.moon
  3. +7 −0 tank.moon
View
@@ -14,18 +14,26 @@ class Enemy extends Tank
super ...
@health = @@health
@ai = Sequence ->
+ wait math.random!
+
dir = Vec2d.random!
during 0.5, (dt) ->
@move dt, dir
- pt = Vec2d.random! * 50 + Vec2d @x, @y
- during 0.5, (dt) ->
- if @aim_to dt, pt
- "cancel"
+ -- if player is in range, shoiot
+ player_pos = Vec2d @world.player.x, @world.player.y
+ vec = player_pos - Vec2d @x, @y
- @shoot dt
- wait 1.0
+ if vec\len! < 250 and math.random! > 0.5
+ during 0.5, (dt) ->
+ if @aim_to dt, player_pos
+ "cancel"
+ @shoot dt
+ else
+ during 1.0, (dt) ->
+ @move dt, vec\normalized!
+ wait math.random!
again!
take_hit: (thing, world) =>
@@ -61,21 +69,29 @@ class Enemy extends Tank
__tostring: => "Enemy<#{@box}>"
class Green extends Enemy
+ score: 78
+
ox: 7
oy: 6
sprite: "17,34,14,12"
class Blue extends Enemy
+ score: 128
+
ox: 9
oy: 7
sprite: "17,49,15,14"
class Red extends Enemy
+ score: 179
+
ox: 5
oy: 7
spite: "17,65,14,14"
class Orange extends Enemy
+ score: 205
+
ox: 8
oy: 6
spite: "15,81,17,12"
@@ -87,5 +103,3 @@ gun_sprites = {
orange: "35,85,8,4"
}
-
-
View
@@ -12,6 +12,8 @@ class Bullet extends Box
speed: -> 130
damage: {1,2}
+ hurts_player: true
+
new: (@vel, x, y, @tank) =>
super x,y, @size, @size
@rads = @vel\normalized!\radians!
@@ -112,6 +114,8 @@ class MachineGun extends Gun
spread: math.pi / 8
bullet: class extends SpriteBullet
+ hurts_player: false
+
damage: {2,4}
ox: 4
View
@@ -125,6 +125,8 @@ class Player extends Tank
score: 0
display_score: 0
+ line: 50
+
inner_ring: {
sprite: "101,133,22,22"
size: 22
@@ -140,6 +142,8 @@ class Player extends Tank
@held_energy = {}
@ring_alpha = 0
+ @life = @@life
+
loadout: =>
-- @mount_gun MachineGun, 0, -4
-- @mount_gun MachineGun, 0, 4
@@ -179,11 +183,14 @@ class Player extends Tank
take_hit: (thing, world) =>
return if @hit_seq
+
if thing.is_enemy
sfx\play "hit2"
world.viewport\shake!
@shove thing.box
+ if thing.is_bullet
+
enemy_killed: (thing, world) =>
@score += thing.score if thing.score
if math.random! > 0.5

0 comments on commit 4010fa1

Please sign in to comment.