|
|
@ -209,7 +209,14 @@ |
|
|
|
operation-type-play-effect |
|
|
|
operation-type-set-value |
|
|
|
operation-type-if-equals |
|
|
|
operation-type-end-if) |
|
|
|
operation-type-if-string-equals |
|
|
|
operation-type-if-greater-than-or-equal |
|
|
|
operation-type-end) |
|
|
|
|
|
|
|
(var c-open-if-blocks ([] operation-type) |
|
|
|
(array operation-type-if-equals |
|
|
|
operation-type-if-string-equals |
|
|
|
operation-type-if-greater-than-or-equal)) |
|
|
|
|
|
|
|
(def-introspect-struct operation |
|
|
|
type int ;; operation-type |
|
|
@ -236,8 +243,14 @@ |
|
|
|
operation-type-if-equals |
|
|
|
"IfEquals" 2) |
|
|
|
(array |
|
|
|
operation-type-end-if |
|
|
|
"EndIf" 0))) |
|
|
|
operation-type-if-string-equals |
|
|
|
"IfStringEquals" 2) |
|
|
|
(array |
|
|
|
operation-type-if-greater-than-or-equal |
|
|
|
"IfGreaterThanOrEqual" 2) |
|
|
|
(array |
|
|
|
operation-type-end |
|
|
|
"End" 0))) |
|
|
|
|
|
|
|
(defenum read-state |
|
|
|
read-state-looking-for-keyword |
|
|
@ -250,7 +263,8 @@ |
|
|
|
(each-char-in-string-const operations current-char |
|
|
|
(cond |
|
|
|
((= state read-state-looking-for-keyword) |
|
|
|
(when (!= ' ' (deref current-char)) |
|
|
|
(when (and (!= ' ' (deref current-char)) |
|
|
|
(!= '\n' (deref current-char))) |
|
|
|
(var argument-end (* (const char)) null) |
|
|
|
(each-char-in-string-const current-char end-char |
|
|
|
(set argument-end end-char) |
|
|
@ -276,7 +290,8 @@ |
|
|
|
;; Always advance by words in this state |
|
|
|
(set current-char argument-end))) |
|
|
|
((= state read-state-reading-arguments) |
|
|
|
(when (!= ' ' (deref current-char)) |
|
|
|
(when (and (!= ' ' (deref current-char)) |
|
|
|
(!= '\n' (deref current-char))) |
|
|
|
(var argument-end (* (const char)) null) |
|
|
|
(each-char-in-string-const current-char end-char |
|
|
|
(set argument-end end-char) |
|
|
@ -402,21 +417,29 @@ |
|
|
|
|
|
|
|
(var s-effects ([] 16 effect) (array 0)) |
|
|
|
|
|
|
|
(defstruct-local enemy |
|
|
|
(defstruct-local actor |
|
|
|
x int |
|
|
|
y int |
|
|
|
anim (* (const animation)) |
|
|
|
animation-start-ticks Uint64) |
|
|
|
|
|
|
|
(var g-wizard-hero actor (array 0)) |
|
|
|
(var g-boar-enemy actor (array 0)) |
|
|
|
|
|
|
|
(defstruct-local power-context |
|
|
|
effect-data (* effect)) |
|
|
|
|
|
|
|
(defun-local update-effects (renderer (* SDL_Renderer) |
|
|
|
boar (* enemy)) |
|
|
|
boar (* actor)) |
|
|
|
(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 > power-id) |
|
|
|
(execute-power current-effect (path current-effect > power-id) power-execute-type-update)) |
|
|
|
(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)) |
|
|
|
(var num-frames int (- (+ 1 (path current-effect > anim > end-frame-index)) ;; TODO: Off by one? |
|
|
@ -458,9 +481,6 @@ |
|
|
|
(return current-effect))) |
|
|
|
(return null)) |
|
|
|
|
|
|
|
(defstruct-local power-context |
|
|
|
effect-data (* effect)) |
|
|
|
|
|
|
|
(defun-local resolve-value-from-name (context (* power-context) |
|
|
|
name (* (const char)) |
|
|
|
&return (* int)) |
|
|
@ -475,7 +495,11 @@ |
|
|
|
(array "positionX" (addr (path context > effect-data > x))) |
|
|
|
(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 "velocityY" (addr (path context > effect-data > velocity-y))) |
|
|
|
(array "enemyX" (addr (field g-boar-enemy x))) |
|
|
|
(array "enemyY" (addr (field g-boar-enemy y))) |
|
|
|
(array "heroX" (addr (field g-wizard-hero x))) |
|
|
|
(array "heroY" (addr (field g-wizard-hero y))))) |
|
|
|
(each-item-addr-in-array name-values i pair (* name-value-pair) |
|
|
|
(unless (= 0 (strcmp (path pair > name) name)) |
|
|
|
(continue)) |
|
|
@ -494,13 +518,61 @@ |
|
|
|
(set value-out (addr literal-value))) |
|
|
|
(return value-out)) |
|
|
|
|
|
|
|
|
|
|
|
(defun-local resolve-string-value-from-name (context (* power-context) |
|
|
|
name (* (const char)) |
|
|
|
&return (* (const char))) |
|
|
|
(unless (path context > effect-data) |
|
|
|
(return null)) |
|
|
|
|
|
|
|
(defstruct name-value-pair |
|
|
|
name (* (const char)) |
|
|
|
value (* (const char))) |
|
|
|
(var name-values ([] name-value-pair) |
|
|
|
(array |
|
|
|
(array "currentSprite" (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)) |
|
|
|
(return (path pair > value))) |
|
|
|
;; (preslog "No value %s bound to context\n" name) |
|
|
|
(return null)) |
|
|
|
|
|
|
|
(defun-local resolve-string-value-or-literal-from-string (context (* power-context) |
|
|
|
name-or-literal (* (const char)) |
|
|
|
&return (* (const char))) |
|
|
|
(var value-out (* (const char)) (resolve-string-value-from-name context name-or-literal)) |
|
|
|
(unless value-out |
|
|
|
(set value-out name-or-literal)) |
|
|
|
(return value-out)) |
|
|
|
|
|
|
|
(defenum power-execute-type |
|
|
|
power-execute-type-create |
|
|
|
power-execute-type-update) |
|
|
|
|
|
|
|
(forward-declare (struct effect)) |
|
|
|
|
|
|
|
(defun execute-power (owner-effect (* effect) |
|
|
|
(forward-declare (struct effect) (struct power-context)) |
|
|
|
|
|
|
|
(var c-wizard-start-effect-x int 186) |
|
|
|
(var c-wizard-start-effect-y int 64) |
|
|
|
|
|
|
|
(defun find-end-index (operations (* operation) start-index int |
|
|
|
&return int) |
|
|
|
(var depth int 0) |
|
|
|
(each-in-interval start-index (dynarray-length operations) i |
|
|
|
(var this-op (* operation) (addr (at i operations))) |
|
|
|
(each-in-array c-open-if-blocks if-block-open-index |
|
|
|
(when (= (path this-op > type) |
|
|
|
(at if-block-open-index c-open-if-blocks)) |
|
|
|
(incr depth) |
|
|
|
(break))) |
|
|
|
(when (= (path this-op > type) operation-type-end) |
|
|
|
(when depth |
|
|
|
(decr depth)) |
|
|
|
(unless depth |
|
|
|
(return i)))) |
|
|
|
(return (- 1 (dynarray-length operations)))) |
|
|
|
|
|
|
|
(defun execute-power (context (* power-context) |
|
|
|
id (* (const char)) |
|
|
|
execute-type power-execute-type) |
|
|
|
(var power-to-execute (* power) null) |
|
|
@ -514,9 +586,6 @@ |
|
|
|
(preslog "Could not find power %s to activate\n" id) |
|
|
|
(return)) |
|
|
|
|
|
|
|
(var context power-context (array 0)) |
|
|
|
(set (field context effect-data) owner-effect) |
|
|
|
|
|
|
|
(var operations-to-run (* operation) null) |
|
|
|
(cond |
|
|
|
((= execute-type power-execute-type-create) |
|
|
@ -528,7 +597,9 @@ |
|
|
|
operation-index op (* operation) |
|
|
|
(cond |
|
|
|
((= (path op > type) operation-type-play-effect) |
|
|
|
(var new-effect (* effect) (get-free-effect)) |
|
|
|
(var new-effect (* effect) (? (path context > effect-data) |
|
|
|
(path context > effect-data) |
|
|
|
(get-free-effect))) |
|
|
|
(unless new-effect |
|
|
|
(preslog "No more effect slots\n") |
|
|
|
(return)) |
|
|
@ -548,7 +619,10 @@ |
|
|
|
(if (and (path new-effect > anim) |
|
|
|
(path new-effect > sprite)) |
|
|
|
(scope |
|
|
|
(set (field context effect-data) new-effect) |
|
|
|
(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)))) |
|
|
|
(set (path context > effect-data) new-effect) |
|
|
|
(set (path new-effect > animation-start-ticks) (SDL_GetPerformanceCounter)) |
|
|
|
(set (path new-effect > power-id) (path power-to-execute > id))) |
|
|
|
(scope |
|
|
@ -556,24 +630,36 @@ |
|
|
|
(preslog "Could not create effect: missing sprite or animation\n")))) |
|
|
|
((= (path op > type) operation-type-set-value) |
|
|
|
(var value-out (* int) (resolve-value-from-name |
|
|
|
(addr context) (path op > string-a))) |
|
|
|
context (path op > string-a))) |
|
|
|
(var set-value-to (* int) (resolve-value-or-literal-from-string |
|
|
|
(addr context) (path op > string-b))) |
|
|
|
context (path op > string-b))) |
|
|
|
(when (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)))) |
|
|
|
((= (path op > type) operation-type-if-equals) |
|
|
|
(var value-a (* int) (resolve-value-or-literal-from-string |
|
|
|
(addr context) (path op > string-a))) |
|
|
|
context (path op > string-a))) |
|
|
|
(var value-b (* int) (resolve-value-or-literal-from-string |
|
|
|
(addr context) (path op > string-b))) |
|
|
|
context (path op > string-b))) |
|
|
|
(when (and value-a value-b) |
|
|
|
(unless (= (deref value-a) (deref value-b)) |
|
|
|
(each-item-addr-in-dynarray operations-to-run |
|
|
|
this-operation-index this-op (* operation) |
|
|
|
(when (= (path this-op > type) operation-type-end-if) |
|
|
|
(set operation-index this-operation-index) |
|
|
|
(break))))))))) |
|
|
|
(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))) |
|
|
|
(var value-b (* (const char)) (resolve-string-value-or-literal-from-string |
|
|
|
context (path op > string-b))) |
|
|
|
(when (and value-a value-b) |
|
|
|
(unless (= 0 (strcmp value-a value-b)) |
|
|
|
(set operation-index (find-end-index operations-to-run operation-index))))) |
|
|
|
((= (path op > type) operation-type-if-greater-than-or-equal) |
|
|
|
(var value-a (* int) (resolve-value-or-literal-from-string |
|
|
|
context (path op > string-a))) |
|
|
|
(var value-b (* int) (resolve-value-or-literal-from-string |
|
|
|
context (path op > string-b))) |
|
|
|
(when (and value-a value-b) |
|
|
|
(unless (>= (deref value-a) (deref value-b)) |
|
|
|
(set operation-index (find-end-index operations-to-run operation-index)))))))) |
|
|
|
|
|
|
|
;; |
|
|
|
;; Text rendering |
|
|
@ -830,10 +916,8 @@ |
|
|
|
(var wizard-ground-height int 80) |
|
|
|
(var boar-ground-height int 220) |
|
|
|
|
|
|
|
(var wizard-animation-start-ticks Uint64 0) |
|
|
|
(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)) |
|
|
|
(set (field g-wizard-hero anim) (addr anim-wizard-jump-in)) |
|
|
|
(set (field g-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) |
|
|
@ -875,12 +959,12 @@ |
|
|
|
(when (at 0 (path current-slide > trigger)) |
|
|
|
(cond |
|
|
|
((= 0 (strcmp (path current-slide > trigger) "enter-wizard")) |
|
|
|
(set wizard-animation-start-ticks (SDL_GetPerformanceCounter)) |
|
|
|
(set current-wizard-animation (addr anim-wizard-jump-in)) |
|
|
|
(set (field g-wizard-hero animation-start-ticks) (SDL_GetPerformanceCounter)) |
|
|
|
(set (field g-wizard-hero anim) (addr anim-wizard-jump-in)) |
|
|
|
(set should-render-wizard true)) |
|
|
|
((= 0 (strcmp (path current-slide > trigger) "enter-boar")) |
|
|
|
(set (field boar-enemy animation-start-ticks) (SDL_GetPerformanceCounter)) |
|
|
|
(set (field boar-enemy anim) (addr anim-boar-jump-in)) |
|
|
|
(set (field g-boar-enemy animation-start-ticks) (SDL_GetPerformanceCounter)) |
|
|
|
(set (field g-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)) |
|
|
@ -893,33 +977,29 @@ |
|
|
|
(when (keybind-tapped (addr s-toggle-debug-overlay-keybind) (addr s-key-states)) |
|
|
|
(set s-enable-debug-overlay (not s-enable-debug-overlay))) |
|
|
|
|
|
|
|
(var wizard-x int (type-cast (* window-width 0.08f) int)) |
|
|
|
(var wizard-y int (- window-height (/ ground-height 2) wizard-ground-height)) |
|
|
|
(set (field g-wizard-hero x) (type-cast (* window-width 0.08f) int)) |
|
|
|
(set (field g-wizard-hero y) (- window-height (/ ground-height 2) wizard-ground-height)) |
|
|
|
|
|
|
|
(when (and |
|
|
|
(!= current-wizard-animation (addr anim-wizard-attack)) |
|
|
|
(!= (field g-wizard-hero anim) (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-attack)) |
|
|
|
;; (set (field boar-enemy animation-start-ticks) (SDL_GetPerformanceCounter)) |
|
|
|
;; (set (field boar-enemy anim) (addr anim-boar-jump-in)) |
|
|
|
(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-fireball)) |
|
|
|
|
|
|
|
(when (and |
|
|
|
(!= current-wizard-animation (addr anim-wizard-attack)) |
|
|
|
(!= (field g-wizard-hero anim) (addr anim-wizard-attack)) |
|
|
|
(keybind-tapped (addr s-attack-2-keybind) (addr s-key-states))) |
|
|
|
(set wizard-animation-start-ticks (SDL_GetPerformanceCounter)) |
|
|
|
(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 (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)) |
|
|
|
|
|
|
|
(when (and (= current-wizard-animation (addr anim-wizard-attack)) |
|
|
|
(when (and (= (field g-wizard-hero anim) (addr anim-wizard-attack)) |
|
|
|
(!= queued-effect effect-id-none)) |
|
|
|
(var current-frame int 0) |
|
|
|
(var current-anim (* (const animation)) current-wizard-animation) |
|
|
|
(var current-anim (* (const animation)) (field g-wizard-hero anim)) |
|
|
|
(when (or (not (animation-get-current-frame current-anim |
|
|
|
wizard-animation-start-ticks c-animation-frame-rate |
|
|
|
(field g-wizard-hero animation-start-ticks) c-animation-frame-rate |
|
|
|
(addr current-frame))) |
|
|
|
(= current-frame wizard-attack-effect-frame)) |
|
|
|
(cond |
|
|
@ -935,11 +1015,12 @@ |
|
|
|
(set (path new-effect > x) mouse-x) |
|
|
|
(set (path new-effect > y) mouse-y)) |
|
|
|
(scope |
|
|
|
(set (path new-effect > x) (+ 186 wizard-x)) |
|
|
|
(set (path new-effect > y) (+ 64 wizard-y)))) |
|
|
|
(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) |
|
|
|
(execute-power null "fireball" power-execute-type-create))) |
|
|
|
(var context power-context (array 0)) |
|
|
|
(execute-power (addr context) "fireball" power-execute-type-create))) |
|
|
|
(set queued-effect effect-id-none))) |
|
|
|
|
|
|
|
(SDL_SetRenderDrawColor renderer 11 19 40 255) |
|
|
@ -1009,26 +1090,26 @@ |
|
|
|
(path slide > body))) |
|
|
|
|
|
|
|
(when should-render-wizard |
|
|
|
(unless wizard-animation-start-ticks |
|
|
|
(set wizard-animation-start-ticks (SDL_GetPerformanceCounter))) |
|
|
|
(unless (field g-wizard-hero animation-start-ticks) |
|
|
|
(set (field g-wizard-hero animation-start-ticks) (SDL_GetPerformanceCounter))) |
|
|
|
(render-animation |
|
|
|
renderer spritesheet-wizard (addr current-wizard-animation) |
|
|
|
wizard-animation-start-ticks c-animation-frame-rate |
|
|
|
wizard-x wizard-y)) |
|
|
|
renderer spritesheet-wizard (addr (field g-wizard-hero anim)) |
|
|
|
(field g-wizard-hero animation-start-ticks) c-animation-frame-rate |
|
|
|
(field g-wizard-hero x) (field g-wizard-hero 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)) |
|
|
|
(set (field g-boar-enemy x) (type-cast (* window-width 0.70f) int)) |
|
|
|
(set (field g-boar-enemy y) (- window-height (/ ground-height 2) boar-ground-height)) |
|
|
|
|
|
|
|
(when should-render-boar |
|
|
|
(unless (field boar-enemy animation-start-ticks) |
|
|
|
(set (field boar-enemy animation-start-ticks) (SDL_GetPerformanceCounter))) |
|
|
|
(unless (field g-boar-enemy animation-start-ticks) |
|
|
|
(set (field g-boar-enemy animation-start-ticks) (SDL_GetPerformanceCounter))) |
|
|
|
(render-animation |
|
|
|
renderer 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))) |
|
|
|
renderer spritesheet-boar (addr (field g-boar-enemy anim)) |
|
|
|
(field g-boar-enemy animation-start-ticks) c-animation-frame-rate |
|
|
|
(field g-boar-enemy x) |
|
|
|
(field g-boar-enemy y))) |
|
|
|
|
|
|
|
(update-effects renderer (addr boar-enemy)) |
|
|
|
(update-effects renderer (addr g-boar-enemy)) |
|
|
|
|
|
|
|
(when s-enable-debug-overlay |
|
|
|
(var buffer ([] 256 char) (array 0)) |
|
|
@ -1038,7 +1119,7 @@ |
|
|
|
(snprintf buffer (- (array-size buffer) 1) "Mouse: %4d %4d Percent of window: %.2f %.2f Wizard relative: %4d %4d" |
|
|
|
mouse-x mouse-y |
|
|
|
(/ mouse-x (type-cast window-width float)) (/ mouse-y (type-cast window-height float)) |
|
|
|
(- mouse-x wizard-x) (- mouse-y wizard-y)) |
|
|
|
(- mouse-x (field g-wizard-hero x)) (- mouse-y (field g-wizard-hero y))) |
|
|
|
(render-string |
|
|
|
renderer (addr ubuntu-mono-font-atlas) ubuntu-mono-texture |
|
|
|
10 (- window-height 20) |
|
|
|