|
|
@ -40,6 +40,17 @@ |
|
|
|
|
|
|
|
(define-keybind s-attack-keybind (array SDL_SCANCODE_1)) |
|
|
|
(define-keybind s-attack-2-keybind (array SDL_SCANCODE_2)) |
|
|
|
(define-keybind s-attack-3-keybind (array SDL_SCANCODE_3)) |
|
|
|
(define-keybind s-attack-4-keybind (array SDL_SCANCODE_4)) |
|
|
|
(define-keybind s-attack-5-keybind (array SDL_SCANCODE_5)) |
|
|
|
|
|
|
|
(defstruct-local power-keybind |
|
|
|
bind (* keybind) |
|
|
|
power-id (* (const char))) |
|
|
|
(var s-power-keybinds ([] power-keybind) |
|
|
|
(array |
|
|
|
(array (addr s-attack-2-keybind) "fireball") |
|
|
|
(array (addr s-attack-3-keybind) "iceStorm"))) |
|
|
|
|
|
|
|
(var s-key-states sdl-key-states (array 0)) |
|
|
|
|
|
|
@ -90,6 +101,12 @@ |
|
|
|
(bundle-file s-start-smoke-explosion-spritesheet s-end-smoke-explosion-spritesheet |
|
|
|
(unsigned char) "/home/macoy/Documents/smokeExplosion.bmp") |
|
|
|
|
|
|
|
(bundle-file s-start-explosion-spritesheet s-end-explosion-spritesheet |
|
|
|
(unsigned char) "/home/macoy/Documents/explosion.bmp") |
|
|
|
|
|
|
|
(bundle-file s-start-ice-explosion-spritesheet s-end-ice-explosion-spritesheet |
|
|
|
(unsigned char) "/home/macoy/Documents/iceExplosion.bmp") |
|
|
|
|
|
|
|
(forward-declare (struct SDL_Texture)) |
|
|
|
|
|
|
|
(def-introspect-struct spritesheet |
|
|
@ -136,6 +153,8 @@ |
|
|
|
(var spritesheet-smoke-explosion (* spritesheet) null) ;; Populated from data |
|
|
|
(var anim-smoke-explosion-idle animation (array 0 4 SDL_FLIP_NONE |
|
|
|
null)) |
|
|
|
(var spritesheet-explosion (* spritesheet) null) ;; Populated from data |
|
|
|
(var spritesheet-ice-explosion (* spritesheet) null) ;; Populated from data |
|
|
|
|
|
|
|
(var c-animation-frame-rate (const float) 0.1f) |
|
|
|
|
|
|
@ -207,7 +226,12 @@ |
|
|
|
|
|
|
|
(defenum operation-type |
|
|
|
operation-type-play-effect |
|
|
|
operation-type-expire-on-animation-end |
|
|
|
operation-type-damage |
|
|
|
operation-type-spawn-power |
|
|
|
|
|
|
|
operation-type-set-value |
|
|
|
|
|
|
|
operation-type-if-equals |
|
|
|
operation-type-if-string-equals |
|
|
|
operation-type-if-greater-than-or-equal |
|
|
@ -236,6 +260,15 @@ |
|
|
|
(array |
|
|
|
operation-type-play-effect |
|
|
|
"PlayEffect" 2) |
|
|
|
(array |
|
|
|
operation-type-expire-on-animation-end |
|
|
|
"Expire" 0) |
|
|
|
(array |
|
|
|
operation-type-damage |
|
|
|
"DamageEnemy" 0) |
|
|
|
(array |
|
|
|
operation-type-spawn-power |
|
|
|
"SpawnPower" 1) |
|
|
|
(array |
|
|
|
operation-type-set-value |
|
|
|
"SetValue" 2) |
|
|
@ -409,11 +442,17 @@ |
|
|
|
sprite (* spritesheet) ;; null = empty slot |
|
|
|
anim (* (const animation)) |
|
|
|
animation-start-ticks Uint64 |
|
|
|
life-start-ticks Uint64 |
|
|
|
num-frames-since-spawned int |
|
|
|
power-id (* (const char)) |
|
|
|
x int |
|
|
|
y int |
|
|
|
velocity-x int |
|
|
|
velocity-y int) |
|
|
|
velocity-y int |
|
|
|
relative-spawn-x int |
|
|
|
relative-spawn-y int |
|
|
|
expire-on-animation-end bool |
|
|
|
user-0 int) |
|
|
|
|
|
|
|
(var s-effects ([] 16 effect) (array 0)) |
|
|
|
|
|
|
@ -427,7 +466,10 @@ |
|
|
|
(var g-boar-enemy actor (array 0)) |
|
|
|
|
|
|
|
(defstruct-local power-context |
|
|
|
effect-data (* effect)) |
|
|
|
effect-data (* effect) |
|
|
|
;; If 0, spawn at the wizard |
|
|
|
start-x int |
|
|
|
start-y int) |
|
|
|
|
|
|
|
(defun-local update-effects (renderer (* SDL_Renderer) |
|
|
|
boar (* actor)) |
|
|
@ -436,19 +478,35 @@ |
|
|
|
(unless (path current-effect > sprite) |
|
|
|
(continue)) |
|
|
|
|
|
|
|
(unless (path current-effect > animation-start-ticks) |
|
|
|
(set (path current-effect > animation-start-ticks) (SDL_GetPerformanceCounter))) |
|
|
|
(unless (path current-effect > life-start-ticks) |
|
|
|
(set (path current-effect > life-start-ticks) (SDL_GetPerformanceCounter))) |
|
|
|
|
|
|
|
(when c-animation-frame-rate |
|
|
|
(var lifetime-seconds float |
|
|
|
(/ (- (SDL_GetPerformanceCounter) (path current-effect > life-start-ticks)) |
|
|
|
(type-cast (SDL_GetPerformanceFrequency) float))) |
|
|
|
(set (path current-effect > num-frames-since-spawned) (/ lifetime-seconds c-animation-frame-rate))) |
|
|
|
|
|
|
|
(when (path current-effect > power-id) |
|
|
|
(preslog "Execute %s [%d] frame %d\n" (path current-effect > power-id) i |
|
|
|
(path current-effect > num-frames-since-spawned)) |
|
|
|
(var context power-context (array 0)) |
|
|
|
(set (field context effect-data) current-effect) |
|
|
|
(execute-power (addr context) (path current-effect > power-id) power-execute-type-update)) |
|
|
|
|
|
|
|
(when (= (path current-effect > anim) (addr anim-smoke-explosion-idle)) |
|
|
|
;; Expire after final frame |
|
|
|
(when (or (= (path current-effect > anim) (addr anim-smoke-explosion-idle)) |
|
|
|
(path current-effect > expire-on-animation-end)) |
|
|
|
(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)) |
|
|
|
(unless loop-rate |
|
|
|
(set loop-rate c-animation-frame-rate)) |
|
|
|
(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))) |
|
|
@ -462,17 +520,21 @@ |
|
|
|
c-animation-frame-rate |
|
|
|
(path current-effect > x) (path current-effect > y)) |
|
|
|
|
|
|
|
;; Colliding power with boar |
|
|
|
;; Don't damage boar if already smoke |
|
|
|
(when (and (> (path current-effect > x) (path boar > x)) |
|
|
|
(!= (path current-effect > anim) (addr anim-smoke-explosion-idle))) |
|
|
|
(set (path current-effect > sprite) 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)))))) |
|
|
|
;; Auto convert non-powers to smoke |
|
|
|
(when (not (path current-effect > power-id)) |
|
|
|
(set (path current-effect > sprite) 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-item-addr-in-array s-effects i current-effect (* effect) |
|
|
@ -496,6 +558,10 @@ |
|
|
|
(array "positionY" (addr (path context > effect-data > y))) |
|
|
|
(array "velocityX" (addr (path context > effect-data > velocity-x))) |
|
|
|
(array "velocityY" (addr (path context > effect-data > velocity-y))) |
|
|
|
(array "relativeSpawnX" (addr (path context > effect-data > relative-spawn-x))) |
|
|
|
(array "relativeSpawnY" (addr (path context > effect-data > relative-spawn-y))) |
|
|
|
(array "lifetimeFrameCount" (addr (path context > effect-data > num-frames-since-spawned))) |
|
|
|
(array "user0" (addr (path context > effect-data > user-0))) |
|
|
|
(array "enemyX" (addr (field g-boar-enemy x))) |
|
|
|
(array "enemyY" (addr (field g-boar-enemy y))) |
|
|
|
(array "heroX" (addr (field g-wizard-hero x))) |
|
|
@ -530,7 +596,7 @@ |
|
|
|
value (* (const char))) |
|
|
|
(var name-values ([] name-value-pair) |
|
|
|
(array |
|
|
|
(array "currentSprite" (path context > effect-data > sprite > id)))) |
|
|
|
(array "currentEffect" (path context > effect-data > sprite > id)))) |
|
|
|
(each-item-addr-in-array name-values i pair (* name-value-pair) |
|
|
|
(unless (= 0 (strcmp (path pair > name) name)) |
|
|
|
(continue)) |
|
|
@ -596,6 +662,17 @@ |
|
|
|
(each-item-addr-in-dynarray operations-to-run |
|
|
|
operation-index op (* operation) |
|
|
|
(cond |
|
|
|
((= (path op > type) operation-type-spawn-power) |
|
|
|
(var spawn-power-context power-context (array 0)) |
|
|
|
(when (path context > effect-data) |
|
|
|
(set (field spawn-power-context start-x) |
|
|
|
(+ (path context > effect-data > x) |
|
|
|
(path context > effect-data > relative-spawn-x))) |
|
|
|
(set (field spawn-power-context start-y) |
|
|
|
(+ (path context > effect-data > y) |
|
|
|
(path context > effect-data > relative-spawn-y)))) |
|
|
|
(execute-power (addr spawn-power-context) (path op > string-a) |
|
|
|
power-execute-type-create)) |
|
|
|
((= (path op > type) operation-type-play-effect) |
|
|
|
(var new-effect (* effect) (? (path context > effect-data) |
|
|
|
(path context > effect-data) |
|
|
@ -619,23 +696,39 @@ |
|
|
|
(if (and (path new-effect > anim) |
|
|
|
(path new-effect > sprite)) |
|
|
|
(scope |
|
|
|
(unless (path context > effect-data) |
|
|
|
(set (path new-effect > x) (+ c-wizard-start-effect-x (field g-wizard-hero x))) |
|
|
|
(set (path new-effect > y) (+ c-wizard-start-effect-y (field g-wizard-hero y)))) |
|
|
|
(cond |
|
|
|
((or (path context > start-x) |
|
|
|
(path context > start-y)) |
|
|
|
(set (path new-effect > x) (path context > start-x)) |
|
|
|
(set (path new-effect > y) (path context > start-y))) |
|
|
|
((path context > effect-data) |
|
|
|
(set (path new-effect > x) (path context > effect-data > x)) |
|
|
|
(set (path new-effect > y) (path context > effect-data > y))) |
|
|
|
(true |
|
|
|
(set (path new-effect > x) (+ c-wizard-start-effect-x (field g-wizard-hero x))) |
|
|
|
(set (path new-effect > y) (+ c-wizard-start-effect-y (field g-wizard-hero y))))) |
|
|
|
(set (path context > effect-data) new-effect) |
|
|
|
(set (path new-effect > animation-start-ticks) (SDL_GetPerformanceCounter)) |
|
|
|
(set (path new-effect > life-start-ticks) (SDL_GetPerformanceCounter)) |
|
|
|
(set (path new-effect > power-id) (path power-to-execute > id))) |
|
|
|
(scope |
|
|
|
(set (path new-effect > sprite) null) |
|
|
|
(preslog "Could not create effect: missing sprite or animation\n")))) |
|
|
|
((= (path op > type) operation-type-expire-on-animation-end) |
|
|
|
(when (path context > effect-data) |
|
|
|
(set (path context > effect-data > expire-on-animation-end) true))) |
|
|
|
((= (path op > type) operation-type-damage) |
|
|
|
(set (field g-boar-enemy anim) (addr anim-boar-damage)) |
|
|
|
(set (field g-boar-enemy animation-start-ticks) (SDL_GetPerformanceCounter))) |
|
|
|
((= (path op > type) operation-type-set-value) |
|
|
|
(var value-out (* int) (resolve-value-from-name |
|
|
|
context (path op > string-a))) |
|
|
|
(var set-value-to (* int) (resolve-value-or-literal-from-string |
|
|
|
context (path op > string-b))) |
|
|
|
(when (and value-out set-value-to) |
|
|
|
(if (and value-out set-value-to) |
|
|
|
;; (preslog "Setting %s to %s\n" (path op > string-a) (path op > string-b)) |
|
|
|
(set (deref value-out) (deref set-value-to)))) |
|
|
|
(set (deref value-out) (deref set-value-to)) |
|
|
|
(preslog "Failed to set %s to %s (not bound)\n" (path op > string-a) (path op > string-b)))) |
|
|
|
((= (path op > type) operation-type-if-equals) |
|
|
|
(var value-a (* int) (resolve-value-or-literal-from-string |
|
|
|
context (path op > string-a))) |
|
|
@ -646,7 +739,7 @@ |
|
|
|
(set operation-index (find-end-index operations-to-run operation-index))))) |
|
|
|
((= (path op > type) operation-type-if-string-equals) |
|
|
|
(var value-a (* (const char)) (resolve-string-value-or-literal-from-string |
|
|
|
context (path op > string-a))) |
|
|
|
context (path op > string-a))) |
|
|
|
(var value-b (* (const char)) (resolve-string-value-or-literal-from-string |
|
|
|
context (path op > string-b))) |
|
|
|
(when (and value-a value-b) |
|
|
@ -858,7 +951,11 @@ |
|
|
|
(array "fireball" (addr spritesheet-fireball) |
|
|
|
s-start-fireball-spritesheet s-end-fireball-spritesheet) |
|
|
|
(array "smoke-explosion" (addr spritesheet-smoke-explosion) |
|
|
|
s-start-smoke-explosion-spritesheet s-end-smoke-explosion-spritesheet))) |
|
|
|
s-start-smoke-explosion-spritesheet s-end-smoke-explosion-spritesheet) |
|
|
|
(array "explosion" (addr spritesheet-explosion) |
|
|
|
s-start-explosion-spritesheet s-end-explosion-spritesheet) |
|
|
|
(array "ice-explosion" (addr spritesheet-ice-explosion) |
|
|
|
s-start-ice-explosion-spritesheet s-end-ice-explosion-spritesheet))) |
|
|
|
|
|
|
|
(each-item-addr-in-array prepare-spritesheets i sheet (* spritesheets-to-prepare) |
|
|
|
;; Associate sheets with sprites from power system |
|
|
@ -923,6 +1020,7 @@ |
|
|
|
(var should-render-ground bool false) |
|
|
|
|
|
|
|
(var queued-effect effect-id effect-id-none) |
|
|
|
(var queued-power-id (* (const char)) null) |
|
|
|
|
|
|
|
(var exit-reason (* (const char)) null) |
|
|
|
(while true |
|
|
@ -987,15 +1085,17 @@ |
|
|
|
(set (field g-wizard-hero anim) (addr anim-wizard-attack)) |
|
|
|
(set queued-effect effect-id-fireball)) |
|
|
|
|
|
|
|
(when (and |
|
|
|
(!= (field g-wizard-hero anim) (addr anim-wizard-attack)) |
|
|
|
(keybind-tapped (addr s-attack-2-keybind) (addr s-key-states))) |
|
|
|
(set (field g-wizard-hero animation-start-ticks) (SDL_GetPerformanceCounter)) |
|
|
|
(set (field g-wizard-hero anim) (addr anim-wizard-attack)) |
|
|
|
(set queued-effect effect-id-power-0)) |
|
|
|
(each-item-addr-in-array s-power-keybinds i power-key (* power-keybind) |
|
|
|
(when (and |
|
|
|
(!= (field g-wizard-hero anim) (addr anim-wizard-attack)) |
|
|
|
(keybind-tapped (path power-key > bind) (addr s-key-states))) |
|
|
|
(set (field g-wizard-hero animation-start-ticks) (SDL_GetPerformanceCounter)) |
|
|
|
(set (field g-wizard-hero anim) (addr anim-wizard-attack)) |
|
|
|
(set queued-power-id (path power-key > power-id)))) |
|
|
|
|
|
|
|
(when (and (= (field g-wizard-hero anim) (addr anim-wizard-attack)) |
|
|
|
(!= queued-effect effect-id-none)) |
|
|
|
(or (!= queued-effect effect-id-none) |
|
|
|
queued-power-id)) |
|
|
|
(var current-frame int 0) |
|
|
|
(var current-anim (* (const animation)) (field g-wizard-hero anim)) |
|
|
|
(when (or (not (animation-get-current-frame current-anim |
|
|
@ -1018,10 +1118,11 @@ |
|
|
|
(set (path new-effect > x) (+ c-wizard-start-effect-x (field g-wizard-hero x))) |
|
|
|
(set (path new-effect > y) (+ c-wizard-start-effect-y (field g-wizard-hero y))))) |
|
|
|
(set (path new-effect > velocity-x) 25)) |
|
|
|
((= queued-effect effect-id-power-0) |
|
|
|
(queued-power-id |
|
|
|
(var context power-context (array 0)) |
|
|
|
(execute-power (addr context) "fireball" power-execute-type-create))) |
|
|
|
(set queued-effect effect-id-none))) |
|
|
|
(execute-power (addr context) queued-power-id power-execute-type-create))) |
|
|
|
(set queued-effect effect-id-none) |
|
|
|
(set queued-power-id null))) |
|
|
|
|
|
|
|
(SDL_SetRenderDrawColor renderer 11 19 40 255) |
|
|
|
(SDL_RenderClear renderer) |
|
|
|