def increase_image_size
self.factor *= 1.05
end
def decrease_image_size
self.factor *= 0.95
end
----------------------------------------------------------------------------------------------------------------
require 'rubygems'
require 'gosu'
class GameWindow < Gosu::Window
POMAK = 5
def initialize
super 1366, 768, true, update_interval = 20
@x = @y = 0
@f_x = @f_y = 1.0
@slika = Gosu::Image.new(self, '18.jpg', false)
@font = Gosu::Font.new(self, Gosu::default_font_name, 20)
end
def update
if button_down?(Gosu::KbLeft)
@x += POMAK
end
if button_down?(Gosu::KbRight)
@x -= POMAK
end
if button_down?(Gosu::KbUp)
@y += POMAK
#@player.accelerate
end
if button_down?(Gosu::KbDown)
@y -= POMAK
end
if button_down?(Gosu::KbNumpadAdd)
@f_x += 0.01
@f_y += 0.01
@x -= 15
@y -= 15
end
if button_down?(Gosu::KbNumpadSubtract)
@f_x -= 0.01
@f_y -= 0.01
@x += 15
@y += 15
end
if button_down?(Gosu::MsWheelUp)
@f_x += 0.01
@f_y += 0.01
@x -= 15
@y -= 15
end
if button_down?(Gosu::MsWheelDown)
@f_x -= 0.01
@f_y -= 0.01
@x += 15
@y += 15
end
end
def draw
@slika.draw(@x, @y, 1, @f_x, @f_y)
@font.draw("Mish_x: #{mouse_x}; Mish_y: #{mouse_y}", 10, 10, 3, 1.0, 1.0, 0xffffff00)
end
def button_down(id)
case id
when Gosu::KbEscape
close
end
# when MsLeft
# not working !
# end
end
def needs_cursor?
true
end
end
window = GameWindow.new
window.show
------------------------------------------------------------------------------------------------------------
MsWheelUp
and MsWheelDown
are sent to button_down(id)
when the wheel is moved.
button_down(id)
) or use simpler solution, store initial position of mouse and image and then translate while button is being pressedif button_down?(Gosu::KbLeft) #button is being hold
if !@drag #store the current position of image and mouse
@drag = [mouse_x, mouse_y]
@origin = [@x, @y]
else
@x = @origin[0] - (mouse_x - @drag[0]) #translate according to mouse movement
@y = @origin[1] - (mouse_y - @drag[1])
end
else #button is released
@drag = @origin = nil #clear variables, so you can re-use them
end
Gosu::default_font_name
use just "Courier New" (string). Gosu will look for the font in your system directory or given path.
if button_down?(Gosu::MsLeft) #button is being hold
if !@drag #this executes only once,when we press mouse button @drag == nil means !@drag is true
@drag = [mouse_x, mouse_y] #store the current position of mouse
@origin = [@x, @y] #store the current position of image
else #after initial mouse click, @drag != nil, meaning !@drag == false, meaning this block executes while we hold mouse button pressed
@x = @origin[0] + (mouse_x - @drag[0]) #translate according to mouse movement
@y = @origin[1] + (mouse_y - @drag[1])
end
else #button is released
@drag = @origin = nil #clear variables, so you can re-use them
end
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill