Browse Source

Add support for if

master
Macoy Madson 1 year ago
parent
commit
9e97c988ea
  1. 6
      data/PowerSystem.cakedata
  2. 53
      src/Presentation.cake

6
data/PowerSystem.cakedata

@ -34,8 +34,8 @@
(power
:id "fireball"
:on-create "PlayEffect fireball fireball-idle
SetValue velocityX 25"
SetValue velocityX 15"
:on-update
"IfEquals positionX enemyX
PlayEffect smoke-explosion smoke-explosion-idle
"IfEquals positionX 800
SetValue velocityX 35
EndIf")))

53
src/Presentation.cake

@ -394,6 +394,7 @@
sprite (* spritesheet) ;; null = empty slot
anim (* (const animation))
animation-start-ticks Uint64
power-id (* (const char))
x int
y int
velocity-x int
@ -414,6 +415,9 @@
(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))
(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)))
@ -460,6 +464,9 @@
(defun-local resolve-value-from-name (context (* power-context)
name (* (const char))
&return (* int))
(unless (path context > effect-data)
(return null))
(defstruct name-value-pair
name (* (const char))
value (* int))
@ -487,21 +494,37 @@
(set value-out (addr literal-value)))
(return value-out))
(defun-local activate-power (id (* (const char)))
(var power-to-activate (* power) null)
(defenum power-execute-type
power-execute-type-create
power-execute-type-update)
(forward-declare (struct effect))
(defun execute-power (owner-effect (* effect)
id (* (const char))
execute-type power-execute-type)
(var power-to-execute (* 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)
(set power-to-execute current-power)
(break))
(unless power-to-activate
(unless power-to-execute
(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)
(set operations-to-run (path power-to-execute > parsed-on-create-operations)))
((= execute-type power-execute-type-update)
(set operations-to-run (path power-to-execute > parsed-on-update-operations))))
(each-item-addr-in-dynarray (path power-to-activate > parsed-on-create-operations)
(each-item-addr-in-dynarray operations-to-run
operation-index op (* operation)
(cond
((= (path op > type) operation-type-play-effect)
@ -525,7 +548,9 @@
(if (and (path new-effect > anim)
(path new-effect > sprite))
(scope
(set (field context effect-data) new-effect))
(set (field 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
(set (path new-effect > sprite) null)
(preslog "Could not create effect: missing sprite or animation\n"))))
@ -536,7 +561,19 @@
(addr 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)))))))
(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)))
(var value-b (* int) (resolve-value-or-literal-from-string
(addr 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)))))))))
;;
;; Text rendering
@ -902,7 +939,7 @@
(set (path new-effect > y) (+ 64 wizard-y))))
(set (path new-effect > velocity-x) 25))
((= queued-effect effect-id-power-0)
(activate-power "fireball")))
(execute-power null "fireball" power-execute-type-create)))
(set queued-effect effect-id-none)))
(SDL_SetRenderDrawColor renderer 11 19 40 255)

Loading…
Cancel
Save