Jay McGavren's Journal

2008-02-28

Die, die, die!!!!

Presenting ShootAction:

shootaction.png

player = Creature.new(
  :location => Location.new(WIDTH / 2, HEIGHT / 2),
  :behaviors => [
    Behavior.new(
      :actions => [FleeAction.new(100)],
      :conditions => [ProximityCondition.new(30)]
    )
  ],
  :size => DEFAULT_OBJECT_SIZE,
  :vector => Vector.new(10, 0),
  :tags => ['player']
)
bullet = Creature.new(
  :behaviors => [
    Behavior.new(
      :actions => [DestroyAction.new(@environment)],
      :conditions => [
        ProximityCondition.new(5),
        TagCondition.new('player')
      ]
    )
  ],
  :vector => Vector.new(100, 0)
)
bullets = [bullet, bullet.copy, bullet.copy]
bullets.first.vector.pitch -= 10
bullets.last.vector.pitch += 10
enemy = Creature.new(
  :vector => Vector.new(30, 45),
  :behaviors => [
    Behavior.new(
      :actions => [ShootAction.new(@environment, bullets)],
      :conditions => [
        ElapsedTimeCondition.new(0.5),
        TagCondition.new('player'),
      ]
    )
  ],
  :color => Color.green,
  :size => DEFAULT_OBJECT_SIZE
)
@environment.objects << player << enemy
comments powered by Disqus