aboutsummaryrefslogtreecommitdiff
path: root/examples/game
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-06 16:07:23 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-06 16:07:23 -0400
commit6782cc5570e194791ca6cdd695b88897e9145564 (patch)
treea428e9d954aca251212ec1cf15bd35e0badce630 /examples/game
parent448e805293989b06e07878a4a87fdd378f7c6e02 (diff)
No more colons for blocks
Diffstat (limited to 'examples/game')
-rw-r--r--examples/game/box.tm4
-rw-r--r--examples/game/game.tm4
-rw-r--r--examples/game/player.tm6
-rw-r--r--examples/game/raylib.tm36
-rw-r--r--examples/game/world.tm50
5 files changed, 50 insertions, 50 deletions
diff --git a/examples/game/box.tm b/examples/game/box.tm
index dda3dd83..41ae10e5 100644
--- a/examples/game/box.tm
+++ b/examples/game/box.tm
@@ -2,6 +2,6 @@
use ./world.tm
use ./raylib.tm
-struct Box(pos:Vector2, size=Vector2(50, 50), color=Color(0x80,0x80,0x80)):
- func draw(b:Box):
+struct Box(pos:Vector2, size=Vector2(50, 50), color=Color(0x80,0x80,0x80))
+ func draw(b:Box)
DrawRectangleV(b.pos, b.size, b.color)
diff --git a/examples/game/game.tm b/examples/game/game.tm
index ce08c329..f82e4f40 100644
--- a/examples/game/game.tm
+++ b/examples/game/game.tm
@@ -2,7 +2,7 @@
use ./raylib.tm
use ./world.tm
-func main(map=(./map.txt)):
+func main(map=(./map.txt))
InitWindow(1600, 900, CString("raylib [core] example - 2d camera"))
map_contents := map.read() or exit("Could not find the game map: $map")
@@ -16,7 +16,7 @@ func main(map=(./map.txt)):
SetTargetFPS(60)
- while not WindowShouldClose():
+ while not WindowShouldClose()
dt := GetFrameTime()
world.update(dt)
diff --git a/examples/game/player.tm b/examples/game/player.tm
index 7f14f51e..9f166d9e 100644
--- a/examples/game/player.tm
+++ b/examples/game/player.tm
@@ -2,14 +2,14 @@
use ./world.tm
use ./raylib.tm
-struct Player(pos,prev_pos:Vector2):
+struct Player(pos,prev_pos:Vector2)
WALK_SPEED := Num32(500.)
ACCEL := Num32(0.3)
FRICTION := Num32(0.99)
SIZE := Vector2(30, 30)
COLOR := Color(0x60, 0x60, 0xbF)
- func update(p:@Player):
+ func update(p:@Player)
target_x := inline C:Num32 {
(Num32_t)((IsKeyDown(KEY_A) ? -1 : 0) + (IsKeyDown(KEY_D) ? 1 : 0))
}
@@ -24,5 +24,5 @@ struct Player(pos,prev_pos:Vector2):
p.prev_pos, p.pos = p.pos, p.pos + World.DT*vel
- func draw(p:Player):
+ func draw(p:Player)
DrawRectangleV(p.pos, Player.SIZE, Player.COLOR)
diff --git a/examples/game/raylib.tm b/examples/game/raylib.tm
index 5e58e996..b2ba53d7 100644
--- a/examples/game/raylib.tm
+++ b/examples/game/raylib.tm
@@ -4,44 +4,44 @@ use <raylib.h>
use <raymath.h>
struct Color(r,g,b:Byte,a=Byte(255); extern)
-struct Rectangle(x,y,width,height:Num32; extern):
- func draw(r:Rectangle, color:Color):
+struct Rectangle(x,y,width,height:Num32; extern)
+ func draw(r:Rectangle, color:Color)
DrawRectangleRec(r, color)
-struct Vector2(x,y:Num32; extern):
+struct Vector2(x,y:Num32; extern)
ZERO := Vector2(0, 0)
- func plus(a,b:Vector2->Vector2; inline):
+ func plus(a,b:Vector2->Vector2; inline)
return Vector2(a.x+b.x, a.y+b.y)
- func minus(a,b:Vector2->Vector2; inline):
+ func minus(a,b:Vector2->Vector2; inline)
return Vector2(a.x-b.x, a.y-b.y)
- func times(a,b:Vector2->Vector2; inline):
+ func times(a,b:Vector2->Vector2; inline)
return Vector2(a.x*b.x, a.y*b.y)
- func negative(v:Vector2->Vector2; inline):
+ func negative(v:Vector2->Vector2; inline)
return Vector2(-v.x, -v.y)
- func dot(a,b:Vector2->Num32; inline):
+ func dot(a,b:Vector2->Num32; inline)
return ((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y))
- func cross(a,b:Vector2->Num32; inline):
+ func cross(a,b:Vector2->Num32; inline)
return a.x*b.y - a.y*b.x
- func scaled_by(v:Vector2, k:Num32->Vector2; inline):
+ func scaled_by(v:Vector2, k:Num32->Vector2; inline)
return Vector2(v.x*k, v.y*k)
- func divided_by(v:Vector2, divisor:Num32->Vector2; inline):
+ func divided_by(v:Vector2, divisor:Num32->Vector2; inline)
return Vector2(v.x/divisor, v.y/divisor)
- func length(v:Vector2->Num32; inline):
+ func length(v:Vector2->Num32; inline)
return (v.x*v.x + v.y*v.y).sqrt()
- func dist(a,b:Vector2->Num32; inline):
+ func dist(a,b:Vector2->Num32; inline)
return a.minus(b).length()
- func angle(v:Vector2->Num32; inline):
+ func angle(v:Vector2->Num32; inline)
return Num32.atan2(v.y, v.x)
- func norm(v:Vector2->Vector2; inline):
- if v.x == 0 and v.y == 0:
+ func norm(v:Vector2->Vector2; inline)
+ if v.x == 0 and v.y == 0
return v
len := v.length()
return Vector2(v.x/len, v.y/len)
- func rotated(v:Vector2, radians:Num32 -> Vector2):
+ func rotated(v:Vector2, radians:Num32 -> Vector2)
cos := radians.cos() or return v
sin := radians.sin() or return v
return Vector2(cos*v.x - sin*v.y, sin*v.x + cos*v.y)
- func mix(a,b:Vector2, amount:Num32 -> Vector2):
+ func mix(a,b:Vector2, amount:Num32 -> Vector2)
return Vector2(
amount.mix(a.x, b.x),
amount.mix(a.y, b.y),
diff --git a/examples/game/world.tm b/examples/game/world.tm
index e8255ab8..0de8ea4b 100644
--- a/examples/game/world.tm
+++ b/examples/game/world.tm
@@ -5,7 +5,7 @@ use ./raylib.tm
use ./box.tm
# Return a displacement relative to `a` that will push it out of `b`
-func solve_overlap(a_pos:Vector2, a_size:Vector2, b_pos:Vector2, b_size:Vector2 -> Vector2):
+func solve_overlap(a_pos:Vector2, a_size:Vector2, b_pos:Vector2, b_size:Vector2 -> Vector2)
a_left := a_pos.x
a_right := a_pos.x + a_size.x
a_top := a_pos.y
@@ -21,68 +21,68 @@ func solve_overlap(a_pos:Vector2, a_size:Vector2, b_pos:Vector2, b_size:Vector2
overlap_y := (a_bottom _min_ b_bottom) - (a_top _max_ b_top)
# If either axis is not overlapping, then there is no collision:
- if overlap_x <= 0 or overlap_y <= 0:
+ if overlap_x <= 0 or overlap_y <= 0
return Vector2(0, 0)
- if overlap_x < overlap_y:
- if a_right > b_left and a_right < b_right:
+ if overlap_x < overlap_y
+ if a_right > b_left and a_right < b_right
return Vector2(-(overlap_x), 0)
- else if a_left < b_right and a_left > b_left:
+ else if a_left < b_right and a_left > b_left
return Vector2(overlap_x, 0)
- else:
- if a_top < b_bottom and a_top > b_top:
+ else
+ if a_top < b_bottom and a_top > b_top
return Vector2(0, overlap_y)
- else if a_bottom > b_top and a_bottom < b_bottom:
+ else if a_bottom > b_top and a_bottom < b_bottom
return Vector2(0, -overlap_y)
return Vector2(0, 0)
-struct World(player:@Player, goal:@Box, boxes:@[@Box], dt_accum=Num32(0.0), won=no):
+struct World(player:@Player, goal:@Box, boxes:@[@Box], dt_accum=Num32(0.0), won=no)
DT := (Num32(1.)/Num32(60.))
STIFFNESS := Num32(0.3)
- func update(w:@World, dt:Num32):
+ func update(w:@World, dt:Num32)
w.dt_accum += dt
- while w.dt_accum > 0:
+ while w.dt_accum > 0
w.update_once()
w.dt_accum -= World.DT
- func update_once(w:@World):
+ func update_once(w:@World)
w.player.update()
- if solve_overlap(w.player.pos, Player.SIZE, w.goal.pos, w.goal.size) != Vector2(0,0):
+ if solve_overlap(w.player.pos, Player.SIZE, w.goal.pos, w.goal.size) != Vector2(0,0)
w.won = yes
# Resolve player overlapping with any boxes:
- for i in 3:
- for b in w.boxes:
+ for i in 3
+ for b in w.boxes
w.player.pos += World.STIFFNESS * solve_overlap(w.player.pos, Player.SIZE, b.pos, b.size)
- func draw(w:@World):
- for b in w.boxes:
+ func draw(w:@World)
+ for b in w.boxes
b.draw()
w.goal.draw()
w.player.draw()
- if w.won:
+ if w.won
DrawText(CString("WINNER"), GetScreenWidth()/Int32(2)-Int32(48*3), GetScreenHeight()/Int32(2)-Int32(24), 48, Color(0,0,0))
- func load_map(w:@World, map:Text):
- if map.has("[]"):
+ func load_map(w:@World, map:Text)
+ if map.has("[]")
map = map.translate({"[]"="#", "@ "="@", " "=" "})
w.boxes = @[]
box_size := Vector2(50., 50.)
- for y,line in map.lines():
- for x,cell in line.split():
- if cell == "#":
+ for y,line in map.lines()
+ for x,cell in line.split()
+ if cell == "#"
pos := Vector2((Num32(x)-1) * box_size.x, (Num32(y)-1) * box_size.y)
box := @Box(pos, size=box_size, color=Color(0x80,0x80,0x80))
w.boxes.insert(box)
- else if cell == "@":
+ else if cell == "@"
pos := Vector2((Num32(x)-1) * box_size.x, (Num32(y)-1) * box_size.y)
pos += box_size/Num32(2) - Player.SIZE/Num32(2)
w.player = @Player(pos,pos)
- else if cell == "?":
+ else if cell == "?"
pos := Vector2((Num32(x)-1) * box_size.x, (Num32(y)-1) * box_size.y)
w.goal.pos = pos