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

  1. ;; Copyright 1995 Crack dot Com,  All Rights reserved
  2. ;; See licencing information for more details on usage rights
  3.  
  4.  
  5.  
  6. (defun make_smart_plat (symbol off_frame on_frame snap_yoffset)
  7.   (eval (list 'def_char symbol
  8.           '(flags (can_block T))
  9.           `(abilities (start_accel ,snap_yoffset))
  10.           '(fields ("xacel" "speed")
  11.                ("yacel" "2nd speed (0=same as 1st)")
  12.                ("xvel"  "current pos (0..speed)")
  13.                ("yvel" "max wait time"))
  14.           '(funs (ai_fun      platform_ai)
  15.              (constructor platform_cons))
  16.           '(range 50 500)
  17.           '(draw_range 30 60)
  18.           `(states "art/chars/platform.spe"
  19.                (stopped   ,off_frame)
  20.                (running   (list ,off_frame ,on_frame) )))))
  21.  
  22.  
  23. (make_smart_plat 'SMART_PLAT_BIG   "big_off"   "big_on"   26)
  24. (make_smart_plat 'SMART_PLAT_SMALL "small_off" "small_on" 22)
  25. (make_smart_plat 'SMART_PLAT_RED   "rplat_off" "rplat_on" 72)
  26.  
  27.  
  28. (defun platform_cons () (set_xacel 20) (set_yvel 50))
  29.  
  30. (defun plat_speed ()
  31.   (if (eq (aistate) 0)
  32.       (xacel)
  33.     (if (eq (yacel) 0)
  34.     (xacel)
  35.       (yacel))))
  36.  
  37. (defun platform_move (source dest)
  38.   (let ((destx (with_object dest (x)))
  39.     (desty (with_object dest (y)))
  40.     (sourcex (with_object source (x)))
  41.     (sourcey (with_object source (y))))
  42.     (if (equal (xvel) 0)  ;; no more steps
  43.     (progn
  44.       (platform_push (- destx (x)) (- desty (y)))
  45.       (set_x destx)
  46.       (set_y desty)
  47.       (set_aistate 0))  ;; stop
  48.       (let ((speed (plat_speed)))
  49.     (let ((newx (- destx (/ (* (- destx sourcex) (xvel)) speed)))
  50.           (newy (- desty (/ (* (- desty sourcey) (xvel)) speed))))    
  51.       (progn
  52.         (platform_push (- newx (x)) (- newy (y)))
  53.         (set_xvel (- (xvel) 1))
  54.         (set_x newx)
  55.         (set_y newy)))))))
  56.  
  57. (defun platform_ai ()
  58.   (if (or (eq (total_objects) 2)                     ;; no switch to listen to processed as normal
  59.       (and (eq (total_objects) 3) 
  60.            (not (eq (with_object (get_object 2) (aistate)) 0))))  ;; see if switch is active
  61.       (progn
  62.     (if (eq (state) stopped)
  63.         (set_state running)
  64.       (next_picture))
  65.     (select (aistate)
  66.         (0 ;; look for a player
  67.          (if (or (not (eq (with_object (get_object (aitype)) (aistate)) 0))
  68.              (and (touching_bg) (with_object (bg) (pressing_action_key))))
  69.              (progn
  70.                (if (and (touching_bg) (with_object (bg) (pressing_action_key)))
  71.                (let ((mex (x))
  72.                  (mey (- (y) (get_ability start_accel))))
  73.                  (with_object (bg) (progn (set_y mey)))))
  74.                (go_state 2))))
  75.  
  76.  
  77.         (2 ;; swap dest and source and go to new dest
  78.          (play_sound PLAT_A_SND 127 (x) (y))
  79.          (set_aitype (- 1 (aitype)))
  80.          (set_xvel (plat_speed));; steps to go         
  81.          (go_state 3))
  82.         
  83.         (3 ;; go to dest
  84.          (if (eq (xvel) 6) 
  85.              (play_sound PLAT_D_SND 127 (x) (y)))
  86.          (platform_move (get_object (aitype)) (get_object (- 1 (aitype)))))
  87.         ))
  88.     (set_state stopped))
  89.   T)
  90.          
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.