unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#20579: 24.4; Pong bat loses 1/3rd of its length if the ball hits it too quickly
@ 2015-05-14 18:58 Matt Lee
  2019-08-07 15:03 ` Mauro Aranda
  0 siblings, 1 reply; 3+ messages in thread
From: Matt Lee @ 2015-05-14 18:58 UTC (permalink / raw)
  To: 20579


* Start Emacs and start pong

* Immediately move the left bat down a square or two

* As the ball is about to miss your bat, move up quickly so your bat
essentially overrwrites the space of the ball on screen

* The ball bounces, but your bat is left as two, not three squares long.



In GNU Emacs 24.4.1 (x86_64-pc-linux-gnu, GTK+ Version 3.14.5)
of 2015-03-07 on trouble, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11604000
System Description: Debian GNU/Linux 8.0 (jessie)

Configured using:
`configure --build x86_64-linux-gnu --prefix=/usr
--sharedstatedir=/var/lib --libexecdir=/usr/lib
--localstatedir=/var/lib --infodir=/usr/share/info
--mandir=/usr/share/man --with-pop=yes
--enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.4/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.4/site-lisp:/usr/share/emacs/site-lisp 

--build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib
--libexecdir=/usr/lib --localstatedir=/var/lib
--infodir=/usr/share/info --mandir=/usr/share/man --with-pop=yes
--enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.4/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.4/site-lisp:/usr/share/emacs/site-lisp 

--with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars
'CFLAGS=-g -O2 -fstack-protector-strong -Wformat
-Werror=format-security -Wall' CPPFLAGS=-D_FORTIFY_SOURCE=2
LDFLAGS=-Wl,-z,relro'

Important settings:
value of $LANG: en_US.UTF-8
locale-coding-system: utf-8-unix

Major mode: Info

Minor modes in effect:
tooltip-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
buffer-read-only: t
line-number-mode: t
transient-mark-mode: t

Recent input:
M-x p o n g <return> <left> <right> <left> <left> <left>
<left> <left> <right> <right> <right> <right> <right>
<right> <right> <help-echo> <right> <left> <left> <left>
<up> <up> <down> <down> <down> <down> <down> <down>
<up> <left> <right> <down> <up> <up> <left> <left>
<left> <left> <left> <left> <left> <left> <left> <left>
<left> <left> <right> <right> <up> <up> <up> <up> <up>
<up> <down> <up> <up> <up> <down> <down> <down> <down>
<down> <up> <right> <right> <right> <right> <right>
<right> <right> <right> <right> <left> <left> <left>
<left> <left> <left> <left> <right> <left> <down> <right>
<right> <left> <down> <up> <up> <down> <left> <right>
<right> <left> <down> <down> <down> <down> <down> <down>
<down> <down> <right> <right> <right> <right> <right>
<right> <right> <right> <right> <right> <right> <left>
<right> <left> <right> <left> <help-echo> <help-echo>
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo>
<menu-bar> <help-menu> <emacs-manual-bug> <help-echo>
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo>
<help-echo> <menu-bar> <help-menu> <send-emacs-bug
-report>

Recent messages:
call-interactively: Buffer is read-only: #<buffer *Pong*> [5 times]
Quit
call-interactively: Buffer is read-only: #<buffer *Pong*>
command-execute: Buffer is read-only: #<buffer *Pong*>
ESC ESC <menu-bar> is undefined
<tools> is undefined
<games> is undefined
<pong> is undefined
Error running timer `kill-buffer': (error "No buffer named *Pong*")
Composing main Info directory...done
user-error: Info file emacs does not exist

Load-path shadows:
/usr/share/emacs/24.4/site-lisp/debian-startup hides 
/usr/share/emacs/site-lisp/debian-startup
/usr/share/emacs24/site-lisp/cmake-data/cmake-mode hides 
/usr/share/emacs/site-lisp/cmake-mode
/usr/share/emacs24/site-lisp/dictionaries-common/ispell hides 
/usr/share/emacs/24.4/lisp/textmodes/ispell
/usr/share/emacs24/site-lisp/dictionaries-common/flyspell hides 
/usr/share/emacs/24.4/lisp/textmodes/flyspell

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
help-fns mail-prsvr mail-utils info easymenu disp-table pong gamegrid
markdown-mode-autoloads multiple-cursors-autoloads php-mode-autoloads
web-mode-autoloads zenburn-theme-autoloads package epg-config time-date
tooltip electric uniquify ediff-hook vc-hooks lisp-float-type mwheel
x-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list
newcomment lisp-mode prog-mode register page menu-bar rfn-eshadow timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai
tai-viet lao korean japanese hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help
simple abbrev minibuffer nadvice loaddefs button faces cus-face macroexp
files text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
dbusbind gfilenotify dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs)

Memory information:
((conses 16 118206 6010)
(symbols 48 20574 0)
(miscs 40 88 185)
(strings 32 21586 4423)
(string-bytes 1 540426)
(vectors 16 12016)
(vector-slots 8 418703 5823)
(floats 8 80 419)
(intervals 56 3093 0)
(buffers 960 14)
(heap 1024 52752 1029))

-- 
Matt Lee
Technical Lead, Creative Commons, Boston, MA
https://keybase.io/mattl

"Creativity can be a social contribution, but only in
so far as society is free to use the results." -- Stallman







^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#20579: 24.4; Pong bat loses 1/3rd of its length if the ball hits it too quickly
  2015-05-14 18:58 bug#20579: 24.4; Pong bat loses 1/3rd of its length if the ball hits it too quickly Matt Lee
@ 2019-08-07 15:03 ` Mauro Aranda
  2019-08-10  8:52   ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Mauro Aranda @ 2019-08-07 15:03 UTC (permalink / raw)
  To: 20579


