Permalink
Browse files

kevinbot follows slightly less crappily

  • Loading branch information...
Kevin Chang
Kevin Chang committed Mar 5, 2012
1 parent 9fc0981 commit 1c42de4523eee95a74635f01d8182f639741ee14
Showing with 27 additions and 21 deletions.
  1. +27 −21 kevinbot.rb
View
@@ -7,6 +7,8 @@
class KevinBot < Bot
def initialize
@targets = {}
+ @jumping_start = Time.at(0)
+ @y_velocity = 0.1
end
def update_distance(target)
@@ -89,36 +91,40 @@ def handle_destroy_entity(fields)
def handle_player_position_and_look(fields = {})
@position = fields
- @landed = true
+ if @y_velocity > 0
+ @jumphit = true
+ else
+ @landed = true
+ @jumping_end = Time.now
+ @y_velocity = 0
+ end
#puts "Received position: #{position_to_string}"
send_player_position_and_look squelch: true
end
- FallRate = 0.5
- JumpRate = 0.5
- JumpTime = 0.2
+ LEASH = 2
+ SPEED_DIVIDER = 4
+ JUMP_VELOCITY = 0.7
+ GRAVITY = 0.1
+ JUMP_COOLDOWN = 0.8
+
def update_position
- if @closest != nil && @position != nil && @closest[:distance] > 2
- @position[:x] += @closest[:look_vector].normalize[0] / 4
- @position[:z] += @closest[:look_vector].normalize[2] / 4
- puts @closest[:look_vector][1]
- if @jumping != true && @landed == true
- @jumping = true
- @jumping_start = Time.now
- @landed = false
- end
+ if @closest != nil && @position != nil && @closest[:distance] > LEASH && @jumphit != true
+ @position[:x] += @closest[:look_vector].normalize[0] / SPEED_DIVIDER
+ @position[:z] += @closest[:look_vector].normalize[2] / SPEED_DIVIDER
end
- if @jumping
- @position[:on_ground] = 0
- change_y JumpRate
- if Time.now - @jumping_start > JumpTime
- @jumping = false
- end
- else
- fall FallRate
+ if @y_velocity <= 0 && @landed == true && Time.now - @jumping_start > JUMP_COOLDOWN && @closest != nil && @closest[:distance] > LEASH
+ @jumphit = false
+ @jumping_start = Time.now
+ @landed = false
+ @y_velocity = JUMP_VELOCITY
end
+ @position[:on_ground] = 0
+ @y_velocity -= GRAVITY
+ change_y @y_velocity
+
@my_position = Vector[@position[:x], @position[:y], @position[:z]]
update_all_distances

0 comments on commit 1c42de4

Please sign in to comment.