Browse Source

Auto-calculate board size

I updated GameLib for vec-xy
master
Macoy Madson 3 years ago
parent
commit
1fa8522639
  1. 2
      Dependencies/gamelib
  2. BIN
      assets/Board.xcf
  3. BIN
      data/Board.bmp
  4. 46
      src/Main.cake

2
Dependencies/gamelib

@ -1 +1 @@
Subproject commit c3e921f9da474708a0f361ab5c8982f04297b155
Subproject commit 81db0329e93f8ef802a6c162e731d63c50d7ee10

BIN
assets/Board.xcf

Binary file not shown.

BIN
data/Board.bmp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 MiB

After

Width:  |  Height:  |  Size: 9.6 MiB

46
src/Main.cake

@ -6,13 +6,31 @@
;; (add-cakelisp-search-directory "Dependencies/gamelib/Dependencies/cakelisp/runtime")
(add-cakelisp-search-directory "src")
(import "SDL.cake")
(import "SDL.cake" "Math.cake")
(c-import "<stdio.h>"
"SDL.h" "SDL_syswm.h" "SDL_timer.h" "SDL_render.h")
(var g-window-width int 1080)
(var g-window-height int 2340)
;; Made for OnePlus 6T screen
(var g-window-width (const int) 1080)
(var g-window-height (const int) 2340)
(var g-window-safe-area-margin-px (const int) 40)
;; Game board
;; Note that these assume portrait aspect ratio by basing the size on the smaller dimension
(var g-game-board-outer-size-px (const int) (- g-window-width (* 2 g-window-safe-area-margin-px)))
(var g-game-board-outer-top-left-px (const vec2)
(array g-window-safe-area-margin-px (/ (- g-window-height g-game-board-outer-size-px) 2)))
(var g-game-board-grid-size (const int) 6)
;; Use the nearest even pixel for pixel-perfect game board
(var g-game-board-margin-px (const int)
(/ (% g-game-board-outer-size-px g-game-board-grid-size) 2))
;; With margins of 2px, that becomes 996, or 166 pixels per column
(var g-game-board-cell-size-px (const int)
(/ (- g-game-board-outer-size-px g-game-board-margin-px) g-game-board-grid-size))
(var g-game-board-inner-top-left-px (const vec2)
(array (+ (vec-x g-game-board-outer-top-left-px) g-game-board-margin-px)
(+ (vec-y g-game-board-outer-top-left-px) g-game-board-margin-px)))
(define-constant DATA_DIR "data/")
@ -54,13 +72,33 @@
(return true))
(defun main (&return int)
(printf "Kitty Gridlock\n
(printf "Kitty Gridlock\n\n
Created by Macoy Madson <macoy@macoy.me>.\n
https://macoy.me/code/macoy/kitty-gridlock\n
Copyright (c) 2021 Macoy Madson.\n
Licensed under GPL-3.0-or-later.\n
Rush Hour database from Michael Fogleman.\n\n")
(printf "Window and board dimensions:\n
\twindow width: %d\n
\twindow height: %d\n
\twindow safe area margin px: %d\n
\tgame board outer size px: %d\n
\tgame board outer top left px: %.2f %.2f\n
\tgame board grid size: %d\n
\tgame board margin px: %d\n
\tgame board cell size px: %d\n
\tgame board inner top left px: %.2f %.2f\n\n"
g-window-width
g-window-height
g-window-safe-area-margin-px
g-game-board-outer-size-px
(vec-xy g-game-board-outer-top-left-px)
g-game-board-grid-size
g-game-board-margin-px
g-game-board-cell-size-px
(vec-xy g-game-board-inner-top-left-px))
;;
;; Initialization
;;

Loading…
Cancel
Save