class Projectile
Attributes
dx[RW]
dy[RW]
h[RW]
owner_id[RW]
r[RW]
w[RW]
x[RW]
y[RW]
Public Class Methods
new()
click to toggle source
# File lib/share/projectile.rb, line 6 def initialize @x = 0 @y = 0 @dx = 0 @dy = 0 @w = 16 @h = 16 @owner = nil @left_owner = false @flying = false @tick = 0 end
Public Instance Methods
calc_rotation()
click to toggle source
^
3 / 7 /
v
# File lib/share/projectile.rb, line 90 def calc_rotation if @dy > -3 && @dy < 3 if @dx < 0 @r = 4 else @r = 0 end elsif @dy < 0 if @dx > -3 && @dx < 3 @r = 6 elsif @dx < 0 @r = 5 else @r = 7 end else if @dx > -3 && @dx < 3 @r = 2 elsif @dx < 0 @r = 3 else @r = 1 end end end
check_hit(players)
click to toggle source
# File lib/share/projectile.rb, line 53 def check_hit(players) owner_hit = false players.each do |player| if player.x + player.w > @x && player.x < @x + @w if player.y + player.h > @y && player.y < @y + @h if @owner.id == player.id owner_hit = true if @left_owner player.damage(@owner) hit() end else player.damage(@owner) hit() end end end end if owner_hit == false @left_owner = true end end
fire(x, y, dx, dy, owner)
click to toggle source
# File lib/share/projectile.rb, line 19 def fire(x, y, dx, dy, owner) return if @flying @x = x @y = y @dx = dx @dy = dy calc_rotation() @owner = owner @left_owner = false @flying = true $console.dbg "Projectile(x=#{x}, y=#{y}, dx=#{dx}, dy=#{dy})" end
hit()
click to toggle source
# File lib/share/projectile.rb, line 33 def hit @flying = false @x = 0 @y = 0 end
tick(players)
click to toggle source
# File lib/share/projectile.rb, line 39 def tick(players) return unless @flying @tick += 1 @x = @x + @dx @y = @y + @dy @dy += 1 if @tick % 3 == 0 calc_rotation() check_hit(players) hit if @y > WINDOW_SIZE_Y hit if @x > WINDOW_SIZE_X hit if @x < 0 end