[-- Attachment #1.1: Type: text/plain, Size: 234 bytes --]

tags 20579 patch
quit

Hello.

I can reproduce this bug in Emacs 25.3, Emacs 26.2 and the current
master.

I attach a patch that fixes this bug, and also does some improvement in
the collision detection of pong.

Best regards,
Mauro.

[-- Attachment #1.2: Type: text/html, Size: 296 bytes --]

[-- Attachment #2: 0001-Fix-pong-collision-detection.patch --]
[-- Type: text/x-patch, Size: 4119 bytes --]

From d1b442f4371193b03af4c6e05119d87fc8512f31 Mon Sep 17 00:00:00 2001
From: Mauro Aranda <maurooaranda@gmail.com>
Date: Tue, 6 Aug 2019 21:48:41 -0300
Subject: [PATCH] Fix pong collision detection

* lisp/play/pong.el (pong-update-game): If the ball hit the bat where
bats are positioned, draw again the bat cell in the old ball
position.  (Bug#20579).
Also, avoid changing the direction of the ball right after hitting the
bats, and improve the collision detection against the borders.
---
 lisp/play/pong.el | 83 ++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 49 insertions(+), 34 deletions(-)

diff --git a/lisp/play/pong.el b/lisp/play/pong.el
index 555c193..759dbb4 100644
--- a/lisp/play/pong.el
+++ b/lisp/play/pong.el
@@ -349,46 +349,61 @@ pong-update-game
 
     (let ((old-x pong-x)
 	  (old-y pong-y))
-
+      ;; 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.
       (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 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.
       (if (and (> pong-y 0)
 	       (< pong-y (- pong-height 1)))
 	  (gamegrid-set-cell pong-x pong-y pong-ball))
 
+      ;; Hit bat, score a goal, or nothing.
       (cond
-       ((or (= pong-x 3) (= pong-x 2))
-	(if (and (>= pong-y pong-bat-player1)
-		 (< pong-y (+ pong-bat-player1 pong-bat-width)))
-	    (and
-	     (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)))))
-
-       ((or (= pong-x (- pong-width 4)) (= pong-x (- pong-width 3)))
-	(if (and (>= pong-y pong-bat-player2)
-		 (< pong-y (+ pong-bat-player2 pong-bat-width)))
-	    (and
-	     (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)))))
-
-       ((<= pong-y 1)
-	(setq pong-yy (- pong-yy)))
-
-       ((>= pong-y (- pong-height 2))
-	(setq pong-yy (- pong-yy)))
+       ((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)))
 
        ((< pong-x 1)
 	(setq pong-score-player2 (1+ pong-score-player2))
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#20579: 24.4; Pong bat loses 1/3rd of its length if the ball hits it too quickly
  2019-08-07 15:03 ` Mauro Aranda
@ 2019-08-10  8:52   ` Eli Zaretskii
  0 siblings, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2019-08-10  8:52 UTC (permalink / raw)
  To: Mauro Aranda; +Cc: 20579-done

> From: Mauro Aranda <maurooaranda@gmail.com>
> Date: Wed, 7 Aug 2019 12:03:49 -0300
> 
> I can reproduce this bug in Emacs 25.3, Emacs 26.2 and the current
> master.
> 
> I attach a patch that fixes this bug, and also does some improvement in
> the collision detection of pong.

Thanks, pushed to the master branch.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-08-10  8:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-14 18:58 bug#20579: 24.4; Pong bat loses 1/3rd of its length if the ball hits it too quickly Matt Lee
2019-08-07 15:03 ` Mauro Aranda
2019-08-10  8:52   ` Eli Zaretskii

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).