-
Notifications
You must be signed in to change notification settings - Fork 1
/
shield.rkt
38 lines (23 loc) · 960 Bytes
/
shield.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
#lang racket/base
(require racket/class
racket/draw)
(require "defs.rkt"
"utils.rkt"
"draw-utils.rkt")
(provide (all-defined-out))
(define SHIELD_LIFE 5000) ; ms after which shield starts fading
(define SHIELD_FADE 1.0) ; energy loss per second after SHIELD_LIFE
(define (shield-energy space s)
(- (shield-e s) (* (max 0.0 (- (obj-age space s) SHIELD_LIFE)) (/ SHIELD_FADE 1000.0))))
(define (shield-sigmoid space s)
(sigmoid (shield-energy space s) 12))
(define (shield-length space s)
(* 30.0 (shield-sigmoid space s)))
(define (shield-dead? space s)
((shield-energy space s) . < . 1))
(define (reduce-shield! space s damage)
(set-shield-e! s (- (shield-e s) damage))
(when ((shield-energy space s) . < . 1)
(set-obj-alive?! s #f)))
(define (draw-shield csd center scale space s fowa layer-ships)
(obj-sprite s csd center scale layer-ships 'shield (shield-length space s) fowa (obj-r s) "blue"))