-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 436fb21
Showing
33 changed files
with
1,533 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 vytautashi | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# go-tank | ||
<div align="center"> | ||
<img src="logo.png"/> | ||
</div> | ||
|
||
--- | ||
Simple multiplayer 'real-time' online game that uses _WebSockets_ and is played via browser. Also known as 'io game' type. Created with [Golang](https://go.dev/) (backend) and [JavaScript/Phaser 3](https://phaser.io/) (frontend). | ||
|
||
[more info](#more-info) | ||
|
||
## Getting Started | ||
### Prerequisites | ||
Things you need to install. | ||
- [Golang](https://go.dev/dl/) _(tested on 1.19.3)_ | ||
- Browser that support JavaScript | ||
|
||
### Installation and Building | ||
1. Clone repository using command `git clone https://github.com/vytautashi/go-tank.git` | ||
2. Run command `go build` within `/game-server` directory | ||
3. Run command `go build` within `/game-client` directory | ||
|
||
### Running Game | ||
1. Run game-server executable in `/game-server` directory | ||
2. Run game-client executable in `/game-client` directory | ||
3. Access game using browser via url http://localhost:8081 _(open on multiple tabs to spawn multiple players)_ | ||
|
||
## More Info | ||
This repository demonstrates basic created 'io game' using _Golang_ and _Phaser_. Player can move and fire bullets which collides with other players. Its not blooted with a lot of functionality in order to make it simple and easy to understand. | ||
|
||
It does have: | ||
* Movable game characters (tanks) | ||
* Bullets collision with players | ||
* Communication between server and clients via _WebSockects_ | ||
* Backend uses concurrency (Golang go routines, communication via channels, non-blocking) | ||
|
||
It does not have: | ||
* IP restrictor _(same person from same computer can have multiple active players in game)_ **(backend)** | ||
* Spam restrictor _(do not limit message count received from clients/players via WebSockects)_ **(backend)** | ||
* Client-side prediction (https://en.wikipedia.org/wiki/Client-side_prediction) **(frontend)** | ||
* Code is not performance friendly _(highly optimised code would be hard to read/understand)_ | ||
* Now bullet objects are recreated everytime in frontend when it gets message about bullets positions from `game-server`, better would be to track bullets using id and move them accordingly instead of recreating **or/and** instead of deleting hide somewhere of the game screen and when command received, just set to correct position. **(frontend)** | ||
* Might be good to send only once Bullet data (position, speed, lifetime, moving direction) and let frontend calculate every next frame bullets positions, only send additional message to frontend if bullet collided with player and exploded so to remove bullet ealier from frontend. **(backend+frontend)** | ||
* And other places. | ||
|
||
## Screenshots | ||
#### Screenshot 1 | ||
![screenshot 1](screenshot1.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# game-client | ||
Frontend also contains: | ||
* js/phaser.min.js (3.55.2) | ||
|
||
## Installation and Building | ||
* To build, run command `go build` within this directory |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/vytautashi/go-tank/game-client | ||
|
||
go 1.19 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>go-tank</title> | ||
<script src="js/phaser.min.js"></script> | ||
<style> | ||
body { | ||
margin: 0px; | ||
background-color: black; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<script src="src/SceneGame.js"></script> | ||
<script src="src/Game.js"></script> | ||
<div id="game-client"></div> | ||
</body> | ||
|
||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
) | ||
|
||
func main() { | ||
log.Println("host: localhost:8081") | ||
|
||
http.Handle("/", http.FileServer(http.Dir("."))) | ||
|
||
err := http.ListenAndServe(":8081", nil) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Game { | ||
static GAME_SERVER_URL = "ws://" + document.location.hostname + ":8080/ws"; | ||
|
||
static config = { | ||
type: Phaser.AUTO, | ||
width: 800, | ||
height: 600, | ||
backgroundColor: '#999999', | ||
parent: 'game-client', | ||
scale: { | ||
mode: Phaser.Scale.FIT, | ||
autoCenter: Phaser.Scale.CENTER_BOTH, | ||
}, | ||
scene: [SceneGame] | ||
}; | ||
|
||
static game = new Phaser.Game(Game.config); | ||
} | ||
|
||
const NOT_FOUND_INDEX = -1; | ||
|
Oops, something went wrong.