emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New snake patch...


From: Deepak Goel
Subject: New snake patch...
Date: 28 Jan 2002 15:32:55 -0500
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1

hello

i submitted a patch for snake.el on g.e.sources sometime ago..  Upon
Pavel's suggestion, i have updated the patch to the latest CVS (gotten
today from savannah) and am including it at the end of this email.  

This patch is a result of 
"diff -cw snake-cvs.el snake.el "

To see what the patch does that is different, type M-x
snake-introduction after applying the patch.  IMHO, the patch removes
a serious bug, and makes the game pleasurable...  The snake now does
what the user wants it to do.. and my scores jumped much higher.. :)

Have a good day,

Deepak                             <http://www.glue.umd.edu/~deego>
-- 
A competent and self-confident person is incapable of jealousy in
anything. Jealousy is invariably a symptom of neurotic insecurity.
-- Lazarus Long




> > > ====================================================
PATCH FOLLOWS:

> > > ====================================================
*** ./snake-cvs.el      Mon Jan 28 15:16:39 2002
--- ./snake.el  Mon Jan 28 15:25:34 2002
***************
*** 1,4 ****
! ;;; snake.el --- implementation of Snake for Emacs
  
  ;; Copyright (C) 1997 Free Software Foundation, Inc.
  
--- 1,4 ----
! ;;; snake.el -- Implementation of Snake for Emacs
  
  ;; Copyright (C) 1997 Free Software Foundation, Inc.
  
***************
*** 6,11 ****
--- 6,12 ----
  ;; Created: 1997-09-10
  ;; Keywords: games
  
+ 
  ;; This file is part of GNU Emacs.
  
  ;; GNU Emacs is free software; you can redistribute it and/or modify
***************
*** 23,37 ****
  ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  ;; Boston, MA 02111-1307, USA.
  
! ;;; Commentary:
  
