summaryrefslogtreecommitdiffhomepage
path: root/run.rb
blob: 7992eb55b08e47a6d714742abbad134a927410eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'ruby2d'

# Number of sprites in the sheet, automatically gets calculated
@iter = 0 

# Displays the sprite index
@text = Text.new(
  @iter,
  x:0, y: 0,
  size: 20,
)

# Amount of sprites in rows/columns
@rows = 13
@columns = 23

# Size of an individual sprite
@width = 64
@height = 64

# Holds manual coordinates
@animations = {}

# Generates the manual coordinates
(0...@rows).each do |row|
  (0...@columns).each do |column|
    @animations[@iter] = [{
      x: column * @width, y: row * @height,
      width: @width, height: @height
    }]
    @iter += 1
  end
end

# The sprite
@sprite = Sprite.new(
  'sheet.png',
  x: 50, y:50,
  clip_width: 64,
  clip_height: 64,
  time: 300,
  animations: @animations
)

# The frame number of Ruby2D
@frame = 0

update do
  @frame += 1
  @sprite.play(
    animation: ((@frame/30) % @iter),
    loop: true
  )
  @text.text = ((@frame/30) % @iter)

end

show