aboutsummaryrefslogtreecommitdiff
path: root/examples/game/player.tm
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-09-01 17:39:20 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-09-01 17:39:20 -0400
commit2538b1b7461f9b06d6a6f43acd5609d916b1addc (patch)
tree061efdfc54351b1c644f1422e4f2c00bfefb1235 /examples/game/player.tm
parentd6d3f5711de85ab1c21f515b9d125d316d853c92 (diff)
parentadc2d81b5683e611c5f3289be6157d4519a60632 (diff)
Merge branch 'main' into formatter
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)