1 # Raylib wrapper for some functions and structs
6 struct Color(r,g,b:Byte,a=Byte(255))
7 struct Rectangle(x,y,width,height:Num32)
8 func draw(r:Rectangle, color:Color)
9 DrawRectangleRec(r, color)
11 struct Vector2(x,y:Num32)
13 func plus(a,b:Vector2->Vector2; inline)
14 return Vector2(a.x+b.x, a.y+b.y)
15 func minus(a,b:Vector2->Vector2; inline)
16 return Vector2(a.x-b.x, a.y-b.y)
17 func times(a,b:Vector2->Vector2; inline)
18 return Vector2(a.x*b.x, a.y*b.y)
19 func negative(v:Vector2->Vector2; inline)
20 return Vector2(-v.x, -v.y)
21 func dot(a,b:Vector2->Num32; inline)
22 return ((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y))
23 func cross(a,b:Vector2->Num32; inline)
24 return a.x*b.y - a.y*b.x
25 func scaled_by(v:Vector2, k:Num32->Vector2; inline)
26 return Vector2(v.x*k, v.y*k)
27 func divided_by(v:Vector2, divisor:Num32->Vector2; inline)
28 return Vector2(v.x/divisor, v.y/divisor)
29 func length(v:Vector2->Num32; inline)
30 return (v.x*v.x + v.y*v.y).sqrt()
31 func dist(a,b:Vector2->Num32; inline)
32 return a.minus(b).length()
33 func angle(v:Vector2->Num32; inline)
34 return Num32.atan2(v.y, v.x)
35 func norm(v:Vector2->Vector2; inline)
36 if v.x == 0 and v.y == 0
39 return Vector2(v.x/len, v.y/len)
40 func rotated(v:Vector2, radians:Num32 -> Vector2)
41 cos := radians.cos() or return v
42 sin := radians.sin() or return v
43 return Vector2(cos*v.x - sin*v.y, sin*v.x + cos*v.y)
44 func mix(a,b:Vector2, amount:Num32 -> Vector2)
50 func InitWindow(width:Int32, height:Int32, title:CString)
51 C_code `InitWindow(@width, @height, @title);`
53 func SetTargetFPS(fps:Int32)
54 C_code `SetTargetFPS(@fps);`
56 func WindowShouldClose(->Bool)
57 return C_code:Bool`WindowShouldClose()`
59 func GetFrameTime(->Num32)
60 return C_code:Num32`GetFrameTime()`
63 C_code `BeginDrawing();`
66 C_code `EndDrawing();`
69 C_code `CloseWindow();`
71 func ClearBackground(color:Color)
72 C_code `ClearBackground((Color){@color.r, @color.g, @color.b, @color.a});`
74 func DrawRectangle(x,y,width,height:Int32, color:Color)
75 C_code `DrawRectangleRec((Rectangle){@x,@y,@width,@height},(Color){@color.r, @color.g, @color.b, @color.a});`
77 func DrawRectangleRec(rec:Rectangle, color:Color)
78 C_code `DrawRectangleRec((Rectangle){@rec.x,@rec.y,@rec.width,@rec.height},(Color){@color.r, @color.g, @color.b, @color.a});`
80 func DrawRectangleV(pos:Vector2, size:Vector2, color:Color)
81 C_code `DrawRectangleV((Vector2){@pos.x,@pos.y}, (Vector2){@size.x,@size.y},(Color){@color.r, @color.g, @color.b, @color.a});`
83 func DrawText(text:CString, x,y:Int32, text_height:Int32, color:Color)
84 C_code `DrawText(@text, @x, @y, @text_height, (Color){@color.r, @color.g, @color.b, @color.a});`
86 func GetScreenWidth(->Int32)
87 return C_code:Int32`GetScreenWidth()`
89 func GetScreenHeight(->Int32)
90 return C_code:Int32`GetScreenHeight()`