home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer 13 / 1995-12_Disc_13.iso / abuse / lisp / switch.lsp < prev    next >
Lisp/Scheme  |  1995-08-31  |  7KB  |  266 lines

  1. ;; Copyright 1995 Crack dot Com,  All Rights reserved
  2. ;; See licencing information for more details on usage rights
  3.  
  4. (defun switcher_ai () 
  5.   (next_picture)
  6.   (select (aistate)
  7.       (0      ; waiting for player to press, then turn to on
  8.        (if (and (< (distx) 20) (< (disty) 30) (with_object (bg) (pressing_action_key)))
  9.            (progn
  10.          (play_sound SWITCH_SND 127 (x) (y))
  11.          (set_state running)         
  12.          (set_aistate 1))))
  13.       (1     ; wait for player to let go of button      
  14.        (if (not (with_object (bg) (pressing_action_key)))
  15.            (set_aistate 2)))
  16.       (2     ; wait for player to press, then turn to off
  17.        (if (and (< (distx) 20) (< (disty) 30) (with_object (bg) (pressing_action_key)))
  18.            (progn
  19.          (play_sound SWITCH_SND 127 (x) (y))
  20.          (set_state stopped)
  21.          (set_aistate 4))))     
  22.        (4     ; wait for player to let go of button
  23.         (if (not (with_object (bg) (pressing_action_key)))
  24.         (set_aistate 0)))
  25.        )
  26. T)
  27.           
  28.  
  29. (defun switch_once_ai () 
  30.   (select (aistate)
  31.       (0      ; waiting for player to press, then turn to on
  32.        (next_picture)
  33.        (if (and (< (distx) 20) (< (disty) 30) (with_object (bg) (pressing_action_key)))
  34.            (progn
  35.          (print (random 1000))
  36.          (play_sound SWITCH_SND 127 (x) (y))
  37.          (set_state running)
  38.          (set_aistate 1)))))
  39.   T)
  40.      
  41. (defun lower_reload () (lower))   ;; move object below all other objects
  42.      
  43. (def_char SWITCH
  44.   (funs (ai_fun switcher_ai)
  45.     (reload_fun lower_reload))
  46.   (range 0 0)  
  47.   (states "art/misc.spe"
  48.       (stopped '("switch_off1" "switch_off2"))
  49.       (running '("switch_on1"  "switch_on2"))))
  50.  
  51. (def_char SWITCH_ONCE
  52.   (funs (ai_fun switch_once_ai)
  53.     (reload_fun lower_reload))
  54.   (range 0 0)  
  55.   (states "art/misc.spe"
  56.       (stopped '("switch_off1" "switch_off2"))
  57.       (running '("switch_on1"  "switch_on2"))))
  58.  
  59.  
  60. (defun switch_delay_cons ()
  61.   (setq reset_time 14))
  62.  
  63. (def_char SWITCH_DELAY
  64.   (funs (ai_fun switch_delay_ai)
  65.     (reload_fun lower_reload)
  66.     (constructor switch_delay_cons))
  67.   (vars reset_time)
  68.   (fields ("reset_time" "reset time"))
  69.   (range 0 0)  
  70.   (states "art/misc.spe"
  71.       (stopped '("switch_off1" "switch_off2"))
  72.       (running '("switch_on1"  "switch_on2"))))
  73.  
  74.  
  75.  
  76. (defun switch_delay_ai ()
  77.   (select (aistate)
  78.       (0      ; waiting for player to press, then turn to on
  79.        (next_picture)
  80.        (if (and (< (distx) 20) (< (disty) 30) (with_object (bg) (pressing_action_key)))
  81.            (progn
  82.          (print (random 1000))
  83.          (play_sound SWITCH_SND 127 (x) (y))
  84.          (set_state running)
  85.          (set_aistate 1))))
  86.       (1     ; wait for player to let go of button
  87.        (if (not (with_object (bg) (pressing_action_key)))
  88.            (set_aistate 2)))
  89.       (2     ; wait for reset time
  90.        (if (> (state_time) reset_time)
  91.            (progn
  92.          (play_sound SWITCH_SND 127 (x) (y))
  93.          (set_state stopped)
  94.          (set_aistate 0)))))
  95. T)
  96.  
  97.  
  98. (defun switch_mover_ai ()
  99.   (if (> (total_objects) 1)
  100.       (select (aistate)
  101.           (0 (if (not (eq (with_object (get_object 0) (aistate)) 0))             
  102.              (let ((mex (x))
  103.                (mey (y)))
  104.                (if (eq (xvel) 0)
  105.                (progn
  106.                  (with_object (get_object 1)
  107.                       (progn
  108.                         (set_x mex)
  109.                         (set_y mey)
  110.                         (set_fade_count 15)
  111.                         ))
  112.                  (set_aistate 1)
  113.                  T)
  114.              (with_object (get_object 1)
  115.                       (progn
  116.                     (set_x mex)
  117.                     (set_y mey)
  118.                     nil))))
  119.            T))
  120.           (1 (let ((count (with_object (get_object 1) (fade_count))))
  121.            (if (equal count 0)
  122.                nil
  123.              (progn
  124.                (with_object (get_object 1) (set_fade_count (- count 1)))
  125.                T)))))
  126.                   
  127.     nil))
  128.  
  129. (def_char SWITCH_MOVER
  130.   (funs (ai_fun   switch_mover_ai)
  131.     (draw_fun dev_draw))
  132.   (range 0 0)
  133.   (states "art/misc.spe" (stopped "switch_mover")))
  134.  
  135.  
  136.  
  137. (defun sensor_cons ()
  138.   (set_aitype 1)
  139.   (add_hp -10))
  140.   
  141.  
  142. /*(defun sensor_ai ()
  143.   (if (eq (aistate) 0)
  144.       (if (and (< (distx) (xvel)) (< (disty) (yvel)))
  145.       (progn 
  146.         (if (eq (hp) 0)  ;; don't time out
  147.         (set_aistate 1)
  148.           (set_aistate (hp)))
  149.         (set_state blocking))
  150.     (set_state stopped))
  151.  
  152.     (if (eq (hp) 0)
  153.         (if (or (> (distx) (xacel)) (> (disty) (yacel)))        
  154.         (set_aistate 0))
  155.       (set_aistate (- (aistate) 1))))
  156. T) */
  157.  
  158. (defun sensor_draw ()
  159.   (if (edit_mode) 
  160.       (progn
  161.     (draw)
  162.     (let ((x1 (- (x) (xvel)))
  163.           (y1 (- (y) (yvel)))
  164.           (x2 (+ (x) (xvel)))
  165.           (y2 (+ (y) (yvel)))
  166.           (c  (find_rgb 0 255 0)))
  167.       (draw_line x1 y1 x2 y1 c)
  168.       (draw_line x2 y1 x2 y2 c)
  169.       (draw_line x2 y2 x1 y2 c)
  170.       (draw_line x1 y2 x1 y1 c))
  171.  
  172.     (let ((x1 (- (x) (xacel)))
  173.           (y1 (- (y) (yacel)))
  174.           (x2 (+ (x) (xacel)))
  175.           (y2 (+ (y) (yacel)))
  176.           (c  (find_rgb 255 0 0)))
  177.       (draw_line x1 y1 x2 y1 c)
  178.       (draw_line x2 y1 x2 y2 c)
  179.       (draw_line x2 y2 x1 y2 c)
  180.       (draw_line x1 y2 x1 y1 c)))
  181.  
  182.  
  183.     nil))
  184.  
  185. (defun sensor_ct ()
  186.   (select (aitype)
  187.       (1 (set_xvel 50)
  188.          (set_yvel 50)
  189.          (set_xacel 100)
  190.          (set_yacel 100))
  191.       (2 (set_xvel 50)
  192.          (set_yvel 30)
  193.          (set_xacel 100)
  194.          (set_yacel 50))
  195.       (3 (set_xvel 50)
  196.          (set_yvel 15)
  197.          (set_xacel 100)
  198.          (set_yacel 30))))
  199.  
  200. (def_char SENSOR
  201.   (range 100 100)
  202.   (funs (ai_fun      sensor_ai)
  203.     (draw_fun    sensor_draw)
  204.     (type_change_fun sensor_ct)
  205.     (constructor sensor_cons))
  206.   (vars unoffable)
  207.   (fields ("xvel" "(on) x dist")
  208.        ("yvel" "(on) y dist")
  209.        ("xacel" "(off) x dist")
  210.        ("yacel" "(off) y dist")
  211.        ("hp"    "(off) reset time")
  212.        ("unoffable" "unoffable (1=yes)")
  213.        ("aistate" "current state"))
  214.   (states "art/misc.spe"
  215.       (stopped "off")
  216.       (blocking "on")))
  217.             
  218.  
  219.  
  220. (defun dead_object (current)
  221.   (if (>= current 0)
  222.       (let ((st (with_object (get_object current) (state))))
  223.     (if (or (eq st dead) (eq st blown_back_dead))
  224.         (let ((dead_guy (get_object current)))          
  225.           (remove_object (get_object current))
  226.           dead_guy)
  227.       (dead_object (- current 1))))
  228.     nil))
  229.  
  230. (defun death_re_ai ()
  231.   (if (> (total_objects) 1)
  232.       (let ((find (dead_object (- (total_objects) 1))))
  233.     (if find
  234.         (add_object (with_object (get_object 0) (otype)) 
  235.             (with_object find (x))
  236.             (with_object find (y))))))
  237.              
  238.   T)
  239.  
  240. (def_char  DEATH_RESPAWNER
  241.   (range 50 50)
  242.   (funs (ai_fun      death_re_ai)
  243.     (draw_fun    dev_draw))
  244.   (states "art/misc.spe"
  245.       (stopped "death_respawn")))
  246.  
  247.  
  248. (defun death_sen_ai () 
  249.   (if (eq (total_objects) 0)
  250.       (progn
  251.     (set_state running)
  252.     (set_aistate 1))
  253.     (if (with_object (get_object 0) (or (eq (state) dead) (eq (state) blown_back_dead)))
  254.     (remove_object (get_object 0))))
  255.   T)
  256.  
  257. (def_char  DEATH_SENSOR
  258.   (range 50 50)
  259.   (funs (ai_fun      death_sen_ai)
  260.     (draw_fun    dev_draw))
  261.   (states "art/misc.spe"
  262.       (stopped "death_sensor0")
  263.       (running "death_sensor1")))
  264.  
  265.  
  266.