Skip to content

Commit

Permalink
more multplayer changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Trystan-Schmits committed Jan 26, 2024
1 parent fd66158 commit a8e50e2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
12 changes: 12 additions & 0 deletions assets/js/platformer2/Character.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ class Character extends GameObject {
this.frameY = frameY;
}

updateInfo(json) {
super.updateInfo(json)
var element = this.canvas;
if (json.id === element.id) {
this.x = json.x * GameEnv.innerWidth;
this.y = (json.y * (GameEnv.bottom - GameEnv.top)) + GameEnv.top;
this.frameY = json.frameY
console.log(this.x, this.y, json.y)
}
return json.id === element.id
}

/* Draw character object
* Canvas and Context
*/
Expand Down
12 changes: 5 additions & 7 deletions assets/js/platformer2/GameControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ const GameControl = {

handleStateUpdates(data){ //listen for stateupdates and update characters if needed
let updated = false
console.log(GameEnv.currentLevel.tag)
if (data.tag === GameEnv.currentLevel.tag) {
for (var gameObj of GameEnv.gameObjects) {
updated = updated || gameObj.updateInfo(data);
Expand All @@ -170,21 +169,20 @@ const GameControl = {
obj = object;
}
});
obj.class = Character; //set to character class (doesn't update with inputs)
// Load the image for the game object.
const image = new Image();
image.src = obj.data.file;
obj.image = image;
// Create a new canvas for the game object.
const canvas = document.createElement("canvas");
canvas.id = data.id;
obj.id = data.id;
document.querySelector("#canvasContainer").appendChild(canvas);
console.log(canvas);
// Create a new instance of the game object.
obj = new obj.class(canvas, obj.image, obj.data, obj.xPercentage, obj.yPercentage, obj.minPosition);

obj.updateInfo(data);
var obj1 = new Character(canvas, image, obj.data, obj.xPercentage, obj.yPercentage, obj.minPosition);

obj1.updateInfo(data);
obj1.size();
console.log(obj1.canvasWidth)
}
}
},
Expand Down
7 changes: 4 additions & 3 deletions assets/js/platformer2/GameObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class GameObject {
filter: element.style.filter,
tag: GameEnv.currentLevel.tag,
x: this.x / GameEnv.innerWidth,
y: (this.y - GameEnv.top) / (this.bottom - GameEnv.top),
y: (this.y - GameEnv.top) / (GameEnv.bottom - GameEnv.top),
frameY: this.frameY
};
}
Expand All @@ -87,12 +87,13 @@ class GameObject {
updateInfo(json) {
var element = this.canvas;
if (json.id === element.id) {
console.log("runs", json.width, json.height)
this.canvas.width = json.width;
this.canvas.height = json.height;
this.canvas.style.filter = json.filter;
var element = this.canvas;
this.x = json.x * GameEnv.innerWidth;
this.y = (json.y * (this.bottom - GameEnv.top)) + GameEnv.top;
//this.x = json.x * GameEnv.innerWidth;
//this.y = (json.y * (GameEnv.bottom - GameEnv.top)) + GameEnv.top;
this.frameY = json.frameY
}
return json.id === element.id
Expand Down
2 changes: 1 addition & 1 deletion assets/js/platformer2/Goomba.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Goomba extends Character {
//Chance To Become Immune to Player
if (GameEnv.difficulty === "normal") {
if (Math.random() < 0.00001) {
this.canvas.style.filter = 'brightness(1000%)';
this.canvas.style.ilter = 'brightness(1000%)';
this.immune = 1;
}
} else if (GameEnv.difficulty === "hard") {
Expand Down
4 changes: 2 additions & 2 deletions assets/js/platformer2/Multiplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class Socket{
*/

static shouldBeSynced = true;
//static socket = io("wss://platformer.nighthawkcodingsociety.com"); //aws server
static socket = io(`ws://${window.location.host.split(":")[0]}:3000`); //local server
static socket = io("wss://platformer.nighthawkcodingsociety.com"); //aws server
//static socket = io(`ws://${window.location.host.split(":")[0]}:3000`); //local server
static socketId;
static {
this.socket.on("id",(id)=>{this.socketId = id});
Expand Down

0 comments on commit a8e50e2

Please sign in to comment.