server/room/public.js
// Update the bullets 60 times per frame and send updates 
Update the bullets 60 times per frame and send updates
Update the bullets 60 times per frame and send updates
ServerGameLoop() {
        for (let i in this.state.bullets) {
            this.state.moveBullet(i);
            if (this.state.bullets[i].x < -10 || this.state.bullets[i].x > 3200 || this.state.bullets[i].y < -10 || this.state.bullets[i].y > 3200 || this.state.bullets[i].distanceTravelled >= 800) {
                this.state.removeBullet(i);
            } else {
                for (let id in this.state.players) {
                    if (this.state.bullets[i].owner_id != id) {
                        let dx = this.state.players[id].x - this.state.bullets[i].x;
                        let dy = this.state.players[id].y - this.state.bullets[i].y;
                        let dist = Math.sqrt(dx * dx + dy * dy);
                        if (dist < 30) {
                            this.broadcast( {
                                event: "hit",
                                punished_id: id,
                                punisher_id: this.state.bullets[i].owner_id
                            });
                            this.state.removeBullet(i);
                            this.state.removePlayer(id);
                            return;
                        }
                    }
                }
            }
        }
    }
ServerGameLoop ( ) { for ( let i in this . state . bullets ) { this . state . moveBullet ( i ) ; if ( this . state . bullets [ i ] . x < - 10 || this . state . bullets [ i ] . x > 3200 || this . state . bullets [ i ] . y < - 10 || this . state . bullets [ i ] . y > 3200 || this . state . bullets [ i ] . distanceTravelled >= 800 ) { this . state . removeBullet ( i ) ; } else { for ( let id in this . state . players ) { if ( this . state . bullets [ i ] . owner_id != id ) { let dx = this . state . players [ id ] . x - this . state . bullets [ i ] . x ; let dy = this . state . players [ id ] . y - this . state . bullets [ i ] . y ; let dist = Math . sqrt ( dx * dx + dy * dy ) ; if ( dist < 30 ) { this . broadcast ( { event : "hit" , punished_id : id , punisher_id : this . state . bullets [ i ] . owner_id } ) ; this . state . removeBullet ( i ) ; this . state . removePlayer ( id ) ; return ; } } } } } }
Update the bullets 60 times per frame and send updates
Update the bullets 60 times per frame and send updates
//remove the bullet if it goes too far //check if this bullet is close enough to hit a player //because your own bullet shouldn't kill hit