Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cirkularka added #44

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added client/src/assets/CIRKULARKA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import { Player } from './objects/player';
import grassTileImg from './assets/grassTile.jpg';
import dirtTileImg from './assets/dirtTile.jpg';
import backgroundImg from './assets/oblakiBG.jpg';
import cirkularkaImg from './assets/CIRKULARKA.png';

import playerImg from './assets/player_image.png';

import animationPng from './assets/player/animation_white.png';
import animationJson from './assets/player/animation.json';
import { Cirkularka } from './objects/cirkularka';

class Game extends Phaser.Scene {
constructor() {
Expand All @@ -29,6 +31,7 @@ class Game extends Phaser.Scene {
this.load.image('dirtTile', dirtTileImg);
this.load.image('grassTile', grassTileImg);
this.load.image('background', backgroundImg);
this.load.image('cirkularka', cirkularkaImg);
//this.load.image('player', playerImg);

this.load.atlas('player', animationPng, animationJson);
Expand All @@ -46,6 +49,7 @@ class Game extends Phaser.Scene {

this.cursors = this.input.keyboard.createCursorKeys();
this.wasd = this.input.keyboard.addKeys('W,S,A,D');
this.spaceKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE);

//this.inputKeys = [
// this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE),
Expand All @@ -59,6 +63,7 @@ class Game extends Phaser.Scene {
update() {
this.handlePlayerMove();
this.background.update();
this.handleCirkularka();
}

handlePlayerMove() {
Expand All @@ -85,6 +90,36 @@ class Game extends Phaser.Scene {
}
}

handleCirkularka() {
if (Phaser.Input.Keyboard.JustDown(this.spaceKey)) {
if (this.player.body.velocity.x >= 0) {
this.cirkularka = new Cirkularka(this, this.player.x + 150, this.player.y, 'cirkularka');
this.cirkularka.setVelocityX(400);
} else {
this.cirkularka = new Cirkularka(this, this.player.x - 150, this.player.y, 'cirkularka');
this.cirkularka.setVelocityX(-400);
}
this.physics.add.collider(this.terrain, this.cirkularka);
this.physics.add.overlap(this.player, this.cirkularka, this.playerDeath, null, this);

this.websocket.cikrularkaSend(this.cirkularka.x, this.cirkularka.y, this.cirkularka.body.velocity.x);
}
}

playerDeath() {
//TODO: explosion
this.player.setPosition(100, 650);
this.websocket.playerMoveSend(this.player.x, this.player.y, this.player.body.velocity.x, this.player.body.velocity.y);
this.cirkularka.destroy();
}

cirkularkaRecieve(id, x, y, dx) {
this.cirkularka = new Cirkularka(this, x, y, 'cirkularka');
this.cirkularka.setVelocityX(dx);
this.physics.add.collider(this.terrain, this.cirkularka);
this.physics.add.overlap(this.player, this.cirkularka, this.playerDeath, null, this);
}

handleMessage(msg) {
if (msg.hasJoin()) {
this.joinRecieve(msg.getPlayerId());
Expand All @@ -93,6 +128,9 @@ class Game extends Phaser.Scene {
this.playerMoveRecieve(msg.getPlayerId(), move.getX(), move.getY(), move.getDx(), move.getDy());
} else if (msg.hasLeave()) {
this.leaveReceive(msg.getPlayerId());
} else if (msg.hasCirkularka()) {
const move = msg.getCirkularka();
this.cirkularkaRecieve(msg.getCirkularkaId(), move.getX(), move.getY(), move.getDx());
}
}

Expand Down
10 changes: 10 additions & 0 deletions client/src/network/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,14 @@ export class Websocket {
move.setDy(dy);
this.sendMessage(message);
}

cikrularkaSend(x, y, dx) {
var message = new messages.Message();
var cirkularka = new messages.Cirkularka();
message.setCirkularka(cirkularka);
cirkularka.setX(x);
cirkularka.setY(y);
cirkularka.setDx(dx);
this.sendMessage(message);
}
}
17 changes: 17 additions & 0 deletions client/src/objects/cirkularka.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Phaser from 'phaser';

export class Cirkularka extends Phaser.Physics.Arcade.Sprite {
constructor(scene, x, y, texture) {
super(scene, x, y, texture);
this.scene.physics.world.enable(this);
this.scene.add.existing(this);
this.setDisplaySize(70, 70);
this.setDepth(70);
this.setBounce(0.2);
// this.setCircle(35);

setTimeout(() => {
this.destroy();
}, 3000);
}
}
8 changes: 8 additions & 0 deletions messages/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ message Move {
float dy = 4;
}

message Cirkularka {
float x = 1;
float y = 2;
float dx = 3;
optional int32 cirkularka_id = 4;
}

message Leave {}

message Message {
Expand All @@ -23,5 +30,6 @@ message Message {
Join join = 4;
Move move = 5;
Leave leave = 6;
Cirkularka cirkularka = 7;
}
}