diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-11 17:49:04 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-11 17:49:04 -0400 |
| commit | 1f6e586b2a3fe7f8ca32ce95659032bafef0ad24 (patch) | |
| tree | 49b6633bf0693952153f12e8ed4dce1dae1443cc /examples/game/player.tm | |
| parent | fb2d7b5379663e929ffabfbd8428de5b35ad67c4 (diff) | |
Support external structs with namespaced methods (also C-strings are now
`const char*` instead of `char*`)
Diffstat (limited to 'examples/game/player.tm')
| -rw-r--r-- | examples/game/player.tm | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/examples/game/player.tm b/examples/game/player.tm index a5c39a8d..dac2508a 100644 --- a/examples/game/player.tm +++ b/examples/game/player.tm @@ -1,25 +1,22 @@ # Defines a struct representing the player, which is controlled by WASD keys -use libraylib.so -use <raylib.h> -use <raymath.h> - -use vectors use ./world.tm +use ./raylib.tm -struct Player(pos,prev_pos:Vec2): - WALK_SPEED := 500. - ACCEL := 0.3 - FRICTION := 0.99 - SIZE := Vec2(30, 30) +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 := inline C:Num { - (Num_t)((IsKeyDown(KEY_A) ? -1 : 0) + (IsKeyDown(KEY_D) ? 1 : 0)) + target_x := inline C:Num32 { + (Num32_t)((IsKeyDown(KEY_A) ? -1 : 0) + (IsKeyDown(KEY_D) ? 1 : 0)) } - target_y := inline C:Num { - (Num_t)((IsKeyDown(KEY_W) ? -1 : 0) + (IsKeyDown(KEY_S) ? 1 : 0)) + target_y := inline C:Num32 { + (Num32_t)((IsKeyDown(KEY_W) ? -1 : 0) + (IsKeyDown(KEY_S) ? 1 : 0)) } - target_vel := Vec2(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 @@ -28,4 +25,4 @@ struct Player(pos,prev_pos:Vec2): p.prev_pos, p.pos = p.pos, p.pos + World.DT*vel func draw(p:Player): - Color.PLAYER:draw_rectangle(p.pos, Player.SIZE) + DrawRectangleRec(Rectangle(p.pos.x, p.pos.y, Player.SIZE.x, Player.SIZE.y), Player.COLOR) |
