Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'gosu'
- include Gosu
- class MouseInfo < Window
- CENTER = 640/2
- BOTTOM = 480
- def initialize
- super(640, 480, false)
- @clicked = ""
- @font = Gosu::Font.new(self, Gosu::default_font_name, 20)
- @missiles = []
- end
- def update
- @x, @y = mouse_x, mouse_y
- @missiles.reject! { |t| t.update == false }
- end
- def draw
- @font.draw_rel("X: #{mouse_x}", CENTER, 100, 1, 0.5, 0.5)
- @font.draw_rel("Y: #{mouse_y}", CENTER, 130, 1, 0.5, 0.5)
- @font.draw_rel("Clicked: #{@clicked}", CENTER, 150, 1, 0.5, 0.5)
- @missiles.each { |o| o.draw }
- end
- def button_down(id)
- if id == Button::KbEscape then close end
- if id == Button::MsLeft then @missiles << Missile.new(self, @x, @y, Gosu::angle(CENTER, BOTTOM, @x, @y)) end
- end
- end
- class Missile
- attr_accessor :end_x, :vx, :end_y, :vy, :window, :x, :y
- def initialize(window, end_x, end_y, angle)
- @vx, @vy = Gosu::offset_x(angle, 5).to_i, Gosu::offset_y(angle, 5).to_i
- @window, @end_x, @end_y = window, end_x, end_y
- @x, @y = 320, 480
- puts "x = #{@end_x} and y=#{@end_y} angle = #{angle}"
- end
- def update
- @x = @x + @vx
- @y = @y + @vy
- if drawable?
- true
- else
- false
- end
- end
- def draw
- @window.draw_line(320, 480,0xffffffff, @x, @y, 0xffffffff)
- end
- def drawable?
- # this is just going to return true fo now....
- # this will check to see if the line has hit the end of it's road eventually
- true
- end
- end
- MouseInfo.new.show
Add Comment
Please, Sign In to add comment