diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-09-01 17:37:24 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-09-01 17:37:24 -0400 |
| commit | 12345a85d9c7d7a56ddf323247a4bdf347021b73 (patch) | |
| tree | 93bafb42c1ec2c22cc2858936034901c39cbca82 /examples/game/player.tm | |
| parent | c778c8822f1c8acf981e26f7b860a384c94cff6f (diff) | |
| parent | adc2d81b5683e611c5f3289be6157d4519a60632 (diff) | |
Merge branch 'main' into optional-list-indexing
Diffstat (limited to 'examples/game/player.tm')
| -rw-r--r-- | examples/game/player.tm | 28 |
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) |
