wads 0.2.0 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/wads/app.rb +16 -0
- data/lib/wads/version.rb +1 -1
- data/lib/wads/widgets.rb +63 -30
- data/media/GreenLight.png +0 -0
- data/media/RedLight.png +0 -0
- data/media/YellowLight.png +0 -0
- data/samples/gosu_bouncing_ball.rb +34 -0
- data/samples/gosu_hello_world.rb +16 -0
- data/samples/gosu_reaction_time.rb +121 -0
- data/samples/stocks.rb +1 -1
- data/samples/wads_reaction_time.rb +117 -0
- data/wads.gemspec +1 -1
- metadata +12 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4dcddbd32da59c1cd1a89fc9abb27b69314b63fcb413753d874140d34db6d5d
|
4
|
+
data.tar.gz: ab05677ab411b91457d17e3acdfa7b6547268af9e42d7364573fed177b989316
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67fb8ee6765014d4704d22cdb251595839f7b22593723204c198a85d943c59a80d37823eaec65aee58bb81177feb03c7fd92e831ada1c08e0cdb1d804a1e69e4
|
7
|
+
data.tar.gz: 3290687b9372191b80690d42f9ef825716898b3e2c123b0bee9ee8e72b630680320279a1a302d06b27f8aaf696dd2b406d13621e2b9a44f835eb230c12460bda
|
data/CHANGELOG.md
CHANGED
@@ -17,3 +17,12 @@
|
|
17
17
|
## [0.2.0] - 2021-10-05
|
18
18
|
|
19
19
|
- Breaking change in order to refactor, including standardizing order of widget constructor args
|
20
|
+
|
21
|
+
## [0.2.3] - 2021-10-21
|
22
|
+
|
23
|
+
- Upgrade dependency versions
|
24
|
+
|
25
|
+
## [0.2.4] - 2021-10-21
|
26
|
+
|
27
|
+
- Add a callback for key up
|
28
|
+
|
data/lib/wads/app.rb
CHANGED
@@ -16,6 +16,7 @@ module Wads
|
|
16
16
|
WadsConfig.instance.set_window(self)
|
17
17
|
set_display(widget)
|
18
18
|
WadsConfig.instance.set_log_level("info")
|
19
|
+
@registered_hold_down_buttons = []
|
19
20
|
end
|
20
21
|
|
21
22
|
#
|
@@ -30,8 +31,23 @@ module Wads
|
|
30
31
|
@main_widget
|
31
32
|
end
|
32
33
|
|
34
|
+
# Register a key (identified by the Gosu id) to check if it is being held down.
|
35
|
+
# If so, the handle_key_held_down callback will be invoked on widgets
|
36
|
+
# For example, register_hold_down_key(Gosu::KbLeft)
|
37
|
+
def register_hold_down_key(id)
|
38
|
+
@registered_hold_down_buttons << id
|
39
|
+
end
|
40
|
+
|
33
41
|
def update
|
34
42
|
@main_widget.update(@update_count, mouse_x, mouse_y)
|
43
|
+
|
44
|
+
# Look for keys that are held down and delegate those events
|
45
|
+
@registered_hold_down_buttons.each do |id|
|
46
|
+
if button_down?(id)
|
47
|
+
@main_widget.handle_key_held_down id, mouse_x, mouse_y
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
35
51
|
@update_count = @update_count + 1
|
36
52
|
end
|
37
53
|
|
data/lib/wads/version.rb
CHANGED
data/lib/wads/widgets.rb
CHANGED
@@ -805,26 +805,6 @@ module Wads
|
|
805
805
|
end
|
806
806
|
container.get_coordinates(element_type, args)
|
807
807
|
end
|
808
|
-
|
809
|
-
#
|
810
|
-
# This is a convenience method that creates a panel divided into a left and right,
|
811
|
-
# or east and west section. It will take up the entire space of the specified
|
812
|
-
# ARG_SECTION in the args map.
|
813
|
-
#
|
814
|
-
def add_east_west_panel(args)
|
815
|
-
section = args[ARG_SECTION]
|
816
|
-
if section.nil?
|
817
|
-
raise "East west panels require the arg '#{ARG_SECTION}' with value #{@container_map.keys.join(', ')}"
|
818
|
-
end
|
819
|
-
container = @container_map[section]
|
820
|
-
new_panel = Panel.new(container.start_x, container.start_y,
|
821
|
-
container.max_width, container.max_height)
|
822
|
-
new_panel.set_layout(LAYOUT_EAST_WEST, args)
|
823
|
-
new_panel.base_z = @parent_widget.base_z
|
824
|
-
new_panel.disable_border
|
825
|
-
@parent_widget.add_child(new_panel)
|
826
|
-
new_panel
|
827
|
-
end
|
828
808
|
end
|
829
809
|
|
830
810
|
# The layout sections are as follows:
|
@@ -841,9 +821,13 @@ module Wads
|
|
841
821
|
super
|
842
822
|
# Divide the height into 100, 100, and the middle gets everything else
|
843
823
|
# Right now we are using 100 pixels rather than a percentage for the borders
|
844
|
-
|
845
|
-
|
846
|
-
|
824
|
+
header_section_height = 100
|
825
|
+
if args[ARG_DESIRED_HEIGHT]
|
826
|
+
header_section_height = args[ARG_DESIRED_HEIGHT]
|
827
|
+
end
|
828
|
+
middle_section_y_start = y + header_section_height
|
829
|
+
height_middle_section = height - header_section_height
|
830
|
+
@container_map[SECTION_NORTH] = GuiContainer.new(x, y, width, header_section_height)
|
847
831
|
@container_map[SECTION_CENTER] = GuiContainer.new(x, middle_section_y_start, width, height_middle_section, FILL_VERTICAL_STACK)
|
848
832
|
end
|
849
833
|
end
|
@@ -1035,6 +1019,14 @@ module Wads
|
|
1035
1019
|
@text_input_fields = []
|
1036
1020
|
end
|
1037
1021
|
|
1022
|
+
def pad(str, size, left_align = false)
|
1023
|
+
str = str.to_s
|
1024
|
+
if left_align
|
1025
|
+
str[0, size].ljust(size, ' ')
|
1026
|
+
else
|
1027
|
+
str[0, size].rjust(size, ' ')
|
1028
|
+
end
|
1029
|
+
end
|
1038
1030
|
def debug(message)
|
1039
1031
|
WadsConfig.instance.get_logger.debug message
|
1040
1032
|
end
|
@@ -1077,8 +1069,10 @@ module Wads
|
|
1077
1069
|
end
|
1078
1070
|
|
1079
1071
|
def add_panel(section, args = {})
|
1080
|
-
get_layout.add_max_panel({ ARG_SECTION => section,
|
1081
|
-
|
1072
|
+
new_panel = get_layout.add_max_panel({ ARG_SECTION => section,
|
1073
|
+
ARG_THEME => @gui_theme}.merge(args))
|
1074
|
+
new_panel.disable_border
|
1075
|
+
new_panel
|
1082
1076
|
end
|
1083
1077
|
|
1084
1078
|
def get_theme
|
@@ -1406,9 +1400,11 @@ module Wads
|
|
1406
1400
|
if id == Gosu::MsLeft
|
1407
1401
|
# Special handling for text input fields
|
1408
1402
|
# Mouse click: Select text field based on mouse position.
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1403
|
+
if not @text_input_fields.empty?
|
1404
|
+
WadsConfig.instance.get_window.text_input = @text_input_fields.find { |tf| tf.under_point?(mouse_x, mouse_y) }
|
1405
|
+
# Advanced: Move caret to clicked position
|
1406
|
+
WadsConfig.instance.get_window.text_input.move_caret(mouse_x) unless WadsConfig.instance.get_window.text_input.nil?
|
1407
|
+
end
|
1412
1408
|
|
1413
1409
|
result = handle_mouse_down mouse_x, mouse_y
|
1414
1410
|
elsif id == Gosu::MsRight
|
@@ -1458,6 +1454,11 @@ module Wads
|
|
1458
1454
|
if not result.nil? and result.is_a? WidgetResult
|
1459
1455
|
return result
|
1460
1456
|
end
|
1457
|
+
else
|
1458
|
+
result = handle_key_up id, mouse_x, mouse_y
|
1459
|
+
if not result.nil? and result.is_a? WidgetResult
|
1460
|
+
return result
|
1461
|
+
end
|
1461
1462
|
end
|
1462
1463
|
|
1463
1464
|
@children.each do |child|
|
@@ -1468,6 +1469,11 @@ module Wads
|
|
1468
1469
|
return result
|
1469
1470
|
end
|
1470
1471
|
end
|
1472
|
+
else
|
1473
|
+
result = handle_key_up id, mouse_x, mouse_y
|
1474
|
+
if not result.nil? and result.is_a? WidgetResult
|
1475
|
+
return result
|
1476
|
+
end
|
1471
1477
|
end
|
1472
1478
|
end
|
1473
1479
|
end
|
@@ -1702,6 +1708,25 @@ module Wads
|
|
1702
1708
|
# empty base implementation
|
1703
1709
|
end
|
1704
1710
|
|
1711
|
+
#
|
1712
|
+
# This callback is invoked for any key registered by the
|
1713
|
+
# register_hold_down_key(id) method.
|
1714
|
+
#
|
1715
|
+
def handle_key_held_down id, mouse_x, mouse_y
|
1716
|
+
# empty base implementation
|
1717
|
+
end
|
1718
|
+
|
1719
|
+
#
|
1720
|
+
# Override this method in your subclass to process when a key is released.
|
1721
|
+
# The base implementation is empty.
|
1722
|
+
# Note that the mouse was not necessarily positioned over this widget.
|
1723
|
+
# You can check this using the contains_click(mouse_x, mouse_y) method
|
1724
|
+
# and decide if you want to process the event based on that, if desired.
|
1725
|
+
#
|
1726
|
+
def handle_key_up id, mouse_x, mouse_y
|
1727
|
+
# empty base implementation
|
1728
|
+
end
|
1729
|
+
|
1705
1730
|
#
|
1706
1731
|
# Override this method in your subclass to perform any logic needed
|
1707
1732
|
# as part of the main Gosu update loop. In most cases, this method is
|
@@ -1762,6 +1787,9 @@ module Wads
|
|
1762
1787
|
@img = Gosu::Image.new(image)
|
1763
1788
|
elsif image.is_a? Gosu::Image
|
1764
1789
|
@img = image
|
1790
|
+
elsif image.is_a? Gosu::Color
|
1791
|
+
@img = nil
|
1792
|
+
@override_color = image
|
1765
1793
|
else
|
1766
1794
|
raise "ImageWidget requires either a filename or a Gosu::Image object"
|
1767
1795
|
end
|
@@ -1771,11 +1799,16 @@ module Wads
|
|
1771
1799
|
@scale = 1
|
1772
1800
|
disable_border
|
1773
1801
|
disable_background
|
1774
|
-
set_dimensions(@img.width, @img.height)
|
1802
|
+
set_dimensions(@img.width, @img.height) if @img
|
1775
1803
|
end
|
1776
1804
|
|
1777
1805
|
def render
|
1778
|
-
@img.
|
1806
|
+
if @img.nil?
|
1807
|
+
# TODO draw a box
|
1808
|
+
Gosu::draw_rect(@x, @y, @width - 1, @height - 1, @override_color, relative_z_order(Z_ORDER_GRAPHIC_ELEMENTS))
|
1809
|
+
else
|
1810
|
+
@img.draw @x, @y, z_order, @scale, @scale
|
1811
|
+
end
|
1779
1812
|
end
|
1780
1813
|
|
1781
1814
|
def widget_z
|
Binary file
|
data/media/RedLight.png
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'gosu'
|
2
|
+
|
3
|
+
class AppWindow < Gosu::Window
|
4
|
+
def initialize
|
5
|
+
super(800, 600)
|
6
|
+
self.caption = 'Bouncing Ball'
|
7
|
+
@img = Gosu::Image.new("media/CircleYellow.png")
|
8
|
+
@x = 400
|
9
|
+
@y = 300
|
10
|
+
@delta_x = 2
|
11
|
+
@delta_y = 2
|
12
|
+
end
|
13
|
+
|
14
|
+
def update
|
15
|
+
@x = @x + @delta_x
|
16
|
+
@y = @y + @delta_y
|
17
|
+
if @x < 0
|
18
|
+
@delta_x = 2
|
19
|
+
elsif @x > 800 - @img.width
|
20
|
+
@delta_x = -2
|
21
|
+
end
|
22
|
+
if @y < 0
|
23
|
+
@delta_y = 2
|
24
|
+
elsif @y > 600 - @img.height
|
25
|
+
@delta_y = -2
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def draw
|
30
|
+
@img.draw @x, @y, 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
AppWindow.new.show
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'gosu'
|
2
|
+
|
3
|
+
class GameWindow < Gosu::Window
|
4
|
+
def initialize
|
5
|
+
super(400, 300)
|
6
|
+
self.caption = 'Hello World App'
|
7
|
+
@font = Gosu::Font.new(24)
|
8
|
+
end
|
9
|
+
|
10
|
+
def draw
|
11
|
+
@font.draw_text("Hello World", 144, 120, 1)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
window = GameWindow.new
|
16
|
+
window.show
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'gosu'
|
2
|
+
|
3
|
+
AVERAGE_RESPONSE_TIME = 284.to_f # Per humanbenchmark.com, in milliseconds
|
4
|
+
GAME_STATE_PROMPT_TO_START = 0
|
5
|
+
GAME_STATE_RED = 1
|
6
|
+
GAME_STATE_YELLOW = 2
|
7
|
+
GAME_STATE_GREEN = 3
|
8
|
+
GAME_STATE_OVER = 4
|
9
|
+
|
10
|
+
class AppWindow < Gosu::Window
|
11
|
+
def initialize
|
12
|
+
super(600, 300)
|
13
|
+
self.caption = 'Reaction Time Game'
|
14
|
+
@update_count = 0
|
15
|
+
@next_light_count = 0
|
16
|
+
@messages = []
|
17
|
+
@font = Gosu::Font.new(32)
|
18
|
+
@red_light = Gosu::Image.new("media/CircleRed.png")
|
19
|
+
@yellow_light = Gosu::Image.new("media/CircleYellow.png")
|
20
|
+
@green_light = Gosu::Image.new("media/CircleGreen.png")
|
21
|
+
# game state 0 1 2 3 4
|
22
|
+
# state Prompt Red Yellow Green Game over
|
23
|
+
@traffic_light_images = [@red_light, @red_light, @yellow_light, @green_light, @green_light]
|
24
|
+
@traffic_light_color = GAME_STATE_PROMPT_TO_START
|
25
|
+
end
|
26
|
+
|
27
|
+
def update
|
28
|
+
@update_count = @update_count + 1
|
29
|
+
@traffic_light_image = @traffic_light_images[@traffic_light_color]
|
30
|
+
|
31
|
+
# Once the game is started, the lights progress automatically until green
|
32
|
+
if @traffic_light_color > GAME_STATE_PROMPT_TO_START
|
33
|
+
next_traffic_light unless @update_count < @next_light_count
|
34
|
+
@button_text = "Click when the light turns green" unless @traffic_light_color > GAME_STATE_GREEN
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def draw
|
39
|
+
@font.draw_text("Reaction Time Game", 180, 10, 1)
|
40
|
+
@traffic_light_image.draw(248, 60, 1)
|
41
|
+
|
42
|
+
if @traffic_light_color == GAME_STATE_PROMPT_TO_START
|
43
|
+
@font.draw_text("Press 'p' to play", 200, 200, 1)
|
44
|
+
elsif @traffic_light_color == GAME_STATE_OVER
|
45
|
+
@font.draw_text("Press 'p' to play again", 50, 200, 1)
|
46
|
+
else
|
47
|
+
draw_button(@button_text) unless @button_text.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
y = 232
|
51
|
+
@messages.each do |msg|
|
52
|
+
@font.draw_text(msg, 50, y, 1)
|
53
|
+
y = y + 32
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def button_down id
|
58
|
+
close if id == Gosu::KbEscape
|
59
|
+
|
60
|
+
if @traffic_light_color == GAME_STATE_PROMPT_TO_START or @traffic_light_color == GAME_STATE_OVER
|
61
|
+
if id == Gosu::KbP
|
62
|
+
next_traffic_light
|
63
|
+
end
|
64
|
+
return
|
65
|
+
end
|
66
|
+
|
67
|
+
if id == Gosu::MsLeft and button_contains_click
|
68
|
+
if @traffic_light_color < GAME_STATE_YELLOW
|
69
|
+
next_traffic_light
|
70
|
+
elsif @traffic_light_color == GAME_STATE_YELLOW
|
71
|
+
@traffic_light_color = GAME_STATE_OVER
|
72
|
+
@messages = ["Sorry, you were too early"]
|
73
|
+
@button_text = "Click to play again"
|
74
|
+
elsif @traffic_light_color == GAME_STATE_GREEN
|
75
|
+
@button_text = nil
|
76
|
+
time_since_green = ((Time.now - @mark_time) * 1000.to_f).round(3)
|
77
|
+
@messages = ["Response time: #{time_since_green} ms"]
|
78
|
+
diff_from_average = (((time_since_green - AVERAGE_RESPONSE_TIME) / AVERAGE_RESPONSE_TIME) * 100).round
|
79
|
+
if diff_from_average > 0
|
80
|
+
@messages << "#{diff_from_average}% slower than the average human"
|
81
|
+
elsif diff_from_average < 0
|
82
|
+
@messages << "#{-diff_from_average}% faster than the average human"
|
83
|
+
else
|
84
|
+
@messages << "Wow, that is exactly the human average."
|
85
|
+
end
|
86
|
+
@button_text = "Click to play again"
|
87
|
+
@traffic_light_color = GAME_STATE_OVER
|
88
|
+
else
|
89
|
+
@traffic_light_color = GAME_STATE_PROMPT_TO_START
|
90
|
+
@messages = []
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def next_traffic_light
|
96
|
+
return unless @traffic_light_color < GAME_STATE_GREEN
|
97
|
+
@traffic_light_color = @traffic_light_color + 1
|
98
|
+
@mark_time = Time.now
|
99
|
+
@next_light_count = @update_count + 60 + rand(100)
|
100
|
+
end
|
101
|
+
|
102
|
+
def button_contains_click
|
103
|
+
mouse_x > 100 and mouse_x < 500 and mouse_y > 198 and mouse_y < 232
|
104
|
+
end
|
105
|
+
|
106
|
+
def draw_button(text)
|
107
|
+
text_width = @font.text_width(text)
|
108
|
+
draw_box(100, 198, 500, 232)
|
109
|
+
text_x = (600 - text_width) / 2
|
110
|
+
@font.draw_text(@button_text, text_x, 200, 1)
|
111
|
+
end
|
112
|
+
|
113
|
+
def draw_box(x1, y1, x2, y2, color = Gosu::Color::WHITE)
|
114
|
+
Gosu::draw_line x1, y1, color, x2, y1, color, 1
|
115
|
+
Gosu::draw_line x1, y1, color, x1, y2, color, 1
|
116
|
+
Gosu::draw_line x1, y2, color, x2, y2, color, 1
|
117
|
+
Gosu::draw_line x2, y1, color, x2, y2, color, 1
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
AppWindow.new.show
|
data/samples/stocks.rb
CHANGED
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'gosu'
|
2
|
+
require_relative '../lib/wads'
|
3
|
+
|
4
|
+
include Wads
|
5
|
+
|
6
|
+
AVERAGE_RESPONSE_TIME = 284.to_f # Per humanbenchmark.com, in milliseconds
|
7
|
+
GAME_STATE_PROMPT_TO_START = 0
|
8
|
+
GAME_STATE_RED = 1
|
9
|
+
GAME_STATE_YELLOW = 2
|
10
|
+
GAME_STATE_GREEN = 3
|
11
|
+
GAME_STATE_OVER = 4
|
12
|
+
|
13
|
+
|
14
|
+
class ReactionTimeApp < WadsApp
|
15
|
+
def initialize
|
16
|
+
super(600, 400, "Reaction Time Game", ReactionTimeDisplay.new)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class ReactionTimeDisplay < Widget
|
21
|
+
def initialize
|
22
|
+
super(0, 0, 600, 400)
|
23
|
+
set_layout(LAYOUT_HEADER_CONTENT)
|
24
|
+
set_theme(WadsAquaTheme.new)
|
25
|
+
disable_border
|
26
|
+
@next_light_count = 0
|
27
|
+
@messages = []
|
28
|
+
@font = Gosu::Font.new(22)
|
29
|
+
@red_light = Gosu::Image.new("media/RedLight.png")
|
30
|
+
@yellow_light = Gosu::Image.new("media/YellowLight.png")
|
31
|
+
@green_light = Gosu::Image.new("media/GreenLight.png")
|
32
|
+
# game state 0 1 2 3 4
|
33
|
+
# state Prompt Red Yellow Green Game over
|
34
|
+
@traffic_light_images = [@red_light, @red_light, @yellow_light, @green_light, @green_light]
|
35
|
+
@traffic_light_color = GAME_STATE_PROMPT_TO_START
|
36
|
+
|
37
|
+
add_panel(SECTION_NORTH).get_layout.add_text("Reaction Time Game",
|
38
|
+
{ ARG_TEXT_ALIGN => TEXT_ALIGN_CENTER,
|
39
|
+
ARG_USE_LARGE_FONT => true})
|
40
|
+
|
41
|
+
content_panel = get_layout.add_max_panel({ARG_SECTION => SECTION_CENTER,
|
42
|
+
ARG_LAYOUT => LAYOUT_EAST_WEST,
|
43
|
+
ARG_THEME => WadsAquaTheme.new,
|
44
|
+
ARG_PANEL_WIDTH => 140})
|
45
|
+
@traffic_light_image = content_panel.get_layout.add_image(@red_light,
|
46
|
+
{ARG_SECTION => SECTION_WEST})
|
47
|
+
|
48
|
+
left_side_panel = content_panel.add_panel(SECTION_EAST)
|
49
|
+
left_side_panel.disable_border
|
50
|
+
@start_button = left_side_panel.get_layout.add_button("Click to play") do
|
51
|
+
handle_button_click
|
52
|
+
end
|
53
|
+
@messages = left_side_panel.get_layout.add_document("")
|
54
|
+
end
|
55
|
+
|
56
|
+
def handle_update update_count, mouse_x, mouse_y
|
57
|
+
@traffic_light_image.img = @traffic_light_images[@traffic_light_color]
|
58
|
+
|
59
|
+
if @traffic_light_color == GAME_STATE_PROMPT_TO_START or @traffic_light_color == GAME_STATE_OVER
|
60
|
+
@start_button.visible = true
|
61
|
+
|
62
|
+
elsif @traffic_light_color == GAME_STATE_RED or
|
63
|
+
@traffic_light_color == GAME_STATE_YELLOW or
|
64
|
+
@traffic_light_color == GAME_STATE_GREEN
|
65
|
+
@messages.lines = ["Hit the space bar when the light turns green"]
|
66
|
+
@start_button.visible = false
|
67
|
+
if @mark_time.nil?
|
68
|
+
@mark_time = Time.now
|
69
|
+
@next_light_count = update_count + 60 + rand(100)
|
70
|
+
end
|
71
|
+
next_traffic_light unless update_count < @next_light_count
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def handle_button_click
|
76
|
+
if @traffic_light_color == GAME_STATE_PROMPT_TO_START or @traffic_light_color == GAME_STATE_OVER
|
77
|
+
@messages.lines = []
|
78
|
+
next_traffic_light
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def handle_key_press id, mouse_x, mouse_y
|
83
|
+
return WidgetResult.new(true) if id == Gosu::KbEscape
|
84
|
+
|
85
|
+
if id == Gosu::KbSpace
|
86
|
+
if @traffic_light_color < GAME_STATE_YELLOW
|
87
|
+
next_traffic_light
|
88
|
+
elsif @traffic_light_color == GAME_STATE_YELLOW
|
89
|
+
@traffic_light_color = GAME_STATE_OVER
|
90
|
+
@messages.lines = ["Sorry, you were too early"]
|
91
|
+
elsif @traffic_light_color == GAME_STATE_GREEN
|
92
|
+
time_since_green = ((Time.now - @mark_time) * 1000.to_f).round(3)
|
93
|
+
@messages.lines = ["Response time: #{time_since_green} ms"]
|
94
|
+
diff_from_average = (((time_since_green - AVERAGE_RESPONSE_TIME) / AVERAGE_RESPONSE_TIME) * 100).round
|
95
|
+
if diff_from_average > 0
|
96
|
+
@messages.lines << "#{diff_from_average}% slower than the average human"
|
97
|
+
elsif diff_from_average < 0
|
98
|
+
@messages.lines << "#{-diff_from_average}% faster than the average human"
|
99
|
+
else
|
100
|
+
@messages.lines << "Wow, that is exactly the human average."
|
101
|
+
end
|
102
|
+
@traffic_light_color = GAME_STATE_OVER
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def next_traffic_light
|
108
|
+
if @traffic_light_color == GAME_STATE_OVER
|
109
|
+
@traffic_light_color = GAME_STATE_RED
|
110
|
+
elsif @traffic_light_color < GAME_STATE_OVER
|
111
|
+
@traffic_light_color = @traffic_light_color + 1
|
112
|
+
end
|
113
|
+
@mark_time = nil
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
ReactionTimeApp.new.show
|
data/wads.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
29
|
spec.require_paths = ["lib"]
|
30
30
|
|
31
|
-
spec.add_dependency "gosu", "
|
31
|
+
spec.add_dependency "gosu", ">= 1.1.0"
|
32
32
|
spec.add_dependency "minigl", "~> 2.3.5"
|
33
33
|
spec.add_dependency "tty-option"
|
34
34
|
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wads
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dbroemme
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 1.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -87,18 +87,25 @@ files:
|
|
87
87
|
- media/CircleRed.png
|
88
88
|
- media/CircleWhite.png
|
89
89
|
- media/CircleYellow.png
|
90
|
+
- media/GreenLight.png
|
91
|
+
- media/RedLight.png
|
90
92
|
- media/SampleGraph.png
|
91
93
|
- media/StocksSample.png
|
92
94
|
- media/WadsScreenshot.png
|
95
|
+
- media/YellowLight.png
|
93
96
|
- run-graph
|
94
97
|
- run-star-wars
|
95
98
|
- run-stocks
|
96
99
|
- run-theme-test
|
97
100
|
- samples/basic_gosu_with_graph_widget.rb
|
101
|
+
- samples/gosu_bouncing_ball.rb
|
102
|
+
- samples/gosu_hello_world.rb
|
103
|
+
- samples/gosu_reaction_time.rb
|
98
104
|
- samples/graph.rb
|
99
105
|
- samples/star_wars.rb
|
100
106
|
- samples/stocks.rb
|
101
107
|
- samples/theme_test.rb
|
108
|
+
- samples/wads_reaction_time.rb
|
102
109
|
- wads.gemspec
|
103
110
|
homepage: https://github.com/dbroemme/ruby-wads
|
104
111
|
licenses: []
|
@@ -121,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
128
|
- !ruby/object:Gem::Version
|
122
129
|
version: '0'
|
123
130
|
requirements: []
|
124
|
-
rubygems_version: 3.
|
131
|
+
rubygems_version: 3.0.3.1
|
125
132
|
signing_key:
|
126
133
|
specification_version: 4
|
127
134
|
summary: Simple, easy to use data structure classes and Gosu widgets
|