;;; Customization
-(defgroup pong nil
+(defgroup pong nil
"Emacs-Lisp implementation of the classical game pong."
:tag "Pong"
:group 'games)
-(defcustom pong-buffer-name "*Pong*"
+(defcustom pong-buffer-name "*Pong*"
"*Name of the buffer used to play."
:group 'pong
:type '(string))
:type 'color)
(defcustom pong-border-color "white"
- "*Color used for pong balls."
+ "*Color used for pong borders."
:group 'pong
:type 'color)
'(((glyph colorize)
(t ?\+))
((color-x color-x)
- (mono-x grid-x))
- ;; The colors used to be [0.5 0.5 0.5], but that produces a black
- ;; color on 8-color tty's, which would make the border invisible.
- ;; 0.51 produces white on such tty's, and at the same time has
- ;; almost no effect on X and similar displays.
- (((glyph color-x) [0.51 0.51 0.51])
+ (mono-x grid-x)
+ (color-tty color-tty))
+ (((glyph color-x) [0.5 0.5 0.5])
(color-tty pong-border-color))))
(defconst pong-blank 0)
(gamegrid-set-cell x (1- y) pong-blank))
(if (< (+ y pong-bat-width) (1- pong-height))
(gamegrid-set-cell x (+ y pong-bat-width) pong-blank)))))
-
+
(defun pong-init ()
"Initialize a game."
-
+
(define-key pong-mode-map pong-pause-key 'pong-pause)
(make-local-hook 'kill-buffer-hook)
detection and checks if a player scores."
(if (not (eq (current-buffer) pong-buffer))
(pong-pause)
-
+
(let ((old-x pong-x)
(old-y pong-y))
-
+
(setq pong-x (+ pong-x pong-xx))
(setq pong-y (+ pong-y pong-yy))
-
+
(if (and (> old-y 0)
(< old-y (- pong-height 1)))
(gamegrid-set-cell old-x old-y pong-blank))
-
+
(if (and (> pong-y 0)
(< pong-y (- pong-height 1)))
(gamegrid-set-cell pong-x pong-y pong-ball))
-
+
(cond
((or (= pong-x 3) (= pong-x 2))
- (if (and (>= pong-y pong-bat-player1)
+ (if (and (>= pong-y pong-bat-player1)
(< pong-y (+ pong-bat-player1 pong-bat-width)))
- (and
+ (and
(setq pong-yy (+ pong-yy
- (cond
+ (cond
((= pong-y pong-bat-player1) -1)
((= pong-y (1+ pong-bat-player1)) 0)
(t 1))))
(setq pong-xx (- pong-xx)))))
((or (= pong-x (- pong-width 4)) (= pong-x (- pong-width 3)))
- (if (and (>= pong-y pong-bat-player2)
+ (if (and (>= pong-y pong-bat-player2)
(< pong-y (+ pong-bat-player2 pong-bat-width)))
- (and
+ (and
(setq pong-yy (+ pong-yy
- (cond
+ (cond
((= pong-y pong-bat-player2) -1)
((= pong-y (1+ pong-bat-player2)) 0)
(t 1))))
(setq pong-xx (- pong-xx)))))
-
+
((<= pong-y 1)
(setq pong-yy (- pong-yy)))