Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
HubertJan committed Jul 17, 2024
2 parents e6793de + bd04f85 commit 41c70cb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions services/game_server/backend/game/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .projectile import Projectile
import math
from backend.constants import X_MAX, Y_MAX
import random
from unique_names_generator import get_random_name
from unique_names_generator.data import ADJECTIVES, ANIMALS

Expand Down Expand Up @@ -70,6 +71,7 @@ def killed_by(self, killer):

def shoot(self, angle):
weapon = self.game.weapons[self.equipped_weapon]
angle = angle * (1 + random.uniform(- weapon["spread"], weapon["spread"]))
self.cooldown = weapon["cooldown"]
distance = 50
new_pos = Pos(self.pos.x + distance * math.cos(angle), self.pos.y + distance * math.sin(angle))
Expand Down
3 changes: 2 additions & 1 deletion services/game_server/data/weapons.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"damage": 25,
"cooldown": 0.25,
"range": 2000,
"speed": 25
"speed": 25,
"spread": 0.05
},
"Rocket Launcher": {
"damage": 100,
Expand Down
23 changes: 18 additions & 5 deletions services/game_server/frontend/src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Game {
playerToLeaderboardText: PIXI.Text[];
vfxHandler: popupMessageQueue;
items: Record<string, Entity>;

currentAim: number[];

constructor(app: PIXI.Application, socket: Socket, keys: Record<string, boolean>
) {
Expand All @@ -51,6 +51,7 @@ export class Game {
this.setupLeaderboard();
this.vfxHandler = new popupMessageQueue(app);
this.items = {};
this.currentAim = [0, 0];
}

get gameSize(): number[] {
Expand All @@ -62,13 +63,25 @@ export class Game {
this.app.stage.addChild(map);
map.interactive = true;
map.on('click', (evt: any) => {
this.try_shoot([evt.data.global.x, evt.data.global.y]);
this.currentAim = [evt.data.global.x, evt.data.global.y]
this.try_shoot();
});
map.on('mousemove', (evt: any) => {
this.currentAim = [evt.data.global.x, evt.data.global.y];
});
map.on('mousedown', (evt: any) => {
this.currentAim = [evt.data.global.x, evt.data.global.y];
this.keys['space'] = true;
});
map.on('mouseup', () => {
this.keys['space'] = false;
});
return map;
}

try_shoot(pos: number[]): void {
try_shoot(): void {
if (this.player.canShoot) {
const pos = this.currentAim;
let angle = Math.atan2(pos[1] - this.gameSize[1] / 2, pos[0] - this.gameSize[0] / 2);
this.socket.emit("player_click", angle);
}
Expand All @@ -83,8 +96,8 @@ export class Game {
if (this.keys['space']) {
// TODO fix this if you can
// const mousePosition = this.app.renderer.plugins.interaction.mouse.global; // @ts-ignore
// this.try_shoot([1, 3]);
console.log("pew pew");
this.try_shoot();
// console.log("pew pew");
};
this.leaderboardGraphic!.visible = this.keys['tab'];
this.draw();
Expand Down

0 comments on commit 41c70cb

Please sign in to comment.