comparison lisp/play/pong.el @ 49598:0d8b17d428b5

Trailing whitepace deleted.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 04 Feb 2003 13:24:35 +0000
parents c48cad4dc557
children 695cf19ef79e d7ddb3e565de
comparison
equal deleted inserted replaced
49597:e88404e8f2cf 49598:0d8b17d428b5
32 32
33 (require 'gamegrid) 33 (require 'gamegrid)
34 34
35 ;;; Customization 35 ;;; Customization
36 36
37 (defgroup pong nil 37 (defgroup pong nil
38 "Emacs-Lisp implementation of the classical game pong." 38 "Emacs-Lisp implementation of the classical game pong."
39 :tag "Pong" 39 :tag "Pong"
40 :group 'games) 40 :group 'games)
41 41
42 (defcustom pong-buffer-name "*Pong*" 42 (defcustom pong-buffer-name "*Pong*"
43 "*Name of the buffer used to play." 43 "*Name of the buffer used to play."
44 :group 'pong 44 :group 'pong
45 :type '(string)) 45 :type '(string))
46 46
47 (defcustom pong-width 50 47 (defcustom pong-width 50
311 (gamegrid-set-cell x (1- (+ y pong-bat-width)) pong-bat) 311 (gamegrid-set-cell x (1- (+ y pong-bat-width)) pong-bat)
312 (if (> y 1) 312 (if (> y 1)
313 (gamegrid-set-cell x (1- y) pong-blank)) 313 (gamegrid-set-cell x (1- y) pong-blank))
314 (if (< (+ y pong-bat-width) (1- pong-height)) 314 (if (< (+ y pong-bat-width) (1- pong-height))
315 (gamegrid-set-cell x (+ y pong-bat-width) pong-blank))))) 315 (gamegrid-set-cell x (+ y pong-bat-width) pong-blank)))))
316 316
317 317
318 318
319 (defun pong-init () 319 (defun pong-init ()
320 "Initialize a game." 320 "Initialize a game."
321 321
322 (define-key pong-mode-map pong-pause-key 'pong-pause) 322 (define-key pong-mode-map pong-pause-key 'pong-pause)
323 323
324 (add-hook 'kill-buffer-hook 'pong-quit nil t) 324 (add-hook 'kill-buffer-hook 'pong-quit nil t)
325 325
326 ;; Initialization of some variables 326 ;; Initialization of some variables
343 It is called every pong-cycle-delay seconds and 343 It is called every pong-cycle-delay seconds and
344 updates ball and bats positions. It is responsible of collision 344 updates ball and bats positions. It is responsible of collision
345 detection and checks if a player scores." 345 detection and checks if a player scores."
346 (if (not (eq (current-buffer) pong-buffer)) 346 (if (not (eq (current-buffer) pong-buffer))
347 (pong-pause) 347 (pong-pause)
348 348
349 (let ((old-x pong-x) 349 (let ((old-x pong-x)
350 (old-y pong-y)) 350 (old-y pong-y))
351 351
352 (setq pong-x (+ pong-x pong-xx)) 352 (setq pong-x (+ pong-x pong-xx))
353 (setq pong-y (+ pong-y pong-yy)) 353 (setq pong-y (+ pong-y pong-yy))
354 354
355 (if (and (> old-y 0) 355 (if (and (> old-y 0)
356 (< old-y (- pong-height 1))) 356 (< old-y (- pong-height 1)))
357 (gamegrid-set-cell old-x old-y pong-blank)) 357 (gamegrid-set-cell old-x old-y pong-blank))
358 358
359 (if (and (> pong-y 0) 359 (if (and (> pong-y 0)
360 (< pong-y (- pong-height 1))) 360 (< pong-y (- pong-height 1)))
361 (gamegrid-set-cell pong-x pong-y pong-ball)) 361 (gamegrid-set-cell pong-x pong-y pong-ball))
362 362
363 (cond 363 (cond
364 ((or (= pong-x 3) (= pong-x 2)) 364 ((or (= pong-x 3) (= pong-x 2))
365 (if (and (>= pong-y pong-bat-player1) 365 (if (and (>= pong-y pong-bat-player1)
366 (< pong-y (+ pong-bat-player1 pong-bat-width))) 366 (< pong-y (+ pong-bat-player1 pong-bat-width)))
367 (and 367 (and
368 (setq pong-yy (+ pong-yy 368 (setq pong-yy (+ pong-yy
369 (cond 369 (cond
370 ((= pong-y pong-bat-player1) -1) 370 ((= pong-y pong-bat-player1) -1)
371 ((= pong-y (1+ pong-bat-player1)) 0) 371 ((= pong-y (1+ pong-bat-player1)) 0)
372 (t 1)))) 372 (t 1))))
373 (setq pong-xx (- pong-xx))))) 373 (setq pong-xx (- pong-xx)))))
374 374
375 ((or (= pong-x (- pong-width 4)) (= pong-x (- pong-width 3))) 375 ((or (= pong-x (- pong-width 4)) (= pong-x (- pong-width 3)))
376 (if (and (>= pong-y pong-bat-player2) 376 (if (and (>= pong-y pong-bat-player2)
377 (< pong-y (+ pong-bat-player2 pong-bat-width))) 377 (< pong-y (+ pong-bat-player2 pong-bat-width)))
378 (and 378 (and
379 (setq pong-yy (+ pong-yy 379 (setq pong-yy (+ pong-yy
380 (cond 380 (cond
381 ((= pong-y pong-bat-player2) -1) 381 ((= pong-y pong-bat-player2) -1)
382 ((= pong-y (1+ pong-bat-player2)) 0) 382 ((= pong-y (1+ pong-bat-player2)) 0)
383 (t 1)))) 383 (t 1))))
384 (setq pong-xx (- pong-xx))))) 384 (setq pong-xx (- pong-xx)))))
385 385
386 ((<= pong-y 1) 386 ((<= pong-y 1)
387 (setq pong-yy (- pong-yy))) 387 (setq pong-yy (- pong-yy)))
388 388
389 ((>= pong-y (- pong-height 2)) 389 ((>= pong-y (- pong-height 2))
390 (setq pong-yy (- pong-yy))) 390 (setq pong-yy (- pong-yy)))