Created
November 16, 2009 05:51
-
-
Save levicole/235775 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| @objects = [] | |
| end | |
| def update | |
| @x, @y = mouse_x, mouse_y | |
| @objects.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) | |
| @objects.each { |o| o.draw } | |
| end | |
| def button_down(id) | |
| if id == Button::KbEscape then close end | |
| if id == Button::MsLeft then @objects << 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, 20).to_i, Gosu::offset_y(angle, 20).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 (@y > 100 && @y < 480) | |
| false | |
| else | |
| puts @y | |
| true | |
| end | |
| end | |
| def draw | |
| @window.draw_line(320, 480,0xffffffff, @x, @y, 0xffffffff) | |
| end | |
| end | |
| MouseInfo.new.show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment