class Sprite

Public Class Methods

new(window) click to toggle source
# File lib/scrit/sprite.rb, line 4
def initialize(window)
    @name = "Untitled"
    @x = @y = @vel_x = @vel_y = @angle = 0.0
    @scale = 1
    @costumes = ["costume1"]
    @sounds = [""]
    @current_costume = 0
    
    init
    
    @window = window

    file = File.join(File.dirname(__FILE__), '..', 'costumes', @costumes[@current_costume] + ".png")
    @image = Gosu::Image.new(window, file, false)

    @@keymap = {
        up_arrow:    Gosu::KbUp,
        down_arrow:  Gosu::KbDown,
        left_arrow:  Gosu::KbLeft,
        right_arrow: Gosu::KbRight,
        space:       Gosu::KbSpace
    }
end

Public Instance Methods

change_x_by(delta) click to toggle source
# File lib/scrit/sprite.rb, line 51
def change_x_by(delta)
    @x += delta
end
change_y_by(delta) click to toggle source
# File lib/scrit/sprite.rb, line 63
def change_y_by(delta)
    @y += delta
end
direction() click to toggle source
# File lib/scrit/sprite.rb, line 35
def direction
    @angle
end
draw() click to toggle source
# File lib/scrit/sprite.rb, line 31
def draw
    @image.draw_rot(@x + 240, 180 - @y, 1, @angle, 0.5, 0.5, @scale, @scale)
end
init() click to toggle source
# File lib/scrit/sprite.rb, line 28
def init
end
key_pressed?(k) click to toggle source
# File lib/scrit/sprite.rb, line 71
def key_pressed?(k)
    @window.button_down? @@keymap[k]
end
set_size_to_percent(p) click to toggle source
# File lib/scrit/sprite.rb, line 75
def set_size_to_percent(p)
    @scale = p
end
set_x_to(x) click to toggle source
# File lib/scrit/sprite.rb, line 47
def set_x_to(x)
    @x = x
end
set_y_to(y) click to toggle source
# File lib/scrit/sprite.rb, line 59
def set_y_to(y)
    @y = y
end
turn_left(angle) click to toggle source
# File lib/scrit/sprite.rb, line 39
def turn_left(angle)
    @angle -= angle
end
turn_right(angle) click to toggle source
# File lib/scrit/sprite.rb, line 43
def turn_right(angle)
    @angle += angle
end
x_position() click to toggle source
# File lib/scrit/sprite.rb, line 55
def x_position
    @x
end
y_position() click to toggle source
# File lib/scrit/sprite.rb, line 67
def y_position
    @y
end