aboutsummaryrefslogtreecommitdiff
path: root/examples/game/player.tm
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-09-01 16:44:58 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-09-01 16:44:58 -0400
commited50c5fefb8892ad2ba5262491669f268ddbd436 (patch)
treee93a6a8b7e963c37a001691751d6845d10e0cbf8 /examples/game/player.tm
parent02a99d24a310c04622a875dcf4b0c6fd2de71332 (diff)
Overhaul code to stop keeping examples and libraries in the same repo,
but instead spin each out into its own repo.
Diffstat (limited to 'examples/game/player.tm')
-rw-r--r--examples/game/player.tm28
1 files changed, 0 insertions, 28 deletions
diff --git a/examples/game/player.tm b/examples/game/player.tm
deleted file mode 100644
index 2e5e54f6..00000000
--- a/examples/game/player.tm
+++ /dev/null
@@ -1,28 +0,0 @@
-# Defines a struct representing the player, which is controlled by WASD keys
-use ./world.tm
-use ./raylib.tm
-
-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)
- target_x := C_code:Num32(
- (Num32_t)((IsKeyDown(KEY_A) ? -1 : 0) + (IsKeyDown(KEY_D) ? 1 : 0))
- )
- target_y := C_code:Num32(
- (Num32_t)((IsKeyDown(KEY_W) ? -1 : 0) + (IsKeyDown(KEY_S) ? 1 : 0))
- )
- 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)
-
- p.prev_pos, p.pos = p.pos, p.pos + World.DT*vel
-
- func draw(p:Player)
- DrawRectangleV(p.pos, Player.SIZE, Player.COLOR)