@@ -34,6 +34,7 @@ export function Deparkanoid() {
34
34
let soundDie : p5 . MediaElement ;
35
35
let ballImage : p5 . Image ;
36
36
let paddleImage : p5 . Image ;
37
+ let autoPlay = false ;
37
38
38
39
function game ( p : p5 ) {
39
40
p . preload = ( ) => {
@@ -72,7 +73,12 @@ export function Deparkanoid() {
72
73
if ( e . key === " " ) {
73
74
enableGame = true ;
74
75
ball . reset ( ) ;
75
- return false ;
76
+ }
77
+ if ( e . key === "≥" && e . altKey ) {
78
+ autoPlay = ! autoPlay ;
79
+ }
80
+ if ( e . key === "÷" && e . altKey ) {
81
+ enableSounds = ! enableSounds
76
82
}
77
83
} ) ;
78
84
el . addEventListener ( "contextmenu" , ( e ) => {
@@ -100,7 +106,12 @@ export function Deparkanoid() {
100
106
}
101
107
102
108
paddle . show ( ) ;
103
- paddle . move ( ) ;
109
+
110
+ if ( autoPlay ) {
111
+ paddle . automove ( ball ) ;
112
+ } else {
113
+ paddle . move ( ) ;
114
+ }
104
115
105
116
ball . show ( ) ;
106
117
if ( enableGame ) {
@@ -917,6 +928,14 @@ export function Deparkanoid() {
917
928
this . x ,
918
929
) ;
919
930
}
931
+
932
+ automove ( ball : Ball ) {
933
+ this . x = uncheckedClamp (
934
+ PADDLE_HEIGHT / 2 ,
935
+ this . p . width - this . width - PADDLE_HEIGHT / 2 ,
936
+ ball . x - this . width / 2 ,
937
+ ) ;
938
+ }
920
939
}
921
940
922
941
class Ball {
@@ -965,7 +984,10 @@ export function Deparkanoid() {
965
984
}
966
985
if ( this . y > this . p . height ) {
967
986
enableGame = false ;
968
- if ( enableSounds ) soundDie . play ( ) ;
987
+ if ( enableSounds ) {
988
+ soundDie . stop ( ) ;
989
+ soundDie . play ( ) ;
990
+ }
969
991
this . reset ( ) ;
970
992
}
971
993
}
@@ -979,7 +1001,10 @@ export function Deparkanoid() {
979
1001
this . ySpeed *= - 1 ;
980
1002
this . y = paddle . y - this . radius ;
981
1003
982
- if ( enableSounds ) soundBounce . play ( ) ;
1004
+ if ( enableSounds ) {
1005
+ soundBounce . stop ( ) ;
1006
+ soundBounce . play ( ) ;
1007
+ }
983
1008
}
984
1009
}
985
1010
@@ -1007,7 +1032,10 @@ export function Deparkanoid() {
1007
1032
collision ||= true ;
1008
1033
score += BRICK_SCORE ;
1009
1034
bricks . splice ( i , 1 ) ;
1010
- if ( enableSounds ) soundBreak . play ( ) ;
1035
+ if ( enableSounds ) {
1036
+ soundBreak . stop ( ) ;
1037
+ soundBreak . play ( ) ;
1038
+ }
1011
1039
}
1012
1040
}
1013
1041
if ( collision ) this . ySpeed *= - 1 ;
0 commit comments