Skip to content

Commit

Permalink
halftheopposite#43 bullets are now visible for all players
Browse files Browse the repository at this point in the history
  • Loading branch information
Tillt14 committed Dec 5, 2022
1 parent 05d4a91 commit bda6580
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
38 changes: 19 additions & 19 deletions packages/client/src/game/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,22 +422,22 @@ export class Game {

this.me.lastShootAt = Date.now();

this.bulletsManager.addOrCreate(
{
x: bulletX,
y: bulletY,
radius: Constants.BULLET_SIZE,
rotation: this.me.rotation,
active: true,
fromX: bulletX,
fromY: bulletY,
playerId: this.me.playerId,
team: this.me.team,
color: this.me.color,
shotAt: this.me.lastShootAt,
},
this.particlesContainer,
);
// this.bulletsManager.addOrCreate(
// {
// x: bulletX,
// y: bulletY,
// radius: Constants.BULLET_SIZE,
// rotation: this.me.rotation,
// active: true,
// fromX: bulletX,
// fromY: bulletY,
// playerId: this.me.playerId,
// team: this.me.team,
// color: this.me.color,
// shotAt: this.me.lastShootAt,
// },
// this.particlesContainer,
// );
this.onActionSend({
type: 'shoot',
ts: Date.now(),
Expand Down Expand Up @@ -678,9 +678,9 @@ export class Game {

// COLYSEUS: Bullets
bulletAdd = (bulletId: string, attributes: Models.BulletJSON) => {
if ((this.me && this.me.playerId === attributes.playerId) || !attributes.active) {
return;
}
// if ((this.me && this.me.playerId === attributes.playerId) || !attributes.active) {
// return;
// }

this.bulletsManager.addOrCreate(attributes, this.particlesContainer);
};
Expand Down
8 changes: 8 additions & 0 deletions packages/client/src/game/utils/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ export class Inputs {
window.addEventListener('keyup', this.handleKeyUp);
window.document.addEventListener('mousedown', this.handleMouseDown);
window.document.addEventListener('mouseup', this.handleMouseUp);
window.document.addEventListener('contextmenu', this.handleMouseUp);
};

public stop = () => {
window.removeEventListener('keydown', this.handleKeyDown);
window.removeEventListener('keyup', this.handleKeyUp);
window.document.removeEventListener('mousedown', this.handleMouseDown);
window.document.removeEventListener('mouseup', this.handleMouseUp);
window.document.removeEventListener('contextmenu', this.handleContextMenu);
};

private handleKeyDown = (event: any) => {
Expand Down Expand Up @@ -106,4 +108,10 @@ export class Inputs {

this.shoot = false;
};

private handleContextMenu = (event: any) => {
event.preventDefault();
event.stopPropagation();

};
}
28 changes: 14 additions & 14 deletions packages/server/src/states/GameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,23 +298,23 @@ export class GameState extends Schema {
const bulletY = player.y + Math.sin(angle) * Constants.PLAYER_WEAPON_SIZE;

// Recycle bullets if some are unused to prevent instantiating too many
const index = this.bullets.findIndex((bullet) => !bullet.active);
if (index === -1) {
// const index = this.bullets.findIndex((bullet) => !bullet.active);
// if (index === -1) {
this.bullets.push(
new Bullet(id, player.team, bulletX, bulletY, Constants.BULLET_SIZE, angle, player.color, Date.now()),
);
} else {
this.bullets[index].reset(
id,
player.team,
bulletX,
bulletY,
Constants.BULLET_SIZE,
angle,
player.color,
Date.now(),
);
}
// } else {
// this.bullets[index].reset(
// id,
// player.team,
// bulletX,
// bulletY,
// Constants.BULLET_SIZE,
// angle,
// player.color,
// Date.now(),
// );
// }
}

private playerUpdateKills(playerId: string) {
Expand Down

0 comments on commit bda6580

Please sign in to comment.