From ffd6706cb02fdd37f5f461a37287a5860e69fb6c Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Mon, 29 Jun 2020 03:14:32 +0530 Subject: [PATCH] :tada: Initial Commit * Integrates Colyseus Server * Implements Basic Player movement * Player Remove/Update Events --- .gitignore | 1 + .vscode/extensions.json | 5 ++ .vscode/launch.json | 21 ++++++++ .vscode/settings.json | 13 +++++ .vscode/tasks.json | 13 +++++ Project.xml | 83 ++++++++++++++++++++++++++++++ assets/data/data-goes-here.txt | 0 assets/images/images-go-here.txt | 0 assets/images/player.png | Bin 0 -> 19237 bytes assets/music/music-goes-here.txt | 0 assets/sounds/sounds-go-here.txt | 0 hxformat.json | 15 ++++++ source/AssetPaths.hx | 4 ++ source/Main.hx | 13 +++++ source/PlayState.hx | 85 +++++++++++++++++++++++++++++++ source/Player.hx | 13 +++++ source/models/Player.hx | 21 ++++++++ source/models/State.hx | 15 ++++++ 18 files changed, 302 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 Project.xml create mode 100644 assets/data/data-goes-here.txt create mode 100644 assets/images/images-go-here.txt create mode 100644 assets/images/player.png create mode 100644 assets/music/music-goes-here.txt create mode 100644 assets/sounds/sounds-go-here.txt create mode 100644 hxformat.json create mode 100644 source/AssetPaths.hx create mode 100644 source/Main.hx create mode 100644 source/PlayState.hx create mode 100644 source/Player.hx create mode 100644 source/models/Player.hx create mode 100644 source/models/State.hx diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1f5d640 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +export \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..419972a --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "openfl.lime-vscode-extension" + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5e9a7a1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Build + Debug", + "type": "lime", + "request": "launch" + }, + { + "name": "Debug", + "type": "lime", + "request": "launch", + "preLaunchTask": null + }, + { + "name": "Macro", + "type": "haxe-eval", + "request": "launch" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4c1a0e9 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "search.exclude": { + "export/**/*.hx": true + }, + "[haxe]": { + "editor.formatOnSave": true, + "editor.formatOnPaste": true, + "editor.codeActionsOnSave": { + "source.sortImports": true + } + }, + "haxe.enableExtendedIndentation": true +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..16a7764 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,13 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "lime", + "command": "test", + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} diff --git a/Project.xml b/Project.xml new file mode 100644 index 0000000..c6ba97d --- /dev/null +++ b/Project.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/data/data-goes-here.txt b/assets/data/data-goes-here.txt new file mode 100644 index 0000000..e69de29 diff --git a/assets/images/images-go-here.txt b/assets/images/images-go-here.txt new file mode 100644 index 0000000..e69de29 diff --git a/assets/images/player.png b/assets/images/player.png new file mode 100644 index 0000000000000000000000000000000000000000..7ddd4044d61b60045600e2dfc8880a39e435c60b GIT binary patch literal 19237 zcmeHN2{@Ep`#58Y#~+59tL)s0AQU8FC2(DJ{zItbRUtD%A zV=)t3gn^v7f-hT&_N>W|{VU5Wp0rD8`mu<304}ENHA0&PgmK`VkE-hY*~N@k0dDIZ zRwhtv8e1$gGlqnpK*l^c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0nBkC(btx+=LqbL*f$G^GZcelh7zQ39%1nxf6}44B z*-tMMNx+EU5kgv#Fi`{$D=RAz)?qcD;5>M!}j2P5KY{_jHBF7XpCL#=C8ibP`tw8sHz(eg597sQjk_rM3E#_yH3Go3L z&fEYwK~z%$Lg1kcf`??GT!9+AWz64j*qF2rADj>Z=IhJ^q+|zvKe@&lR3A|L5IiJ| z8aN#Kqu}8?XuSl85Dd~Ns^LT^OZ16YtO>OrnoHU9^Y3X*z=#N_wM%fA`NcS#);>Ti z+Cr8=3xcJQRFg=AKIMOF31GATh7U?&&^`fyr|kQNSB*MkLVN(64FoXK+J*pOA0^EP&!H0B(zkL&s(0Q2HYo zA*~6(d;kn*s34H2hH^**H3?`utRZP?E1?zqn;uj4f6x86M*)fmfPshR4!u8I3NRW_ zf<+UD;3*v?l9OuW?J=hZEdfRalvKgZ)%PBZ(8>b7I0QvoVFV1BK5QfK(9uyw2-rt@ z4sCoO5f}-d{lUK^z;WMGXhi^dPAHT?fS<$JzuJZt0X2^fKgbV_;|;B&0Cu>EPJtj$ z2pG1}J#~14O9owE<6*4PfL0a&!yjg{5Fkv0F!QExhLqqwr@Yx1aB;dL&^@$<@ham=04WC` zgNGoYMzLI;ga%pxAf52QgAN$KQGxxLTAy2x2w2dMBA=xIP~;X!L}?Xd*|*$`Ya#>* zKxr$~DEh?*ZL^^AqE;jbDlp(O#BLxfYH zJnkMorO_qOdeHT=mH{mZfXFZspa~Cch`x0lk7xxyZqt zx?uZ9ErAwJkem%d)W`{942zpzb zMiYZIRnGsl_xx}CON8-eL3jO~5cpelfvs3;4wpJ`C; + + private var players:Map = new Map(); + + override public function create() + { + super.create(); + + this.client.joinOrCreate("my_room", [], State, function(err, room) + { + if (err != null) + { + trace("JOIN ERROR: " + err); + return; + } + + this.room = room; + + this.room.state.players.onAdd = function(player, key) + { + trace("Player" + player.x); + var _player = new Player(player.x, player.y); + this.players[key] = _player; + add(_player); + } + + this.room.state.players.onChange = function(player, key) + { + trace("PLAYER CHANGED AT: ", key); + this.players[key].x = player.x; + this.players[key].y = player.y; + } + + this.room.state.players.onRemove = function(player, key) + { + trace("PLAYER REMOVED AT: ", key); + remove(this.players[key]); + } + }); + } + + override public function update(elapsed:Float) + { + if (FlxG.keys.pressed.UP) + { + // The up arrow key is currently pressed + // This code is executed every frame, while the key is pressed\ + this.room.send("move", {y: -1}); + } + + if (FlxG.keys.justPressed.DOWN) + { + // The left arrow key has just been pressed + // This code is only executed once, on the frame immediately after the key has been pressed + this.room.send("move", {y: 1}); + } + + if (FlxG.keys.justReleased.LEFT) + { + // The left arrow key has just been released + // This code is only executed once, on the frame immediately after the key has been released + this.room.send("move", {x: -1}); + } + + if (FlxG.keys.justReleased.RIGHT) + { + // The left arrow key has just been released + // This code is only executed once, on the frame immediately after the key has been released + this.room.send("move", {x: 1}); + } + super.update(elapsed); + } +} diff --git a/source/Player.hx b/source/Player.hx new file mode 100644 index 0000000..80c3f78 --- /dev/null +++ b/source/Player.hx @@ -0,0 +1,13 @@ +package; + +import flixel.FlxSprite; +import flixel.util.FlxColor; + +class Player extends FlxSprite +{ + public function new(x:Float = 0, y:Float = 0) + { + super(x, y); + loadGraphic("assets/images/player.png"); + } +} diff --git a/source/models/Player.hx b/source/models/Player.hx new file mode 100644 index 0000000..1de9b3a --- /dev/null +++ b/source/models/Player.hx @@ -0,0 +1,21 @@ +// +// THIS FILE HAS BEEN GENERATED AUTOMATICALLY +// DO NOT CHANGE IT MANUALLY UNLESS YOU KNOW WHAT YOU'RE DOING +// +// GENERATED USING @colyseus/schema 0.5.39 +// +package models; + +import io.colyseus.serializer.schema.Schema; + +class Player extends Schema +{ + @:type("number") + public var x:Dynamic = 0; + + @:type("number") + public var y:Dynamic = 0; + + @:type("string") + public var name:String = ""; +} diff --git a/source/models/State.hx b/source/models/State.hx new file mode 100644 index 0000000..4f89d35 --- /dev/null +++ b/source/models/State.hx @@ -0,0 +1,15 @@ +// +// THIS FILE HAS BEEN GENERATED AUTOMATICALLY +// DO NOT CHANGE IT MANUALLY UNLESS YOU KNOW WHAT YOU'RE DOING +// +// GENERATED USING @colyseus/schema 0.5.39 +// +package models; + +import io.colyseus.serializer.schema.Schema; + +class State extends Schema +{ + @:type("map", Player) + public var players:MapSchema = new MapSchema(); +}