SHOW:
|
|
- or go back to the newest paste.
1 | class Game_Actor < Game_Battler | |
2 | ||
3 | def needed_exp(current_level) | |
4 | return @exp_list[current_level + 1] | |
5 | end | |
6 | ||
7 | def gained_exp(current_level, current_exp) | |
8 | return (current_exp - @exp_list[current_level]) | |
9 | end | |
10 | ||
11 | def lvl | |
12 | return @level | |
13 | end | |
14 | ||
15 | end | |
16 | ||
17 | ||
18 | ||
19 | class Window_Base < Window | |
20 | ||
21 | ||
22 | def bar_color(n) | |
23 | case n | |
24 | when 0 | |
25 | return Color.new(0, 0, 0) # black | |
26 | when 1 | |
27 | return Color.new(0, 255, 0) # green | |
28 | when 2 | |
29 | return Color.new(0, 0, 255) # blue | |
30 | when 3 | |
31 | return Color.new(255, 0, 0) # red | |
32 | end | |
33 | end | |
34 | ||
35 | def draw_hp_bar(actor, x, y, w = 100) | |
36 | hp = actor.hp | |
37 | max_hp = actor.maxhp | |
38 | border_color = bar_color(0) | |
39 | health_color = bar_color(1) | |
40 | hp_percentage = hp * 1.0 / max_hp | |
41 | health_fill = w * hp_percentage | |
42 | border = Rect.new(x - 1, y, w + 2, 10) | |
43 | health = Rect.new(x, y, health_fill, 8) | |
44 | self.contents.fill_rect(border, border_color) | |
45 | self.contents.fill_rect(health, health_color) | |
46 | end | |
47 | ||
48 | def draw_xp_bar(actor, x, y, w = 100) | |
49 | exp = actor.exp | |
50 | gained_exp = actor.gained_exp(actor.level, exp) | |
51 | needed_exp = actor.needed_exp(actor.level) | |
52 | exp_percentage = (gained_exp * 1.0 / needed_exp) * w | |
53 | background_color = bar_color(0) | |
54 | first_bar_color = bar_color(4) | |
55 | second_bar_color = bar_color(5) | |
56 | background_bar = Rect.new(x - 1, y, w + 2, 10) | |
57 | first_bar = Rect.new(x, y + 1, exp_percentage, 8) | |
58 | second_bar = Rect.new(x, y + 3, exp_percentage, 4) | |
59 | self.contents.fill_rect(background_bar, background_color) | |
60 | self.contents.fill_rect(first_bar, first_bar_color) | |
61 | self.contents.fill_rect(second_bar, second_bar_color) | |
62 | end | |
63 | ||
64 | end |