Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Sep 18, 2022
2 parents 4518c50 + fb93308 commit 8eae373
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 31 deletions.
23 changes: 23 additions & 0 deletions dfsdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
b59cfa8 (HEAD -> games3, origin/games3) merged with games
26e2acb (origin/games) firebase for bullets
440d0b0 spawn locations
f46b50d merged
1ee53fd (games) meow
76d9437 sdf
149a0a0 added aim shooting
bf79487 added health bars
d460f1b (games2) fixed duplicate
80e74d4 (origin/games2) woeds
1225894 z_
ca732f8 edit
8ed2173 d
d69e111 (origin/lobby) finished lobby
882ee48 (origin/main, origin/HEAD, main) Merge pull request #2 from astrocat879/codes2
1b78505 (origin/codes2, codes2) merged with codes
b8b53aa (origin/game, origin/codes, codes) fixed game codes
133584b ss
9a28ed5 codes
e2d0683 (brrrrrrrr) lobby and main menu
7fd74f6 added stufff
dc1d189 setup
46d8418 Initial commit
Binary file added dist/assets/you-lose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dist/assets/you-win.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 dist/bundle.js

Large diffs are not rendered by default.

102 changes: 72 additions & 30 deletions src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class Game extends Phaser.Scene {
this.firebaseApp = initializeApp(FBconfig);
this.db = getDatabase(this.firebaseApp);
this.playerData = {};
this.playerData = [];
this.prevShoot = -100;
this.bulletImgs = {};
this.character;
Expand Down Expand Up @@ -121,6 +120,8 @@ class Game extends Phaser.Scene {
'assets/wind-right.png',
{ frameWidth: 68, frameHeight: 36 }
);
this.load.image('you-win','assets/you-win.png');
this.load.image('you-lose','assets/you-lose.png');
this.load.spritesheet('tabby',
'assets/cat-tabby.png',
{ frameWidth: 52, frameHeight: 48 }
Expand Down Expand Up @@ -167,7 +168,13 @@ class Game extends Phaser.Scene {
this.player.body.setGravityY(700);
this.player.setCollideWorldBounds(true);

this.playerHealth = new HealthBar(this, 46, 107);
if (this.playerCount == 1){
this.playerHealth = new HealthBar(this, 46, 107);
}
else{
this.playerHealth = new HealthBar(this, 706, 107);
}


this.anims.create({
key: 'wind-left',
Expand Down Expand Up @@ -294,10 +301,43 @@ class Game extends Phaser.Scene {
// FIrebase player stuff

const allPlayersRef = ref(this.db, `${this.gameCode}/players`);

onChildAdded(allPlayersRef, (snapshot) => { // draw all the other players
const addedPlayer = snapshot.val();
if(addedPlayer.playerCount==1) this.add.image(70,70,addedPlayer.character);
else this.add.image(730,70,addedPlayer.character);
if (addedPlayer.id != this.playerNumber){
console.log("ON CHILD ADDED");
console.log(addedPlayer.id);
var newChar = this.physics.add.sprite(addedPlayer.x, addedPlayer.y, addedPlayer.character);
this.physics.add.collider(newChar, this.platforms);
this.physics.add.collider(newChar, this.drawnPlatform);
newChar.setBounce(0.2);
newChar.body.setGravityY(700);
if (this.playerCount == 1){
newChar.otherplayerHealth = new HealthBar(this, 706, 107);
}
else{
newChar.otherplayerHealth = new HealthBar(this, 46, 107);
}
// newChar.otherplayerHealth = new HealthBar(this, 706, 107);
newChar.id = addedPlayer.id;
newChar.x = addedPlayer.x;
newChar.y = addedPlayer.y;
this.playerData[addedPlayer.id] = newChar;
this.otherPlayer = addedPlayer.id;
}
// var par = document.getElementById("box");
// var bt = document.createElement("button");
// bt.textContent = addedPlayer.x;
// par.appendChild(bt);
});

onValue(allPlayersRef, (snapshot) => { // update location of all the other players
this.players = snapshot.val() || {};
Object.keys(this.players).forEach(characterKey => {
if (characterKey != this.playerNumber){
console.log("ON VALUE");
const updatedPlayer = this.players[characterKey];
const curPlayer = this.playerData[characterKey];
curPlayer.x = updatedPlayer.x;
Expand All @@ -306,10 +346,17 @@ class Game extends Phaser.Scene {
curPlayer.body.velocity.y = 0;
curPlayer.x = updatedPlayer.x;
curPlayer.y = updatedPlayer.y;
curPlayer.otherplayerHealth.value = updatedPlayer.health;
curPlayer.otherplayerHealth.draw();
curPlayer.anims.play(updatedPlayer.animation, true);

if (curPlayer.otherplayerHealth.value === 0){
this.add.image(400,100,'you-win').setOrigin(0.5).setScale(1.5);
this.scene.pause();
}
}
})
})
});

onChildChanged(ref(this.db,`${this.gameCode}/players`), (snapshot) => {
const player = snapshot.val();
Expand Down Expand Up @@ -360,41 +407,27 @@ class Game extends Phaser.Scene {
console.log(bullet.id);
console.log(this.gameCode);

var res = this.playerHealth.decrease(10);

// console.log("healhtvalue : "+ this.otherplayerNumber + " "+ this.playerData[this.otherPlayer].otherplayerHealth.value);

set(ref(getDatabase(initializeApp(FBconfig)), `${this.gameCode}/bullets/${bullet.id}`), {
x: bullet.x,
y: bullet.y,
id: bullet.id,
status: false,
owner:bullet.owner
});
update(this.uref, {health: this.playerHealth.value});

if (res == true){
this.add.image(400,100,'you-lose').setOrigin(0.5).setScale(1.5);
this.scene.pause();
}
}
}
}
})

onChildAdded(allPlayersRef, (snapshot) => { // draw all the other players
const addedPlayer = snapshot.val();
if(addedPlayer.playerCount==1) this.add.image(70,70,addedPlayer.character);
else this.add.image(730,70,addedPlayer.character);
if (addedPlayer.id != this.playerNumber){
console.log(addedPlayer.id);
var newChar = this.physics.add.sprite(addedPlayer.x, addedPlayer.y, addedPlayer.character);
this.physics.add.collider(newChar, this.platforms);
this.physics.add.collider(newChar, this.drawnPlatform);
newChar.setBounce(0.2);
newChar.body.setGravityY(700);
newChar.playerHealth = new HealthBar(this, 706, 107);
newChar.id = addedPlayer.id;
newChar.x = addedPlayer.x;
newChar.y = addedPlayer.y;
this.playerData[addedPlayer.id] = newChar;
this.otherPlayer = addedPlayer.id;
}
// var par = document.getElementById("box");
// var bt = document.createElement("button");
// bt.textContent = addedPlayer.x;
// par.appendChild(bt);
})
});

// Bullet Class
var Bullet = new Phaser.Class({
Expand Down Expand Up @@ -441,6 +474,7 @@ class Game extends Phaser.Scene {
if(key=='status') status = data.val()[key];
}
});
// console.log(status);
if(this.gameCode && status) {
set(ref(getDatabase(initializeApp(FBconfig)), `${this.gameCode}/bullets/${this.id}`), {
x: this.x,
Expand Down Expand Up @@ -478,11 +512,20 @@ class Game extends Phaser.Scene {
var otherHealth = this.playerData[this.otherPlayer].health - 5;
update(ref(getDatabase(initializeApp(FBconfig)), `${this.gameCode}/players/${this.otherPlayer}`), { health: otherHealth });
}*/

function g (a, b) {
a.setActive(false);
a.setVisible(false);
}

this.physics.add.overlap(this.bullets, this.platforms, f, null, this);
//this.physics.add.overlap(this.bullets, this.players[this.otherPlayer], g, null, this);

this.physics.add.collider(this.bullets, this.platforms);
//this.physics.add.collider(this.bullets, this.players[this.otherPlayer]);

this.physics.add.overlap(this.bullets, this.playerData[this.otherPlayer], g, null, this);
this.physics.add.collider(this.bullets, this.playerData[this.otherPlayer]);
}

update (){
Expand Down Expand Up @@ -599,14 +642,13 @@ class Game extends Phaser.Scene {
// update ur position in firebase
if (Math.round(this.player.x) != this.previousX || Math.round(this.player.y) != this.previousY || this.player.anims.currentAnim.key != this.prevAnim) {
this.uref = ref(this.db, `${this.gameCode}/players/${this.playerNumber}`);
set(this.uref, {
update(this.uref, {
id: this.playerNumber,
playerCount: this.playerCount,
character: this.playerChar,
x: Math.round(this.player.x),
y: Math.floor(this.player.y),
animation: this.player.anims.currentAnim.key,
health: this.playerHealth.value
})
}
this.previousX = Math.round(this.player.x);
Expand Down

0 comments on commit 8eae373

Please sign in to comment.