fantasy 0.1.9 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -10
- data/COLOR_PALETTE.md +159 -0
- data/README.md +4 -4
- data/lib/fantasy/actor.rb +62 -65
- data/lib/fantasy/color.rb +182 -1
- data/lib/fantasy/cursor.rb +21 -0
- data/lib/fantasy/global.rb +4 -1
- data/lib/fantasy/hud_text.rb +17 -7
- data/lib/fantasy/image.rb +2 -0
- data/lib/fantasy/includes/jumper.rb +4 -24
- data/lib/fantasy/includes/move_by_cursors.rb +34 -17
- data/lib/fantasy/includes/move_by_direction.rb +2 -2
- data/lib/fantasy/includes/mover.rb +3 -3
- data/lib/fantasy/includes/user_inputs.rb +60 -0
- data/lib/fantasy/loop.rb +58 -8
- data/lib/fantasy/mouse.rb +9 -0
- data/lib/fantasy/music.rb +2 -0
- data/lib/fantasy/shape.rb +55 -0
- data/lib/fantasy/sound.rb +2 -0
- data/lib/fantasy/version.rb +1 -1
- data/lib/fantasy.rb +4 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb68d8561352d746b2ccdbec94196c568436a0164619f325f0762c200d9d4a71
|
4
|
+
data.tar.gz: a11a5b19442edc60fc11d3c803ec40df543c9f1a176f7f7d6a3b11ad4dcf2eed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e705ad65f134cf775e3bf2ef847643bbd8a2efcc49630837f555f57df019573c9356190db394cddb647ed95420441ea0ce8d42099ba43f006c89e05b63452fa9
|
7
|
+
data.tar.gz: c6e6506581053c11940b0fd3bed2205ae4b003a2efd35016a84e04640cc75ad9300a8276ff8562ec8f33eba229b3017c7ba4f38306d165271d637e7c0e51b66a
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,24 @@
|
|
1
|
-
## [
|
1
|
+
## [0.1.11] - 2022-03-26
|
2
2
|
|
3
|
-
|
3
|
+
- Better jumping and gravity physics
|
4
|
+
- Support Shape.rectangle
|
5
|
+
- Support on_click callback on Shapes and Actors
|
6
|
+
- Support on_cursor_* callbacks on Shapes and Actors
|
7
|
+
- Support Color.palette with 150 colors + transparent
|
8
|
+
|
9
|
+
|
10
|
+
## [0.1.9] - 2022-03-25
|
11
|
+
|
12
|
+
- Adding platformer support
|
13
|
+
- Jump
|
14
|
+
- Gravity
|
15
|
+
- Music background support
|
16
|
+
|
17
|
+
|
18
|
+
## [0.1.7] - 2022-03-17
|
19
|
+
|
20
|
+
- HudText accepts alignment property. Valid values: 'top-left, top-right, center'
|
4
21
|
|
5
|
-
- Initial release
|
6
22
|
|
7
23
|
## [0.1.5] - 2022-03-16
|
8
24
|
|
@@ -11,13 +27,10 @@
|
|
11
27
|
- Camera can be controlled by cursors
|
12
28
|
- Background image can be replicable
|
13
29
|
|
14
|
-
## [0.1.7] - 2022-03-17
|
15
30
|
|
16
|
-
|
31
|
+
## [0.1.0] - 2022-03-11
|
17
32
|
|
18
|
-
|
33
|
+
- Initial release
|
19
34
|
|
20
|
-
|
21
|
-
|
22
|
-
- Gravity
|
23
|
-
- Music background support
|
35
|
+
|
36
|
+
## [Unreleased]
|
data/COLOR_PALETTE.md
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
# Color.palette
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
Color.palette.orange
|
5
|
+
Color.palette.crimson
|
6
|
+
Color.palette.transparent
|
7
|
+
[...]
|
8
|
+
```
|
9
|
+
|
10
|
+
- ![orange](https://via.placeholder.com/150x50/ffa500/000000?text=+) orange
|
11
|
+
- ![red](https://via.placeholder.com/150x50/ff0000/000000?text=+) red
|
12
|
+
- ![orange_red](https://via.placeholder.com/150x50/ff4500/000000?text=+) orange_red
|
13
|
+
- ![tomato](https://via.placeholder.com/150x50/ff6347/000000?text=+) tomato
|
14
|
+
- ![dark_red](https://via.placeholder.com/150x50/8b0000/000000?text=+) dark_red
|
15
|
+
- ![fire_brick](https://via.placeholder.com/150x50/b22222/000000?text=+) fire_brick
|
16
|
+
- ![crimson](https://via.placeholder.com/150x50/dc143c/000000?text=+) crimson
|
17
|
+
- ![deep_pink](https://via.placeholder.com/150x50/ff1493/000000?text=+) deep_pink
|
18
|
+
- ![maroon](https://via.placeholder.com/150x50/b03060/000000?text=+) maroon
|
19
|
+
- ![indian_red](https://via.placeholder.com/150x50/cd5c5c/000000?text=+) indian_red
|
20
|
+
- ![medium_violet_red](https://via.placeholder.com/150x50/c71585/000000?text=+) medium_violet_red
|
21
|
+
- ![violet_red](https://via.placeholder.com/150x50/d02090/000000?text=+) violet_red
|
22
|
+
- ![light_coral](https://via.placeholder.com/150x50/f08080/000000?text=+) light_coral
|
23
|
+
- ![hot_pink](https://via.placeholder.com/150x50/ff69b4/000000?text=+) hot_pink
|
24
|
+
- ![pale_violet_red](https://via.placeholder.com/150x50/db7093/000000?text=+) pale_violet_red
|
25
|
+
- ![light_pink](https://via.placeholder.com/150x50/ffb6c1/000000?text=+) light_pink
|
26
|
+
- ![rosy_brown](https://via.placeholder.com/150x50/bc8f8f/000000?text=+) rosy_brown
|
27
|
+
- ![pink](https://via.placeholder.com/150x50/ffc0cb/000000?text=+) pink
|
28
|
+
- ![orchid](https://via.placeholder.com/150x50/da70d6/000000?text=+) orchid
|
29
|
+
- ![lavender_blush](https://via.placeholder.com/150x50/fff0f5/000000?text=+) lavender_blush
|
30
|
+
- ![snow](https://via.placeholder.com/150x50/fffafa/000000?text=+) snow
|
31
|
+
- ![chocolate](https://via.placeholder.com/150x50/d2691e/000000?text=+) chocolate
|
32
|
+
- ![saddle_brown](https://via.placeholder.com/150x50/8b4513/000000?text=+) saddle_brown
|
33
|
+
- ![brown](https://via.placeholder.com/150x50/843c24/000000?text=+) brown
|
34
|
+
- ![dark_orange](https://via.placeholder.com/150x50/ff8c00/000000?text=+) dark_orange
|
35
|
+
- ![coral](https://via.placeholder.com/150x50/ff7f50/000000?text=+) coral
|
36
|
+
- ![sienna](https://via.placeholder.com/150x50/a0522d/000000?text=+) sienna
|
37
|
+
- ![salmon](https://via.placeholder.com/150x50/fa8072/000000?text=+) salmon
|
38
|
+
- ![peru](https://via.placeholder.com/150x50/cd853f/000000?text=+) peru
|
39
|
+
- ![dark_goldenrod](https://via.placeholder.com/150x50/b8860b/000000?text=+) dark_goldenrod
|
40
|
+
- ![goldenrod](https://via.placeholder.com/150x50/daa520/000000?text=+) goldenrod
|
41
|
+
- ![sandy_brown](https://via.placeholder.com/150x50/f4a460/000000?text=+) sandy_brown
|
42
|
+
- ![light_salmon](https://via.placeholder.com/150x50/ffa07a/000000?text=+) light_salmon
|
43
|
+
- ![dark_salmon](https://via.placeholder.com/150x50/e9967a/000000?text=+) dark_salmon
|
44
|
+
- ![gold](https://via.placeholder.com/150x50/ffd700/000000?text=+) gold
|
45
|
+
- ![yellow](https://via.placeholder.com/150x50/ffff00/000000?text=+) yellow
|
46
|
+
- ![olive](https://via.placeholder.com/150x50/808000/000000?text=+) olive
|
47
|
+
- ![burlywood](https://via.placeholder.com/150x50/deb887/000000?text=+) burlywood
|
48
|
+
- ![tan](https://via.placeholder.com/150x50/d2b48c/000000?text=+) tan
|
49
|
+
- ![navajo_white](https://via.placeholder.com/150x50/ffdead/000000?text=+) navajo_white
|
50
|
+
- ![peach_puff](https://via.placeholder.com/150x50/ffdab9/000000?text=+) peach_puff
|
51
|
+
- ![khaki](https://via.placeholder.com/150x50/f0e68c/000000?text=+) khaki
|
52
|
+
- ![dark_khaki](https://via.placeholder.com/150x50/bdb76b/000000?text=+) dark_khaki
|
53
|
+
- ![moccasin](https://via.placeholder.com/150x50/ffe4b5/000000?text=+) moccasin
|
54
|
+
- ![wheat](https://via.placeholder.com/150x50/f5deb3/000000?text=+) wheat
|
55
|
+
- ![bisque](https://via.placeholder.com/150x50/ffe4c4/000000?text=+) bisque
|
56
|
+
- ![pale_goldenrod](https://via.placeholder.com/150x50/eee8aa/000000?text=+) pale_goldenrod
|
57
|
+
- ![blanched_almond](https://via.placeholder.com/150x50/ffebcd/000000?text=+) blanched_almond
|
58
|
+
- ![medium_goldenrod](https://via.placeholder.com/150x50/eaeaad/000000?text=+) medium_goldenrod
|
59
|
+
- ![papaya_whip](https://via.placeholder.com/150x50/ffefd5/000000?text=+) papaya_whip
|
60
|
+
- ![misty_rose](https://via.placeholder.com/150x50/ffe4e1/000000?text=+) misty_rose
|
61
|
+
- ![lemon_chiffon](https://via.placeholder.com/150x50/fffacd/000000?text=+) lemon_chiffon
|
62
|
+
- ![antique_white](https://via.placeholder.com/150x50/faebd7/000000?text=+) antique_white
|
63
|
+
- ![cornsilk](https://via.placeholder.com/150x50/fff8dc/000000?text=+) cornsilk
|
64
|
+
- ![light_goldenrod_yellow](https://via.placeholder.com/150x50/fafad2/000000?text=+) light_goldenrod_yellow
|
65
|
+
- ![old_lace](https://via.placeholder.com/150x50/fdf5e6/000000?text=+) old_lace
|
66
|
+
- ![linen](https://via.placeholder.com/150x50/faf0e6/000000?text=+) linen
|
67
|
+
- ![light_yellow](https://via.placeholder.com/150x50/ffffe0/000000?text=+) light_yellow
|
68
|
+
- ![seashell](https://via.placeholder.com/150x50/fff5ee/000000?text=+) seashell
|
69
|
+
- ![beige](https://via.placeholder.com/150x50/f5f5dc/000000?text=+) beige
|
70
|
+
- ![floral_white](https://via.placeholder.com/150x50/fffaf0/000000?text=+) floral_white
|
71
|
+
- ![ivory](https://via.placeholder.com/150x50/fffff0/000000?text=+) ivory
|
72
|
+
- ![green](https://via.placeholder.com/150x50/00ff00/000000?text=+) green
|
73
|
+
- ![lawn_green](https://via.placeholder.com/150x50/7cfc00/000000?text=+) lawn_green
|
74
|
+
- ![chartreuse](https://via.placeholder.com/150x50/7fff00/000000?text=+) chartreuse
|
75
|
+
- ![green_yellow](https://via.placeholder.com/150x50/adff2f/000000?text=+) green_yellow
|
76
|
+
- ![yellow_green](https://via.placeholder.com/150x50/9acd32/000000?text=+) yellow_green
|
77
|
+
- ![medium_forest_green](https://via.placeholder.com/150x50/6b8e23/000000?text=+) medium_forest_green
|
78
|
+
- ![olive_drab](https://via.placeholder.com/150x50/6b8e23/000000?text=+) olive_drab
|
79
|
+
- ![dark_olive_green](https://via.placeholder.com/150x50/556b2f/000000?text=+) dark_olive_green
|
80
|
+
- ![dark_sea_green](https://via.placeholder.com/150x50/8fbc8b/000000?text=+) dark_sea_green
|
81
|
+
- ![lime](https://via.placeholder.com/150x50/00ff00/000000?text=+) lime
|
82
|
+
- ![dark_green](https://via.placeholder.com/150x50/006400/000000?text=+) dark_green
|
83
|
+
- ![lime_green](https://via.placeholder.com/150x50/32cd32/000000?text=+) lime_green
|
84
|
+
- ![forest_green](https://via.placeholder.com/150x50/228b22/000000?text=+) forest_green
|
85
|
+
- ![spring_green](https://via.placeholder.com/150x50/00ff7f/000000?text=+) spring_green
|
86
|
+
- ![medium_spring_green](https://via.placeholder.com/150x50/00fa9a/000000?text=+) medium_spring_green
|
87
|
+
- ![sea_green](https://via.placeholder.com/150x50/2e8b57/000000?text=+) sea_green
|
88
|
+
- ![medium_sea_green](https://via.placeholder.com/150x50/3cb371/000000?text=+) medium_sea_green
|
89
|
+
- ![aquamarine](https://via.placeholder.com/150x50/70d890/000000?text=+) aquamarine
|
90
|
+
- ![light_green](https://via.placeholder.com/150x50/90ee90/000000?text=+) light_green
|
91
|
+
- ![pale_green](https://via.placeholder.com/150x50/98fb98/000000?text=+) pale_green
|
92
|
+
- ![medium_aquamarine](https://via.placeholder.com/150x50/66cdaa/000000?text=+) medium_aquamarine
|
93
|
+
- ![turquoise](https://via.placeholder.com/150x50/40e0d0/000000?text=+) turquoise
|
94
|
+
- ![light_sea_green](https://via.placeholder.com/150x50/20b2aa/000000?text=+) light_sea_green
|
95
|
+
- ![medium_turquoise](https://via.placeholder.com/150x50/48d1cc/000000?text=+) medium_turquoise
|
96
|
+
- ![honeydew](https://via.placeholder.com/150x50/f0fff0/000000?text=+) honeydew
|
97
|
+
- ![mint_cream](https://via.placeholder.com/150x50/f5fffa/000000?text=+) mint_cream
|
98
|
+
- ![royal_blue](https://via.placeholder.com/150x50/4169e1/000000?text=+) royal_blue
|
99
|
+
- ![dodger_blue](https://via.placeholder.com/150x50/1e90ff/000000?text=+) dodger_blue
|
100
|
+
- ![deep_sky_blue](https://via.placeholder.com/150x50/00bfff/000000?text=+) deep_sky_blue
|
101
|
+
- ![cornflower_blue](https://via.placeholder.com/150x50/6495ed/000000?text=+) cornflower_blue
|
102
|
+
- ![steel_blue](https://via.placeholder.com/150x50/4682b4/000000?text=+) steel_blue
|
103
|
+
- ![light_sky_blue](https://via.placeholder.com/150x50/87cefa/000000?text=+) light_sky_blue
|
104
|
+
- ![dark_turquoise](https://via.placeholder.com/150x50/00ced1/000000?text=+) dark_turquoise
|
105
|
+
- ![cyan](https://via.placeholder.com/150x50/00ffff/000000?text=+) cyan
|
106
|
+
- ![aqua](https://via.placeholder.com/150x50/00ffff/000000?text=+) aqua
|
107
|
+
- ![dark_cyan](https://via.placeholder.com/150x50/008b8b/000000?text=+) dark_cyan
|
108
|
+
- ![teal](https://via.placeholder.com/150x50/008080/000000?text=+) teal
|
109
|
+
- ![sky_blue](https://via.placeholder.com/150x50/87ceeb/000000?text=+) sky_blue
|
110
|
+
- ![cadet_blue](https://via.placeholder.com/150x50/5f9ea0/000000?text=+) cadet_blue
|
111
|
+
- ![dark_slate_gray](https://via.placeholder.com/150x50/2f4f4f/000000?text=+) dark_slate_gray
|
112
|
+
- ![dark_slate_grey](https://via.placeholder.com/150x50/2f4f4f/000000?text=+) dark_slate_grey
|
113
|
+
- ![light_slate_gray](https://via.placeholder.com/150x50/778899/000000?text=+) light_slate_gray
|
114
|
+
- ![light_slate_grey](https://via.placeholder.com/150x50/778899/000000?text=+) light_slate_grey
|
115
|
+
- ![slate_gray](https://via.placeholder.com/150x50/708090/000000?text=+) slate_gray
|
116
|
+
- ![slate_grey](https://via.placeholder.com/150x50/708090/000000?text=+) slate_grey
|
117
|
+
- ![light_steel_blue](https://via.placeholder.com/150x50/b0c4de/000000?text=+) light_steel_blue
|
118
|
+
- ![light_blue](https://via.placeholder.com/150x50/add8e6/000000?text=+) light_blue
|
119
|
+
- ![powder_blue](https://via.placeholder.com/150x50/b0e0e6/000000?text=+) powder_blue
|
120
|
+
- ![pale_turquoise](https://via.placeholder.com/150x50/afeeee/000000?text=+) pale_turquoise
|
121
|
+
- ![light_cyan](https://via.placeholder.com/150x50/e0ffff/000000?text=+) light_cyan
|
122
|
+
- ![alice_blue](https://via.placeholder.com/150x50/f0f8ff/000000?text=+) alice_blue
|
123
|
+
- ![azure](https://via.placeholder.com/150x50/f0ffff/000000?text=+) azure
|
124
|
+
- ![medium_blue](https://via.placeholder.com/150x50/0000cd/000000?text=+) medium_blue
|
125
|
+
- ![dark_blue](https://via.placeholder.com/150x50/00008b/000000?text=+) dark_blue
|
126
|
+
- ![midnight_blue](https://via.placeholder.com/150x50/191970/000000?text=+) midnight_blue
|
127
|
+
- ![navy](https://via.placeholder.com/150x50/24248c/000000?text=+) navy
|
128
|
+
- ![blue](https://via.placeholder.com/150x50/0000ff/000000?text=+) blue
|
129
|
+
- ![indigo](https://via.placeholder.com/150x50/4b0082/000000?text=+) indigo
|
130
|
+
- ![blue_violet](https://via.placeholder.com/150x50/8a2be2/000000?text=+) blue_violet
|
131
|
+
- ![medium_slate_blue](https://via.placeholder.com/150x50/7b68ee/000000?text=+) medium_slate_blue
|
132
|
+
- ![slate_blue](https://via.placeholder.com/150x50/6a5acd/000000?text=+) slate_blue
|
133
|
+
- ![purple](https://via.placeholder.com/150x50/a020f0/000000?text=+) purple
|
134
|
+
- ![dark_slate_blue](https://via.placeholder.com/150x50/483d8b/000000?text=+) dark_slate_blue
|
135
|
+
- ![dark_violet](https://via.placeholder.com/150x50/9400d3/000000?text=+) dark_violet
|
136
|
+
- ![dark_orchid](https://via.placeholder.com/150x50/9932cc/000000?text=+) dark_orchid
|
137
|
+
- ![medium_purple](https://via.placeholder.com/150x50/9370db/000000?text=+) medium_purple
|
138
|
+
- ![medium_orchid](https://via.placeholder.com/150x50/ba55d3/000000?text=+) medium_orchid
|
139
|
+
- ![magenta](https://via.placeholder.com/150x50/ff00ff/000000?text=+) magenta
|
140
|
+
- ![fuchsia](https://via.placeholder.com/150x50/ff00ff/000000?text=+) fuchsia
|
141
|
+
- ![dark_magenta](https://via.placeholder.com/150x50/8b008b/000000?text=+) dark_magenta
|
142
|
+
- ![violet](https://via.placeholder.com/150x50/ee82ee/000000?text=+) violet
|
143
|
+
- ![plum](https://via.placeholder.com/150x50/dda0dd/000000?text=+) plum
|
144
|
+
- ![lavender](https://via.placeholder.com/150x50/e6e6fa/000000?text=+) lavender
|
145
|
+
- ![thistle](https://via.placeholder.com/150x50/d8bfd8/000000?text=+) thistle
|
146
|
+
- ![ghost_white](https://via.placeholder.com/150x50/f8f8ff/000000?text=+) ghost_white
|
147
|
+
- ![white](https://via.placeholder.com/150x50/ffffff/000000?text=+) white
|
148
|
+
- ![white_smoke](https://via.placeholder.com/150x50/f5f5f5/000000?text=+) white_smoke
|
149
|
+
- ![gainsboro](https://via.placeholder.com/150x50/dcdcdc/000000?text=+) gainsboro
|
150
|
+
- ![light_gray](https://via.placeholder.com/150x50/d3d3d3/000000?text=+) light_gray
|
151
|
+
- ![light_grey](https://via.placeholder.com/150x50/d3d3d3/000000?text=+) light_grey
|
152
|
+
- ![silver](https://via.placeholder.com/150x50/c0c0c0/000000?text=+) silver
|
153
|
+
- ![gray](https://via.placeholder.com/150x50/bebebe/000000?text=+) gray
|
154
|
+
- ![grey](https://via.placeholder.com/150x50/bebebe/000000?text=+) grey
|
155
|
+
- ![dark_gray](https://via.placeholder.com/150x50/a9a9a9/000000?text=+) dark_gray
|
156
|
+
- ![dark_grey](https://via.placeholder.com/150x50/a9a9a9/000000?text=+) dark_grey
|
157
|
+
- ![dim_gray](https://via.placeholder.com/150x50/696969/000000?text=+) dim_gray
|
158
|
+
- ![dim_grey](https://via.placeholder.com/150x50/696969/000000?text=+) dim_grey
|
159
|
+
- ![black](https://via.placeholder.com/150x50/000000/000000?text=+) black
|
data/README.md
CHANGED
@@ -182,9 +182,9 @@ Actors in the game will be rendered in the relative position to this camera.
|
|
182
182
|
- Allow camera move
|
183
183
|
- Easy to follow one actor
|
184
184
|
|
185
|
-
### Colors palette
|
185
|
+
### Colors palette
|
186
186
|
|
187
|
-
- Not deal with RGB or anything, just a list of colors (
|
187
|
+
- Not deal with RGB or anything, just a list of colors. See [Color.palette](COLOR_PALETTE.md)
|
188
188
|
|
189
189
|
|
190
190
|
### Pause Game (TODO)
|
@@ -366,12 +366,12 @@ player.jump = 150
|
|
366
366
|
player.gravity = 200
|
367
367
|
player.move_with_cursors(left: true, right: true, up: false, down: false, jump: true)
|
368
368
|
|
369
|
-
player.
|
369
|
+
player.on_jumping do
|
370
370
|
Sound.play("jump")
|
371
371
|
player.image = "warrior_jump")
|
372
372
|
end
|
373
373
|
|
374
|
-
player.
|
374
|
+
player.on_floor do
|
375
375
|
player.image = "warrior")
|
376
376
|
end
|
377
377
|
```
|
data/lib/fantasy/actor.rb
CHANGED
@@ -4,9 +4,10 @@ class Actor
|
|
4
4
|
include Mover
|
5
5
|
include Gravitier
|
6
6
|
include Jumper
|
7
|
+
include UserInputs
|
7
8
|
|
8
9
|
attr_reader :image, :moving_with_cursors
|
9
|
-
attr_accessor :image_name, :position, :direction, :speed, :
|
10
|
+
attr_accessor :image_name, :position, :direction, :speed, :jump_force, :gravity, :solid, :scale, :name, :layer
|
10
11
|
attr_accessor :collision_with
|
11
12
|
|
12
13
|
def initialize(image_name)
|
@@ -25,7 +26,7 @@ class Actor
|
|
25
26
|
@dragging_offset = nil
|
26
27
|
@layer = 0
|
27
28
|
@gravity = 0
|
28
|
-
@
|
29
|
+
@jump_force = 0
|
29
30
|
@collision_with = "all"
|
30
31
|
|
31
32
|
@on_floor = false
|
@@ -33,8 +34,8 @@ class Actor
|
|
33
34
|
@on_after_move_callback = nil
|
34
35
|
@on_collision_callback = nil
|
35
36
|
@on_destroy_callback = nil
|
36
|
-
@
|
37
|
-
@
|
37
|
+
@on_jumping_callback = nil
|
38
|
+
@on_floor_callback = nil
|
38
39
|
|
39
40
|
Global.actors << self
|
40
41
|
end
|
@@ -107,10 +108,8 @@ class Actor
|
|
107
108
|
else
|
108
109
|
# Direction moving
|
109
110
|
unless @direction.zero?
|
110
|
-
@velocity = Coordinates.zero
|
111
111
|
last_position = @position
|
112
|
-
|
113
|
-
apply_forces(max_speed: @speed)
|
112
|
+
move_by_direction
|
114
113
|
|
115
114
|
# Check collision after cursor moving
|
116
115
|
if @solid && @position != last_position
|
@@ -119,43 +118,41 @@ class Actor
|
|
119
118
|
end
|
120
119
|
|
121
120
|
# Cursors moving
|
122
|
-
@velocity = Coordinates.zero
|
123
121
|
last_position = @position
|
124
|
-
|
125
|
-
apply_forces(max_speed: @speed)
|
122
|
+
move_by_cursors
|
126
123
|
|
127
124
|
# Check collision after cursor moving
|
128
125
|
if @solid && @position != last_position
|
129
126
|
manage_collisions(last_position)
|
130
127
|
end
|
131
128
|
|
132
|
-
# Jump moving
|
133
|
-
unless @
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
129
|
+
# # Jump moving
|
130
|
+
# unless @jump_force.zero?
|
131
|
+
# last_position = @position
|
132
|
+
# add_force_by_jump
|
133
|
+
# apply_forces(max_speed: @jump_speed || @jump_force)
|
134
|
+
|
135
|
+
# # Check collision after jump moving
|
136
|
+
# if @solid && @position != last_position
|
137
|
+
# if manage_collisions(last_position)
|
138
|
+
# @jumping = false
|
139
|
+
# end
|
140
|
+
# end
|
141
|
+
# end
|
142
|
+
|
143
|
+
# Gravity force
|
144
|
+
if !@gravity.zero?
|
145
|
+
add_force_by_gravity
|
145
146
|
end
|
146
147
|
|
147
|
-
#
|
148
|
-
|
149
|
-
|
150
|
-
last_position = @position
|
151
|
-
add_force_by_gravity
|
152
|
-
apply_forces(max_speed: @gravity)
|
148
|
+
# Apply forces
|
149
|
+
last_position = @position
|
150
|
+
apply_forces(max_speed: @speed)
|
153
151
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
end
|
152
|
+
# Check collision after gravity moving
|
153
|
+
if @solid && @position != last_position
|
154
|
+
@on_floor = false
|
155
|
+
manage_collisions(last_position)
|
159
156
|
end
|
160
157
|
end
|
161
158
|
|
@@ -168,7 +165,15 @@ class Actor
|
|
168
165
|
other.on_collision_do(self)
|
169
166
|
|
170
167
|
if other.position.y > (last_position.y + height)
|
168
|
+
on_floor_do unless @on_floor
|
169
|
+
|
171
170
|
@on_floor = true
|
171
|
+
@jumping = false
|
172
|
+
@velocity.y = 0
|
173
|
+
end
|
174
|
+
|
175
|
+
if other.position.y + other.height < last_position.y
|
176
|
+
@velocity.y = 0
|
172
177
|
end
|
173
178
|
end
|
174
179
|
|
@@ -198,12 +203,12 @@ class Actor
|
|
198
203
|
@on_destroy_callback = block
|
199
204
|
end
|
200
205
|
|
201
|
-
def
|
202
|
-
@
|
206
|
+
def on_jumping(&block)
|
207
|
+
@on_jumping_callback = block
|
203
208
|
end
|
204
209
|
|
205
|
-
def
|
206
|
-
@
|
210
|
+
def on_floor(&block)
|
211
|
+
@on_floor_callback = block
|
207
212
|
end
|
208
213
|
|
209
214
|
|
@@ -220,16 +225,15 @@ class Actor
|
|
220
225
|
instance_exec(&@on_destroy_callback) unless @on_destroy_callback.nil?
|
221
226
|
end
|
222
227
|
|
223
|
-
def
|
224
|
-
instance_exec(&@
|
228
|
+
def on_jumping_do
|
229
|
+
instance_exec(&@on_jumping_callback) unless @on_jumping_callback.nil?
|
225
230
|
end
|
226
231
|
|
227
|
-
def
|
228
|
-
instance_exec(&@
|
232
|
+
def on_floor_do
|
233
|
+
instance_exec(&@on_floor_callback) unless @on_floor_callback.nil?
|
229
234
|
end
|
230
235
|
|
231
236
|
|
232
|
-
|
233
237
|
def collisions
|
234
238
|
Global.actors.reject { |e| e == self }.select { |e| e.solid? }.select do |other|
|
235
239
|
if(
|
@@ -259,37 +263,30 @@ class Actor
|
|
259
263
|
actor.solid = @solid
|
260
264
|
actor.layer = @layer
|
261
265
|
actor.gravity = @gravity
|
262
|
-
actor.
|
266
|
+
actor.jump_force = @jump_force
|
263
267
|
actor.collision_with = @collision_with
|
264
268
|
|
265
269
|
actor.on_after_move_callback = @on_after_move_callback
|
266
270
|
actor.on_collision_callback = @on_collision_callback
|
267
271
|
actor.on_destroy_callback = @on_destroy_callback
|
268
|
-
actor.
|
269
|
-
actor.
|
270
|
-
|
271
|
-
actor
|
272
|
-
end
|
273
|
-
|
274
|
-
protected
|
272
|
+
actor.on_jumping_callback = @on_jumping_callback
|
273
|
+
actor.on_floor_callback = @on_floor_callback
|
275
274
|
|
276
|
-
|
277
|
-
|
278
|
-
|
275
|
+
actor.on_cursor_down_callback = @on_cursor_down_callback
|
276
|
+
actor.on_cursor_up_callback = @on_cursor_up_callback
|
277
|
+
actor.on_cursor_left_callback = @on_cursor_left_callback
|
278
|
+
actor.on_cursor_right_callback = @on_cursor_right_callback
|
279
|
+
actor.on_space_bar_callback = @on_space_bar_callback
|
280
|
+
actor.on_mouse_button_left_callback = @on_mouse_button_left_callback
|
279
281
|
|
280
|
-
|
281
|
-
@on_collision_callback = block
|
282
|
-
end
|
282
|
+
actor.on_click_callback = @on_click_callback
|
283
283
|
|
284
|
-
|
285
|
-
@on_destroy_callback = block
|
284
|
+
actor
|
286
285
|
end
|
287
286
|
|
288
|
-
|
289
|
-
@on_start_jumping_callback = block
|
290
|
-
end
|
287
|
+
protected
|
291
288
|
|
292
|
-
|
293
|
-
|
294
|
-
|
289
|
+
attr_accessor :on_after_move_callback, :on_collision_callback, :on_destroy_callback, :on_jumping_callback, :on_floor_callback
|
290
|
+
attr_accessor :on_cursor_down_callback, :on_cursor_up_callback, :on_cursor_left_callback, :on_cursor_right_callback, :on_space_bar_callback, :on_mouse_button_left_callback
|
291
|
+
attr_accessor :on_click_callback
|
295
292
|
end
|
data/lib/fantasy/color.rb
CHANGED
@@ -1,5 +1,186 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
|
1
3
|
class Color < Gosu::Color
|
2
|
-
|
4
|
+
attr_reader :a, :r, :g, :b, :name
|
5
|
+
|
6
|
+
def initialize(r:, g:, b:, a: 255, name: nil)
|
3
7
|
super(a, r, g, b)
|
8
|
+
|
9
|
+
@a = a
|
10
|
+
@r = r
|
11
|
+
@g = g
|
12
|
+
@b = b
|
13
|
+
@name = name
|
4
14
|
end
|
15
|
+
|
16
|
+
def hex
|
17
|
+
[@r, @g, @b].map do |e|
|
18
|
+
e.to_s(16).rjust(2, "0")
|
19
|
+
end.join
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
result = "r:#{@r}, g:#{@g}, b:#{@b}, a:#{@a}, hex:#{hex}"
|
24
|
+
result += " (#{name})" unless name.nil?
|
25
|
+
|
26
|
+
result
|
27
|
+
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
attr_reader :palette
|
31
|
+
end
|
32
|
+
|
33
|
+
@palette = OpenStruct.new({
|
34
|
+
"orange" => Color.new(r:255, g:165, b:0, a:255, name: "orange"),
|
35
|
+
"red" => Color.new(r:255, g:0, b:0, a:255, name: "red"),
|
36
|
+
"orange_red" => Color.new(r:255, g:69, b:0, a:255, name: "orange_red"),
|
37
|
+
"tomato" => Color.new(r:255, g:99, b:71, a:255, name: "tomato"),
|
38
|
+
"dark_red" => Color.new(r:139, g:0, b:0, a:255, name: "dark_red"),
|
39
|
+
"fire_brick" => Color.new(r:178, g:34, b:34, a:255, name: "fire_brick"),
|
40
|
+
"crimson" => Color.new(r:220, g:20, b:60, a:255, name: "crimson"),
|
41
|
+
"deep_pink" => Color.new(r:255, g:20, b:147, a:255, name: "deep_pink"),
|
42
|
+
"maroon" => Color.new(r:176, g:48, b:96, a:255, name: "maroon"),
|
43
|
+
"indian_red" => Color.new(r:205, g:92, b:92, a:255, name: "indian_red"),
|
44
|
+
"medium_violet_red" => Color.new(r:199, g:21, b:133, a:255, name: "medium_violet_red"),
|
45
|
+
"violet_red" => Color.new(r:208, g:32, b:144, a:255, name: "violet_red"),
|
46
|
+
"light_coral" => Color.new(r:240, g:128, b:128, a:255, name: "light_coral"),
|
47
|
+
"hot_pink" => Color.new(r:255, g:105, b:180, a:255, name: "hot_pink"),
|
48
|
+
"pale_violet_red" => Color.new(r:219, g:112, b:147, a:255, name: "pale_violet_red"),
|
49
|
+
"light_pink" => Color.new(r:255, g:182, b:193, a:255, name: "light_pink"),
|
50
|
+
"rosy_brown" => Color.new(r:188, g:143, b:143, a:255, name: "rosy_brown"),
|
51
|
+
"pink" => Color.new(r:255, g:192, b:203, a:255, name: "pink"),
|
52
|
+
"orchid" => Color.new(r:218, g:112, b:214, a:255, name: "orchid"),
|
53
|
+
"lavender_blush" => Color.new(r:255, g:240, b:245, a:255, name: "lavender_blush"),
|
54
|
+
"snow" => Color.new(r:255, g:250, b:250, a:255, name: "snow"),
|
55
|
+
"chocolate" => Color.new(r:210, g:105, b:30, a:255, name: "chocolate"),
|
56
|
+
"saddle_brown" => Color.new(r:139, g:69, b:19, a:255, name: "saddle_brown"),
|
57
|
+
"brown" => Color.new(r:132, g:60, b:36, a:255, name: "brown"),
|
58
|
+
"dark_orange" => Color.new(r:255, g:140, b:0, a:255, name: "dark_orange"),
|
59
|
+
"coral" => Color.new(r:255, g:127, b:80, a:255, name: "coral"),
|
60
|
+
"sienna" => Color.new(r:160, g:82, b:45, a:255, name: "sienna"),
|
61
|
+
"salmon" => Color.new(r:250, g:128, b:114, a:255, name: "salmon"),
|
62
|
+
"peru" => Color.new(r:205, g:133, b:63, a:255, name: "peru"),
|
63
|
+
"dark_goldenrod" => Color.new(r:184, g:134, b:11, a:255, name: "dark_goldenrod"),
|
64
|
+
"goldenrod" => Color.new(r:218, g:165, b:32, a:255, name: "goldenrod"),
|
65
|
+
"sandy_brown" => Color.new(r:244, g:164, b:96, a:255, name: "sandy_brown"),
|
66
|
+
"light_salmon" => Color.new(r:255, g:160, b:122, a:255, name: "light_salmon"),
|
67
|
+
"dark_salmon" => Color.new(r:233, g:150, b:122, a:255, name: "dark_salmon"),
|
68
|
+
"gold" => Color.new(r:255, g:215, b:0, a:255, name: "gold"),
|
69
|
+
"yellow" => Color.new(r:255, g:255, b:0, a:255, name: "yellow"),
|
70
|
+
"olive" => Color.new(r:128, g:128, b:0, a:255, name: "olive"),
|
71
|
+
"burlywood" => Color.new(r:222, g:184, b:135, a:255, name: "burlywood"),
|
72
|
+
"tan" => Color.new(r:210, g:180, b:140, a:255, name: "tan"),
|
73
|
+
"navajo_white" => Color.new(r:255, g:222, b:173, a:255, name: "navajo_white"),
|
74
|
+
"peach_puff" => Color.new(r:255, g:218, b:185, a:255, name: "peach_puff"),
|
75
|
+
"khaki" => Color.new(r:240, g:230, b:140, a:255, name: "khaki"),
|
76
|
+
"dark_khaki" => Color.new(r:189, g:183, b:107, a:255, name: "dark_khaki"),
|
77
|
+
"moccasin" => Color.new(r:255, g:228, b:181, a:255, name: "moccasin"),
|
78
|
+
"wheat" => Color.new(r:245, g:222, b:179, a:255, name: "wheat"),
|
79
|
+
"bisque" => Color.new(r:255, g:228, b:196, a:255, name: "bisque"),
|
80
|
+
"pale_goldenrod" => Color.new(r:238, g:232, b:170, a:255, name: "pale_goldenrod"),
|
81
|
+
"blanched_almond" => Color.new(r:255, g:235, b:205, a:255, name: "blanched_almond"),
|
82
|
+
"medium_goldenrod" => Color.new(r:234, g:234, b:173, a:255, name: "medium_goldenrod"),
|
83
|
+
"papaya_whip" => Color.new(r:255, g:239, b:213, a:255, name: "papaya_whip"),
|
84
|
+
"misty_rose" => Color.new(r:255, g:228, b:225, a:255, name: "misty_rose"),
|
85
|
+
"lemon_chiffon" => Color.new(r:255, g:250, b:205, a:255, name: "lemon_chiffon"),
|
86
|
+
"antique_white" => Color.new(r:250, g:235, b:215, a:255, name: "antique_white"),
|
87
|
+
"cornsilk" => Color.new(r:255, g:248, b:220, a:255, name: "cornsilk"),
|
88
|
+
"light_goldenrod_yellow" => Color.new(r:250, g:250, b:210, a:255, name: "light_goldenrod_yellow"),
|
89
|
+
"old_lace" => Color.new(r:253, g:245, b:230, a:255, name: "old_lace"),
|
90
|
+
"linen" => Color.new(r:250, g:240, b:230, a:255, name: "linen"),
|
91
|
+
"light_yellow" => Color.new(r:255, g:255, b:224, a:255, name: "light_yellow"),
|
92
|
+
"seashell" => Color.new(r:255, g:245, b:238, a:255, name: "seashell"),
|
93
|
+
"beige" => Color.new(r:245, g:245, b:220, a:255, name: "beige"),
|
94
|
+
"floral_white" => Color.new(r:255, g:250, b:240, a:255, name: "floral_white"),
|
95
|
+
"ivory" => Color.new(r:255, g:255, b:240, a:255, name: "ivory"),
|
96
|
+
"green" => Color.new(r:0, g:255, b:0, a:255, name: "green"),
|
97
|
+
"lawn_green" => Color.new(r:124, g:252, b:0, a:255, name: "lawn_green"),
|
98
|
+
"chartreuse" => Color.new(r:127, g:255, b:0, a:255, name: "chartreuse"),
|
99
|
+
"green_yellow" => Color.new(r:173, g:255, b:47, a:255, name: "green_yellow"),
|
100
|
+
"yellow_green" => Color.new(r:154, g:205, b:50, a:255, name: "yellow_green"),
|
101
|
+
"medium_forest_green" => Color.new(r:107, g:142, b:35, a:255, name: "medium_forest_green"),
|
102
|
+
"olive_drab" => Color.new(r:107, g:142, b:35, a:255, name: "olive_drab"),
|
103
|
+
"dark_olive_green" => Color.new(r:85, g:107, b:47, a:255, name: "dark_olive_green"),
|
104
|
+
"dark_sea_green" => Color.new(r:143, g:188, b:139, a:255, name: "dark_sea_green"),
|
105
|
+
"lime" => Color.new(r:0, g:255, b:0, a:255, name: "lime"),
|
106
|
+
"dark_green" => Color.new(r:0, g:100, b:0, a:255, name: "dark_green"),
|
107
|
+
"lime_green" => Color.new(r:50, g:205, b:50, a:255, name: "lime_green"),
|
108
|
+
"forest_green" => Color.new(r:34, g:139, b:34, a:255, name: "forest_green"),
|
109
|
+
"spring_green" => Color.new(r:0, g:255, b:127, a:255, name: "spring_green"),
|
110
|
+
"medium_spring_green" => Color.new(r:0, g:250, b:154, a:255, name: "medium_spring_green"),
|
111
|
+
"sea_green" => Color.new(r:46, g:139, b:87, a:255, name: "sea_green"),
|
112
|
+
"medium_sea_green" => Color.new(r:60, g:179, b:113, a:255, name: "medium_sea_green"),
|
113
|
+
"aquamarine" => Color.new(r:112, g:216, b:144, a:255, name: "aquamarine"),
|
114
|
+
"light_green" => Color.new(r:144, g:238, b:144, a:255, name: "light_green"),
|
115
|
+
"pale_green" => Color.new(r:152, g:251, b:152, a:255, name: "pale_green"),
|
116
|
+
"medium_aquamarine" => Color.new(r:102, g:205, b:170, a:255, name: "medium_aquamarine"),
|
117
|
+
"turquoise" => Color.new(r:64, g:224, b:208, a:255, name: "turquoise"),
|
118
|
+
"light_sea_green" => Color.new(r:32, g:178, b:170, a:255, name: "light_sea_green"),
|
119
|
+
"medium_turquoise" => Color.new(r:72, g:209, b:204, a:255, name: "medium_turquoise"),
|
120
|
+
"honeydew" => Color.new(r:240, g:255, b:240, a:255, name: "honeydew"),
|
121
|
+
"mint_cream" => Color.new(r:245, g:255, b:250, a:255, name: "mint_cream"),
|
122
|
+
"royal_blue" => Color.new(r:65, g:105, b:225, a:255, name: "royal_blue"),
|
123
|
+
"dodger_blue" => Color.new(r:30, g:144, b:255, a:255, name: "dodger_blue"),
|
124
|
+
"deep_sky_blue" => Color.new(r:0, g:191, b:255, a:255, name: "deep_sky_blue"),
|
125
|
+
"cornflower_blue" => Color.new(r:100, g:149, b:237, a:255, name: "cornflower_blue"),
|
126
|
+
"steel_blue" => Color.new(r:70, g:130, b:180, a:255, name: "steel_blue"),
|
127
|
+
"light_sky_blue" => Color.new(r:135, g:206, b:250, a:255, name: "light_sky_blue"),
|
128
|
+
"dark_turquoise" => Color.new(r:0, g:206, b:209, a:255, name: "dark_turquoise"),
|
129
|
+
"cyan" => Color.new(r:0, g:255, b:255, a:255, name: "cyan"),
|
130
|
+
"aqua" => Color.new(r:0, g:255, b:255, a:255, name: "aqua"),
|
131
|
+
"dark_cyan" => Color.new(r:0, g:139, b:139, a:255, name: "dark_cyan"),
|
132
|
+
"teal" => Color.new(r:0, g:128, b:128, a:255, name: "teal"),
|
133
|
+
"sky_blue" => Color.new(r:135, g:206, b:235, a:255, name: "sky_blue"),
|
134
|
+
"cadet_blue" => Color.new(r:95, g:158, b:160, a:255, name: "cadet_blue"),
|
135
|
+
"dark_slate_gray" => Color.new(r:47, g:79, b:79, a:255, name: "dark_slate_gray"),
|
136
|
+
"dark_slate_grey" => Color.new(r:47, g:79, b:79, a:255, name: "dark_slate_grey"),
|
137
|
+
"light_slate_gray" => Color.new(r:119, g:136, b:153, a:255, name: "light_slate_gray"),
|
138
|
+
"light_slate_grey" => Color.new(r:119, g:136, b:153, a:255, name: "light_slate_grey"),
|
139
|
+
"slate_gray" => Color.new(r:112, g:128, b:144, a:255, name: "slate_gray"),
|
140
|
+
"slate_grey" => Color.new(r:112, g:128, b:144, a:255, name: "slate_grey"),
|
141
|
+
"light_steel_blue" => Color.new(r:176, g:196, b:222, a:255, name: "light_steel_blue"),
|
142
|
+
"light_blue" => Color.new(r:173, g:216, b:230, a:255, name: "light_blue"),
|
143
|
+
"powder_blue" => Color.new(r:176, g:224, b:230, a:255, name: "powder_blue"),
|
144
|
+
"pale_turquoise" => Color.new(r:175, g:238, b:238, a:255, name: "pale_turquoise"),
|
145
|
+
"light_cyan" => Color.new(r:224, g:255, b:255, a:255, name: "light_cyan"),
|
146
|
+
"alice_blue" => Color.new(r:240, g:248, b:255, a:255, name: "alice_blue"),
|
147
|
+
"azure" => Color.new(r:240, g:255, b:255, a:255, name: "azure"),
|
148
|
+
"medium_blue" => Color.new(r:0, g:0, b:205, a:255, name: "medium_blue"),
|
149
|
+
"dark_blue" => Color.new(r:0, g:0, b:139, a:255, name: "dark_blue"),
|
150
|
+
"midnight_blue" => Color.new(r:25, g:25, b:112, a:255, name: "midnight_blue"),
|
151
|
+
"navy" => Color.new(r:36, g:36, b:140, a:255, name: "navy"),
|
152
|
+
"blue" => Color.new(r:0, g:0, b:255, a:255, name: "blue"),
|
153
|
+
"indigo" => Color.new(r:75, g:0, b:130, a:255, name: "indigo"),
|
154
|
+
"blue_violet" => Color.new(r:138, g:43, b:226, a:255, name: "blue_violet"),
|
155
|
+
"medium_slate_blue" => Color.new(r:123, g:104, b:238, a:255, name: "medium_slate_blue"),
|
156
|
+
"slate_blue" => Color.new(r:106, g:90, b:205, a:255, name: "slate_blue"),
|
157
|
+
"purple" => Color.new(r:160, g:32, b:240, a:255, name: "purple"),
|
158
|
+
"dark_slate_blue" => Color.new(r:72, g:61, b:139, a:255, name: "dark_slate_blue"),
|
159
|
+
"dark_violet" => Color.new(r:148, g:0, b:211, a:255, name: "dark_violet"),
|
160
|
+
"dark_orchid" => Color.new(r:153, g:50, b:204, a:255, name: "dark_orchid"),
|
161
|
+
"medium_purple" => Color.new(r:147, g:112, b:219, a:255, name: "medium_purple"),
|
162
|
+
"medium_orchid" => Color.new(r:186, g:85, b:211, a:255, name: "medium_orchid"),
|
163
|
+
"magenta" => Color.new(r:255, g:0, b:255, a:255, name: "magenta"),
|
164
|
+
"fuchsia" => Color.new(r:255, g:0, b:255, a:255, name: "fuchsia"),
|
165
|
+
"dark_magenta" => Color.new(r:139, g:0, b:139, a:255, name: "dark_magenta"),
|
166
|
+
"violet" => Color.new(r:238, g:130, b:238, a:255, name: "violet"),
|
167
|
+
"plum" => Color.new(r:221, g:160, b:221, a:255, name: "plum"),
|
168
|
+
"lavender" => Color.new(r:230, g:230, b:250, a:255, name: "lavender"),
|
169
|
+
"thistle" => Color.new(r:216, g:191, b:216, a:255, name: "thistle"),
|
170
|
+
"ghost_white" => Color.new(r:248, g:248, b:255, a:255, name: "ghost_white"),
|
171
|
+
"white" => Color.new(r:255, g:255, b:255, a:255, name: "white"),
|
172
|
+
"white_smoke" => Color.new(r:245, g:245, b:245, a:255, name: "white_smoke"),
|
173
|
+
"gainsboro" => Color.new(r:220, g:220, b:220, a:255, name: "gainsboro"),
|
174
|
+
"light_gray" => Color.new(r:211, g:211, b:211, a:255, name: "light_gray"),
|
175
|
+
"light_grey" => Color.new(r:211, g:211, b:211, a:255, name: "light_grey"),
|
176
|
+
"silver" => Color.new(r:192, g:192, b:192, a:255, name: "silver"),
|
177
|
+
"gray" => Color.new(r:190, g:190, b:190, a:255, name: "gray"),
|
178
|
+
"grey" => Color.new(r:190, g:190, b:190, a:255, name: "grey"),
|
179
|
+
"dark_gray" => Color.new(r:169, g:169, b:169, a:255, name: "dark_gray"),
|
180
|
+
"dark_grey" => Color.new(r:169, g:169, b:169, a:255, name: "dark_grey"),
|
181
|
+
"dim_gray" => Color.new(r:105, g:105, b:105, a:255, name: "dim_gray"),
|
182
|
+
"dim_grey" => Color.new(r:105, g:105, b:105, a:255, name: "dim_grey"),
|
183
|
+
"black" => Color.new(r:0, g:0, b:0, a:255, name: "black"),
|
184
|
+
"transparent" => Color.new(r:0, g:0, b:0, a:0, name: "transparent")
|
185
|
+
})
|
5
186
|
end
|
data/lib/fantasy/global.rb
CHANGED
@@ -2,7 +2,7 @@ require "ostruct"
|
|
2
2
|
|
3
3
|
module Global
|
4
4
|
class << self
|
5
|
-
attr_accessor :actors, :hud_texts, :hud_images, :backgrounds, :tile_maps, :clocks
|
5
|
+
attr_accessor :actors, :hud_texts, :hud_images, :backgrounds, :tile_maps, :clocks, :shapes
|
6
6
|
attr_accessor :debug
|
7
7
|
attr_accessor :setup_proc, :loop_proc, :button_proc
|
8
8
|
attr_accessor :presentation_proc, :game_proc, :end_proc
|
@@ -28,6 +28,7 @@ module Global
|
|
28
28
|
@backgrounds = []
|
29
29
|
@tile_maps = []
|
30
30
|
@clocks = []
|
31
|
+
@shapes = []
|
31
32
|
@last_frame_at = Time.now
|
32
33
|
@debug = false
|
33
34
|
|
@@ -116,6 +117,7 @@ module Global
|
|
116
117
|
@hud_images.clear
|
117
118
|
@backgrounds.clear
|
118
119
|
@tile_maps.clear
|
120
|
+
@shapes.clear
|
119
121
|
@camera.position = Coordinates.zero
|
120
122
|
|
121
123
|
@clocks.reject(&:persistent?).each do |clock|
|
@@ -142,6 +144,7 @@ module Global
|
|
142
144
|
def setup
|
143
145
|
Sound.preload_sounds
|
144
146
|
Image.preload_images
|
147
|
+
Music.preload_musics
|
145
148
|
end
|
146
149
|
|
147
150
|
def seconds_in_scene
|
data/lib/fantasy/hud_text.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
class HudText
|
2
|
-
attr_accessor :text, :size, :color, :visible, :layer, :in_world, :position, :alignment
|
2
|
+
attr_accessor :text, :size, :color, :background_color, :visible, :layer, :in_world, :position, :alignment
|
3
3
|
|
4
4
|
def initialize(position:, text: "")
|
5
5
|
@position = position
|
6
6
|
@text = text
|
7
7
|
@size = "medium"
|
8
|
-
@color =
|
8
|
+
@color = Color.palette.white
|
9
|
+
@background_color = Color.palette.black
|
9
10
|
@visible = true
|
10
11
|
@layer = 100
|
11
12
|
@in_world = false
|
@@ -18,7 +19,9 @@ class HudText
|
|
18
19
|
|
19
20
|
def draw
|
20
21
|
if visible
|
21
|
-
|
22
|
+
unless @background_color.nil?
|
23
|
+
font.draw_markup_rel(text, screen_position.x + shadow_offset, screen_position.y + shadow_offset, 1, position_rel.x, position_rel.y, 1, 1, background_color)
|
24
|
+
end
|
22
25
|
font.draw_markup_rel(text, screen_position.x, screen_position.y, 1, position_rel.x, position_rel.y, 1, 1, color)
|
23
26
|
end
|
24
27
|
|
@@ -33,6 +36,17 @@ class HudText
|
|
33
36
|
found_font
|
34
37
|
end
|
35
38
|
|
39
|
+
def destroy
|
40
|
+
Global.hud_texts.delete(self)
|
41
|
+
end
|
42
|
+
|
43
|
+
def width
|
44
|
+
font.markup_width(text, 1)
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
private
|
49
|
+
|
36
50
|
def position_rel
|
37
51
|
case @alignment
|
38
52
|
when "top-left"
|
@@ -69,10 +83,6 @@ class HudText
|
|
69
83
|
end
|
70
84
|
end
|
71
85
|
|
72
|
-
def destroy
|
73
|
-
Global.hud_texts.delete(self)
|
74
|
-
end
|
75
|
-
|
76
86
|
def draw_debug
|
77
87
|
Global.pixel_fonts["medium"].draw_text("#{@position.x.floor},#{@position.y.floor}", screen_position.x, screen_position.y, 1)
|
78
88
|
end
|
data/lib/fantasy/image.rb
CHANGED
@@ -1,30 +1,10 @@
|
|
1
1
|
module Jumper
|
2
|
-
def
|
3
|
-
|
4
|
-
execute_jump
|
5
|
-
end
|
6
|
-
|
7
|
-
if @jumping
|
8
|
-
continue_jump
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def execute_jump
|
2
|
+
def jump
|
3
|
+
add_force(Coordinates.up * @jump_force)
|
13
4
|
@jumping = true
|
14
5
|
@on_floor = false
|
15
|
-
@final_vertical_position = @position.y - @
|
16
|
-
|
17
|
-
on_start_jumping_do
|
18
|
-
end
|
19
|
-
|
20
|
-
def continue_jump
|
21
|
-
add_force(Coordinates.up * @jump)
|
22
|
-
|
23
|
-
if(@position.y <= @final_vertical_position)
|
24
|
-
@position.y = @final_vertical_position
|
25
|
-
@jumping = false
|
6
|
+
@final_vertical_position = @position.y - @jump_force
|
26
7
|
|
27
|
-
|
28
|
-
end
|
8
|
+
on_jumping_do
|
29
9
|
end
|
30
10
|
end
|
@@ -1,26 +1,43 @@
|
|
1
1
|
module MoveByCursor
|
2
|
-
def
|
3
|
-
if Gosu.button_down?(
|
4
|
-
|
5
|
-
elsif Gosu.button_down?(Gosu::KB_UP) && @move_with_cursors_up
|
6
|
-
add_force(Coordinates.up * @speed)
|
7
|
-
elsif Gosu.button_down?(Gosu::KB_RIGHT) && @move_with_cursors_right
|
8
|
-
add_force(Coordinates.right * @speed)
|
9
|
-
elsif Gosu.button_down?(Gosu::KB_LEFT) && @move_with_cursors_left
|
10
|
-
add_force(Coordinates.left * @speed)
|
11
|
-
else
|
12
|
-
# @velocity.x = 0
|
2
|
+
def move_by_cursors
|
3
|
+
if Gosu.button_down?(Cursor.down) && @move_with_cursors_down
|
4
|
+
move_by(Coordinates.down)
|
13
5
|
end
|
14
6
|
|
7
|
+
if Gosu.button_down?(Cursor.up) && @move_with_cursors_up
|
8
|
+
move_by(Coordinates.up)
|
9
|
+
end
|
10
|
+
|
11
|
+
if Gosu.button_down?(Cursor.right) && @move_with_cursors_right
|
12
|
+
move_by(Coordinates.right)
|
13
|
+
end
|
14
|
+
|
15
|
+
if Gosu.button_down?(Cursor.left) && @move_with_cursors_left
|
16
|
+
move_by(Coordinates.left)
|
17
|
+
end
|
15
18
|
|
19
|
+
if Gosu.button_down?(Cursor.space_bar) && !@jumping && @on_floor && @move_with_cursors_jump
|
20
|
+
jump
|
21
|
+
end
|
16
22
|
end
|
17
23
|
|
18
|
-
def move_with_cursors(down:
|
24
|
+
def move_with_cursors(down: nil, up: nil, left: nil, right: nil, jump: false)
|
19
25
|
puts "#{@name}: move_with_cursors(down: #{down}, up: #{up}, left: #{left}, right: #{right}), jump: #{jump}"
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
|
27
|
+
if down.nil? and up.nil? and left.nil? and right.nil?
|
28
|
+
down = true
|
29
|
+
up = true
|
30
|
+
left = true
|
31
|
+
right = true
|
32
|
+
end
|
33
|
+
@move_with_cursors_down = down || false
|
34
|
+
@move_with_cursors_up = up || false
|
35
|
+
@move_with_cursors_left = left || false
|
36
|
+
@move_with_cursors_right = right || false
|
37
|
+
@move_with_cursors_jump = jump || false
|
38
|
+
end
|
39
|
+
|
40
|
+
def move_by(direction)
|
41
|
+
@position += direction * @speed * Global.frame_time
|
25
42
|
end
|
26
43
|
end
|
@@ -4,15 +4,15 @@ module Mover
|
|
4
4
|
@acceleration += force
|
5
5
|
end
|
6
6
|
|
7
|
-
def apply_forces(max_speed:)
|
7
|
+
def apply_forces(max_speed: Float::INFINITY)
|
8
8
|
@acceleration ||= Coordinates.zero
|
9
9
|
@velocity ||= Coordinates.zero
|
10
10
|
|
11
11
|
@velocity += @acceleration
|
12
|
+
@velocity.resize(max_speed) if @velocity.length > max_speed
|
12
13
|
|
13
14
|
unless @velocity.length.zero?
|
14
|
-
@
|
15
|
-
@position += @velocity
|
15
|
+
@position += @velocity * Global.frame_time
|
16
16
|
end
|
17
17
|
|
18
18
|
@acceleration = Coordinates.zero
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module UserInputs
|
2
|
+
# Set callbacks
|
3
|
+
def on_cursor_down(&block)
|
4
|
+
@on_cursor_down_callback = block
|
5
|
+
end
|
6
|
+
|
7
|
+
def on_cursor_up(&block)
|
8
|
+
@on_cursor_up_callback = block
|
9
|
+
end
|
10
|
+
|
11
|
+
def on_cursor_left(&block)
|
12
|
+
@on_cursor_left_callback = block
|
13
|
+
end
|
14
|
+
|
15
|
+
def on_cursor_right(&block)
|
16
|
+
@on_cursor_right_callback = block
|
17
|
+
end
|
18
|
+
|
19
|
+
def on_space_bar(&block)
|
20
|
+
@on_space_bar_callback = block
|
21
|
+
end
|
22
|
+
|
23
|
+
def on_mouse_button_left(&block)
|
24
|
+
@on_mouse_button_left_callback = block
|
25
|
+
end
|
26
|
+
|
27
|
+
def on_click(&block)
|
28
|
+
@on_click_callback = block
|
29
|
+
end
|
30
|
+
|
31
|
+
# Execute callbacks
|
32
|
+
def on_cursor_down_do
|
33
|
+
instance_exec(&@on_cursor_down_callback) unless @on_cursor_down_callback.nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
def on_cursor_up_do
|
37
|
+
instance_exec(&@on_cursor_up_callback) unless @on_cursor_up_callback.nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_cursor_left_do
|
41
|
+
instance_exec(&@on_cursor_left_callback) unless @on_cursor_left_callback.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
def on_cursor_right_do
|
45
|
+
instance_exec(&@on_cursor_right_callback) unless @on_cursor_right_callback.nil?
|
46
|
+
end
|
47
|
+
|
48
|
+
def on_space_bar_do
|
49
|
+
instance_exec(&@on_space_bar_callback) unless @on_space_bar_callback.nil?
|
50
|
+
end
|
51
|
+
|
52
|
+
def on_mouse_button_left_do
|
53
|
+
instance_exec(&@on_mouse_button_left_callback) unless @on_mouse_button_left_callback.nil?
|
54
|
+
end
|
55
|
+
|
56
|
+
def on_click_do
|
57
|
+
puts "XXX: on_click_do: #{@on_click_callback}"
|
58
|
+
instance_exec(&@on_click_callback) unless @on_click_callback.nil?
|
59
|
+
end
|
60
|
+
end
|
data/lib/fantasy/loop.rb
CHANGED
@@ -9,13 +9,13 @@ class Game < Gosu::Window
|
|
9
9
|
|
10
10
|
def button_down(button_id)
|
11
11
|
case button_id
|
12
|
-
when
|
13
|
-
when
|
14
|
-
when
|
15
|
-
when
|
16
|
-
when
|
17
|
-
|
18
|
-
when
|
12
|
+
when Cursor.down then cursor_down_pressed
|
13
|
+
when Cursor.up then cursor_up_pressed
|
14
|
+
when Cursor.left then cursor_left_pressed
|
15
|
+
when Cursor.right then cursor_right_pressed
|
16
|
+
when Cursor.space_bar then space_bar_pressed
|
17
|
+
|
18
|
+
when Mouse.left then mouse_button_left_pressed
|
19
19
|
end
|
20
20
|
|
21
21
|
Global.button_proc.call(button_id) unless Global.button_proc.nil?
|
@@ -23,6 +23,46 @@ class Game < Gosu::Window
|
|
23
23
|
super
|
24
24
|
end
|
25
25
|
|
26
|
+
def cursor_down_pressed
|
27
|
+
Global.cursor_down_proc.call unless Global.cursor_down_proc.nil?
|
28
|
+
invoke_input_method("on_cursor_down_do")
|
29
|
+
end
|
30
|
+
|
31
|
+
def cursor_up_pressed
|
32
|
+
Global.cursor_up_proc.call unless Global.cursor_up_proc.nil?
|
33
|
+
invoke_input_method("on_cursor_up_do")
|
34
|
+
end
|
35
|
+
|
36
|
+
def cursor_left_pressed
|
37
|
+
Global.cursor_left_proc.call unless Global.cursor_left_proc.nil?
|
38
|
+
invoke_input_method("on_cursor_left_do")
|
39
|
+
end
|
40
|
+
|
41
|
+
def cursor_right_pressed
|
42
|
+
Global.cursor_right_proc.call unless Global.cursor_right_proc.nil?
|
43
|
+
invoke_input_method("on_cursor_right_do")
|
44
|
+
end
|
45
|
+
|
46
|
+
def space_bar_pressed
|
47
|
+
Global.space_bar_proc.call unless Global.space_bar_proc.nil?
|
48
|
+
invoke_input_method("on_space_bar_do")
|
49
|
+
end
|
50
|
+
|
51
|
+
def mouse_button_left_pressed
|
52
|
+
Global.mouse_button_left_proc.call unless Global.mouse_button_left_proc.nil?
|
53
|
+
|
54
|
+
check_click
|
55
|
+
end
|
56
|
+
|
57
|
+
def invoke_input_method(input_method_name)
|
58
|
+
(
|
59
|
+
Global.actors +
|
60
|
+
Global.shapes
|
61
|
+
).sort_by(&:layer).each do |e|
|
62
|
+
e.send(input_method_name)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
26
66
|
def update
|
27
67
|
Global.update
|
28
68
|
|
@@ -51,9 +91,19 @@ class Game < Gosu::Window
|
|
51
91
|
Global.tile_maps +
|
52
92
|
Global.actors +
|
53
93
|
Global.hud_texts +
|
54
|
-
Global.hud_images
|
94
|
+
Global.hud_images +
|
95
|
+
Global.shapes
|
55
96
|
).sort_by(&:layer).each do |e|
|
56
97
|
e.draw
|
57
98
|
end
|
58
99
|
end
|
100
|
+
|
101
|
+
def check_click
|
102
|
+
(
|
103
|
+
Global.actors +
|
104
|
+
Global.shapes
|
105
|
+
).sort_by(&:layer).each do |e|
|
106
|
+
e.on_click_do if Utils.collision_at?(e, mouse_x, mouse_y)
|
107
|
+
end
|
108
|
+
end
|
59
109
|
end
|
data/lib/fantasy/music.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
class Shape
|
2
|
+
include UserInputs
|
3
|
+
|
4
|
+
attr_accessor :kind, :position, :width, :height, :stroke, :color, :fill, :stroke_color, :layer
|
5
|
+
|
6
|
+
def initialize(kind:, position:, width:, height:, stroke: 1, fill: true, color: Color.palette.black, stroke_color: nil)
|
7
|
+
@kind = kind
|
8
|
+
@position = position
|
9
|
+
@width = width
|
10
|
+
@height = height
|
11
|
+
@stroke = stroke
|
12
|
+
@color = color
|
13
|
+
@fill = fill
|
14
|
+
@stroke_color = stroke_color
|
15
|
+
@layer = 1
|
16
|
+
|
17
|
+
Global.shapes << self
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.rectangle(position:, width:, height:, color: Color.palette.black)
|
21
|
+
Shape.new(kind: "rectangle", position: position, width: width, height: height)
|
22
|
+
end
|
23
|
+
|
24
|
+
def draw
|
25
|
+
case @kind
|
26
|
+
when "rectangle"
|
27
|
+
draw_rectangle
|
28
|
+
else
|
29
|
+
raise "Shape.kind not supported: '#{@kind}'. Supported kinds: 'rectangle'"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def destroy
|
34
|
+
Global.shapes.delete(self)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def draw_rectangle
|
40
|
+
if fill
|
41
|
+
Gosu.draw_rect(@position.x, @position.y, @width, @height, @color)
|
42
|
+
end
|
43
|
+
|
44
|
+
unless stroke.zero?
|
45
|
+
draw_frame(@position.x, @position.y, @width, @height, @stroke, @stroke_color || @color)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def draw_frame(x, y, width, height, stroke, color)
|
50
|
+
Gosu.draw_rect(x, y, width, stroke, color)
|
51
|
+
Gosu.draw_rect(width - stroke + x, y, stroke, height, color)
|
52
|
+
Gosu.draw_rect(x, height - stroke + y, width, stroke, color)
|
53
|
+
Gosu.draw_rect(x, y, stroke, height, color)
|
54
|
+
end
|
55
|
+
end
|
data/lib/fantasy/sound.rb
CHANGED
data/lib/fantasy/version.rb
CHANGED
data/lib/fantasy.rb
CHANGED
@@ -4,14 +4,18 @@ require "gosu"
|
|
4
4
|
require_relative "fantasy/version"
|
5
5
|
|
6
6
|
require_relative "fantasy/coordinates"
|
7
|
+
require_relative "fantasy/cursor"
|
8
|
+
require_relative "fantasy/mouse"
|
7
9
|
require_relative "fantasy/includes/move_by_cursors"
|
8
10
|
require_relative "fantasy/includes/move_by_direction"
|
9
11
|
require_relative "fantasy/includes/mover"
|
10
12
|
require_relative "fantasy/includes/gravitier"
|
11
13
|
require_relative "fantasy/includes/jumper"
|
14
|
+
require_relative "fantasy/includes/user_inputs"
|
12
15
|
require_relative "fantasy/tween"
|
13
16
|
require_relative "fantasy/draggable"
|
14
17
|
require_relative "fantasy/color"
|
18
|
+
require_relative "fantasy/shape"
|
15
19
|
require_relative "fantasy/actor"
|
16
20
|
require_relative "fantasy/utils"
|
17
21
|
require_relative "fantasy/global"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fantasy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernando Guillen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -47,6 +47,7 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- ".rubocop.yml"
|
49
49
|
- CHANGELOG.md
|
50
|
+
- COLOR_PALETTE.md
|
50
51
|
- Gemfile
|
51
52
|
- LICENSE.txt
|
52
53
|
- README.md
|
@@ -64,6 +65,7 @@ files:
|
|
64
65
|
- lib/fantasy/clock.rb
|
65
66
|
- lib/fantasy/color.rb
|
66
67
|
- lib/fantasy/coordinates.rb
|
68
|
+
- lib/fantasy/cursor.rb
|
67
69
|
- lib/fantasy/draggable.rb
|
68
70
|
- lib/fantasy/global.rb
|
69
71
|
- lib/fantasy/hud_image.rb
|
@@ -74,8 +76,11 @@ files:
|
|
74
76
|
- lib/fantasy/includes/move_by_cursors.rb
|
75
77
|
- lib/fantasy/includes/move_by_direction.rb
|
76
78
|
- lib/fantasy/includes/mover.rb
|
79
|
+
- lib/fantasy/includes/user_inputs.rb
|
77
80
|
- lib/fantasy/loop.rb
|
81
|
+
- lib/fantasy/mouse.rb
|
78
82
|
- lib/fantasy/music.rb
|
83
|
+
- lib/fantasy/shape.rb
|
79
84
|
- lib/fantasy/sound.rb
|
80
85
|
- lib/fantasy/tilemap.rb
|
81
86
|
- lib/fantasy/tween.rb
|