games/example/lib/npc.rb in game_machine-0.0.10 vs games/example/lib/npc.rb in game_machine-0.0.11
- old
+ new
@@ -67,18 +67,13 @@
position.distance(a[:vector]) <=> position.distance(b[:vector])
end
end
def get_players
+ @players = {}
commands.grid.neighbors(position.x,position.y).each do |player|
- if @players[player.id]
- @players[player.id][:vector].x = player.x
- @players[player.id][:vector].y = player.y
- @players[player.id][:vector].z = player.z
- else
- @players[player.id] = {:id => player.id, :vector => GameMachine::Vector.from(player)}
- end
+ @players[player.id] = {:id => player.id, :vector => GameMachine::Vector.from(player)}
end
end
def check_players
get_players
@@ -89,9 +84,15 @@
end
def pick_random_target
@target.x = position.x + rand(-30..30)
@target.y = position.y + rand(-30..30)
+ if @target.x < 2 || @target.x > 2045
+ @target.x = rand(5..2045)
+ end
+ if @target.y < 2 || @target.y > 2045
+ @target.x = rand(5..2045)
+ end
movement.set_target(@target)
end
def update
return if dead