Browse Source

Add boar

master
Macoy Madson 5 months ago
parent
commit
0134537e12
  1. 68
      src/Presentation.cake

68
src/Presentation.cake

@ -63,6 +63,8 @@
(bundle-file s-start-wizard-spritesheet s-end-wizard-spritesheet
(unsigned char) "/home/macoy/Documents/wizard.bmp")
(bundle-file s-start-boar-spritesheet s-end-boar-spritesheet
(unsigned char) "/home/macoy/Documents/boar.bmp")
;;
;; Text rendering
@ -145,6 +147,24 @@
(return false)))
(return true))
(defun-local sdl-texture-from-bmp-data (renderer (* SDL_Renderer)
data-start (* (unsigned char))
data-end (* (unsigned char))
&return (* SDL_Texture))
(var surface (* SDL_Surface)
(SDL_LoadBMP_RW (SDL_RWFromMem data-start (- data-end data-start))
;; freesrc (free the RWOps)
1))
(unless surface
(sdl-print-error)
(return null))
(defer (SDL_FreeSurface surface))
(var texture (* SDL_Texture) (SDL_CreateTextureFromSurface renderer surface))
(unless texture
(sdl-print-error)
(return null))
(return texture))
;;
;; Main
;;
@ -197,23 +217,22 @@
code-font-size-points)
(return 1))
(var wizard-texture (* SDL_Texture) null)
(scope
(var wizard-surface (* SDL_Surface)
(SDL_LoadBMP_RW (SDL_RWFromMem s-start-wizard-spritesheet
(- s-end-wizard-spritesheet s-start-wizard-spritesheet))
;; freesrc (free the RWOps)
1))
(unless wizard-surface
(sdl-print-error)
(return 1))
(defer (SDL_FreeSurface wizard-surface))
(set wizard-texture (SDL_CreateTextureFromSurface renderer wizard-surface))
(unless wizard-texture
(sdl-print-error)
(return 1)))
(var wizard-width int 161)
(var wizard-height int 106)
(var wizard-texture (* SDL_Texture)
(sdl-texture-from-bmp-data renderer s-start-wizard-spritesheet s-end-wizard-spritesheet))
(unless wizard-texture
(return 1))
(defer (SDL_DestroyTexture wizard-texture))
(var boar-width int 239)
(var boar-height int 178)
(var boar-texture (* SDL_Texture)
(sdl-texture-from-bmp-data renderer s-start-boar-spritesheet s-end-boar-spritesheet))
(unless boar-texture
(return 1))
(defer (SDL_DestroyTexture boar-texture))
;; current-key-states is owned by SDL, but we own last-frame-states
(defer (dynarray-free (field s-key-states last-frame-states)))
@ -336,8 +355,6 @@
;; return 1;
;; }#"#)
(var wizard-width int 161)
(var wizard-height int 106)
(var animation-time-seconds float
(/ (- (SDL_GetPerformanceCounter) animation-start-ticks)
(type-cast (SDL_GetPerformanceFrequency) float)))
@ -366,6 +383,23 @@
(sdl-print-error)
(set exit-reason "SDL failed to render wizard")))
(when (> current-slide-index 0)
(var source-rectangle SDL_Rect
(array (* current-frame boar-width) 0
boar-width
boar-height))
(var destination-rectangle SDL_Rect
(array (type-cast (* window-width 0.70f) int)
(type-cast (* window-height 0.63f) int)
(* 2 boar-width)
(* 2 boar-height)))
(unless (= 0 (SDL_RenderCopyEx renderer boar-texture
(addr source-rectangle) (addr destination-rectangle)
0.f null ;; no rotation
SDL_FLIP_HORIZONTAL))
(sdl-print-error)
(set exit-reason "SDL failed to render boar")))
(SDL_RenderPresent renderer)
(SDL_UpdateWindowSurface window)

Loading…
Cancel
Save