Sha256: d840522c8aebc48bbfbfb6b9ea898e508e1a78b4e1eb91a2ac8a989377ca178a

Contents?: true

Size: 939 Bytes

Versions: 2

Compression:

Stored size: 939 Bytes

Contents

#!/usr/bin/ruby -w

require "graphics"

class TargetSimulation < Graphics::Simulation
  attr_accessor :bombs

  def initialize
    super 640, 640, 16, "Target Practice"

    self.bombs = []
    register_color :darker_green,  0, 16,  0
    register_color :dark_green,   64, 96, 64
    register_color :dark_blue,     0,  0, 96
  end

  def handle_event event, n
    bombs << [n, event.x, h-event.y] if SDL::Event::Mousedown === event
    super
  end

  def draw n
    clear :darker_green

    bombs.each do |(birth, bx, by)|
      r = n - birth
      r = [r, 100].min
      circle bx, by, r, :dark_blue, :fill
      circle bx, by, r, :red unless r == 100
    end

    (0..640).step(64).each do |r|
      hline r, :dark_green
      vline r, :dark_green
      circle 320, 320, r, :dark_green unless r > 320
    end

    x, y, * = mouse
    line x, 0, x, 640, :white
    line 0, y, 640, y, :white

    fps n
  end
end

TargetSimulation.new.run

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
graphics-1.0.0b5 examples/targeting.rb
graphics-1.0.0b4 examples/targeting.rb