Content-transfer-encoding: 7BIT
Newsgroups: alt.cad.autocad
Date:         Wed, 23 Dec 1992 13:46:45 +0100
From:         Turi Maria Spinozzi <MC3470@MCLINK.IT>
Subject: Space Wars ! Sw.Lsp File

Ok Guys..... i think now this List is becoming a REAL autocad
list !! Thanks to everyone sending in List AutoLIsp  material
Now it's my turn ...  and i have for you an Autolisp War Game

This game has to be played by two person .. it's a space fight
beetween two players . To play this load the Lisp in a  EMPTY
DWG (new) . You have only to define Two blocks ... and have fun !!!
(never seen a WC firing torpedoes to a chair ??? :-D )
Bye and... HAPPY NEW YEAR !!

                                              Turi Maria Spinozzi
                                               MC3470@MCLINK.IT
Run game using SW


------cut here------------------------------------------------


 (setq TURN_ANG (/ PI 20)    ; Global set up variables
     TURN_TIME 0.000005787
     TORP_LIFE 20)
 (setvaR "CMDECHO" 0)
 (setvaR "BLIPMODE" 0)


 (defun C:SW ()
 (setupvars)
 (setq NO_STOP nil)
 (prompt
      "\nGame about to start, move crosshairs out of screen area.")
  (prompt "\nShip 1: (A) left (S) thruster (D) right (F) fire")
  (prompt "\nShip 2: (J)          (K)        (L)      (;)")
  (getstring)
  (while (null NO_STOP)
    (setq GAME_ON 'T)
    (prompt "\nBattle start")
    (while GAME_ON
    (setq KEY (grread 'T))
     (if KEY (key_action KEY))
     (move_action)
    )
    (command ".REDRAW")
    (initget 0 "Y N")
    (setq NO_STOP (getkword
    "\nBattle over, play another? <Y>: "))
    (if (and Tl_OBJ (entget (last T1_OBJ))) (entdel (last

T1_OBJ)))
      (if (and T2_OBJ (entget (last T2_OBJ))) (entdel (last
T2_OBJ)))
    (setq T1_OBJ nil T2_OBJ nil
          T1_LIFE -1 T2_LIFE -1)
  )
(prompt "\nGame over")
(princ)
)






(defun SETUPVARS ()
 (setq USCALE (/ (getvar "VIEWSIZE") 100.0)
       T1_LIFE -1

    T2_LIFE -1

    T1_OBJ nil
    T2_OBJ nil

    UMIN (getpoint "\nLower left corner of Universe: ")
    UMAX (getpoint "\nUpper right corner of Universe: ")
    S1_OBJ (entseL "\nLocate ship 1 bLock: ")

    EL (entget (caR S1_OBJ))
    S1_OBJ

      (list
        (cdR (assoc 10 EL))
        (/ USCALE 5)
        (cdR (assoc 50 EL))
        (getdist (cdR (assoc 10 EL))
             "\nInfluence Radius: ")
         (car S1_OBJ)
          )
     S2_OBJ (entsel "\nLocate ship 2 bLock: ")

     EL (entget (caR S2_OBJ))
     S2_OBJ

      (list
         (cdR (assoc 10 EL))
         (/ USCALE 5)
         (cdR (assoc 50 EL))
         (getdist (cdR (assoc 10 EL))
             "\nInfluence radius: ")
         (caR S2_OBJ)
      )
 )


(initget 0 "L M S")
(setq EL (getkword
    "\nWeapons are Long/Medium/Short range <L>: "))
(setq TORP_LIFE
 (cond
   ((null EL) 100)
   ((= EL "L") 100)
   ((= EL "M") 70)
   ((= EL "S") 25) )
 )
)
(defun KEY_ACTION ( KEY)
 (if (= (car KEY) 2)
  (progn
   (setq KEY (strcase (chr (cadr KEY))))
   (cond
    ((= KEY "S")
     (prompt "\nShip 1: Thruster fire")
        (setq s1_OBJ (thrust s1_OBJ)))
    ((= KEY "A")
     (prompt "\nShip 1: Turn left")
        (turn S1_OBJ TURN_ANG))
    ((= KEY "D")
      (prompt "\nShip 1: Turn right")
        (turn S1_OBJ (* -1 TURN_ANG)))
    ((= KEY "F")
      (prompt "\nShip 1: Fire request")
      (if (null T1_oBJ)
       (setq T1_OBJ (fire s1_oBJ 4)
             T1_LIFE TORP_LIFE)
    ))
    ((= KEY "K")
      (prompt "\nShip 2: Thruster fire")
        (setq S2_OBJ (thrust S2_OBJ)))
    ((= KEY "J")
      (prompt "\nShip 2: Turn ieft")
        (turn S2_OBJ TURN_ANG))
    ((= KEY "L")
      (prompt "\nShip 2: Turn right")
        (turn S2_OBJ (* -1 TURN_ANG)))
    ((= KEY ";")
      (prompt "\nShip 2: Fire request")
      (if (nuLL T2_OBJ)
       (setq T2_OBJ (fire S2_OBJ 2)
             T2_LIFE TORP_LIFE)
     )) )) ))





; Move Action  Updates objects on the screen

;
(defun MOVE_ACTION ()
 (setq VMAX (list (cadr S1_OBJ) (cadr S2_OBJ)))
 (if T1_OBJ (setq VMAX (cons (cadr T1_OBJ) VMAX)))
 (if T2_OBJ (setq VMAX (cons (cadr T2_OBJ) VMAX)))
 (setq VMAX (appLy 'max VMAX)
       TT (/ VMAX USCALE)
       CNT 0
 )
 (if (not (zerop TT))
  (whiLe (< CNT (1+ (fix TT)))
    (setq S1_OBJ (move_obj S1_OBJ (/ (cadr S1_OBJ) TT))
          S2_OBJ (move_obj S2_OBJ (/ (cadr S2_OBJ) TT))
          GAME_ON (hit_miss S1_OBJ S2_OBJ))
    (if (nuLL GAME_ON) (prompt "\nBoth ships destroyed!"))
    (if (and T1_OBJ (> T1_LIFE 0))
     (progn
      (setq T1_OBJ (move_obj T1_OBJ (/ (cadr T1_OBJ) TT))
            T1_LIFE (1- T1_LIFE)
            GAME_ON (hit_miss T1_OBJ S2_OBJ))
      (if (NULL GAME_ON) (prompt "\nShip 2 destroyed!"))
     )
    )
    (if (and T2_OBJ (> T2_LIFE 0))
     (progn
      (setq T2_OBJ (move_obj T2_OBJ (/ (cadr T2_OBJ) TT))
            T2_LIFE (1- T2_LIFE)
            GAME_ON (hit_miss T2_OBJ S1_OBJ))
      (if (null GAME_ON) (prompt "\nShip 1 destroyed!"))
     )
    )
    (if (and GAME_ON T1_OBJ T2_OBJ)
      (if (nuLL (hit_miss T1_OBJ T2_OBJ))
       (setq T1_OBJ (torp_expl T1_OBJ)
             T2_OBJ (torp_expl T2_OBJ)
             T1_LIFE -1
             T2_LIFE -1

       )
      )
    )
    (setq CNT (1+ CNT))
    (if (null GAME_ON) (setq CNT (1+ TT)))
  )
 )
(  if (zerop T1_LIFE)
   (pRogn
    (entdeL (last T1_OBJ))
    (toRp_expL T1_OBJ)
    (setq T1_OBJ nil T1_LTFE -1)
   )
)
(  if (zerop T2_LIFE)
   (progn
    (entdel (last T2_OBJ))
    (torp_expl T2_OBJ)
    (setq T2_OBj nil T2_LIFE -1)
   )
)
)


; Update THRUST vectors fop object
;
(defun THRUST (OBJ)
 (setq V1 (polar (list  0 0)
                 (caddr OBJ)
                 (cadr  OBJ)
          )
       V2 (polar (list 0 0)
          (cdr (assoc 50 (entget (last OBJ))))
            (/ USCALE 25))
     V1 (mapcar '+ V1 V2)
 )
 (if (> (distance (list 0 0) V1) (* USCALE 2))
   (setq V1 (polar (list 0 0) (angle (list 0 0) V1) (* USCALE
2))))
 (list (car OBJ)
     (distance (list 0 0) v1)
     (angle (list 0 0) V1)
     (cadddr OBJ)
     (last OBJ)
 )
)


(defun TURN (OBJ ANG)
 (setq EL (entget (last OBJ))
    EL (subst (cons 50 (+ (cdr (assoc 50 EL)) ANG))
            (assoc 50 EL)
            EL)
 )
 (entmod EL)
)

;
; Fire Control
;
(defun FIRE (OBJ CLR)
 (entmake (list
  (cons 0 "CIRCLE")
  (cons 8 "0")
  (cons 62 CLR)
  (cons 10 (car OBJ))
  (cons 40 (/ USCALE 2))
 ))
 (setq EL (entget (entlast)))
 (list (cdr (assoc 10 EL))
       (* USCALE 2)
    (cdr (assoc 50 (entget (last OBJ))))
    USCALE
    (entlast)
 )
)

;  hit miss determination
;  return 'T if miss, nil if hit
;
(defun HIT_MISS (M_OBJ  T_OBJ)
 (setq DD (distance (car M_OBJ) (car T_OBJ)))
 (if (and (> DD (+ (cadddr M_OBJ) (cadddr T_OBJ))) GAME_ON)
   'T;; No hit
   (explosion M_OBJ)
 )
)


(defun EXPLOSION (OBJ / CNT)
 (setq CNT 0.5)
 (repeat 10
  (entmake (list
   (cons 0 "CIRCLE")
   (cons 8 "0")
   (cons 62 1)
   (cons 10 (car OBJ))
   (cons 40 (* CNT USCALE))
  ))
  (setq EN (entlast))
  (repeat 11
  (entdeL EN))
  (setq CNT (+ CNT 0.5))
 )
 niL
)

     (defun TORP_EXPL (OBJ / CNT)
      (setq CNT 0.5)
      (repeat 2
       (entmake (list
         (cons 0 "CIRCLE")
         (cons 8 "0")
         (cons 62 1)
         (cons 10 (car OBJ))
         (cons 40  (*  CNT USCALE))
        ))
        (setq EN (entlast))
        (repeat 5
        (entdeL EN))
        (setq CNT (+ CNT 0.5))
       )
       niL
      )

       (defun MOVE_OBJ (OBJ FAR / P1 EL)
           (setq P1 (polar (car OBJ) (caddr OBJ) FAR))

       (if (< (car P1)   (car UMIN )) (setq P1 (list (car UMAX)
            (cadr P1) 0.0  )))
       (if (< (cadR P1)  (cadr UMIN)) (setq P1 (list (car P1)
            (cadr UMAX) 0.0)))
       (if (> (car P1)   (car UMAX )) (setq P1 (list (car UMIN)
            (cadr P1) 0.0 )))
       (if (> (cadr P1) (cadr UMAX)) (setq P1 (list (car P1)
            (cadr UMIN) 0.0)))
       (if (or (= (length P1) 2) (/= (caddr P1) 0.000))
            (setq P1 (list (car P1) (cadr P1) 0.0)))
       ( setq EL (entget (last OBJ))
              EL (subst (cons 10 P1) (assoc 10 EL) EL)
       )
       (entmod EL)
       (cons P1 (cdr OBJ))
      )
(TEXTSCR)
(princ "\n")
(princ "\n")
(princ "\n")
(princ "\n")
(princ "\n")
(princ "\n")
(princ "\n")
(princ "\n")
(princ "\n")
(princ "\n")
(princ "\n")
(princ "\n")
(princ "\n")
(princ "\n")
(princ "\n")
(PRINC "\n           Space War    IL PRIMO ARCADE PER AUTOCAD")
(PRINC "\n")
(PRINC "\n                PER GIOCARE DIGITA    SW <Enter> ")
(Princ "\n")
(princ "\n   Per poter giocare il disegno deve essere nuovo e contenere SOLO ")
(princ "\n   2 blocchi gia' inseriti nel disegno.... buon divertimento !!!   ")
(princ "\n")
(princ "\n   Per Autocad 11 Versione Inglese")
(Princ)
Newsgroups: alt.cad.autocad