Skip to content

Commit

Permalink
fixes , assetchanges
Browse files Browse the repository at this point in the history
  • Loading branch information
codergautam committed Aug 8, 2022
1 parent ae3f1b9 commit 3c0f9a6
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 19 deletions.
Binary file added assets/images/pistol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion classes/Island.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = class Island {
this.getPeppers(room).forEach(pepper => {
if(pepper.color != this.capturedBy) {
room.peppers.delete(pepper.id);
ws.helper.to(room.id).emit("pepperCollected", pepper.id);
ws.helper.to(room.id).emit("pepperCollected", {id: pepper.id});
}
}
);
Expand Down
4 changes: 2 additions & 2 deletions classes/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Player {
this.maxHealth = 100;
this.damage = 7;

this.bodySize = 80 + (this.sizeLevel == 1 ? 0 : this.sizeLevel == 2 ? 20 : 40);
this.bodySize = 100 + (this.sizeLevel == 1 ? 0 : this.sizeLevel == 2 ? 20 : 40);


this.team = Math.random() > 0.5 ? "red" : "blue";
Expand Down Expand Up @@ -278,7 +278,7 @@ class Player {
}
}

this.bodySize = 80 + (this.sizeLevel == 1 ? 0 : this.sizeLevel == 2 ? 50 : 100);
this.bodySize = 100 + (this.sizeLevel == 1 ? 0 : this.sizeLevel == 2 ? 50 : 100);
// console.log(this.bodySize);/

var corners = this.getCorners(0.5);
Expand Down
6 changes: 2 additions & 4 deletions src/GameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@ this.lastKnownMyDisplayWidth = 0;
if(this.vid && this.vid.visible) {
var vidEnds = [3, 7, 11, 15, 19, 23];
// var vidStops = [1, 5.7, 9, 14, 17.5, 23];
console.log(this.vid.getCurrentTime());
this.vid.setPaused(false);
console.log("Playing");
this.vidText.setVisible(false);


Expand Down Expand Up @@ -438,6 +436,7 @@ this.minimap.setVisible(false);
this.socket.on("pepperCollected", (data: {id: string, who: string}) => {
var id = data.id;
var who = data.who;
console.log(id, who);
if(this.peppers.has(id)) {
var pepper= this.peppers.get(id);
if(who == this.socket.id) this.pick.play();
Expand Down Expand Up @@ -468,7 +467,6 @@ this.minimap.setVisible(false);
});
this.socket.on("islandState", ( data: {id: number, what: {state: number, capturedBy: string, capturingBy: string, dir: number}, percent: number}) => {
if(this.islands.find(i => i.id == data.id)) {
console.log("islandUpdate", data);

var island = this.islands.find(i => i.id == data.id);
island.setCurState({dir: data.what.dir, capturedBy: data.what.capturedBy, capturingBy: data.what.capturingBy, state: data.what.state}, data.percent);
Expand Down Expand Up @@ -499,7 +497,7 @@ try {

this.players.delete(id);
} catch(e) {
console.log("vdgj")
console.log(e)
}
},
});
Expand Down
2 changes: 2 additions & 0 deletions src/OpenScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ var progress = (1 - (remainder / total) as any);
this.load.audio("titleMusic", "/assets/audio/title.mp3");
this.load.audio("pick", "/assets/audio/pick.wav");

this.load.image("pistol", "/assets/images/pistol.png");

// this.load.video("intro", "/assets/videos/intro.mp4", 'canplaythrough', false, true);

this.load.image("redFlag", "/assets/images/redFlag.png");
Expand Down
6 changes: 3 additions & 3 deletions src/components/Island.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class Island extends Phaser.GameObjects.Container {
this.setTeam(state.capturedBy);
this.dir = state.dir;
this.capturingBy = state.capturingBy;
console.log(state.capturedBy, state.capturingBy);
// console.log(state.capturedBy, state.capturingBy);
this.setPercent(capturedPercentage, state.capturingBy);
}
setTeam(team: string) {
Expand Down Expand Up @@ -140,7 +140,7 @@ export default class Island extends Phaser.GameObjects.Container {
}
}
setPercent(percent: number, team: string) {
console.log(team, percent)
// console.log(team, percent)
this.capturingCircle.setFillStyle(team == "red" ? 0xFF3632 : team == "none" ? 0x838579 : 0x0096ff);
this.capturingCircle.setVisible(true);
this.capturingCircle.setScale(percent/100);
Expand All @@ -153,7 +153,7 @@ export default class Island extends Phaser.GameObjects.Container {
var x2 = this.x;
var y2 = this.y;
var dist = Math.sqrt(Math.pow(x - x2, 2) + Math.pow(y - y2, 2));
console.log(dist, radius, dist < radius);
// console.log(dist, radius, dist < radius);
return dist < radius;
}
preUpdate(delta) {
Expand Down
30 changes: 23 additions & 7 deletions src/components/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import HealthBar from "./HealthBar";

export default class Player extends Phaser.GameObjects.Container {
gun: Phaser.GameObjects.Rectangle;
pistol: Phaser.GameObjects.Image;
square: Phaser.GameObjects.Rectangle;
bodySize: number;
lastTick: number;
Expand Down Expand Up @@ -63,10 +64,17 @@ export default class Player extends Phaser.GameObjects.Container {
0,
team == "red" ? "redPlayer" : "bluePlayer"
).setOrigin(0.5);
this.pistol = new Phaser.GameObjects.Image(
scene,
0,
0,
"pistol"
).setOrigin(0.5).setScale(1.5);


const convert = (num, val, newNum) => (newNum * val) / num

this.realScaleX = convert(100, 0.5, this.bodySize);
this.realScaleX = convert(100, 0.25, this.bodySize);
this.image.setScale(this.realScaleX);

this.circle = new Phaser.GameObjects.Ellipse(this.scene, 0, 0, this.bodySize, this.bodySize, team == "red" ? 0xFF0000 : 0x0000FF).setDepth(4958).setOrigin(0.5);
Expand Down Expand Up @@ -110,14 +118,17 @@ export default class Player extends Phaser.GameObjects.Container {

// this.add(this.square);
// this.add(this.gun);
this.add(this.pistol);

this.add(this.image);
this.add(this.healthBar);

this.add(this.circle)
if (this.id != (this.scene as GameScene).socket.id) this.add(this.nameTag);
this.scene.add.existing(this);
(this.scene as GameScene).uiCam.ignore(this);
(this.scene as GameScene).minimap.ignore([this.healthBar, this.nameTag, this.image]);
console.log(this.joinTime, this.name, Date.now() - this.joinTime)
// console.log(this.joinTime, this.name, Date.now() - this.joinTime)
if(Date.now() - this.joinTime < 3000) {
this.scene.tweens.add({
targets: this.image,
Expand Down Expand Up @@ -163,7 +174,7 @@ export default class Player extends Phaser.GameObjects.Container {
// this.nameTag.x = 0


this.realScaleX = convert(100, 0.5, data.bodySize);
this.realScaleX = convert(100, 0.25, data.bodySize);
// console.log(data.bodySize);

if(this.realScaleX != this.image.scaleX) {
Expand All @@ -172,8 +183,8 @@ export default class Player extends Phaser.GameObjects.Container {
this.circle.displayWidth = data.bodySize;
this.circle.setFillStyle(this.id == (this.scene as GameScene).socket.id ? 0xFFFF00 : this.team == "red" ? 0xFF0000 : 0x0000FF);
this.healthBar.y = 0;
this.healthBar.bar.y = -1.1 * (this.image.displayHeight / 2);
this.nameTag.y = -1.3 * (this.image.displayHeight / 2);
this.healthBar.bar.y = -1.6 * (this.image.displayHeight / 2);
this.nameTag.y = -1.9 * (this.image.displayHeight / 2);
}

this.healthBar.maxValue = data.maxHealth;
Expand All @@ -195,7 +206,7 @@ export default class Player extends Phaser.GameObjects.Container {
if(!this.oldUntilNextLevel) this.oldUntilNextLevel = [data.untilNextLevel];
if(this.oldLevel != data.level) {
(this.scene as GameScene).spicyMeter.setLerpValue(0);
console.log("level up");
// console.log("level up");
this.oldUntilNextLevel.push(data.untilNextLevel);
}
// console.log(data.peppers/data.untilNextLevel*100);
Expand Down Expand Up @@ -264,9 +275,14 @@ export default class Player extends Phaser.GameObjects.Container {
this.image.setRotation(rLerp(this.image.rotation, this.toAngle, 0.6));
else
this.image.setRotation(
(this.scene as GameScene).mouseAngle + Math.PI + 0.35
(this.scene as GameScene).mouseAngle + Math.PI
);

this.pistol.setRotation(this.image.rotation+(Math.PI/2));
//move pistol by angle
this.pistol.x = this.image.x - Math.cos(this.image.rotation)*this.image.displayWidth/2;
this.pistol.y = this.image.y - Math.sin(this.image.rotation)*this.image.displayWidth/2;

// console.log(this.image.rotation);

// if(this.id == (this.scene as GameScene).socket.id) {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/mySocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export default class MySocket extends EventEmitter {
this.socket = socket;

this.socket.onmessage = (e) => {
console.log('onmessage');
// console.log('onmessage');
var rec = JSON.parse(e.data);
if(rec.t == "id") this.id = rec.d;
console.log(rec);
// console.log(rec);
this.emit(rec.t, rec.d);
};
}
Expand Down

0 comments on commit 3c0f9a6

Please sign in to comment.