fantasy 0.1.5.1 → 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 +32 -1
- data/COLOR_PALETTE.md +159 -0
- data/README.md +59 -9
- data/lib/fantasy/actor.rb +170 -40
- data/lib/fantasy/clock.rb +1 -0
- data/lib/fantasy/color.rb +182 -1
- data/lib/fantasy/coordinates.rb +4 -0
- data/lib/fantasy/cursor.rb +21 -0
- data/lib/fantasy/global.rb +30 -4
- data/lib/fantasy/hud_image.rb +1 -1
- data/lib/fantasy/hud_text.rb +43 -11
- data/lib/fantasy/image.rb +2 -0
- data/lib/fantasy/includes/gravitier.rb +5 -0
- data/lib/fantasy/includes/jumper.rb +10 -0
- data/lib/fantasy/includes/move_by_cursors.rb +39 -11
- data/lib/fantasy/includes/move_by_direction.rb +5 -0
- data/lib/fantasy/includes/mover.rb +20 -0
- 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 +51 -0
- data/lib/fantasy/shape.rb +55 -0
- data/lib/fantasy/sound.rb +2 -0
- data/lib/fantasy/{tile_map.rb → tilemap.rb} +10 -4
- data/lib/fantasy/utils.rb +5 -0
- data/lib/fantasy/version.rb +1 -1
- data/lib/fantasy.rb +12 -2
- metadata +13 -3
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,5 +1,36 @@
|
|
1
|
-
## [
|
1
|
+
## [0.1.11] - 2022-03-26
|
2
|
+
|
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'
|
21
|
+
|
22
|
+
|
23
|
+
## [0.1.5] - 2022-03-16
|
24
|
+
|
25
|
+
- Background color or image
|
26
|
+
- Tilemap
|
27
|
+
- Camera can be controlled by cursors
|
28
|
+
- Background image can be replicable
|
29
|
+
|
2
30
|
|
3
31
|
## [0.1.0] - 2022-03-11
|
4
32
|
|
5
33
|
- Initial release
|
34
|
+
|
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
@@ -116,12 +116,13 @@ Managing game elements which have (optionally) image, movement and collision
|
|
116
116
|
- Easy to set an `image`
|
117
117
|
- Managing movement through `direction` and `speed`
|
118
118
|
- Built-in movement control through cursors
|
119
|
-
- Collision detection, OnCollision callback
|
120
|
-
- Jump
|
121
|
-
- Gravity
|
119
|
+
- Collision detection, OnCollision callback, Collision matrix
|
120
|
+
- Jump
|
121
|
+
- Gravity
|
122
122
|
- Animations (TODO)
|
123
123
|
- Possibility to extend Actor class or instantiate it directly for simple characters
|
124
124
|
- Allowing magic instance properties (Like in OpenStruct). So programmer can do `actor.stuff = 1` and it is valid (TODO)
|
125
|
+
- Alignment "center" and "top-left" (TODO)
|
125
126
|
|
126
127
|
### Clock
|
127
128
|
|
@@ -181,9 +182,9 @@ Actors in the game will be rendered in the relative position to this camera.
|
|
181
182
|
- Allow camera move
|
182
183
|
- Easy to follow one actor
|
183
184
|
|
184
|
-
### Colors palette
|
185
|
+
### Colors palette
|
185
186
|
|
186
|
-
- 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)
|
187
188
|
|
188
189
|
|
189
190
|
### Pause Game (TODO)
|
@@ -196,7 +197,9 @@ Move the core functions to the top level hierarchy so I don't need to create a `
|
|
196
197
|
|
197
198
|
### Sound
|
198
199
|
|
199
|
-
Direct and easy way to play a sound
|
200
|
+
- Direct and easy way to play a sound
|
201
|
+
- Direct and easy way to play a background music
|
202
|
+
|
200
203
|
|
201
204
|
### Background
|
202
205
|
|
@@ -219,12 +222,13 @@ Easy access to keyboard and mouse inputs on any part of the code. Specially in t
|
|
219
222
|
- Remove "on_space_bar" when changing scene (TODO)
|
220
223
|
- Detect when key/mouse button is pressed in the actual frame in any part of the code (TODO)
|
221
224
|
|
222
|
-
###
|
225
|
+
### Tilemap (TODO)
|
223
226
|
|
224
227
|
For easy creation of:
|
225
228
|
|
226
|
-
- Top-down map levels
|
229
|
+
- Top-down map levels
|
227
230
|
- Platformer map levels (TODO)
|
231
|
+
- Allow specific map keys like a=>actor_1, b=>actor_2 (TODO)
|
228
232
|
|
229
233
|
### Tweens (TODO)
|
230
234
|
|
@@ -301,6 +305,7 @@ player.solid = true
|
|
301
305
|
player.speed = 200
|
302
306
|
player.layer = 1
|
303
307
|
player.move_with_cursors
|
308
|
+
player.collision_with = ["enemy", "bullets"] # default "all"
|
304
309
|
|
305
310
|
player.on_collision do |other|
|
306
311
|
if other.name == "enemy"
|
@@ -330,6 +335,7 @@ class Player < Actor
|
|
330
335
|
@speed = 200
|
331
336
|
@layer = 1
|
332
337
|
@direction = Coordinates.zero
|
338
|
+
@collision_with = ["enemy", "bullets"] # default "all"
|
333
339
|
move_with_cursors
|
334
340
|
end
|
335
341
|
|
@@ -351,6 +357,25 @@ class Player < Actor
|
|
351
357
|
end
|
352
358
|
```
|
353
359
|
|
360
|
+
Actor settings for a platformer:
|
361
|
+
|
362
|
+
```ruby
|
363
|
+
player = Actor.new("warrior") # ./images/warrior.png
|
364
|
+
player.solid = true
|
365
|
+
player.jump = 150
|
366
|
+
player.gravity = 200
|
367
|
+
player.move_with_cursors(left: true, right: true, up: false, down: false, jump: true)
|
368
|
+
|
369
|
+
player.on_jumping do
|
370
|
+
Sound.play("jump")
|
371
|
+
player.image = "warrior_jump")
|
372
|
+
end
|
373
|
+
|
374
|
+
player.on_floor do
|
375
|
+
player.image = "warrior")
|
376
|
+
end
|
377
|
+
```
|
378
|
+
|
354
379
|
### Clock
|
355
380
|
|
356
381
|
```ruby
|
@@ -397,18 +422,43 @@ end
|
|
397
422
|
|
398
423
|
### Sound
|
399
424
|
|
425
|
+
Plays only once:
|
426
|
+
|
400
427
|
```ruby
|
401
428
|
Sound.play("shoot") # ./sounds/shoot.wav
|
402
429
|
```
|
403
430
|
|
431
|
+
Plays in loop:
|
432
|
+
|
433
|
+
```ruby
|
434
|
+
Music.play("music") # ./musics/music.mp3
|
435
|
+
Music.volume = 0.5
|
436
|
+
Music.stop
|
437
|
+
```
|
438
|
+
|
439
|
+
### Tilemap
|
440
|
+
|
441
|
+
```ruby
|
442
|
+
# ./maps/sky.txt
|
443
|
+
#0 0 0
|
444
|
+
# 1 0
|
445
|
+
#
|
446
|
+
#0 0 0
|
447
|
+
|
448
|
+
planet = Actor.new("planet")
|
449
|
+
star = Actor.new("star")
|
450
|
+
map = Tilemap.new(map_name: "sky", tiles: [planet, star], tile_size: 30)
|
451
|
+
map.spawn
|
452
|
+
```
|
404
453
|
|
405
454
|
### UI
|
406
455
|
|
407
456
|
#### HUD Text
|
408
457
|
|
409
458
|
```ruby
|
410
|
-
timer = HudText.new(position: Coordinates.new(
|
459
|
+
timer = HudText.new(position: Coordinates.new(SCREEN_WIDTH / 2, 10))
|
411
460
|
timer.text = 0
|
461
|
+
timer.alignment = "center"
|
412
462
|
timer.size = "big"
|
413
463
|
|
414
464
|
Clock.new { timer.text += 1 }.repeat(seconds: 1)
|
data/lib/fantasy/actor.rb
CHANGED
@@ -1,26 +1,41 @@
|
|
1
1
|
class Actor
|
2
2
|
include MoveByCursor
|
3
|
+
include MoveByDirection
|
4
|
+
include Mover
|
5
|
+
include Gravitier
|
6
|
+
include Jumper
|
7
|
+
include UserInputs
|
3
8
|
|
4
9
|
attr_reader :image, :moving_with_cursors
|
5
|
-
attr_accessor :image_name, :position, :direction, :speed, :solid, :scale, :name, :layer
|
10
|
+
attr_accessor :image_name, :position, :direction, :speed, :jump_force, :gravity, :solid, :scale, :name, :layer
|
11
|
+
attr_accessor :collision_with
|
6
12
|
|
7
13
|
def initialize(image_name)
|
8
14
|
@image_name = image_name
|
9
15
|
@image = Image.new(image_name)
|
10
16
|
@name = image_name
|
11
|
-
@position = Coordinates.
|
12
|
-
@direction = Coordinates.
|
17
|
+
@position = Coordinates.zero
|
18
|
+
@direction = Coordinates.zero
|
13
19
|
@speed = 0
|
14
20
|
@scale = 1
|
15
|
-
|
21
|
+
|
16
22
|
@moving_with_cursors = false
|
17
23
|
@solid = false
|
18
24
|
@draggable_on_debug = true
|
19
25
|
@dragging = false
|
20
26
|
@dragging_offset = nil
|
21
27
|
@layer = 0
|
28
|
+
@gravity = 0
|
29
|
+
@jump_force = 0
|
30
|
+
@collision_with = "all"
|
22
31
|
|
32
|
+
@on_floor = false
|
33
|
+
|
34
|
+
@on_after_move_callback = nil
|
23
35
|
@on_collision_callback = nil
|
36
|
+
@on_destroy_callback = nil
|
37
|
+
@on_jumping_callback = nil
|
38
|
+
@on_floor_callback = nil
|
24
39
|
|
25
40
|
Global.actors << self
|
26
41
|
end
|
@@ -30,20 +45,16 @@ class Actor
|
|
30
45
|
end
|
31
46
|
|
32
47
|
def width
|
33
|
-
@image.width
|
48
|
+
@image.width * @scale
|
34
49
|
end
|
35
50
|
|
36
51
|
def height
|
37
|
-
@image.height
|
38
|
-
end
|
39
|
-
|
40
|
-
def move_with_cursors
|
41
|
-
@moving_with_cursors = true
|
52
|
+
@image.height * @scale
|
42
53
|
end
|
43
54
|
|
44
55
|
def direction=(value)
|
45
56
|
@direction = value
|
46
|
-
@direction = @direction.normalize
|
57
|
+
@direction = @direction.normalize unless @direction.zero?
|
47
58
|
end
|
48
59
|
|
49
60
|
def draw
|
@@ -54,13 +65,32 @@ class Actor
|
|
54
65
|
|
55
66
|
def draw_debug
|
56
67
|
Utils.draw_frame(position_in_camera.x, position_in_camera.y, width, height, 1, Gosu::Color::RED) if solid
|
57
|
-
Global.
|
68
|
+
Global.pixel_fonts["medium"].draw_text("#{@position.x.floor},#{@position.y.floor}", position_in_camera.x, position_in_camera.y - 20, 1)
|
58
69
|
end
|
59
70
|
|
60
71
|
def position_in_camera
|
61
72
|
@position - Global.camera.position
|
62
73
|
end
|
63
74
|
|
75
|
+
# TODO: make this work optimized
|
76
|
+
# def position_top_left
|
77
|
+
# @position - position_delta
|
78
|
+
# end
|
79
|
+
|
80
|
+
# def position_delta
|
81
|
+
# case @alignment
|
82
|
+
# when "top-left"
|
83
|
+
# Coordinates.zero
|
84
|
+
# when "center"
|
85
|
+
# Coordinates.new(width/2, height/2)
|
86
|
+
# else
|
87
|
+
# raise "Actor.alignment value not valid '#{@alignment}'. Valid values: 'top-left, center'"
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
|
91
|
+
# TODO: I made more of this code while I was with Covid
|
92
|
+
# It looks horrible and it is crap
|
93
|
+
# I'll improve it some day :)
|
64
94
|
def move
|
65
95
|
mouse_position = Global.mouse_position + Global.camera.position
|
66
96
|
|
@@ -76,30 +106,91 @@ class Actor
|
|
76
106
|
if @dragging
|
77
107
|
@position = mouse_position - @dragging_offset
|
78
108
|
else
|
79
|
-
|
109
|
+
# Direction moving
|
110
|
+
unless @direction.zero?
|
111
|
+
last_position = @position
|
112
|
+
move_by_direction
|
113
|
+
|
114
|
+
# Check collision after cursor moving
|
115
|
+
if @solid && @position != last_position
|
116
|
+
manage_collisions(last_position)
|
117
|
+
end
|
118
|
+
end
|
80
119
|
|
81
|
-
|
82
|
-
|
83
|
-
|
120
|
+
# Cursors moving
|
121
|
+
last_position = @position
|
122
|
+
move_by_cursors
|
84
123
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
end
|
124
|
+
# Check collision after cursor moving
|
125
|
+
if @solid && @position != last_position
|
126
|
+
manage_collisions(last_position)
|
127
|
+
end
|
90
128
|
|
91
|
-
|
92
|
-
|
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
|
146
|
+
end
|
147
|
+
|
148
|
+
# Apply forces
|
149
|
+
last_position = @position
|
150
|
+
apply_forces(max_speed: @speed)
|
151
|
+
|
152
|
+
# Check collision after gravity moving
|
153
|
+
if @solid && @position != last_position
|
154
|
+
@on_floor = false
|
155
|
+
manage_collisions(last_position)
|
93
156
|
end
|
94
157
|
end
|
95
158
|
|
96
|
-
|
159
|
+
on_after_move_do
|
160
|
+
end
|
161
|
+
|
162
|
+
def manage_collisions(last_position)
|
163
|
+
collisions.each do |other|
|
164
|
+
on_collision_do(other)
|
165
|
+
other.on_collision_do(self)
|
166
|
+
|
167
|
+
if other.position.y > (last_position.y + height)
|
168
|
+
on_floor_do unless @on_floor
|
169
|
+
|
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
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
if collisions.any? # we don't cache collisions because position may be changed on collision callback
|
181
|
+
@position = last_position
|
182
|
+
|
183
|
+
return true
|
184
|
+
end
|
185
|
+
|
186
|
+
false
|
97
187
|
end
|
98
188
|
|
99
189
|
def solid?
|
100
190
|
@solid
|
101
191
|
end
|
102
192
|
|
193
|
+
# Set callbacks
|
103
194
|
def on_after_move(&block)
|
104
195
|
@on_after_move_callback = block
|
105
196
|
end
|
@@ -112,18 +203,50 @@ class Actor
|
|
112
203
|
@on_destroy_callback = block
|
113
204
|
end
|
114
205
|
|
115
|
-
def
|
116
|
-
@
|
206
|
+
def on_jumping(&block)
|
207
|
+
@on_jumping_callback = block
|
117
208
|
end
|
118
209
|
|
210
|
+
def on_floor(&block)
|
211
|
+
@on_floor_callback = block
|
212
|
+
end
|
213
|
+
|
214
|
+
|
215
|
+
# Execute callbacks
|
216
|
+
def on_after_move_do
|
217
|
+
instance_exec(&@on_after_move_callback) unless @on_after_move_callback.nil?
|
218
|
+
end
|
219
|
+
|
220
|
+
def on_collision_do(other)
|
221
|
+
instance_exec(other, &@on_collision_callback) unless @on_collision_callback.nil?
|
222
|
+
end
|
223
|
+
|
224
|
+
def on_destroy_do
|
225
|
+
instance_exec(&@on_destroy_callback) unless @on_destroy_callback.nil?
|
226
|
+
end
|
227
|
+
|
228
|
+
def on_jumping_do
|
229
|
+
instance_exec(&@on_jumping_callback) unless @on_jumping_callback.nil?
|
230
|
+
end
|
231
|
+
|
232
|
+
def on_floor_do
|
233
|
+
instance_exec(&@on_floor_callback) unless @on_floor_callback.nil?
|
234
|
+
end
|
235
|
+
|
236
|
+
|
119
237
|
def collisions
|
120
|
-
Global.actors.reject { |e| e == self }.select { |e| e.solid? }.select do |
|
121
|
-
|
238
|
+
Global.actors.reject { |e| e == self }.select { |e| e.solid? }.select do |other|
|
239
|
+
if(
|
240
|
+
(@collision_with == "all" || @collision_with.include?(other.name)) &&
|
241
|
+
(other.collision_with == "all" || other.collision_with.include?(self.name))
|
242
|
+
)
|
243
|
+
Utils.collision? self, other
|
244
|
+
end
|
122
245
|
end
|
123
246
|
end
|
124
247
|
|
125
248
|
def destroy
|
126
|
-
|
249
|
+
on_destroy_do
|
127
250
|
Global.actors.delete(self)
|
128
251
|
end
|
129
252
|
|
@@ -133,30 +256,37 @@ class Actor
|
|
133
256
|
actor.name = @name
|
134
257
|
actor.position = @position.clone
|
135
258
|
actor.direction = @direction.clone
|
259
|
+
|
136
260
|
actor.speed = @speed
|
137
261
|
actor.scale = @scale
|
138
262
|
actor.moving_with_cursors if @moving_with_cursors
|
139
263
|
actor.solid = @solid
|
140
264
|
actor.layer = @layer
|
265
|
+
actor.gravity = @gravity
|
266
|
+
actor.jump_force = @jump_force
|
267
|
+
actor.collision_with = @collision_with
|
141
268
|
|
142
269
|
actor.on_after_move_callback = @on_after_move_callback
|
143
270
|
actor.on_collision_callback = @on_collision_callback
|
144
271
|
actor.on_destroy_callback = @on_destroy_callback
|
272
|
+
actor.on_jumping_callback = @on_jumping_callback
|
273
|
+
actor.on_floor_callback = @on_floor_callback
|
145
274
|
|
146
|
-
actor
|
147
|
-
|
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
|
148
281
|
|
149
|
-
|
282
|
+
actor.on_click_callback = @on_click_callback
|
150
283
|
|
151
|
-
|
152
|
-
@on_after_move_callback = block
|
284
|
+
actor
|
153
285
|
end
|
154
286
|
|
155
|
-
|
156
|
-
@on_collision_callback = block
|
157
|
-
end
|
287
|
+
protected
|
158
288
|
|
159
|
-
|
160
|
-
|
161
|
-
|
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
|
162
292
|
end
|