* Randomise spawning apples in snake.el
@ 2009-05-07 19:57 Stuart Hacking
2009-05-08 0:57 ` Stefan Monnier
2009-08-19 20:05 ` Stefan Monnier
0 siblings, 2 replies; 3+ messages in thread
From: Stuart Hacking @ 2009-05-07 19:57 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 716 bytes --]
Hi,
This is my first quick modification to emacs. I hope I've produced
the .diff correctly, if not, please yell at me for not correctly
reading the submission guidelines. (Also: I apologise if this is not
the correct place to submit patches - I didn't see anything about code
submission on savannah. Please advise if necessary.)
The modification changes snake.el so that new apples will be spawned
at random locations rather than being deposited behind the snake. I
intended to govern the spawn rate based on score, however, since the
game speed increases I decided this was unnecessary.
Hope this provides enjoyment for someone - now onto bigger and better
things! :-)
Kindest Regards
Stuart
[-- Attachment #1.2: snake_rand_apples.el.diff --]
[-- Type: application/octet-stream, Size: 770 bytes --]
Index: lisp/play/snake.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/play/snake.el,v
retrieving revision 1.24
diff -r1.24 snake.el
149a150
> (defvar spawn-rate 10)
169a171
> (make-variable-buffer-local 'spawn-rate)
242a245
> spawn-rate 10
280,282c283,285
< (if (= (% snake-cycle 5) 0)
< snake-dot
< snake-blank))
---
> snake-blank)
> (if (= (% snake-cycle spawn-rate) 0)
> (snake-put-dot))
289a293,298
> (defun snake-put-dot ()
> (let ((x (1+ (random (- snake-width 2))))
> (y (1+ (random (- snake-height 2)))))
> (if (= (gamegrid-get-cell x y) snake-blank)
> (gamegrid-set-cell x y snake-dot))))
>
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 186 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Randomise spawning apples in snake.el
2009-05-07 19:57 Randomise spawning apples in snake.el Stuart Hacking
@ 2009-05-08 0:57 ` Stefan Monnier
2009-08-19 20:05 ` Stefan Monnier
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2009-05-08 0:57 UTC (permalink / raw)
To: Stuart Hacking; +Cc: emacs-devel
> This is my first quick modification to emacs. I hope I've produced the
> .diff correctly, if not, please yell at me for not correctly reading the
> submission guidelines.
Please use "diff -u" to get context diffs which are more readable for
humans and more robust (they can often be applied to slightly different
versions of the file).
> (Also: I apologise if this is not the correct place
> to submit patches - I didn't see anything about code submission on
> savannah. Please advise if necessary.)
This is the right place.
> The modification changes snake.el so that new apples will be spawned at
> random locations rather than being deposited behind the snake. I intended
> to govern the spawn rate based on score, however, since the game speed
> increases I decided this was unnecessary.
We're in pretest for Emacs-23.1, so new features like this one are
currently on-hold for now. But thank you for your submission, we'll
reconsider it once we open up the trunk for new changes for Emacs-23.2.
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Randomise spawning apples in snake.el
2009-05-07 19:57 Randomise spawning apples in snake.el Stuart Hacking
2009-05-08 0:57 ` Stefan Monnier
@ 2009-08-19 20:05 ` Stefan Monnier
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2009-08-19 20:05 UTC (permalink / raw)
To: Stuart Hacking; +Cc: emacs-devel
> This is my first quick modification to emacs. I hope I've produced the
> .diff correctly, if not, please yell at me for not correctly reading the
> submission guidelines. (Also: I apologise if this is not the correct place
> to submit patches - I didn't see anything about code submission on
> savannah. Please advise if necessary.)
> The modification changes snake.el so that new apples will be spawned at
> random locations rather than being deposited behind the snake. I intended
> to govern the spawn rate based on score, however, since the game speed
> increases I decided this was unnecessary.
This looks like an acceptable improvement, but the patch needs a few
tweaks: your new spawn-rate variable seems to be a customization
variable, which is never set directly by the game, so it should be
declared with defcustom and should not be made-variable-buffer-local.
Of course, maybe it doesn't deserve a customization (after all, 5 was
hardcoded before), in which case the `defvar' is fine (but the
make-variable-buffer-local is not).
Also, I'm not sure why it defaults to 10, where the current code seems
to use 5 for the same purpose.
Finally, it'd be good to make it so that the current behavior can be
preserved (under the constrol of a customization variable, or some
argument when starting the game, or ...).
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-08-19 20:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-07 19:57 Randomise spawning apples in snake.el Stuart Hacking
2009-05-08 0:57 ` Stefan Monnier
2009-08-19 20:05 ` Stefan Monnier
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).