-
Notifications
You must be signed in to change notification settings - Fork 1
/
effect.rkt
65 lines (51 loc) · 2.37 KB
/
effect.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#lang racket/base
(require racket/class
mode-lambda
racket/draw)
(require "defs.rkt"
"utils.rkt"
"warp.rkt"
"draw-utils.rkt")
(provide (all-defined-out))
(define (make-backeffect! space o)
(when (ship? o)
(define eng (ship-tool o 'engine))
(cond
((and eng (or (missile? o) (probe? o)))
(define c (tool-count space eng o))
(when (or (and (missile? o) (time-for (obj-age space o) 200))
(and (time-for (obj-age space o) 800)
(c . > . 0)))
(define l (- (ship-radius o)))
(define t (posvel-r (obj-posvel o)))
(define be (backeffect 0 (space-time space) #t 1.0
(posvel 0
(+ (posvel-x (obj-posvel o)) (* l (cos t)))
(+ (posvel-y (obj-posvel o)) (* l (sin t)))
0
(if (missile? o)
(- (* 16.0 (cos (obj-r o))))
(- (posvel-dx (obj-posvel o))))
(if (missile? o)
(- (* 16.0 (sin (obj-r o))))
(- (posvel-dy (obj-posvel o))))
0)
1.5
(if (missile? o) 200 1000)))
be)))))
(define (effect-dead? space e)
((obj-age space e) . > . (effect-duration e)))
(define (draw-effect csd center scale space e fowa layer-effects)
(cond ((backeffect? e)
(draw-backeffect csd center scale space e fowa))
(else
(define agep (linear-fade (obj-age space e) 0 (effect-duration e)))
(define col (linear-color "yellow" "yellow" 0 agep))
(define rad (* (+ 1.0 (- 1.0 agep)) (effect-size e)))
(obj-sprite e csd center scale layer-effects 'circle
(/ (* 2.0 (+ 1.0 rad)) 100) (* fowa agep) 0 col))))
(define (draw-backeffect csd center scale space e fowa)
(define z (linear-fade (obj-age space e) 0.0 (effect-duration e)))
(define col (linear-color "white" "red" (- 1.0 z) z))
(obj-sprite e csd center scale LAYER_MAP 'circle
(/ (* 2.0 (+ 1.0 (effect-size e))) 100) (* fowa z) 0 col))