Browse Source

Add ground

master
Macoy Madson 1 year ago
parent
commit
69b2b9b621
  1. 2
      data/DrivingCodeWithData.cakedata
  2. 49
      src/Presentation.cake

2
data/DrivingCodeWithData.cakedata

@ -2,7 +2,7 @@
:slides
(array
(slide-data :heading "Driving code with data" :body "Macoy Madson")
(slide-data :heading "Setting the stage")
(slide-data :heading "Setting the stage" :trigger "show-ground")
(slide-data :heading "Setting the stage" :trigger "enter-wizard")
(slide-data :heading "Setting the stage" :trigger "enter-boar")
(slide-data :heading "Setting the stage"

49
src/Presentation.cake

@ -78,6 +78,9 @@
(bundle-file s-start-boar-spritesheet s-end-boar-spritesheet
(unsigned char) "/home/macoy/Documents/boar.bmp")
(bundle-file s-start-ground-bmp s-end-ground-bmp
(unsigned char) "/home/macoy/Documents/Ground.bmp")
(defstruct-local spritesheet
texture (* SDL_Texture)
width uint16_t
@ -357,6 +360,12 @@
(set (field spritesheet-wizard texture) wizard-texture)
(set (field spritesheet-boar texture) boar-texture)
(var ground-texture (* SDL_Texture)
(sdl-texture-from-bmp-data renderer s-start-ground-bmp s-end-ground-bmp))
(unless ground-texture
(return 1))
(defer (SDL_DestroyTexture ground-texture))
;; current-key-states is owned by SDL, but we own last-frame-states
(defer (dynarray-free (field s-key-states last-frame-states)))
@ -382,12 +391,20 @@
(var current-slide-index int 0)
(var slide-start-ticks Uint64 0)
(var ground-width int 1359)
(var ground-height int 450)
;; (var wizard-height int 106) ;; Unused
;; (var boar-height int 178)
(var wizard-ground-height int 80)
(var boar-ground-height int 220)
(var wizard-animation-start-ticks Uint64 0)
(var boar-animation-start-ticks Uint64 0)
(var current-wizard-animation (* (const animation)) (addr anim-wizard-attack))
(var current-boar-animation (* (const animation)) (addr anim-boar-jump-in))
(var render-wizard bool false)
(var render-boar bool false)
(var should-render-wizard bool false)
(var should-render-boar bool false)
(var should-render-ground bool false)
(var exit-reason (* (const char)) null)
(while true
@ -426,11 +443,13 @@
((= 0 (strcmp (path current-slide > trigger) "enter-wizard"))
(set wizard-animation-start-ticks (SDL_GetPerformanceCounter))
(set current-wizard-animation (addr anim-wizard-attack))
(set render-wizard true))
(set should-render-wizard true))
((= 0 (strcmp (path current-slide > trigger) "enter-boar"))
(set boar-animation-start-ticks (SDL_GetPerformanceCounter))
(set current-boar-animation (addr anim-boar-jump-in))
(set render-boar true))
(set should-render-boar true))
((= 0 (strcmp (path current-slide > trigger) "show-ground"))
(set should-render-ground true))
(true
(preslog "Unrecognized trigger: %s" (path current-slide > trigger))))))
@ -519,23 +538,37 @@
;; return 1;
;; }#"#)
(when render-wizard
(when should-render-ground
(var source-rectangle SDL_Rect
(array 0 0
ground-width
ground-height))
(var destination-rectangle SDL_Rect
(array 0 (- window-height ground-height)
window-width
ground-height))
(unless (= 0 (SDL_RenderCopy renderer ground-texture
(addr source-rectangle) (addr destination-rectangle)))
(sdl-print-error)
(set exit-reason "SDL failed to render ground")))
(when should-render-wizard
(unless wizard-animation-start-ticks
(set wizard-animation-start-ticks (SDL_GetPerformanceCounter)))
(render-animation
renderer (addr spritesheet-wizard) (addr current-wizard-animation)
wizard-animation-start-ticks c-animation-frame-rate
(type-cast (* window-width 0.08f) int)
(type-cast (* window-height 0.77f) int)))
(- window-height (/ ground-height 2) wizard-ground-height)))
(when render-boar
(when should-render-boar
(unless boar-animation-start-ticks
(set boar-animation-start-ticks (SDL_GetPerformanceCounter)))
(render-animation
renderer (addr spritesheet-boar) (addr current-boar-animation)
boar-animation-start-ticks c-animation-frame-rate
(type-cast (* window-width 0.70f) int)
(type-cast (* window-height 0.63f) int)))
(- window-height (/ ground-height 2) boar-ground-height)))
(SDL_RenderPresent renderer)
(SDL_UpdateWindowSurface window)

Loading…
Cancel
Save