diff --git a/django/chat/models.py b/django/chat/models.py index 0d3d402..6e68a9a 100644 --- a/django/chat/models.py +++ b/django/chat/models.py @@ -1,4 +1,4 @@ -from django.db.models import Model, IntegerField, ForeignKey, CharField, CASCADE +from django.db.models import BigIntegerField, Model, IntegerField, ForeignKey, CharField, CASCADE from django.db.models.signals import post_delete from django.dispatch import receiver from django.contrib.auth.models import User @@ -28,8 +28,8 @@ def delete_channel_when_member_deleted(sender, instance, **kwargs): class ChatMessageModel(Model): channel = ForeignKey(ChatChannelModel, on_delete=CASCADE) author = ForeignKey(User, on_delete=CASCADE) - content = CharField(max_length=255) - time = IntegerField(primary_key=False) + content = CharField(max_length=1024) + time = BigIntegerField(primary_key=False) class AskModel(Model): diff --git a/django/frontend/static/js/api/Notice.js b/django/frontend/static/js/api/Notice.js index 57a253b..43e1771 100644 --- a/django/frontend/static/js/api/Notice.js +++ b/django/frontend/static/js/api/Notice.js @@ -24,8 +24,6 @@ export default class Notice { this._socket.onmessage = async message => { const data = JSON.parse(message.data); - console.log(data); - if (data.type === 'friend_request') { this.friend_request(data.author); } else if (data.type === 'new_friend') { diff --git a/django/frontend/static/js/api/game/pong/PongGame.js b/django/frontend/static/js/api/game/pong/PongGame.js index d323c6b..c4f3e91 100644 --- a/django/frontend/static/js/api/game/pong/PongGame.js +++ b/django/frontend/static/js/api/game/pong/PongGame.js @@ -149,8 +149,6 @@ export class PongGame extends AGame */ async _receive(data) { - console.log(data) - if (this._inited === false && data.detail === "init_game") { this._initGame(data); @@ -167,6 +165,16 @@ export class PongGame extends AGame await this._receiveFinish(data); else if (data.detail === "start") await this._receiveStart(); + else if (data.detail === "eliminated") + await this._receiveEliminated(data) + } + + async _receiveEliminated(data) + { + console.log('bozo') + let eliminated = this.players.find(player => player.id === data.eliminated_id) + eliminated.isEliminated = true; + console.log(eliminated) } async _receiveFinish(data) @@ -194,7 +202,6 @@ export class PongGame extends AGame } player.score.push(data.timestamp) - console.log(player) await this._goalHandler(player); } diff --git a/django/frontend/static/js/api/game/pong/PongMyPlayer.js b/django/frontend/static/js/api/game/pong/PongMyPlayer.js index 7d89401..d1c313f 100644 --- a/django/frontend/static/js/api/game/pong/PongMyPlayer.js +++ b/django/frontend/static/js/api/game/pong/PongMyPlayer.js @@ -12,10 +12,11 @@ export class PongMyPlayer extends PongPlayer * @param {Segment} rail * @param {[Number]} score * @param {Position} position + * @param {Boolean} isEliminated */ - constructor(client, game, score, rail, position = new Position(0.5)) + constructor(client, game, score, rail, position = new Position(0.5), isEliminated) { - super(client, game, client.me.id, client.me.username, client.me.avatar, score, rail, position, true); + super(client, game, client.me.id, client.me.username, client.me.avatar, score, rail, position, true, isEliminated); /** * @type {Client} */ diff --git a/django/frontend/static/js/api/game/pong/PongPlayer.js b/django/frontend/static/js/api/game/pong/PongPlayer.js index 8c739be..1c5e851 100644 --- a/django/frontend/static/js/api/game/pong/PongPlayer.js +++ b/django/frontend/static/js/api/game/pong/PongPlayer.js @@ -65,8 +65,7 @@ export class PongPlayer extends APlayer { if (this.isConnected === false || this.isEliminated === true) { - ctx.moveTo(this.rail.start.x, this.rail.start.y); - ctx.lineTo(this.rail.stop.x, this.rail.stop.y); + this.rail.draw(ctx) return; } diff --git a/django/frontend/static/js/views/PongOfflineView.js b/django/frontend/static/js/views/PongOfflineView.js index a823d17..4eaf323 100644 --- a/django/frontend/static/js/views/PongOfflineView.js +++ b/django/frontend/static/js/views/PongOfflineView.js @@ -280,8 +280,8 @@ class Game { PADDLESPEED: 3, BALLRADIUS: 5, BALLSPEED: 2, - BALLMAXSPEED: 4, - BALLSPEEDINCR: 0.15, + BALLMAXSPEED: 10, + BALLSPEEDINCR: 0.2, MAXBOUNCEANGLE: 10 * (Math.PI / 12), MAXSCORE: 2 }; diff --git a/django/frontend/static/js/views/PongOnlineView.js b/django/frontend/static/js/views/PongOnlineView.js index 9edc05a..6290826 100644 --- a/django/frontend/static/js/views/PongOnlineView.js +++ b/django/frontend/static/js/views/PongOnlineView.js @@ -71,6 +71,7 @@ export default class PongOnlineView extends AbstractAuthenticatedView myPlayer.score, myPlayer.rail, myPlayer.position, + myPlayer.isEliminated ); myPlayer = this.myPlayer; @@ -87,7 +88,6 @@ export default class PongOnlineView extends AbstractAuthenticatedView keyPressHandler(event) { - console.log("bozo") if (!this.keysPressed.includes(event.key)) this.keysPressed.push(event.key); } diff --git a/django/frontend/static/js/views/Search.js b/django/frontend/static/js/views/Search.js index e1c74e6..1357346 100644 --- a/django/frontend/static/js/views/Search.js +++ b/django/frontend/static/js/views/Search.js @@ -31,11 +31,6 @@ export default class extends AbstractView { this.profiles.filter(user => user.username.toLowerCase().startsWith(search) == true).forEach(async (user) => { - if (user.id == null) { - console.log("list User one with id null;"); - return; - } - const new_user = document.createElement("li"); // username @@ -46,7 +41,7 @@ export default class extends AbstractView { if (this.logged && user.id == client.me.id) username.style.color = "green"; else { - const online = user.online; + let online = (await client.profiles.getProfile(user.username)).online; if (online == undefined) username.style.color = "gray"; else if (online == true) diff --git a/django/games/objects/pong/Ball.py b/django/games/objects/pong/Ball.py index d0cdcc5..b117d67 100644 --- a/django/games/objects/pong/Ball.py +++ b/django/games/objects/pong/Ball.py @@ -10,18 +10,14 @@ import math class Ball: def __init__(self) -> None: - self.size: float - self.position: Position - self.angle: float - self.speed: float - - self.reset() - self.speed = 0 + self.size: float = config.BALL_SIZE + self.position: Position = Position(Point(config.BALL_SPAWN_POS_X + self.size / 2, config.BALL_SPAWN_POS_Y + self.size / 2), time.time()) + self.angle: float = 0 + self.speed: float = 0 - def reset(self) -> None: - self.size = config.BALL_SIZE - self.position = Position(Point(config.BALL_SPAWN_POS_X + self.size / 2, config.BALL_SPAWN_POS_Y + self.size / 2), time.time()) - self.angle = math.pi * 0 + def reset(self, target: Point) -> None: + self.position: Position = Position(Point(config.BALL_SPAWN_POS_X + self.size / 2, config.BALL_SPAWN_POS_Y + self.size / 2), time.time()) + self.angle = math.atan2(target.y - self.position.location.y, target.x - self.position.location.x) self.speed = config.BALL_SPEED_START def to_dict(self) -> dict: diff --git a/django/games/objects/pong/PongGame.py b/django/games/objects/pong/PongGame.py index b852963..5b1e3c2 100644 --- a/django/games/objects/pong/PongGame.py +++ b/django/games/objects/pong/PongGame.py @@ -14,6 +14,7 @@ from django.contrib.auth.models import User from ...routine import routine +import random import threading class PongGame(AGame): @@ -54,6 +55,7 @@ class PongGame(AGame): else: self.walls.append(Segment(corners[i].copy(), corners[(i + 1) % 4].copy())) + self.ball: Ball = Ball() def goal(self, goal_defenser: PongPlayer) -> None: @@ -73,7 +75,7 @@ class PongGame(AGame): self.finish(player_list[0]) return - self.ball.reset() + self.ball.reset(goal_defenser.rail.center()) def get_valid_players(self) -> list[PongPlayer]: return [player for player in self.players if player.is_connected and not player.is_eliminated] @@ -92,7 +94,9 @@ class PongGame(AGame): self.broadcast("start") - self.ball.reset() + players: list[PongPlayer] = self.get_valid_players() + + self.ball.reset(players[random.randint(0, len(players) -1)].rail.center()) self.broadcast("update_ball", self.ball.to_dict()) diff --git a/django/games/objects/pong/Segment.py b/django/games/objects/pong/Segment.py index c45ee33..a48aea1 100644 --- a/django/games/objects/pong/Segment.py +++ b/django/games/objects/pong/Segment.py @@ -28,6 +28,9 @@ class Segment: def copy(self): return Segment(self.start.copy(), self.stop.copy()) + def center(self): + return Point((self.start.x + self.stop.x) / 2, (self.start.y + self.stop.y) / 2) + def to_dict(self) -> dict: data: dict[str: dict] = { diff --git a/django/games/routine.py b/django/games/routine.py index 84b6ccb..962123c 100644 --- a/django/games/routine.py +++ b/django/games/routine.py @@ -16,8 +16,6 @@ import asyncio import math -import time - from asgiref.sync import SyncToAsync diff --git a/django/notice/models.py b/django/notice/models.py index cf26f6a..03b9089 100644 --- a/django/notice/models.py +++ b/django/notice/models.py @@ -4,4 +4,4 @@ from django.contrib.auth.models import User class NoticeModel(Model): user = ForeignKey(User, on_delete=CASCADE) - data = CharField(max_length=100) + data = CharField(max_length=1024)