|
|
@ -39,6 +39,7 @@ |
|
|
|
(define-keybind s-toggle-debug-overlay-keybind (array SDL_SCANCODE_F1)) |
|
|
|
|
|
|
|
(define-keybind s-attack-keybind (array SDL_SCANCODE_1)) |
|
|
|
(define-keybind s-attack-2-keybind (array SDL_SCANCODE_2)) |
|
|
|
|
|
|
|
(var s-key-states sdl-key-states (array 0)) |
|
|
|
|
|
|
@ -73,7 +74,7 @@ |
|
|
|
;; Game |
|
|
|
;; |
|
|
|
|
|
|
|
;; TODO: Decide how to version control this |
|
|
|
;; TODO: Decide how to version control these |
|
|
|
(bundle-file s-start-wizard-spritesheet s-end-wizard-spritesheet |
|
|
|
(unsigned char) "/home/macoy/Documents/wizard.bmp") |
|
|
|
|
|
|
@ -212,14 +213,14 @@ |
|
|
|
|
|
|
|
(def-introspect-struct operation |
|
|
|
type int ;; operation-type |
|
|
|
stringA ([] 32 char) |
|
|
|
stringB ([] 32 char)) |
|
|
|
string-a ([] 32 char) |
|
|
|
string-b ([] 32 char)) |
|
|
|
|
|
|
|
(defun-local parse-power-operations (operations (* (const char)) |
|
|
|
&return (* operation)) ;; dynarray |
|
|
|
(var new-operations (* operation) null) |
|
|
|
|
|
|
|
(defstruct-local operation-reader |
|
|
|
(defstruct operation-reader |
|
|
|
type operation-type |
|
|
|
keyword (* (const char)) |
|
|
|
num-arguments char) |
|
|
@ -227,7 +228,7 @@ |
|
|
|
(array |
|
|
|
(array |
|
|
|
operation-type-play-effect |
|
|
|
"PlayEffect" 1) |
|
|
|
"PlayEffect" 2) |
|
|
|
(array |
|
|
|
operation-type-set-value |
|
|
|
"SetValue" 2) |
|
|
@ -268,8 +269,9 @@ |
|
|
|
(set current-operation-reader reader)) |
|
|
|
;; No arguments, push now |
|
|
|
(dynarray-push new-operations new-operation)) |
|
|
|
(set current-char argument-end) |
|
|
|
(break))))) |
|
|
|
(break))) |
|
|
|
;; Always advance by words in this state |
|
|
|
(set current-char argument-end))) |
|
|
|
((= state read-state-reading-arguments) |
|
|
|
(when (!= ' ' (deref current-char)) |
|
|
|
(var argument-end (* (const char)) null) |
|
|
@ -283,9 +285,9 @@ |
|
|
|
(preslog "\n") |
|
|
|
(cond |
|
|
|
((= argument-index 0) |
|
|
|
(strncpy (field new-operation stringA) current-char (- argument-end current-char))) |
|
|
|
(strncpy (field new-operation string-a) current-char (- argument-end current-char))) |
|
|
|
((= argument-index 1) |
|
|
|
(strncpy (field new-operation stringB) current-char (- argument-end current-char)))) |
|
|
|
(strncpy (field new-operation string-b) current-char (- argument-end current-char)))) |
|
|
|
(incr argument-index) |
|
|
|
(when (>= argument-index (path current-operation-reader > num-arguments)) |
|
|
|
(dynarray-push new-operations new-operation) |
|
|
@ -295,17 +297,37 @@ |
|
|
|
|
|
|
|
(def-introspect-struct power |
|
|
|
id ([] 32 char) |
|
|
|
operations ([] 1024 char) |
|
|
|
|
|
|
|
;; Operations |
|
|
|
on-create ([] 1024 char) |
|
|
|
on-update ([] 1024 char) |
|
|
|
|
|
|
|
;; Parsed at runtime, though they could be written by hand if you wanted |
|
|
|
parsed-operations (* operation) ('dynarray)) |
|
|
|
parsed-on-create-operations (* operation) ('dynarray) |
|
|
|
parsed-on-update-operations (* operation) ('dynarray)) |
|
|
|
|
|
|
|
(forward-declare (struct animation)) |
|
|
|
|
|
|
|
(def-introspect-struct animation-data |
|
|
|
id ([] 32 char) |
|
|
|
|
|
|
|
start-frame int |
|
|
|
end-frame int |
|
|
|
flip-horizontal bool |
|
|
|
|
|
|
|
next-animation-id ([] 32 char) |
|
|
|
|
|
|
|
runtime-anim (* animation) (ignore)) |
|
|
|
|
|
|
|
(def-introspect-struct power-system |
|
|
|
sprites ([] 16 spritesheet) ('array-allow-subset) |
|
|
|
animations ([] 16 animation-data) ('array-allow-subset) |
|
|
|
powers ([] 16 power) ('array-allow-subset)) |
|
|
|
|
|
|
|
(var s-power-system power-system (array 0)) |
|
|
|
|
|
|
|
(var s-power-system-runtime-animations ([] 16 animation) (array 0)) |
|
|
|
|
|
|
|
(bundle-file s-start-power-system s-end-power-system |
|
|
|
(const char) "data/PowerSystem.cakedata") |
|
|
|
|
|
|
@ -330,8 +352,36 @@ |
|
|
|
(each-item-addr-in-array (field s-power-system powers) i current-power (* power) |
|
|
|
(unless (at 0 (path current-power > id)) |
|
|
|
(continue)) |
|
|
|
(set (path current-power > parsed-operations) |
|
|
|
(parse-power-operations (path current-power > operations)))) |
|
|
|
(set (path current-power > parsed-on-create-operations) |
|
|
|
(parse-power-operations (path current-power > on-create))) |
|
|
|
(set (path current-power > parsed-on-update-operations) |
|
|
|
(parse-power-operations (path current-power > on-update)))) |
|
|
|
|
|
|
|
(each-item-addr-in-array (field s-power-system animations) |
|
|
|
animation-index anim-data (* animation-data) |
|
|
|
(unless (at 0 (path anim-data > id)) |
|
|
|
(continue)) |
|
|
|
(var runtime-anim (* animation) |
|
|
|
(addr (at animation-index s-power-system-runtime-animations))) |
|
|
|
(set (path runtime-anim > start-frame-index) (path anim-data > start-frame)) |
|
|
|
(set (path runtime-anim > end-frame-index) (path anim-data > end-frame)) |
|
|
|
(set (path runtime-anim > flip) (? (path anim-data > flip-horizontal) |
|
|
|
SDL_FLIP_HORIZONTAL |
|
|
|
SDL_FLIP_NONE)) |
|
|
|
(set (path anim-data > runtime-anim) runtime-anim)) |
|
|
|
;; Fix up references |
|
|
|
(each-item-addr-in-array (field s-power-system animations) |
|
|
|
animation-index anim-data (* animation-data) |
|
|
|
(unless (at 0 (path anim-data > id)) |
|
|
|
(continue)) |
|
|
|
(when (at 0 (path anim-data > next-animation-id)) |
|
|
|
(each-item-addr-in-array (field s-power-system animations) |
|
|
|
other-animation-index other-anim-data (* animation-data) |
|
|
|
(unless (= 0 (strcmp (path anim-data > next-animation-id) |
|
|
|
(path other-anim-data > id))) |
|
|
|
(continue)) |
|
|
|
(set (field (at animation-index s-power-system-runtime-animations) next-animation) |
|
|
|
(addr (at other-animation-index s-power-system-runtime-animations)))))) |
|
|
|
(return true)) |
|
|
|
|
|
|
|
(defstruct-local effect |
|
|
@ -392,13 +442,50 @@ |
|
|
|
(set (path boar > animation-start-ticks) (SDL_GetPerformanceCounter)))))) |
|
|
|
|
|
|
|
(defun-local get-free-effect (&return (* effect)) |
|
|
|
(each-in-array s-effects i |
|
|
|
(var current-effect (* effect) (addr (at i s-effects))) |
|
|
|
(each-item-addr-in-array s-effects i current-effect (* effect) |
|
|
|
(unless (path current-effect > sprite) |
|
|
|
(memset current-effect 0 (sizeof (type effect))) |
|
|
|
(return current-effect))) |
|
|
|
(return null)) |
|
|
|
|
|
|
|
(defun-local activate-power (id (* (const char))) |
|
|
|
(var power-to-activate (* power) null) |
|
|
|
(each-item-addr-in-array (field s-power-system powers) power-index current-power (* power) |
|
|
|
(unless (and (at 0 (path current-power > id)) |
|
|
|
(= 0 (strcmp (path current-power > id) id))) |
|
|
|
(continue)) |
|
|
|
(set power-to-activate current-power) |
|
|
|
(break)) |
|
|
|
(unless power-to-activate |
|
|
|
(preslog "Could not find power %s to activate\n" id) |
|
|
|
(return)) |
|
|
|
|
|
|
|
(each-item-addr-in-dynarray (path power-to-activate > parsed-on-create-operations) |
|
|
|
operation-index op (* operation) |
|
|
|
(cond |
|
|
|
((= (path op > type) operation-type-play-effect) |
|
|
|
(var new-effect (* effect) (get-free-effect)) |
|
|
|
(unless new-effect |
|
|
|
(preslog "No more effect slots\n") |
|
|
|
(return)) |
|
|
|
(preslog "Create effect %s with animation %s\n" (path op > string-a) (path op > string-b)) |
|
|
|
(each-item-addr-in-array (field s-power-system sprites) |
|
|
|
sprite-index sprite (* spritesheet) |
|
|
|
(unless (= 0 (strcmp (path sprite > id) (path op > string-a))) |
|
|
|
(continue)) |
|
|
|
(set (path new-effect > sprite) sprite) |
|
|
|
(break)) |
|
|
|
(each-item-addr-in-array (field s-power-system animations) |
|
|
|
animation-index anim-data (* animation-data) |
|
|
|
(unless (= 0 (strcmp (path anim-data > id) (path op > string-b))) |
|
|
|
(continue)) |
|
|
|
(set (path new-effect > anim) (path anim-data > runtime-anim)) |
|
|
|
(break)) |
|
|
|
(unless (and (path new-effect > anim) |
|
|
|
(path new-effect > sprite)) |
|
|
|
(set (path new-effect > sprite) null) |
|
|
|
(preslog "Could not create effect: missing sprite or animation\n")))))) |
|
|
|
|
|
|
|
;; |
|
|
|
;; Text rendering |
|
|
|
;; |
|
|
@ -512,7 +599,8 @@ |
|
|
|
|
|
|
|
(defenum effect-id |
|
|
|
effect-id-none |
|
|
|
effect-id-fireball) |
|
|
|
effect-id-fireball |
|
|
|
effect-id-power-0) |
|
|
|
|
|
|
|
(defun main (&return int) |
|
|
|
(data-bundle-load-all-resources) |
|
|
@ -728,28 +816,41 @@ |
|
|
|
;; (set (field boar-enemy anim) (addr anim-boar-jump-in)) |
|
|
|
(set queued-effect effect-id-fireball)) |
|
|
|
|
|
|
|
(when (and |
|
|
|
(!= current-wizard-animation (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 queued-effect effect-id-power-0)) |
|
|
|
|
|
|
|
(when (and (= current-wizard-animation (addr anim-wizard-attack)) |
|
|
|
(= queued-effect effect-id-fireball)) |
|
|
|
(!= queued-effect effect-id-none)) |
|
|
|
(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-attack-effect-frame)) |
|
|
|
(var new-effect (* effect) (get-free-effect)) |
|
|
|
(set (path new-effect > sprite) spritesheet-fireball) |
|
|
|
(set (path new-effect > anim) (addr anim-fireball-idle)) |
|
|
|
(var mouse-x int 0) |
|
|
|
(var mouse-y int 0) |
|
|
|
(SDL_GetMouseState (addr mouse-x) (addr mouse-y)) |
|
|
|
(if (and mouse-x mouse-y s-enable-debug-overlay) |
|
|
|
(scope |
|
|
|
(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 > velocity-x) 25) |
|
|
|
(cond |
|
|
|
((= queued-effect effect-id-fireball) |
|
|
|
(var new-effect (* effect) (get-free-effect)) |
|
|
|
(set (path new-effect > sprite) spritesheet-fireball) |
|
|
|
(set (path new-effect > anim) (addr anim-fireball-idle)) |
|
|
|
(var mouse-x int 0) |
|
|
|
(var mouse-y int 0) |
|
|
|
(SDL_GetMouseState (addr mouse-x) (addr mouse-y)) |
|
|
|
(if (and mouse-x mouse-y s-enable-debug-overlay) |
|
|
|
(scope |
|
|
|
(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 > velocity-x) 25)) |
|
|
|
((= queued-effect effect-id-power-0) |
|
|
|
(activate-power "fireball"))) |
|
|
|
(set queued-effect effect-id-none))) |
|
|
|
|
|
|
|
(SDL_SetRenderDrawColor renderer 11 19 40 255) |
|
|
|