Module: Termfront::Sprite

Defined in:
lib/termfront/sprite.rb

Constant Summary collapse

REGISTRY =
{
  executor: method(:executor),
  crawler: method(:crawler),
  player: method(:player),
  training_dummy: method(:training_dummy)
}

Class Method Summary collapse

Class Method Details

.crawler(nx, ny) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/termfront/sprite.rb', line 19

def crawler(nx, ny)
  return "255;240;100" if ((nx - 0.36) / 0.063)**2 + ((ny - 0.28) / 0.063)**2 <= 1.0
  return "255;240;100" if ((nx - 0.64) / 0.063)**2 + ((ny - 0.28) / 0.063)**2 <= 1.0
  return "220;140;30" if ((nx - 0.5) / 0.40)**2 + ((ny - 0.40) / 0.40)**2 <= 1.0
  return "160;100;20" if ((nx - 0.35) / 0.12)**2 + ((ny - 0.90) / 0.10)**2 <= 1.0
  return "160;100;20" if ((nx - 0.65) / 0.12)**2 + ((ny - 0.90) / 0.10)**2 <= 1.0

  nil
end

.executor(nx, ny) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/termfront/sprite.rb', line 7

def executor(nx, ny)
  return "180;120;255" if ((nx - 0.43) / 0.045)**2 + ((ny - 0.11) / 0.045)**2 <= 1.0
  return "180;120;255" if ((nx - 0.57) / 0.045)**2 + ((ny - 0.11) / 0.045)**2 <= 1.0
  return "130;80;220" if ((nx - 0.5) / 0.18)**2 + ((ny - 0.12) / 0.12)**2 <= 1.0
  return "90;50;180" if ((nx - 0.5) / 0.38)**2 + ((ny - 0.30) / 0.08)**2 <= 1.0
  return "80;40;160" if ((nx - 0.5) / 0.25)**2 + ((ny - 0.50) / 0.22)**2 <= 1.0
  return "80;40;160" if ((nx - 0.38) / 0.10)**2 + ((ny - 0.85) / 0.15)**2 <= 1.0
  return "80;40;160" if ((nx - 0.62) / 0.10)**2 + ((ny - 0.85) / 0.15)**2 <= 1.0

  nil
end

.for(sprite_id, nx, ny) ⇒ Object



64
65
66
67
# File 'lib/termfront/sprite.rb', line 64

def self.for(sprite_id, nx, ny)
  fn = REGISTRY[sprite_id]
  fn ? fn.call(nx, ny) : nil
end

.player(nx, ny) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/termfront/sprite.rb', line 29

def player(nx, ny)
  return "140;220;255" if ((nx - 0.43) / 0.045)**2 + ((ny - 0.11) / 0.045)**2 <= 1.0
  return "140;220;255" if ((nx - 0.57) / 0.045)**2 + ((ny - 0.11) / 0.045)**2 <= 1.0
  return "40;130;180" if ((nx - 0.5) / 0.18)**2 + ((ny - 0.12) / 0.12)**2 <= 1.0
  return "30;100;160" if ((nx - 0.5) / 0.38)**2 + ((ny - 0.30) / 0.08)**2 <= 1.0
  return "25;80;140" if ((nx - 0.5) / 0.25)**2 + ((ny - 0.50) / 0.22)**2 <= 1.0
  return "25;80;140" if ((nx - 0.38) / 0.10)**2 + ((ny - 0.85) / 0.15)**2 <= 1.0
  return "25;80;140" if ((nx - 0.62) / 0.10)**2 + ((ny - 0.85) / 0.15)**2 <= 1.0

  nil
end

.register(sprite_id, &block) ⇒ Object



69
70
71
# File 'lib/termfront/sprite.rb', line 69

def self.register(sprite_id, &block)
  REGISTRY[sprite_id] = block
end

.training_dummy(nx, ny) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/termfront/sprite.rb', line 41

def training_dummy(nx, ny)
  return "235;80;80" if ((nx - 0.5) / 0.18)**2 + ((ny - 0.18) / 0.14)**2 <= 1.0
  return "210;210;210" if ((nx - 0.5) / 0.08)**2 + ((ny - 0.42) / 0.14)**2 <= 1.0
  return "200;200;200" if ((nx - 0.5) / 0.22)**2 + ((ny - 0.66) / 0.12)**2 <= 1.0
  return "180;180;180" if ((nx - 0.38) / 0.08)**2 + ((ny - 0.90) / 0.12)**2 <= 1.0
  return "180;180;180" if ((nx - 0.62) / 0.08)**2 + ((ny - 0.90) / 0.12)**2 <= 1.0

  nil
end

.wall_brightness(dist, side) ⇒ Object



51
52
53
54
55
# File 'lib/termfront/sprite.rb', line 51

def wall_brightness(dist, side)
  b = 255 - [[(dist * 2.5).to_i, 0].max, 19].min
  b -= 3 if side == 1
  b.clamp(233, 255)
end