Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions Web_Based_Ubuntu_Linux/app/src/apps/Pong.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,15 @@ export default function Pong() {

// Move paddles
const paddleSpeed = 6;
if (keys.current['w'] || keys.current['W']) leftPaddle.current.y = Math.max(0, leftPaddle.current.y - paddleSpeed);
if (keys.current['s'] || keys.current['S']) leftPaddle.current.y = Math.min(CANVAS_H - PADDLE_H, leftPaddle.current.y + paddleSpeed);


if (keys.current['KeyW']) {leftPaddle.current.y = Math.max(0, leftPaddle.current.y - paddleSpeed);}

if (keys.current['KeyS']) {leftPaddle.current.y = Math.min(CANVAS_H - PADDLE_H, leftPaddle.current.y + paddleSpeed);}

if (modeRef.current === '2p') {
if (keys.current['ArrowUp']) rightPaddle.current.y = Math.max(0, rightPaddle.current.y - paddleSpeed);
if (keys.current['ArrowDown']) rightPaddle.current.y = Math.min(CANVAS_H - PADDLE_H, rightPaddle.current.y + paddleSpeed);
if (keys.current['ArrowUp']) {rightPaddle.current.y = Math.max(0, rightPaddle.current.y - paddleSpeed);}

if (keys.current['ArrowDown']) {rightPaddle.current.y = Math.min(CANVAS_H - PADDLE_H, rightPaddle.current.y + paddleSpeed);}
} else {
// AI
const diff = aiDiffRef.current;
Expand Down Expand Up @@ -238,24 +241,31 @@ export default function Pong() {
// Keyboard
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
keys.current[e.key] = true;
if (e.key === ' ' && gameStateRef.current === 'playing' && waitingForServe.current) {
keys.current[e.code] = true;

if (e.code === 'Space' && gameStateRef.current === 'playing' && waitingForServe.current) {
e.preventDefault();
waitingForServe.current = false;
}
if ((e.key === 'p' || e.key === 'P') && gameStateRef.current === 'playing') {
setGameState('paused');
gameStateRef.current = 'paused';
} else if ((e.key === 'p' || e.key === 'P') && gameStateRef.current === 'paused') {
setGameState('playing');
gameStateRef.current = 'playing';

if (e.code === 'KeyP') {
if (gameStateRef.current === 'playing') {
setGameState('paused');
gameStateRef.current = 'paused';
} else if (gameStateRef.current === 'paused') {
setGameState('playing');
gameStateRef.current = 'playing';
}
}
};

const handleKeyUp = (e: KeyboardEvent) => {
keys.current[e.key] = false;
keys.current[e.code] = false;
};

window.addEventListener('keydown', handleKeyDown);
window.addEventListener('keyup', handleKeyUp);

return () => {
window.removeEventListener('keydown', handleKeyDown);
window.removeEventListener('keyup', handleKeyUp);
Expand Down
8 changes: 4 additions & 4 deletions Web_Based_Ubuntu_Linux/app/src/apps/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export const APP_REGISTRY: AppDefinition[] = [
icon: 'MessageSquare',
category: 'Internet',
description: 'Instant messaging interface',
defaultSize: { width: 480, height: 600 },
defaultSize: { width: 580, height: 600 },
minSize: { width: 320, height: 400 },
},
{
Expand Down Expand Up @@ -234,7 +234,7 @@ export const APP_REGISTRY: AppDefinition[] = [
icon: 'Music',
category: 'Media',
description: 'Audio player with playlist and visualization',
defaultSize: { width: 520, height: 440 },
defaultSize: { width: 520, height: 600 },
minSize: { width: 360, height: 320 },
},
{
Expand Down Expand Up @@ -326,7 +326,7 @@ export const APP_REGISTRY: AppDefinition[] = [
icon: 'X',
category: 'Games',
description: '2-player and AI tic-tac-toe',
defaultSize: { width: 400, height: 440 },
defaultSize: { width: 400, height: 490 },
minSize: { width: 280, height: 320 },
},
{
Expand All @@ -335,7 +335,7 @@ export const APP_REGISTRY: AppDefinition[] = [
icon: 'Hash',
category: 'Games',
description: 'Number sliding puzzle',
defaultSize: { width: 400, height: 480 },
defaultSize: { width: 400, height: 530 },
minSize: { width: 320, height: 400 },
},
{
Expand Down
Loading