File: boot.scm

package info (click to toggle)
trackballs 1.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,072 kB
  • sloc: cpp: 17,863; lisp: 4,626; xml: 51; sh: 24; makefile: 7
file content (42 lines) | stat: -rw-r--r-- 1,555 bytes parent folder | download | duplicates (5)
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
;;; boot.scm

(define last-level #f)
(define return-level #f)

;;**************************************
;; Utility functions
;; You can use these to simplify doing
;; more complicated map things
;;**************************************

(define (nth n l)
  (if (= 0 n) (car l) (nth (- n 1) (cdr l))))

;; coords is a list of coordinates. eg ((247.5 246.5 1.5) (250.5 246.5 1.5) (251.5 247.5 1.5))
;; radius is the radius which will be used for all pipes
;; connectors is a boolean if we should use connectors
;; result is a list of pipes and connectors
(define (multi-pipe coords radius connectors)
  (let ((p0 (nth 0 coords))
    (p1 (nth 1 coords)))
  (if (= (length coords) 2)
    (list (pipe (nth 0 p0) (nth 1 p0) (nth 2 p0) (nth 0 p1) (nth 1 p1) (nth 2 p1) radius))
    (cons (pipe (nth 0 p0) (nth 1 p0) (nth 2 p0) (nth 0 p1) (nth 1 p1) (nth 2 p1) radius)
        (if connectors 
          (cons (pipe-connector (nth 0 p1) (nth 1 p1) (nth 2 p1) radius)
            (multi-pipe (cdr coords) radius connectors))
          (multi-pipe (cdr coords) radius connectors))))))
          
;; arguments are like (trigger . . . .)
;; namely, position x y, radius of effect, and function to call
;; the thunk is executed only the first time the player enters the
;; radius and never again.
;; useful to avoid overcreating a fixed object (pipe, teleporter)
(define trigger-once
  (lambda (x y r thunk)
    (let ((first-time #t))
      (trigger x y r
        (lambda ()
          (if first-time
            (begin (set! first-time #f)
              (thunk))))))))