diff --git a/back/volume/src/pong/dtos/GameInfo.ts b/back/volume/src/pong/dtos/GameInfo.ts index 97734ce..95f36f7 100644 --- a/back/volume/src/pong/dtos/GameInfo.ts +++ b/back/volume/src/pong/dtos/GameInfo.ts @@ -6,7 +6,6 @@ export class GameInfo { gameId!: string walls!: Rect[] paddleSize!: Point - playerXOffset!: number ballSize!: Point winScore!: number ranked!: boolean diff --git a/back/volume/src/pong/game/Ball.ts b/back/volume/src/pong/game/Ball.ts index 69633b8..fe5f76f 100644 --- a/back/volume/src/pong/game/Ball.ts +++ b/back/volume/src/pong/game/Ball.ts @@ -4,7 +4,9 @@ import { type MapDtoValidated } from '../dtos/MapDtoValidated' import { DEFAULT_BALL_SIZE, DEFAULT_BALL_INITIAL_SPEED, - GAME_TICKS + GAME_TICKS, + DEFAULT_BALL_SPEED_INCREMENT, + DEFAULT_MAX_BALL_SPEED } from './constants' export class Ball { @@ -22,7 +24,7 @@ export class Ball { ) { this.rect = new Rect(spawn, size) this.speed = speed - this.initial_speed = speed + this.initial_speed = speed.clone() this.spawn = spawn.clone() this.indexPlayerScored = -1 this.timeoutTime = 0 @@ -73,6 +75,19 @@ export class Ball { } if (!canvasRect.contains_y(this.rect)) this.speed.y = this.speed.y * -1 + + if (this.speed.x > 0 && this.speed.x < DEFAULT_MAX_BALL_SPEED.x) { + this.speed.x += DEFAULT_BALL_SPEED_INCREMENT.x + } + if (this.speed.x < 0 && this.speed.x > -DEFAULT_MAX_BALL_SPEED.x) { + this.speed.x -= DEFAULT_BALL_SPEED_INCREMENT.x + } + if (this.speed.y > 0 && this.speed.y > DEFAULT_MAX_BALL_SPEED.y) { + this.speed.y += DEFAULT_MAX_BALL_SPEED.y + } + if (this.speed.y < 0 && this.speed.y < -DEFAULT_MAX_BALL_SPEED.y) { + this.speed.y -= DEFAULT_MAX_BALL_SPEED.y + } this.rect.center.add_inplace(this.speed) } @@ -85,10 +100,11 @@ export class Ball { } this.rect.center = this.spawn.clone() - this.speed.x = this.speed.x * -1 if (this.speed.x < 0) { + this.speed.x = this.initial_speed.x this.speed.y = -this.initial_speed.y } else { + this.speed.x = -this.initial_speed.x this.speed.y = this.initial_speed.y } diff --git a/back/volume/src/pong/game/Game.ts b/back/volume/src/pong/game/Game.ts index 74304db..4336be4 100644 --- a/back/volume/src/pong/game/Game.ts +++ b/back/volume/src/pong/game/Game.ts @@ -5,7 +5,6 @@ import { Player } from './Player' import { DEFAULT_BALL_SIZE, DEFAULT_PADDLE_SIZE, - DEFAULT_PLAYER_X_OFFSET, DEFAULT_WIN_SCORE, GAME_EVENTS, GAME_TICKS @@ -57,7 +56,6 @@ export class Game { gameId: this.id, walls: this.map.walls, paddleSize: DEFAULT_PADDLE_SIZE, - playerXOffset: DEFAULT_PLAYER_X_OFFSET, ballSize: DEFAULT_BALL_SIZE, winScore: DEFAULT_WIN_SCORE, ranked: this.ranked @@ -65,10 +63,13 @@ export class Game { } private addPlayer (socket: Socket, uuid: string, name: string): void { - let paddleCoords = new Point(DEFAULT_PLAYER_X_OFFSET, this.map.size.y / 2) + let paddleCoords = new Point( + DEFAULT_PADDLE_SIZE.x / 2, + this.map.size.y / 2 + ) if (this.players.length === 1) { paddleCoords = new Point( - this.map.size.x - DEFAULT_PLAYER_X_OFFSET, + this.map.size.x - DEFAULT_PADDLE_SIZE.x / 2, this.map.size.y / 2 ) } @@ -114,13 +115,16 @@ export class Game { this.playing = false clearInterval(this.timer) this.timer = null - this.pongService.saveResult(this.players, this.ranked).then(() => { - this.gameStoppedCallback(this.players[0].name) - this.players = [] - }).catch(() => { - this.gameStoppedCallback(this.players[0].name) - this.players = [] - }) + this.pongService + .saveResult(this.players, this.ranked) + .then(() => { + this.gameStoppedCallback(this.players[0].name) + this.players = [] + }) + .catch(() => { + this.gameStoppedCallback(this.players[0].name) + this.players = [] + }) } } diff --git a/back/volume/src/pong/game/Games.ts b/back/volume/src/pong/game/Games.ts index 2a794e1..f93f760 100644 --- a/back/volume/src/pong/game/Games.ts +++ b/back/volume/src/pong/game/Games.ts @@ -9,7 +9,6 @@ import { DEFAULT_BALL_SIZE, DEFAULT_MAP_SIZE, DEFAULT_PADDLE_SIZE, - DEFAULT_PLAYER_X_OFFSET, DEFAULT_WIN_SCORE } from './constants' @@ -80,7 +79,6 @@ export class Games { mapSize: new Point(0, 0), walls: [], paddleSize: DEFAULT_PADDLE_SIZE, - playerXOffset: DEFAULT_PLAYER_X_OFFSET, ballSize: DEFAULT_BALL_SIZE, winScore: DEFAULT_WIN_SCORE, ranked: false diff --git a/back/volume/src/pong/game/constants.ts b/back/volume/src/pong/game/constants.ts index 1dacbe4..4516899 100644 --- a/back/volume/src/pong/game/constants.ts +++ b/back/volume/src/pong/game/constants.ts @@ -13,9 +13,10 @@ export const GAME_EVENTS = { } export const DEFAULT_MAP_SIZE = new Point(500, 400) -export const DEFAULT_PADDLE_SIZE = new Point(6, 30) +export const DEFAULT_PADDLE_SIZE = new Point(30, 50) 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_MAX_BALL_SPEED = new Point(30, 20) +export const DEFAULT_BALL_SPEED_INCREMENT = new Point(0.05, 0) export const DEFAULT_WIN_SCORE = 5 export const GAME_TICKS = 30 diff --git a/back/volume/src/users/entity/user.entity.ts b/back/volume/src/users/entity/user.entity.ts index f1369ae..6a8e5ec 100644 --- a/back/volume/src/users/entity/user.entity.ts +++ b/back/volume/src/users/entity/user.entity.ts @@ -34,7 +34,7 @@ export class User { @Column({ default: false, nullable: true }) isVerified: boolean - @Column('uuid',{ unique: true }) + @Column('uuid', { unique: true }) socketKey: string @Column({ unique: true }) diff --git a/front/volume/src/components/Channels.svelte b/front/volume/src/components/Channels.svelte index 6a7b989..058ff5f 100644 --- a/front/volume/src/components/Channels.svelte +++ b/front/volume/src/components/Channels.svelte @@ -13,7 +13,6 @@