|
|
@ -84,6 +84,9 @@ |
|
|
|
(bundle-file s-start-fireball-spritesheet s-end-fireball-spritesheet |
|
|
|
(unsigned char) "/home/macoy/Documents/fireball.bmp") |
|
|
|
|
|
|
|
(bundle-file s-start-smoke-explosion-spritesheet s-end-smoke-explosion-spritesheet |
|
|
|
(unsigned char) "/home/macoy/Documents/smokeExplosion.bmp") |
|
|
|
|
|
|
|
(defstruct-local spritesheet |
|
|
|
texture (* SDL_Texture) |
|
|
|
width uint16_t |
|
|
@ -110,7 +113,10 @@ |
|
|
|
(addr anim-wizard-idle))) |
|
|
|
(var anim-wizard-fast-attack animation (array 7 13 SDL_FLIP_HORIZONTAL |
|
|
|
(addr anim-wizard-idle))) |
|
|
|
(var wizard-fast-attack-effect-frame int 11) |
|
|
|
(var anim-wizard-jump-in animation (array 7 13 SDL_FLIP_HORIZONTAL |
|
|
|
(addr anim-wizard-idle))) |
|
|
|
;; (var wizard-attack-effect-frame int 10) |
|
|
|
(var wizard-attack-effect-frame int 28) |
|
|
|
|
|
|
|
(var spritesheet-boar spritesheet (array null |
|
|
|
1434 1068 |
|
|
@ -130,6 +136,13 @@ |
|
|
|
(var anim-fireball-idle animation (array 0 2 SDL_FLIP_NONE |
|
|
|
null)) |
|
|
|
|
|
|
|
(var spritesheet-smoke-explosion spritesheet (array null |
|
|
|
630 116 |
|
|
|
5 1 |
|
|
|
2)) |
|
|
|
(var anim-smoke-explosion-idle animation (array 0 4 SDL_FLIP_NONE |
|
|
|
null)) |
|
|
|
|
|
|
|
(var c-animation-frame-rate (const float) 0.1f) |
|
|
|
|
|
|
|
;; Returns whether the next animation should be started instead |
|
|
@ -195,7 +208,7 @@ |
|
|
|
(sdl-print-error))) |
|
|
|
|
|
|
|
(defstruct-local effect |
|
|
|
sprite (* spritesheet) |
|
|
|
sprite (* spritesheet) ;; null = empty slot |
|
|
|
anim (* (const animation)) |
|
|
|
animation-start-ticks Uint64 |
|
|
|
x int |
|
|
@ -205,11 +218,31 @@ |
|
|
|
|
|
|
|
(var s-effects ([] 16 effect) (array 0)) |
|
|
|
|
|
|
|
(defun-local update-effects (renderer (* SDL_Renderer)) |
|
|
|
(defstruct-local enemy |
|
|
|
x int |
|
|
|
y int |
|
|
|
anim (* (const animation)) |
|
|
|
animation-start-ticks Uint64) |
|
|
|
|
|
|
|
(defun-local update-effects (renderer (* SDL_Renderer) |
|
|
|
boar (* enemy)) |
|
|
|
(each-in-array s-effects i |
|
|
|
(var current-effect (* effect) (addr (at i s-effects))) |
|
|
|
(unless (path current-effect > sprite) |
|
|
|
(continue)) |
|
|
|
|
|
|
|
(when (= (path current-effect > anim) (addr anim-smoke-explosion-idle)) |
|
|
|
(var num-frames int (- (+ 1 (path current-effect > anim > end-frame-index)) ;; TODO: Off by one? |
|
|
|
(path current-effect > anim > start-frame-index))) |
|
|
|
(var loop-rate float (* c-animation-frame-rate num-frames)) |
|
|
|
(var animation-time-seconds float |
|
|
|
(/ (- (SDL_GetPerformanceCounter) (path current-effect > animation-start-ticks)) |
|
|
|
(type-cast (SDL_GetPerformanceFrequency) float))) |
|
|
|
|
|
|
|
(when (> animation-time-seconds loop-rate) |
|
|
|
(set (path current-effect > sprite) null) |
|
|
|
(continue))) |
|
|
|
|
|
|
|
;; TODO: Frame independence |
|
|
|
(set (path current-effect > x) (+ (path current-effect > x) (path current-effect > velocity-x))) |
|
|
|
(set (path current-effect > y) (+ (path current-effect > y) (path current-effect > velocity-y))) |
|
|
@ -219,8 +252,17 @@ |
|
|
|
c-animation-frame-rate |
|
|
|
(path current-effect > x) (path current-effect > y)) |
|
|
|
|
|
|
|
(when (> (path current-effect > x) 3000) |
|
|
|
(set (path current-effect > sprite) null)))) |
|
|
|
(when (and (> (path current-effect > x) (path boar > x)) |
|
|
|
(!= (path current-effect > anim) (addr anim-smoke-explosion-idle))) |
|
|
|
(set (path current-effect > sprite) (addr spritesheet-smoke-explosion)) |
|
|
|
(set (path current-effect > velocity-x) 0) |
|
|
|
(set (path current-effect > velocity-y) 0) |
|
|
|
(set (path current-effect > y) (- (path current-effect > y) 75)) |
|
|
|
(set (path current-effect > anim) (addr anim-smoke-explosion-idle)) |
|
|
|
(set (path current-effect > animation-start-ticks) (SDL_GetPerformanceCounter)) |
|
|
|
(unless (= (path boar > anim) (addr anim-boar-damage)) |
|
|
|
(set (path boar > anim) (addr anim-boar-damage)) |
|
|
|
(set (path boar > animation-start-ticks) (SDL_GetPerformanceCounter)))))) |
|
|
|
|
|
|
|
(defun-local get-free-effect (&return (* effect)) |
|
|
|
(each-in-array s-effects i |
|
|
@ -429,6 +471,13 @@ |
|
|
|
(defer (SDL_DestroyTexture fireball-texture)) |
|
|
|
(set (field spritesheet-fireball texture) fireball-texture) |
|
|
|
|
|
|
|
(var smoke-explosion-texture (* SDL_Texture) |
|
|
|
(sdl-texture-from-bmp-data renderer s-start-smoke-explosion-spritesheet s-end-smoke-explosion-spritesheet)) |
|
|
|
(unless smoke-explosion-texture |
|
|
|
(return 1)) |
|
|
|
(defer (SDL_DestroyTexture smoke-explosion-texture)) |
|
|
|
(set (field spritesheet-smoke-explosion texture) smoke-explosion-texture) |
|
|
|
|
|
|
|
(var ground-texture (* SDL_Texture) |
|
|
|
(sdl-texture-from-bmp-data renderer s-start-ground-bmp s-end-ground-bmp)) |
|
|
|
(unless ground-texture |
|
|
@ -468,9 +517,9 @@ |
|
|
|
(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 current-wizard-animation (* (const animation)) (addr anim-wizard-jump-in)) |
|
|
|
(var boar-enemy enemy (array 0)) |
|
|
|
(set (field boar-enemy anim) (addr anim-boar-jump-in)) |
|
|
|
(var should-render-wizard bool false) |
|
|
|
(var should-render-boar bool false) |
|
|
|
(var should-render-ground bool false) |
|
|
@ -513,11 +562,11 @@ |
|
|
|
(cond |
|
|
|
((= 0 (strcmp (path current-slide > trigger) "enter-wizard")) |
|
|
|
(set wizard-animation-start-ticks (SDL_GetPerformanceCounter)) |
|
|
|
(set current-wizard-animation (addr anim-wizard-attack)) |
|
|
|
(set current-wizard-animation (addr anim-wizard-jump-in)) |
|
|
|
(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 (field boar-enemy animation-start-ticks) (SDL_GetPerformanceCounter)) |
|
|
|
(set (field boar-enemy anim) (addr anim-boar-jump-in)) |
|
|
|
(set should-render-boar true)) |
|
|
|
((= 0 (strcmp (path current-slide > trigger) "show-ground")) |
|
|
|
(set should-render-ground true)) |
|
|
@ -534,22 +583,22 @@ |
|
|
|
(var wizard-y int (- window-height (/ ground-height 2) wizard-ground-height)) |
|
|
|
|
|
|
|
(when (and |
|
|
|
(!= current-wizard-animation (addr anim-wizard-fast-attack)) |
|
|
|
(!= current-wizard-animation (addr anim-wizard-attack)) |
|
|
|
(keybind-tapped (addr s-attack-keybind) (addr s-key-states))) |
|
|
|
(set wizard-animation-start-ticks (SDL_GetPerformanceCounter)) |
|
|
|
(set current-wizard-animation (addr anim-wizard-fast-attack)) |
|
|
|
(set boar-animation-start-ticks (SDL_GetPerformanceCounter)) |
|
|
|
(set current-boar-animation (addr anim-boar-jump-in)) |
|
|
|
(set current-wizard-animation (addr anim-wizard-attack)) |
|
|
|
;; (set (field boar-enemy animation-start-ticks) (SDL_GetPerformanceCounter)) |
|
|
|
;; (set (field boar-enemy anim) (addr anim-boar-jump-in)) |
|
|
|
(set queued-effect effect-id-fireball)) |
|
|
|
|
|
|
|
(when (and (= current-wizard-animation (addr anim-wizard-fast-attack)) |
|
|
|
(when (and (= current-wizard-animation (addr anim-wizard-attack)) |
|
|
|
(= queued-effect effect-id-fireball)) |
|
|
|
(var current-frame int 0) |
|
|
|
(var current-anim (* (const animation)) current-wizard-animation) |
|
|
|
(when (or (not (animation-get-current-frame current-anim |
|
|
|
wizard-animation-start-ticks c-animation-frame-rate |
|
|
|
(addr current-frame))) |
|
|
|
(= current-frame wizard-fast-attack-effect-frame)) |
|
|
|
(= current-frame wizard-attack-effect-frame)) |
|
|
|
(var new-effect (* effect) (get-free-effect)) |
|
|
|
(set (path new-effect > sprite) (addr spritesheet-fireball)) |
|
|
|
(set (path new-effect > anim) (addr anim-fireball-idle)) |
|
|
@ -640,16 +689,19 @@ |
|
|
|
wizard-animation-start-ticks c-animation-frame-rate |
|
|
|
wizard-x wizard-y)) |
|
|
|
|
|
|
|
(set (field boar-enemy x) (type-cast (* window-width 0.70f) int)) |
|
|
|
(set (field boar-enemy y) (- window-height (/ ground-height 2) boar-ground-height)) |
|
|
|
|
|
|
|
(when should-render-boar |
|
|
|
(unless boar-animation-start-ticks |
|
|
|
(set boar-animation-start-ticks (SDL_GetPerformanceCounter))) |
|
|
|
(unless (field boar-enemy animation-start-ticks) |
|
|
|
(set (field boar-enemy 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) |
|
|
|
(- window-height (/ ground-height 2) boar-ground-height))) |
|
|
|
renderer (addr spritesheet-boar) (addr (field boar-enemy anim)) |
|
|
|
(field boar-enemy animation-start-ticks) c-animation-frame-rate |
|
|
|
(field boar-enemy x) |
|
|
|
(field boar-enemy y))) |
|
|
|
|
|
|
|
(update-effects renderer) |
|
|
|
(update-effects renderer (addr boar-enemy)) |
|
|
|
|
|
|
|
(when s-enable-debug-overlay |
|
|
|
(var buffer ([] 256 char) (array 0)) |
|
|
|