2020-08-31 18:41:45 +00:00
|
|
|
;;; pong.el --- classical implementation of pong -*- lexical-binding:t -*-
|
2000-01-07 12:20:57 +00:00
|
|
|
|
2022-01-01 07:45:51 +00:00
|
|
|
;; Copyright (C) 1999-2022 Free Software Foundation, Inc.
|
2000-01-07 12:20:57 +00:00
|
|
|
|
2001-07-17 07:37:19 +00:00
|
|
|
;; Author: Benjamin Drieu <bdrieu@april.org>
|
2000-01-07 12:20:57 +00:00
|
|
|
;; Keywords: games
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 07:25:26 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2000-01-07 12:20:57 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 07:25:26 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 22:52:52 +00:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; This is an implementation of the classical game pong.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
(eval-when-compile (require 'cl-lib))
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
(require 'gamegrid)
|
|
|
|
|
|
|
|
;;; Customization
|
|
|
|
|
2003-02-04 13:24:35 +00:00
|
|
|
(defgroup pong nil
|
2020-08-31 18:41:45 +00:00
|
|
|
"Emacs Lisp implementation of the classical game pong."
|
2000-01-07 12:20:57 +00:00
|
|
|
:tag "Pong"
|
|
|
|
:group 'games)
|
|
|
|
|
2003-02-04 13:24:35 +00:00
|
|
|
(defcustom pong-buffer-name "*Pong*"
|
2009-09-04 07:00:22 +00:00
|
|
|
"Name of the buffer used to play."
|
2000-01-07 12:20:57 +00:00
|
|
|
:type '(string))
|
|
|
|
|
|
|
|
(defcustom pong-width 50
|
2009-09-04 07:00:22 +00:00
|
|
|
"Width of the playfield."
|
2000-01-07 12:20:57 +00:00
|
|
|
:type '(integer))
|
|
|
|
|
2002-02-06 11:35:49 +00:00
|
|
|
(defcustom pong-height (min 30 (- (frame-height) 6))
|
2009-09-04 07:00:22 +00:00
|
|
|
"Height of the playfield."
|
2000-01-07 12:20:57 +00:00
|
|
|
:type '(integer))
|
|
|
|
|
|
|
|
(defcustom pong-bat-width 3
|
2009-09-04 07:00:22 +00:00
|
|
|
"Width of the bats for pong."
|
2000-01-07 12:20:57 +00:00
|
|
|
:type '(integer))
|
|
|
|
|
|
|
|
(defcustom pong-blank-color "black"
|
2009-09-04 07:00:22 +00:00
|
|
|
"Color used for background."
|
2001-02-08 00:05:15 +00:00
|
|
|
:type 'color)
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
(defcustom pong-bat-color "yellow"
|
2009-09-04 07:00:22 +00:00
|
|
|
"Color used for bats."
|
2001-02-08 00:05:15 +00:00
|
|
|
:type 'color)
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
(defcustom pong-ball-color "red"
|
2009-09-04 07:00:22 +00:00
|
|
|
"Color used for the ball."
|
2001-02-08 00:05:15 +00:00
|
|
|
:type 'color)
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
(defcustom pong-border-color "white"
|
2009-09-04 07:00:22 +00:00
|
|
|
"Color used for pong borders."
|
2001-02-08 00:05:15 +00:00
|
|
|
:type 'color)
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
(defcustom pong-left-key "4"
|
2009-09-04 07:00:22 +00:00
|
|
|
"Alternate key to press for bat 1 to go up (primary one is [left])."
|
2001-02-08 00:05:15 +00:00
|
|
|
:type '(restricted-sexp :match-alternatives (stringp vectorp)))
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
(defcustom pong-right-key "6"
|
2009-09-04 07:00:22 +00:00
|
|
|
"Alternate key to press for bat 1 to go down (primary one is [right])."
|
2001-02-08 00:05:15 +00:00
|
|
|
:type '(restricted-sexp :match-alternatives (stringp vectorp)))
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
(defcustom pong-up-key "8"
|
2009-09-04 07:00:22 +00:00
|
|
|
"Alternate key to press for bat 2 to go up (primary one is [up])."
|
2001-02-08 00:05:15 +00:00
|
|
|
:type '(restricted-sexp :match-alternatives (stringp vectorp)))
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
(defcustom pong-down-key "2"
|
2009-09-04 07:00:22 +00:00
|
|
|
"Alternate key to press for bat 2 to go down (primary one is [down])."
|
2001-02-08 00:05:15 +00:00
|
|
|
:type '(restricted-sexp :match-alternatives (stringp vectorp)))
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
(defcustom pong-quit-key "q"
|
2009-09-04 07:00:22 +00:00
|
|
|
"Key to press to quit pong."
|
2001-02-08 00:05:15 +00:00
|
|
|
:type '(restricted-sexp :match-alternatives (stringp vectorp)))
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
(defcustom pong-pause-key "p"
|
|
|
|
"Key to press to pause pong."
|
2001-02-08 00:05:15 +00:00
|
|
|
:type '(restricted-sexp :match-alternatives (stringp vectorp)))
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
(defcustom pong-resume-key "p"
|
2009-09-04 07:00:22 +00:00
|
|
|
"Key to press to resume pong."
|
2001-02-08 00:05:15 +00:00
|
|
|
:type '(restricted-sexp :match-alternatives (stringp vectorp)))
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
(defcustom pong-timer-delay 0.1
|
2009-09-04 07:00:22 +00:00
|
|
|
"Time to wait between every cycle."
|
2001-02-08 00:05:15 +00:00
|
|
|
:type 'number)
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; This is black magic. Define colors used
|
|
|
|
|
|
|
|
(defvar pong-blank-options
|
|
|
|
'(((glyph colorize)
|
|
|
|
(t ?\040))
|
|
|
|
((color-x color-x)
|
|
|
|
(mono-x grid-x)
|
|
|
|
(color-tty color-tty))
|
|
|
|
(((glyph color-x) [0 0 0])
|
|
|
|
(color-tty pong-blank-color))))
|
|
|
|
|
|
|
|
(defvar pong-bat-options
|
|
|
|
'(((glyph colorize)
|
|
|
|
(emacs-tty ?O)
|
|
|
|
(t ?\040))
|
|
|
|
((color-x color-x)
|
|
|
|
(mono-x mono-x)
|
|
|
|
(color-tty color-tty)
|
|
|
|
(mono-tty mono-tty))
|
|
|
|
(((glyph color-x) [1 1 0])
|
|
|
|
(color-tty pong-bat-color))))
|
|
|
|
|
|
|
|
(defvar pong-ball-options
|
|
|
|
'(((glyph colorize)
|
|
|
|
(t ?\*))
|
|
|
|
((color-x color-x)
|
|
|
|
(mono-x grid-x)
|
|
|
|
(color-tty color-tty))
|
|
|
|
(((glyph color-x) [1 0 0])
|
|
|
|
(color-tty pong-ball-color))))
|
|
|
|
|
|
|
|
(defvar pong-border-options
|
|
|
|
'(((glyph colorize)
|
|
|
|
(t ?\+))
|
|
|
|
((color-x color-x)
|
2002-09-13 13:30:09 +00:00
|
|
|
(mono-x grid-x)
|
|
|
|
(color-tty color-tty))
|
|
|
|
(((glyph color-x) [0.5 0.5 0.5])
|
2000-01-07 12:20:57 +00:00
|
|
|
(color-tty pong-border-color))))
|
|
|
|
|
|
|
|
(defconst pong-blank 0)
|
|
|
|
(defconst pong-bat 1)
|
|
|
|
(defconst pong-ball 2)
|
|
|
|
(defconst pong-border 3)
|
|
|
|
|
|
|
|
|
|
|
|
;;; Determine initial positions for bats and ball
|
|
|
|
|
|
|
|
(defvar pong-xx nil
|
|
|
|
"Horizontal speed of the ball.")
|
|
|
|
|
|
|
|
(defvar pong-yy nil
|
|
|
|
"Vertical speed of the ball.")
|
|
|
|
|
|
|
|
(defvar pong-x nil
|
|
|
|
"Horizontal position of the ball.")
|
|
|
|
|
|
|
|
(defvar pong-y nil
|
|
|
|
"Vertical position of the ball.")
|
|
|
|
|
|
|
|
(defvar pong-bat-player1 nil
|
|
|
|
"Vertical position of bat 1.")
|
|
|
|
|
|
|
|
(defvar pong-bat-player2 nil
|
|
|
|
"Vertical position of bat 2.")
|
|
|
|
|
|
|
|
(defvar pong-score-player1 nil)
|
|
|
|
(defvar pong-score-player2 nil)
|
|
|
|
|
|
|
|
;;; Initialize maps
|
|
|
|
|
2021-12-31 16:17:16 +00:00
|
|
|
(defvar-keymap pong-mode-map
|
|
|
|
:doc "Modemap for pong-mode."
|
|
|
|
:name 'pong-mode-map
|
|
|
|
"<left>" #'pong-move-left
|
|
|
|
"<right>" #'pong-move-right
|
|
|
|
"<up>" #'pong-move-up
|
|
|
|
"<down>" #'pong-move-down
|
|
|
|
pong-left-key #'pong-move-left
|
|
|
|
pong-right-key #'pong-move-right
|
|
|
|
pong-up-key #'pong-move-up
|
|
|
|
pong-down-key #'pong-move-down
|
|
|
|
pong-quit-key #'pong-quit
|
|
|
|
pong-pause-key #'pong-pause)
|
|
|
|
|
|
|
|
(defvar-keymap pong-null-map
|
|
|
|
:doc "Null map for pong-mode."
|
|
|
|
:name 'pong-null-map)
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Fun stuff -- The code
|
|
|
|
|
|
|
|
(defun pong-display-options ()
|
|
|
|
"Computes display options (required by gamegrid for colors)."
|
|
|
|
(let ((options (make-vector 256 nil)))
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
(dotimes (c 256)
|
2000-01-07 12:20:57 +00:00
|
|
|
(aset options c
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
(cond ((= c pong-blank)
|
|
|
|
pong-blank-options)
|
2000-01-07 12:20:57 +00:00
|
|
|
((= c pong-bat)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
pong-bat-options)
|
2000-01-07 12:20:57 +00:00
|
|
|
((= c pong-ball)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
pong-ball-options)
|
2000-01-07 12:20:57 +00:00
|
|
|
((= c pong-border)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
pong-border-options)
|
2000-01-07 12:20:57 +00:00
|
|
|
(t
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
'(nil nil nil)))))
|
2000-01-07 12:20:57 +00:00
|
|
|
options))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun pong-init-buffer ()
|
|
|
|
"Initialize pong buffer and draw stuff thanks to gamegrid library."
|
|
|
|
(get-buffer-create pong-buffer-name)
|
|
|
|
(switch-to-buffer pong-buffer-name)
|
|
|
|
(use-local-map pong-mode-map)
|
|
|
|
|
|
|
|
(setq gamegrid-use-glyphs t)
|
|
|
|
(setq gamegrid-use-color t)
|
|
|
|
(gamegrid-init (pong-display-options))
|
|
|
|
|
|
|
|
(gamegrid-init-buffer pong-width
|
|
|
|
(+ 2 pong-height)
|
2006-06-09 14:23:49 +00:00
|
|
|
?\s)
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
(let ((buffer-read-only nil))
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
(dotimes (y pong-height)
|
|
|
|
(dotimes (x pong-width)
|
|
|
|
(gamegrid-set-cell x y pong-border)))
|
|
|
|
(cl-loop for y from 1 to (- pong-height 2) do
|
|
|
|
(cl-loop for x from 1 to (- pong-width 2) do
|
|
|
|
(gamegrid-set-cell x y pong-blank))))
|
2000-01-07 12:20:57 +00:00
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
(cl-loop for y from pong-bat-player1
|
|
|
|
to (1- (+ pong-bat-player1 pong-bat-width))
|
|
|
|
do (gamegrid-set-cell 2 y pong-bat))
|
|
|
|
(cl-loop for y from pong-bat-player2
|
|
|
|
to (1- (+ pong-bat-player2 pong-bat-width))
|
|
|
|
do (gamegrid-set-cell (- pong-width 3) y pong-bat)))
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
(defun pong-move-left ()
|
2019-08-07 14:55:54 +00:00
|
|
|
"Move bat 1 up.
|
2000-01-07 12:20:57 +00:00
|
|
|
This is called left for historical reasons, since in some pong
|
|
|
|
implementations you move with left/right paddle."
|
2021-09-16 12:47:51 +00:00
|
|
|
(interactive nil pong-mode)
|
2000-01-07 12:20:57 +00:00
|
|
|
(if (> pong-bat-player1 1)
|
|
|
|
(and
|
|
|
|
(setq pong-bat-player1 (1- pong-bat-player1))
|
|
|
|
(pong-update-bat 2 pong-bat-player1))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun pong-move-right ()
|
2019-08-07 14:55:54 +00:00
|
|
|
"Move bat 1 down."
|
2021-09-16 12:47:51 +00:00
|
|
|
(interactive nil pong-mode)
|
2000-01-07 12:20:57 +00:00
|
|
|
(if (< (+ pong-bat-player1 pong-bat-width) (1- pong-height))
|
|
|
|
(and
|
|
|
|
(setq pong-bat-player1 (1+ pong-bat-player1))
|
|
|
|
(pong-update-bat 2 pong-bat-player1))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun pong-move-up ()
|
|
|
|
"Move bat 2 up."
|
2021-09-16 12:47:51 +00:00
|
|
|
(interactive nil pong-mode)
|
2000-01-07 12:20:57 +00:00
|
|
|
(if (> pong-bat-player2 1)
|
|
|
|
(and
|
|
|
|
(setq pong-bat-player2 (1- pong-bat-player2))
|
|
|
|
(pong-update-bat (- pong-width 3) pong-bat-player2))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun pong-move-down ()
|
|
|
|
"Move bat 2 down."
|
2021-09-16 12:47:51 +00:00
|
|
|
(interactive nil pong-mode)
|
2000-01-07 12:20:57 +00:00
|
|
|
(if (< (+ pong-bat-player2 pong-bat-width) (1- pong-height))
|
|
|
|
(and
|
|
|
|
(setq pong-bat-player2 (1+ pong-bat-player2))
|
|
|
|
(pong-update-bat (- pong-width 3) pong-bat-player2))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun pong-update-bat (x y)
|
|
|
|
"Move a bat (suppress a cell and draw another one on the other side)."
|
|
|
|
|
|
|
|
(cond
|
|
|
|
((string-equal (buffer-name (current-buffer)) pong-buffer-name)
|
|
|
|
(gamegrid-set-cell x y pong-bat)
|
|
|
|
(gamegrid-set-cell x (1- (+ y pong-bat-width)) pong-bat)
|
|
|
|
(if (> y 1)
|
|
|
|
(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)))))
|
2003-02-04 13:24:35 +00:00
|
|
|
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
(defun pong-init ()
|
|
|
|
"Initialize a game."
|
2003-02-04 13:24:35 +00:00
|
|
|
|
2000-01-07 12:20:57 +00:00
|
|
|
(define-key pong-mode-map pong-pause-key 'pong-pause)
|
|
|
|
|
|
|
|
(add-hook 'kill-buffer-hook 'pong-quit nil t)
|
|
|
|
|
|
|
|
;; Initialization of some variables
|
|
|
|
(setq pong-bat-player1 (1+ (/ (- pong-height pong-bat-width) 2)))
|
|
|
|
(setq pong-bat-player2 pong-bat-player1)
|
|
|
|
(setq pong-xx -1)
|
|
|
|
(setq pong-yy 0)
|
|
|
|
(setq pong-x (/ pong-width 2))
|
|
|
|
(setq pong-y (/ pong-height 2))
|
|
|
|
|
|
|
|
(pong-init-buffer)
|
|
|
|
(gamegrid-kill-timer)
|
|
|
|
(gamegrid-start-timer pong-timer-delay 'pong-update-game)
|
|
|
|
(pong-update-score))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun pong-update-game (pong-buffer)
|
|
|
|
"\"Main\" function for pong.
|
|
|
|
It is called every pong-cycle-delay seconds and
|
|
|
|
updates ball and bats positions. It is responsible of collision
|
|
|
|
detection and checks if a player scores."
|
|
|
|
(if (not (eq (current-buffer) pong-buffer))
|
|
|
|
(pong-pause)
|
2003-02-04 13:24:35 +00:00
|
|
|
|
2000-01-07 12:20:57 +00:00
|
|
|
(let ((old-x pong-x)
|
|
|
|
(old-y pong-y))
|
2019-08-07 00:48:41 +00:00
|
|
|
;; Erase the last ball position.
|
|
|
|
(when (and (> old-y 0)
|
|
|
|
(< old-y (- pong-height 1)))
|
|
|
|
;; If the ball hit the bat in the column where bats are positioned,
|
|
|
|
;; and therefore changed its x direction, draw again the bat cell.
|
|
|
|
(if (or (and (= old-x 2) (< 0 pong-xx))
|
|
|
|
(and (= old-x (- pong-width 3)) (> 0 pong-xx)))
|
|
|
|
(gamegrid-set-cell old-x old-y pong-bat)
|
|
|
|
(gamegrid-set-cell old-x old-y pong-blank)))
|
|
|
|
|
|
|
|
;; Update the ball position.
|
2000-01-07 12:20:57 +00:00
|
|
|
(setq pong-x (+ pong-x pong-xx))
|
2019-08-07 00:48:41 +00:00
|
|
|
;; If the ball would go out of bounds, put it against the border.
|
|
|
|
(cond
|
|
|
|
((<= (+ pong-y pong-yy) 0)
|
|
|
|
(setq pong-yy (- pong-yy))
|
|
|
|
(setq pong-y 1))
|
|
|
|
((>= (+ pong-y pong-yy) (- pong-height 1))
|
|
|
|
(setq pong-yy (- pong-yy))
|
|
|
|
(setq pong-y (- pong-height 2)))
|
|
|
|
(t
|
|
|
|
(setq pong-y (+ pong-y pong-yy))
|
|
|
|
;; Check if the ball is against the border now,
|
|
|
|
;; and change the y direction if it is.
|
|
|
|
(when (or (<= pong-y 1) (>= pong-y (- pong-height 2)))
|
|
|
|
(setq pong-yy (- pong-yy)))))
|
|
|
|
|
|
|
|
;; Draw the ball in its new position.
|
2000-01-07 12:20:57 +00:00
|
|
|
(if (and (> pong-y 0)
|
|
|
|
(< pong-y (- pong-height 1)))
|
|
|
|
(gamegrid-set-cell pong-x pong-y pong-ball))
|
2003-02-04 13:24:35 +00:00
|
|
|
|
2019-08-07 00:48:41 +00:00
|
|
|
;; Hit bat, score a goal, or nothing.
|
2000-01-07 12:20:57 +00:00
|
|
|
(cond
|
2019-08-07 00:48:41 +00:00
|
|
|
((and (or (= pong-x 3) (= pong-x 2))
|
|
|
|
(> 0 pong-xx) ; Collide with the bat if headed towards it.
|
|
|
|
(>= pong-y pong-bat-player1)
|
|
|
|
(< pong-y (+ pong-bat-player1 pong-bat-width)))
|
|
|
|
(setq pong-yy (+ pong-yy
|
|
|
|
(cond
|
|
|
|
((= pong-y pong-bat-player1) -1)
|
|
|
|
((= pong-y (1+ pong-bat-player1)) 0)
|
|
|
|
(t 1))))
|
|
|
|
(setq pong-xx (- pong-xx)))
|
|
|
|
|
|
|
|
((and (or (= pong-x (- pong-width 4)) (= pong-x (- pong-width 3)))
|
|
|
|
(< 0 pong-xx) ; Collide with the bat if headed towards it.
|
|
|
|
(>= pong-y pong-bat-player2)
|
|
|
|
(< pong-y (+ pong-bat-player2 pong-bat-width)))
|
|
|
|
(setq pong-yy (+ pong-yy
|
|
|
|
(cond
|
|
|
|
((= pong-y pong-bat-player2) -1)
|
|
|
|
((= pong-y (1+ pong-bat-player2)) 0)
|
|
|
|
(t 1))))
|
|
|
|
(setq pong-xx (- pong-xx)))
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
((< pong-x 1)
|
|
|
|
(setq pong-score-player2 (1+ pong-score-player2))
|
|
|
|
(pong-init))
|
|
|
|
|
|
|
|
((>= pong-x (- pong-width 1))
|
|
|
|
(setq pong-score-player1 (1+ pong-score-player1))
|
|
|
|
(pong-init))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun pong-update-score ()
|
|
|
|
"Update score and print it on bottom of the game grid."
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
(let* ((string (format "Score: %d / %d"
|
|
|
|
pong-score-player1 pong-score-player2))
|
2000-01-07 12:20:57 +00:00
|
|
|
(len (length string)))
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
(dotimes (x len)
|
|
|
|
(if (string-equal (buffer-name (current-buffer)) pong-buffer-name)
|
|
|
|
(gamegrid-set-cell x pong-height (aref string x))))))
|
2000-01-07 12:20:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun pong-pause ()
|
|
|
|
"Pause the game."
|
2021-09-16 12:47:51 +00:00
|
|
|
(interactive nil pong-mode)
|
2000-01-07 12:20:57 +00:00
|
|
|
(gamegrid-kill-timer)
|
|
|
|
;; Oooohhh ugly. I don't know why, gamegrid-kill-timer don't do the
|
|
|
|
;; jobs it is made for. So I have to do it "by hand". Anyway, next
|
|
|
|
;; line is harmless.
|
|
|
|
(cancel-function-timers 'pong-update-game)
|
|
|
|
(define-key pong-mode-map pong-resume-key 'pong-resume))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun pong-resume ()
|
|
|
|
"Resume a paused game."
|
2021-09-16 12:47:51 +00:00
|
|
|
(interactive nil pong-mode)
|
2000-01-07 12:20:57 +00:00
|
|
|
(define-key pong-mode-map pong-pause-key 'pong-pause)
|
|
|
|
(gamegrid-start-timer pong-timer-delay 'pong-update-game))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun pong-quit ()
|
|
|
|
"Quit the game and kill the pong buffer."
|
2021-09-16 12:47:51 +00:00
|
|
|
(interactive nil pong-mode)
|
2000-01-07 12:20:57 +00:00
|
|
|
(gamegrid-kill-timer)
|
|
|
|
;; Be sure not to draw things in another buffer and wait for some
|
|
|
|
;; time.
|
|
|
|
(run-with-timer pong-timer-delay nil 'kill-buffer pong-buffer-name))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun pong ()
|
|
|
|
"Play pong and waste time.
|
|
|
|
This is an implementation of the classical game pong.
|
|
|
|
Move left and right bats and try to bounce the ball to your opponent.
|
|
|
|
|
2000-08-16 19:07:04 +00:00
|
|
|
pong-mode keybindings:\\<pong-mode-map>
|
2000-01-07 12:20:57 +00:00
|
|
|
|
2000-08-16 19:07:04 +00:00
|
|
|
\\{pong-mode-map}"
|
2000-01-07 12:20:57 +00:00
|
|
|
(interactive)
|
|
|
|
(setq pong-score-player1 0)
|
|
|
|
(setq pong-score-player2 0)
|
|
|
|
(pong-init))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'pong)
|
2001-07-16 09:10:19 +00:00
|
|
|
|
|
|
|
;;; pong.el ends here
|