From e629f334424f6ce66e19339eff6db67399a3b359 Mon Sep 17 00:00:00 2001 From: vvandenb Date: Mon, 13 Mar 2023 11:52:14 +0100 Subject: [PATCH] * Modified settings to make pong more faitful --- back/volume/src/pong/game/Ball.ts | 13 +++++-- back/volume/src/pong/game/constants.ts | 7 ++-- front/volume/src/components/Pong/constants.ts | 35 ++++++++++--------- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/back/volume/src/pong/game/Ball.ts b/back/volume/src/pong/game/Ball.ts index e47eae3..b5c7265 100644 --- a/back/volume/src/pong/game/Ball.ts +++ b/back/volume/src/pong/game/Ball.ts @@ -1,10 +1,11 @@ import { type Paddle } from './Paddle' -import { Point, Rect } from './utils' +import { type Point, Rect } from './utils' import { type MapDtoValidated } from '../dtos/MapDtoValidated' -import { DEFAULT_BALL_SIZE } from './constants' +import { DEFAULT_BALL_SIZE, DEFAULT_BALL_INITIAL_SPEED } from './constants' export class Ball { rect: Rect + initial_speed: Point speed: Point spawn: Point indexPlayerScored: number @@ -12,10 +13,11 @@ export class Ball { constructor ( spawn: Point, size: Point = DEFAULT_BALL_SIZE, - speed: Point = new Point(10, 2) + speed: Point = DEFAULT_BALL_INITIAL_SPEED ) { this.rect = new Rect(spawn, size) this.speed = speed + this.initial_speed = speed this.spawn = spawn.clone() this.indexPlayerScored = -1 } @@ -73,6 +75,11 @@ export class Ball { this.rect.center = this.spawn.clone() this.speed.x = this.speed.x * -1 + if (this.speed.x < 0) { + this.speed.y = -this.initial_speed.y + } else { + this.speed.y = this.initial_speed.y + } return indexPlayerScored } diff --git a/back/volume/src/pong/game/constants.ts b/back/volume/src/pong/game/constants.ts index 87b07a6..1dacbe4 100644 --- a/back/volume/src/pong/game/constants.ts +++ b/back/volume/src/pong/game/constants.ts @@ -12,9 +12,10 @@ export const GAME_EVENTS = { LEAVE_GAME: 'LEAVE_GAME' } -export const DEFAULT_MAP_SIZE = new Point(600, 400) -export const DEFAULT_PADDLE_SIZE = new Point(6, 50) -export const DEFAULT_BALL_SIZE = new Point(20, 20) +export const DEFAULT_MAP_SIZE = new Point(500, 400) +export const DEFAULT_PADDLE_SIZE = new Point(6, 30) +export const DEFAULT_BALL_SIZE = new Point(10, 10) +export const DEFAULT_BALL_INITIAL_SPEED = new Point(10, 2) export const DEFAULT_PLAYER_X_OFFSET = 50 export const DEFAULT_WIN_SCORE = 5 export const GAME_TICKS = 30 diff --git a/front/volume/src/components/Pong/constants.ts b/front/volume/src/components/Pong/constants.ts index 57c010f..1dacbe4 100644 --- a/front/volume/src/components/Pong/constants.ts +++ b/front/volume/src/components/Pong/constants.ts @@ -1,20 +1,21 @@ -import { Point } from "./utils"; +import { Point } from './utils' export const GAME_EVENTS = { - START_GAME: "START_GAME", - READY: "READY", - GAME_TICK: "GAME_TICK", - PLAYER_MOVE: "PLAYER_MOVE", - GET_GAME_INFO: "GET_GAME_INFO", - CREATE_GAME: "CREATE_GAME", - REGISTER_PLAYER: "REGISTER_PLAYER", - MATCHMAKING: "MATCHMAKING", - LEAVE_GAME: "LEAVE_GAME", -}; + START_GAME: 'START_GAME', + READY: 'READY', + GAME_TICK: 'GAME_TICK', + PLAYER_MOVE: 'PLAYER_MOVE', + GET_GAME_INFO: 'GET_GAME_INFO', + CREATE_GAME: 'CREATE_GAME', + REGISTER_PLAYER: 'REGISTER_PLAYER', + MATCHMAKING: 'MATCHMAKING', + LEAVE_GAME: 'LEAVE_GAME' +} -export const DEFAULT_MAP_SIZE = new Point(600, 400); -export const DEFAULT_PADDLE_SIZE = new Point(6, 50); -export const DEFAULT_BALL_SIZE = new Point(20, 20); -export const DEFAULT_PLAYER_X_OFFSET = 50; -export const DEFAULT_WIN_SCORE = 5; -export const GAME_TICKS = 30; +export const DEFAULT_MAP_SIZE = new Point(500, 400) +export const DEFAULT_PADDLE_SIZE = new Point(6, 30) +export const DEFAULT_BALL_SIZE = new Point(10, 10) +export const DEFAULT_BALL_INITIAL_SPEED = new Point(10, 2) +export const DEFAULT_PLAYER_X_OFFSET = 50 +export const DEFAULT_WIN_SCORE = 5 +export const GAME_TICKS = 30