Class: Sprite

Inherits:
Object
  • Object
show all
Defined in:
lib/scrit/sprite.rb

Instance Method Summary collapse

Constructor Details

#initialize(window) ⇒ Sprite

Returns a new instance of Sprite.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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

Instance Method Details

#change_x_by(delta) ⇒ Object



51
52
53
# File 'lib/scrit/sprite.rb', line 51

def change_x_by(delta)
    @x += delta
end

#change_y_by(delta) ⇒ Object



63
64
65
# File 'lib/scrit/sprite.rb', line 63

def change_y_by(delta)
    @y += delta
end

#directionObject



35
36
37
# File 'lib/scrit/sprite.rb', line 35

def direction
    @angle
end

#drawObject



31
32
33
# 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

#initObject



28
29
# File 'lib/scrit/sprite.rb', line 28

def init
end

#key_pressed?(k) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/scrit/sprite.rb', line 71

def key_pressed?(k)
    @window.button_down? @@keymap[k]
end

#set_size_to_percent(p) ⇒ Object



75
76
77
# File 'lib/scrit/sprite.rb', line 75

def set_size_to_percent(p)
    @scale = p
end

#set_x_to(x) ⇒ Object



47
48
49
# File 'lib/scrit/sprite.rb', line 47

def set_x_to(x)
    @x = x
end

#set_y_to(y) ⇒ Object



59
60
61
# File 'lib/scrit/sprite.rb', line 59

def set_y_to(y)
    @y = y
end

#turn_left(angle) ⇒ Object



39
40
41
# File 'lib/scrit/sprite.rb', line 39

def turn_left(angle)
    @angle -= angle
end

#turn_right(angle) ⇒ Object



43
44
45
# File 'lib/scrit/sprite.rb', line 43

def turn_right(angle)
    @angle += angle
end

#x_positionObject



55
56
57
# File 'lib/scrit/sprite.rb', line 55

def x_position
    @x
end

#y_positionObject



67
68
69
# File 'lib/scrit/sprite.rb', line 67

def y_position
    @y
end