-
Notifications
You must be signed in to change notification settings - Fork 1
/
explosion.rkt
48 lines (34 loc) · 1.44 KB
/
explosion.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#lang racket/base
(require mode-lambda
mode-lambda/static)
(require "defs.rkt"
"utils.rkt"
"draw-utils.rkt")
(provide (all-defined-out))
(define EXPLOSION_FADE 0.33) ; fraction of maxsize around which we fade
(define (explosion-setup-pre! sd)
(void))
(define EXPLOSION_SPRITE_IDX #f)
(define EXPLOSION_SPRITE_SIZE #f)
(define (explosion-setup-post! csd)
(set! EXPLOSION_SPRITE_IDX (sprite-idx csd 'circle))
(define w (sprite-width csd EXPLOSION_SPRITE_IDX))
(define h (sprite-height csd EXPLOSION_SPRITE_IDX))
(set! EXPLOSION_SPRITE_SIZE (max w h)))
(define (explosion-fade e)
(linear-fade (explosion-size e)
(- (explosion-maxsize e) (* (explosion-maxsize e) EXPLOSION_FADE))
(explosion-maxsize e)))
(define (explosion-damage e dt)
(* (explosion-dmg-rate e) (explosion-fade e) dt))
(define (explosion-radius e)
(explosion-size e))
(define (explosion-dead? e)
(= 0.0 (explosion-fade e)))
(define (update-explosion! space e dt)
(set-explosion-size! e (+ (explosion-size e) (* (explosion-expand e) dt))))
(define (draw-explosion csd center scale e space fowa layer-effects)
(define z (/ (min (explosion-size e) (explosion-maxsize e)) (explosion-maxsize e)))
(define col (linear-color "white" "orange" (* z z) (explosion-fade e)))
(obj-sprite e csd center scale layer-effects 'circle
(/ (* 2.0 (+ 1.0 (explosion-radius e))) 100) (* fowa (explosion-fade e)) 0 col))