aboutsummaryrefslogtreecommitdiff
path: root/examples/game
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-06 14:20:18 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-06 14:20:18 -0400
commit2bb2ff871fa1761478442bec5f6a32c9428360a1 (patch)
tree9b73df7a0c50c02353ae7bca7c2cd54788ef0077 /examples/game
parent59845e610f2c90474f34079d27b5f1e07071ded4 (diff)
Change method calls to use `foo.baz()` instead of `foo:baz()`
Diffstat (limited to 'examples/game')
-rw-r--r--examples/game/game.tm8
-rw-r--r--examples/game/player.tm4
-rw-r--r--examples/game/raylib.tm42
-rw-r--r--examples/game/world.tm20
4 files changed, 37 insertions, 37 deletions
diff --git a/examples/game/game.tm b/examples/game/game.tm
index 36ef14ff..ce08c329 100644
--- a/examples/game/game.tm
+++ b/examples/game/game.tm
@@ -5,24 +5,24 @@ use ./world.tm
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")
+ map_contents := map.read() or exit("Could not find the game map: $map")
world := @World(
player=@Player(Vector2(0,0), Vector2(0,0)),
goal=@Box(Vector2(0,0), Vector2(50,50), color=Color(0x10,0xa0,0x10)),
boxes=@[],
)
- world:load_map(map_contents)
+ world.load_map(map_contents)
SetTargetFPS(60)
while not WindowShouldClose():
dt := GetFrameTime()
- world:update(dt)
+ world.update(dt)
BeginDrawing()
ClearBackground(Color(0xCC, 0xCC, 0xCC, 0xFF))
- world:draw()
+ world.draw()
EndDrawing()
CloseWindow()
diff --git a/examples/game/player.tm b/examples/game/player.tm
index f73dcf6a..7f14f51e 100644
--- a/examples/game/player.tm
+++ b/examples/game/player.tm
@@ -16,11 +16,11 @@ struct Player(pos,prev_pos:Vector2):
target_y := inline C:Num32 {
(Num32_t)((IsKeyDown(KEY_W) ? -1 : 0) + (IsKeyDown(KEY_S) ? 1 : 0))
}
- target_vel := Vector2(target_x, target_y):norm() * Player.WALK_SPEED
+ target_vel := Vector2(target_x, target_y).norm() * Player.WALK_SPEED
vel := (p.pos - p.prev_pos)/World.DT
vel *= Player.FRICTION
- vel = vel:mix(target_vel, Player.ACCEL)
+ vel = vel.mix(target_vel, Player.ACCEL)
p.prev_pos, p.pos = p.pos, p.pos + World.DT*vel
diff --git a/examples/game/raylib.tm b/examples/game/raylib.tm
index ad248e4f..5e58e996 100644
--- a/examples/game/raylib.tm
+++ b/examples/game/raylib.tm
@@ -27,37 +27,37 @@ struct Vector2(x,y:Num32; extern):
func divided_by(v:Vector2, divisor:Num32->Vector2; inline):
return Vector2(v.x/divisor, v.y/divisor)
func length(v:Vector2->Num32; inline):
- return (v.x*v.x + v.y*v.y):sqrt()
+ return (v.x*v.x + v.y*v.y).sqrt()
func dist(a,b:Vector2->Num32; inline):
- return a:minus(b):length()
+ return a.minus(b).length()
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:
return v
- len := v:length()
+ len := v.length()
return Vector2(v.x/len, v.y/len)
func rotated(v:Vector2, radians:Num32 -> Vector2):
- cos := radians:cos() or return v
- sin := radians:sin() or return v
+ 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):
return Vector2(
- amount:mix(a.x, b.x),
- amount:mix(a.y, b.y),
+ amount.mix(a.x, b.x),
+ amount.mix(a.y, b.y),
)
-extern InitWindow:func(width:Int32, height:Int32, title:CString)
-extern SetTargetFPS:func(fps:Int32)
-extern WindowShouldClose:func(->Bool)
-extern GetFrameTime:func(->Num32)
-extern BeginDrawing:func()
-extern EndDrawing:func()
-extern CloseWindow:func()
-extern ClearBackground:func(color:Color)
-extern DrawRectangle:func(x,y,width,height:Int32, color:Color)
-extern DrawRectangleRec:func(rec:Rectangle, color:Color)
-extern DrawRectangleV:func(pos:Vector2, size:Vector2, color:Color)
-extern DrawText:func(text:CString, x,y:Int32, text_height:Int32, color:Color)
-extern GetScreenWidth:func(->Int32)
-extern GetScreenHeight:func(->Int32)
+extern InitWindow : func(width:Int32, height:Int32, title:CString)
+extern SetTargetFPS : func(fps:Int32)
+extern WindowShouldClose : func(->Bool)
+extern GetFrameTime : func(->Num32)
+extern BeginDrawing : func()
+extern EndDrawing : func()
+extern CloseWindow : func()
+extern ClearBackground : func(color:Color)
+extern DrawRectangle : func(x,y,width,height:Int32, color:Color)
+extern DrawRectangleRec : func(rec:Rectangle, color:Color)
+extern DrawRectangleV : func(pos:Vector2, size:Vector2, color:Color)
+extern DrawText : func(text:CString, x,y:Int32, text_height:Int32, color:Color)
+extern GetScreenWidth : func(->Int32)
+extern GetScreenHeight : func(->Int32)
diff --git a/examples/game/world.tm b/examples/game/world.tm
index 76acac6b..e8255ab8 100644
--- a/examples/game/world.tm
+++ b/examples/game/world.tm
@@ -44,11 +44,11 @@ struct World(player:@Player, goal:@Box, boxes:@[@Box], dt_accum=Num32(0.0), won=
func update(w:@World, dt:Num32):
w.dt_accum += dt
while w.dt_accum > 0:
- w:update_once()
+ w.update_once()
w.dt_accum -= World.DT
func update_once(w:@World):
- w.player:update()
+ w.player.update()
if solve_overlap(w.player.pos, Player.SIZE, w.goal.pos, w.goal.size) != Vector2(0,0):
w.won = yes
@@ -60,24 +60,24 @@ struct World(player:@Player, goal:@Box, boxes:@[@Box], dt_accum=Num32(0.0), won=
func draw(w:@World):
for b in w.boxes:
- b:draw()
- w.goal:draw()
- w.player:draw()
+ b.draw()
+ w.goal.draw()
+ w.player.draw()
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("[]"):
- map = map:translate({"[]"="#", "@ "="@", " "=" "})
+ 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():
+ 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)
+ w.boxes.insert(box)
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)