! ;;; Code:
  
  (eval-when-compile
    (require 'cl))
  
  (require 'gamegrid)
  
  ;; ;;;;;;;;;;;;; customization variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
  (defvar snake-use-glyphs t
--- 24,82 ----
  ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  ;; Boston, MA 02111-1307, USA.
  
! ;;; Introduction:
! ;; Stuff that gets posted to gnu.emacs.sources
! ;; as introduction
! 
! ;;; 2001-09-19 T09:35:26-0400 (Wednesday)    Deepak Goel
! ;; Removed a bug that kills you if your keystroke movements are too
! ;; rapid.
! ;; Also added a feature so that snake now respects all your keystrokes
! ;; even if they are too rapid..
! 
! (defvar snake-introduction
!   "Greetings
!       
!  Have you ever  wished snake didn't kill you for  'no fault of yours'?
!  Snake had  a bug.  Imagine  you are moving  to the right. Now  if you
!  either press \"up\" it is fine,  if you press \"left\" snake just ignores
!  it.  If you press \"up\" followed by a \"left\", that is fine too as long
!  as it is not too quick. But  if you press \"up\" followed by a \"left\" a
!  bit too  quickly, snake  disregards your 'up'.   Okay, that  is still
!  acceptable. The  problem is that  snake then does not  disregard your
!  left and slams into itself and kills you.  This was definitely a bug.
!  Snake should not accept the left..
! 
!  But there is an even better solution --- the snake should accept both
!  your up  and a  left..  should move  up just  one step and  them move
!  left..   none of your  commands should  ever be  ignored.. yes,  i am
!  talking of a que..
! 
!  To see what i am saying, you  just gotta play the old version and the
!  new version..  btw,  what's the max anyone got  with default settings
!  ---- mine is, like, 350's..
!               ")
! 
! 
! (defun snake-introduction ()
!   "Provides electric help for function `snake-introduction'."
!   (interactive)
!   (with-electric-help
!    '(lambda () (insert snake-introduction) nil) "*doc*"))
! 
! ;;
  
! 
! 
! ;;; Commentary:
  
  (eval-when-compile
    (require 'cl))
  
  (require 'gamegrid)
  
+ (defvar snake-moved-p nil)
+ 
  ;; ;;;;;;;;;;;;; customization variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
  (defvar snake-use-glyphs t
***************
*** 82,88 ****
  (defvar snake-score-y snake-height
    "Y position of score.")
  
! (defvar snake-score-file (concat temporary-file-directory "snake-scores")
    "File for holding high scores.")
  
  ;; ;;;;;;;;;;;;; display options ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
--- 127,133 ----
  (defvar snake-score-y snake-height
    "Y position of score.")
  
! (defvar snake-score-file "/tmp/snake-scores"
    "File for holding high scores.")
  
  ;; ;;;;;;;;;;;;; display options ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
***************
*** 238,243 ****
--- 283,290 ----
  Advances the snake one square, testing for collision."
    (if (and (not snake-paused)
           (eq (current-buffer) snake-buffer))
+       (progn
+       (snake-update-velocity)
        (let* ((pos (car snake-positions))
               (x (+ (aref pos 0) snake-velocity-x))
               (y (+ (aref pos 1) snake-velocity-y))
***************
*** 263,297 ****
                   (setcdr last-cons nil))))
          (gamegrid-set-cell x y snake-snake)
          (setq snake-positions
!               (cons (vector x y) snake-positions))))))
  
  (defun snake-move-left ()
    "Makes the snake move left"
    (interactive)
!   (unless (= snake-velocity-x 1)
!     (setq snake-velocity-x -1
!         snake-velocity-y 0)))
  
  (defun snake-move-right ()
    "Makes the snake move right"
    (interactive)
!   (unless (= snake-velocity-x -1)
!     (setq snake-velocity-x 1
!         snake-velocity-y 0)))
  
  (defun snake-move-up ()
    "Makes the snake move up"
    (interactive)
!   (unless (= snake-velocity-y 1)
!     (setq snake-velocity-x 0
!         snake-velocity-y -1)))
  
  (defun snake-move-down ()
    "Makes the snake move down"
    (interactive)
!   (unless (= snake-velocity-y -1)
!     (setq snake-velocity-x 0
!         snake-velocity-y 1)))
  
  (defun snake-end-game ()
    "Terminates the current game"
--- 310,375 ----
                     (setcdr last-cons nil))))
            (gamegrid-set-cell x y snake-snake)
            (setq snake-positions
!                 (cons (vector x y) snake-positions)))
!         (setq snake-moved-p nil)))))
! 
! (defvar snake-velocity-que nil
!   "Is a que..")
! 
! (defun snake-update-velocity ()
!   (unless snake-moved-p
!     (if snake-velocity-que
!       (let ((new-vel (reverse snake-velocity-que)))
!         (setq snake-velocity-x (first (first new-vel))
!               snake-velocity-y (second (first new-vel)))
!         (setq snake-velocity-que (reverse (cdr new-vel)))))
!     (setq snake-moved-p t)))
! 
! (defun snake-final-x-velocity ()
!   (if (null snake-velocity-que)
!       snake-velocity-x
!     (caar snake-velocity-que)))
! 
! (defun snake-final-y-velocity ()
!   (if (null snake-velocity-que)
!       snake-velocity-y
!     (cadar snake-velocity-que)))
  
  (defun snake-move-left ()
    "Makes the snake move left"
    (interactive)
!   (when
!       (zerop (snake-final-x-velocity))
!     (setq snake-velocity-que
!         (cons '(-1 0)
!               snake-velocity-que))))
  
  (defun snake-move-right ()
    "Makes the snake move right"
    (interactive)
!   (when
!       (zerop (snake-final-x-velocity))
!     (setq snake-velocity-que
!         (cons '(1 0)
!               snake-velocity-que))))
  
  (defun snake-move-up ()
    "Makes the snake move up"
    (interactive)
!   (when
!       (zerop (snake-final-y-velocity))
!     (setq snake-velocity-que
!         (cons '(0 -1)
!               snake-velocity-que))))
  
  (defun snake-move-down ()
    "Makes the snake move down"
    (interactive)
!   (when
!       (zerop (snake-final-y-velocity))
!     (setq snake-velocity-que
!         (cons '(0 1)
!               snake-velocity-que))))
  
  (defun snake-end-game ()
    "Terminates the current game"
***************
*** 304,309 ****
--- 382,388 ----
    "Starts a new game of Snake"
    (interactive)
    (snake-reset-game)
+   (setq snake-velocity-que nil)
    (use-local-map snake-mode-map)
    (gamegrid-start-timer snake-tick-period 'snake-update-game))
  
***************
*** 326,331 ****
--- 405,413 ----
  "
    (kill-all-local-variables)
  
+   ;; 2002-01-28 T15:25:26-0500 (Monday)    Deepak Goel
+   ;; now removed because is also removed in the latest cvs..
+   ;; (make-local-hook 'kill-buffer-hook)
    (add-hook 'kill-buffer-hook 'gamegrid-kill-timer nil t)
  
    (use-local-map snake-null-map)
***************
*** 373,378 ****
--- 455,461 ----
    (switch-to-buffer snake-buffer-name)
    (gamegrid-kill-timer)
    (snake-mode)
+   (setq snake-moved-p nil)
    (snake-start-game))
  
  (provide 'snake)






reply via email to

[Prev in Thread] Current Thread [Next in Thread]