Browse Source

* Modified settings to make pong more faitful

master
vvandenb 2 years ago
parent
commit
e629f33442
  1. 13
      back/volume/src/pong/game/Ball.ts
  2. 7
      back/volume/src/pong/game/constants.ts
  3. 35
      front/volume/src/components/Pong/constants.ts

13
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
}

7
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

35
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

Loading…
Cancel
Save