Skip to content

Commit a742cbe

Browse files
committed
-3 = 230 bytes: simplify direction change
1 parent 956b570 commit a742cbe

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ A super minimalistic clone of the classic Pong game in < 256 bytes of HTML and J
88

99
Use your keyboard to control the paddle movement.
1010

11-
### Source (233 bytes)
11+
### Source (230 bytes)
1212

1313
```html
14-
<body onload=k=13,x=W=27,X=Y=
15-
1,setInterval('for(i=h="",k=k
16-
<0?0:24<k?24:k,X*=x%W?1:-1,Y*
17-
=x<0?-1:297<x?(Q=x-299-k)*Q<4
18-
?-1:p:1,x+=Y*(W+X*Y);i++<297+
19-
k;p.innerHTML=h+888)h+=i%W?i^
20-
x?" ":0:"|\\n"',99) onkeydown
21-
=k+=event.which-38><pre id=p>
14+
<body onload=k=13,x=W=27,X=
15+
Y=1,setInterval('for(i=h=""
16+
,k=k<0?0:24<k?24:k,X=x%W?X:
17+
-X,Y=x<0?1:297<x?(Q=x-299-k
18+
)*Q<4?-1:p:Y,x+=Y*(W+X*Y);i
19+
++<297+k;p.innerHTML=h+888)
20+
h+=i%W?i^x?" ":0:"|\\n"',99
21+
) onkeydown=k+=event.which-
22+
38><pre id=p>
2223
```
2324

2425
### Gameplay Video

annotated.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ setInterval(function() {
1414
24 < k ? 24 :
1515
k,
1616

17-
X *= x % W ? // reflect if ball hits wall
18-
1 :
19-
-1,
17+
X = x % W ? // reflect if ball hits wall
18+
X :
19+
-X,
2020

21-
Y *= // change Y direction
22-
x < 0 ? -1 : // reflect if ball hit top border
21+
Y = // change Y direction
22+
x < 0 ? 1 : // reflect if ball hit top border
2323
297 < x ? ( // if ball hits bottom border ...
2424
(
2525
Q = x - 299 - k // calculate distance to paddle center
2626
) * Q < 4 ? // if distance^2 is less than four
2727
-1 : // ... reflect up
2828
p // otherwise break the game
29-
) : 1,
29+
) : Y,
3030

3131
x += Y * (W + X * Y); // update ball position based on direction
3232

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<body onload=k=13,x=W=27,X=Y=1,setInterval('for(i=h="",k=k<0?0:24<k?24:k,X*=x%W?1:-1,Y*=x<0?-1:297<x?(Q=x-299-k)*Q<4?-1:p:1,x+=Y*(W+X*Y);i++<297+k;p.innerHTML=h+888)h+=i%W?i^x?" ":0:"|\\n"',99) onkeydown=k+=event.which-38><pre id=p>
1+
<body onload=k=13,x=W=27,X=Y=1,setInterval('for(i=h="",k=k<0?0:24<k?24:k,X=x%W?X:-X,Y=x<0?1:297<x?(Q=x-299-k)*Q<4?-1:p:Y,x+=Y*(W+X*Y);i++<297+k;p.innerHTML=h+888)h+=i%W?i^x?" ":0:"|\\n"',99) onkeydown=k+=event.which-38><pre id=p>

min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)