Class: GamesAndRpgParadise::GUI::Gtk::Ball

Inherits:
Object
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/gui/gtk3/block/ball.rb

Overview

GamesAndRpgParadise::GUI::Gtk::Ball

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ Ball

#

initialize

#


24
25
26
27
28
# File 'lib/games_and_rpg_paradise/gui/gtk3/block/ball.rb', line 24

def initialize(x, y)
  reset
  @x  =  x
  @y  =  y
end

Instance Method Details

#drawObject

#

draw

#


66
67
68
69
70
# File 'lib/games_and_rpg_paradise/gui/gtk3/block/ball.rb', line 66

def draw
  Nyle.draw_circle(
    @x, @y, @r, **{color: :WHITE, fill: true}
  )
end

#resetObject

#

reset

#


33
34
35
36
37
# File 'lib/games_and_rpg_paradise/gui/gtk3/block/ball.rb', line 33

def reset
  @r  = 10
  @dx =  5
  @dy = -5
end

#update(walls, blocks, paddle) ⇒ Object

#

update

#


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/games_and_rpg_paradise/gui/gtk3/block/ball.rb', line 42

def update(walls, blocks, paddle)
  @x += @dx
  if _atari_array?(walls) or _atari?(paddle)
    @x -= @dx
    @dx *= -1
  end

  @y += @dy
  if _atari_array?(walls) or _atari?(paddle)
    @y -= @dy
    @dy *= -1
  end

  blocks.delete_if { |block|
    if _atari?(block)
      @y -= @dy
      @dy *= -1
    end
  }
end