mmo-project/lisp/client/racket/client.rkt

51 lines
1.5 KiB
Racket

#!/usr/bin/env racket
#lang racket/base
(module+ main
(require raylib/generated/unsafe)
(define (sync-camera camera camera_pos target_pos)
(set-Camera3D-target! camera target_pos)
(set-Vector3-x! camera_pos (Vector3-x target_pos))
(set-Vector3-y! camera_pos (+ (Vector3-y target_pos) 10.0))
(set-Vector3-z! camera_pos (+ (Vector3-z target_pos) 10.0))
(set-Camera3D-position! camera camera_pos))
(define (move-user camera pos scale)
(when (IsKeyDown KEY_RIGHT)
(set-Vector3-x! pos (+ (Vector3-x (Camera3D-target camera)) scale)))
(when (IsKeyDown KEY_LEFT)
(set-Vector3-x! pos (- (Vector3-x (Camera3D-target camera)) scale)))
(when (IsKeyDown KEY_UP)
(set-Vector3-z! pos (- (Vector3-z (Camera3D-target camera)) scale)))
(when (IsKeyDown KEY_DOWN)
(set-Vector3-z! pos (+ (Vector3-z (Camera3D-target camera)) scale))))
(InitWindow 800 450 "racket lisp client : raylib")
(define camera_pos (make-Vector3 0.0 12.0 14.0))
(define target_pos (make-Vector3 0.0 2.0 0.0))
(define camera (make-Camera3D camera_pos target_pos (make-Vector3 0.0 1.0 0.0) 60.0 CAMERA_PERSPECTIVE))
(SetTargetFPS 60)
(let loop ()
(when (not (WindowShouldClose))
(BeginDrawing)
(ClearBackground RAYWHITE)
(move-user camera target_pos 0.2)
(sync-camera camera camera_pos target_pos)
(BeginMode3D camera)
(DrawGrid 30 1.0)
(DrawCube (Camera3D-target camera) 0.5 0.5 0.5 PURPLE)
(EndMode3D)
(EndDrawing)
(loop)))
(CloseWindow))