aboutsummaryrefslogtreecommitdiff
path: root/examples/game/color.tm
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-08 19:49:47 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-08 19:49:47 -0400
commita7ae25ec086117e133b2dfbbc1c5025aa2f29964 (patch)
tree45bcab3728e0998205e280a0dd84a44bcb2925be /examples/game/color.tm
parentf86cc6549ff6075c3963fce819391d8d8d6960dc (diff)
Add example game using raylib
Diffstat (limited to 'examples/game/color.tm')
-rw-r--r--examples/game/color.tm22
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/game/color.tm b/examples/game/color.tm
new file mode 100644
index 00000000..79807a6d
--- /dev/null
+++ b/examples/game/color.tm
@@ -0,0 +1,22 @@
+# Defines a struct used to represent colors using 64-bit floats (0.0 - 1.0),
+# which can be used to draw colored rectangles in raylib
+use <raylib.h>
+use vectors
+
+struct Color(r,g,b:Num32,a=1.0f32):
+ RED := Color(1,0,0)
+ GRAY := Color(.2f32,.2f32,.2f32)
+ LIGHT_GRAY := Color(.7f32,.7f32,.7f32)
+
+ func draw_rectangle(c:Color, pos:Vec2, size:Vec2):
+ inline C {
+ DrawRectangle(
+ (int)($pos.$x), (int)($pos.$y), (int)($size.$x), (int)($size.$y),
+ ((Color){
+ (int8_t)(uint8_t)(255.*$c.$r),
+ (int8_t)(uint8_t)(255.*$c.$g),
+ (int8_t)(uint8_t)(255.*$c.$b),
+ (int8_t)(uint8_t)(255.*$c.$a),
+ })
+ );
+ }