Add player weapon system

This commit is contained in:
Trevor Slocum 2021-12-26 15:13:32 -08:00
parent c9ceabcbcf
commit 04d855a92a
17 changed files with 460 additions and 335 deletions

View File

@ -19,6 +19,7 @@ const sampleRate = 44100
var FS embed.FS
var ImgWhiteSquare = ebiten.NewImage(8, 8)
var ImgBlackSquare = ebiten.NewImage(8, 8)
var (
ImgBat = LoadImage("image/bat.png")
@ -35,6 +36,7 @@ var (
func init() {
ImgWhiteSquare.Fill(color.White)
ImgBlackSquare.Fill(color.Black)
}
func LoadSounds(ctx *audio.Context) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

After

Width:  |  Height:  |  Size: 97 KiB

View File

@ -1,130 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="20" height="120" tilewidth="32" tileheight="32" infinite="0" nextlayerid="6" nextobjectid="45">
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="20" height="120" tilewidth="32" tileheight="32" infinite="0" backgroundcolor="#181818" nextlayerid="7" nextobjectid="80">
<tileset firstgid="1" name="tileset" tilewidth="32" tileheight="32" tilecount="72" columns="9">
<image source="../image/tileset/tileset.png" width="288" height="256"/>
</tileset>
<layer id="2" name="BG" width="20" height="120" locked="1">
<data encoding="csv">
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27
</data>
</layer>
<layer id="1" name="FG" width="20" height="120">
@ -160,12 +160,12 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,2147483684,2147483683,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,2147483693,2147483692,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,35,36,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,44,45,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
33,33,33,33,2147483679,50,50,31,33,33,33,33,33,33,33,32,33,33,33,33,
33,33,33,33,2147483679,0,0,31,33,33,33,33,33,33,33,32,33,33,33,33,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@ -212,12 +212,12 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,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,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<objectgroup id="6" name="CREEPS">
<object id="50" gid="50" x="288" y="3232" width="32" height="32"/>
<object id="52" gid="52" x="96" y="2880" width="32" height="32"/>
<object id="53" gid="52" x="96" y="2816" width="32" height="32"/>
<object id="54" gid="52" x="96" y="2752" width="32" height="32"/>
<object id="55" gid="50" x="544" y="2304" width="32" height="32"/>
<object id="56" gid="50" x="448" y="2304" width="32" height="32"/>
<object id="58" gid="50" x="160" y="2304" width="32" height="32"/>
<object id="60" gid="50" x="64" y="2304" width="32" height="32"/>
<object id="61" gid="50" x="160" y="1472" width="32" height="32"/>
<object id="62" gid="50" x="320" y="1536" width="32" height="32"/>
<object id="63" gid="50" x="512" y="1600" width="32" height="32"/>
<object id="64" gid="50" x="448" y="1472" width="32" height="32"/>
<object id="69" gid="52" x="0" y="1088" width="32" height="32"/>
<object id="70" gid="52" x="64" y="1088" width="32" height="32"/>
<object id="71" gid="52" x="96" y="1056" width="32" height="32"/>
<object id="72" gid="52" x="96" y="992" width="32" height="32"/>
<object id="73" gid="52" x="32" y="1152" width="32" height="32"/>
<object id="75" gid="52" x="32" y="992" width="32" height="32"/>
<object id="78" gid="50" x="608" y="1152" width="32" height="32"/>
</objectgroup>
<objectgroup color="#ce0003" id="5" name="HAZARDS">
<object id="1" x="486" y="3392" width="16" height="27"/>
<object id="2" x="518" y="3346" width="15" height="27"/>
@ -417,7 +314,10 @@
<object id="39" x="621" y="3251" width="7" height="18"/>
<object id="40" x="450" y="2701" width="21" height="34"/>
<object id="42" x="340" y="3197" width="35" height="12"/>
<object id="43" x="95" y="1028" width="40" height="20" rotation="180"/>
<object id="44" x="76" y="1034" width="35" height="12" rotation="180"/>
<object id="43" x="33" y="1008" width="40" height="20"/>
<object id="44" x="52" y="1022" width="35" height="12"/>
<object id="45" x="6" y="2656" width="17" height="27"/>
<object id="46" x="67" y="2826" width="24" height="16"/>
<object id="47" x="129" y="2769" width="28" height="9"/>
</objectgroup>
</map>

View File

@ -1,23 +0,0 @@
package component
import (
. "code.rocketnine.space/tslocum/brownboxbatman/ecs"
"code.rocketnine.space/tslocum/gohan"
)
type BulletComponent struct {
}
var BulletComponentID = ECS.NewComponentID()
func (p *BulletComponent) ComponentID() gohan.ComponentID {
return BulletComponentID
}
func Bullet(ctx *gohan.Context) *BulletComponent {
c, ok := ctx.Component(BulletComponentID).(*BulletComponent)
if !ok {
return nil
}
return c
}

View File

@ -8,13 +8,27 @@ import (
)
type CreepComponent struct {
Active bool
Health int
FireAmount int
FireRate int // In ticks
Ticks int // Ticks until next action
Rand *rand.Rand
FireTicks int //Ticks until next action
Movement int
Movements [][3]float64 // X, Y, pre-delay in ticks
MovementTicks int // Ticks until next action
DamageTicks int
Rand *rand.Rand
}
const (
CreepSnowGunner = iota + 1
CreepSnowmanHead
)
var CreepComponentID = ECS.NewComponentID()
func (p *CreepComponent) ComponentID() gohan.ComponentID {

23
component/creepbullet.go Normal file
View File

@ -0,0 +1,23 @@
package component
import (
. "code.rocketnine.space/tslocum/brownboxbatman/ecs"
"code.rocketnine.space/tslocum/gohan"
)
type CreepBulletComponent struct {
}
var CreepBulletComponentID = ECS.NewComponentID()
func (p *CreepBulletComponent) ComponentID() gohan.ComponentID {
return CreepBulletComponentID
}
func CreepBullet(ctx *gohan.Context) *CreepBulletComponent {
c, ok := ctx.Component(CreepBulletComponentID).(*CreepBulletComponent)
if !ok {
return nil
}
return c
}

23
component/playerbullet.go Normal file
View File

@ -0,0 +1,23 @@
package component
import (
. "code.rocketnine.space/tslocum/brownboxbatman/ecs"
"code.rocketnine.space/tslocum/gohan"
)
type PlayerBulletComponent struct {
}
var PlayerBulletComponentID = ECS.NewComponentID()
func (p *PlayerBulletComponent) ComponentID() gohan.ComponentID {
return PlayerBulletComponentID
}
func PlayerBullet(ctx *gohan.Context) *PlayerBulletComponent {
c, ok := ctx.Component(PlayerBulletComponentID).(*PlayerBulletComponent)
if !ok {
return nil
}
return c
}

View File

@ -1,8 +1,6 @@
package component
import (
"time"
. "code.rocketnine.space/tslocum/brownboxbatman/ecs"
"code.rocketnine.space/tslocum/gohan"
)
@ -12,8 +10,9 @@ type WeaponComponent struct {
Damage int
FireRate time.Duration
LastFire time.Time
// In ticks
FireRate int
NextFire int
BulletSpeed float64
}

View File

@ -7,7 +7,7 @@ import (
"code.rocketnine.space/tslocum/gohan"
)
func NewBullet(x, y, xSpeed, ySpeed float64) gohan.Entity {
func NewCreepBullet(x, y, xSpeed, ySpeed float64) gohan.Entity {
bullet := ECS.NewEntity()
ECS.AddComponent(bullet, &component.PositionComponent{
@ -24,7 +24,7 @@ func NewBullet(x, y, xSpeed, ySpeed float64) gohan.Entity {
Image: asset.ImgWhiteSquare,
})
ECS.AddComponent(bullet, &component.BulletComponent{})
ECS.AddComponent(bullet, &component.CreepBulletComponent{})
return bullet
}

View File

@ -1,8 +1,6 @@
package entity
import (
"time"
"code.rocketnine.space/tslocum/brownboxbatman/asset"
"code.rocketnine.space/tslocum/brownboxbatman/component"
. "code.rocketnine.space/tslocum/brownboxbatman/ecs"
@ -18,8 +16,8 @@ func NewPlayer() gohan.Entity {
weapon := &component.WeaponComponent{
Damage: 1,
FireRate: 100 * time.Millisecond,
BulletSpeed: 15,
FireRate: 144 / 16,
BulletSpeed: 8,
}
ECS.AddComponent(player, weapon)

30
entity/playerbullet.go Normal file
View File

@ -0,0 +1,30 @@
package entity
import (
"code.rocketnine.space/tslocum/brownboxbatman/asset"
"code.rocketnine.space/tslocum/brownboxbatman/component"
. "code.rocketnine.space/tslocum/brownboxbatman/ecs"
"code.rocketnine.space/tslocum/gohan"
)
func NewPlayerBullet(x, y, xSpeed, ySpeed float64) gohan.Entity {
bullet := ECS.NewEntity()
ECS.AddComponent(bullet, &component.PositionComponent{
X: x,
Y: y,
})
ECS.AddComponent(bullet, &component.VelocityComponent{
X: xSpeed,
Y: ySpeed,
})
ECS.AddComponent(bullet, &component.SpriteComponent{
Image: asset.ImgBlackSquare,
})
ECS.AddComponent(bullet, &component.PlayerBulletComponent{})
return bullet
}

View File

@ -163,6 +163,7 @@ func (g *game) addSystems() {
g.movementSystem = system.NewMovementSystem()
ecs.AddSystem(system.NewPlayerMoveSystem(g.player, g.movementSystem))
ecs.AddSystem(system.NewplayerFireSystem())
ecs.AddSystem(g.movementSystem)

View File

@ -8,6 +8,7 @@ import (
"github.com/hajimehoshi/ebiten/v2"
)
// pause time, screen X, screen Y
type CreepSystem struct {
}
@ -37,33 +38,67 @@ func (s *CreepSystem) Update(ctx *gohan.Context) error {
creep := component.Creep(ctx)
position := component.Position(ctx)
if creep.Health <= 0 {
for i, e := range world.World.CreepEntities {
if e == ctx.Entity {
world.World.CreepRects = append(world.World.CreepRects[:i], world.World.CreepRects[i+1:]...)
world.World.CreepEntities = append(world.World.CreepEntities[:i], world.World.CreepEntities[i+1:]...)
ctx.RemoveEntity()
return nil
}
}
}
// Skip inactive creeps.
sx, sy := world.LevelCoordinatesToScreen(position.X, position.Y)
if sx < 0 || sy < 0 || sx > 640 || sy > 480 {
inactive := sx < 0 || sy < 0 || sx > 640 || sy > 480
if creep.Active != !inactive {
creep.Active = !inactive
}
if inactive {
return nil
}
randSpeed := func() float64 {
return 0.5 + creep.Rand.Float64()*0.5 + (0.5 - creep.Rand.Float64())
}
l := len(creep.Movements)
if l > creep.Movement {
if creep.MovementTicks == 0 {
m := creep.Movements[creep.Movement]
position.X, position.Y = m[0], m[1]
creep.Movement++
if creep.Ticks == 0 {
for i := 0; i < 8; i++ {
speedA := randSpeed()
speedB := randSpeed()
if creep.Rand.Intn(2) == 0 {
speedA *= -1
}
if creep.Rand.Intn(2) == 0 {
speedB *= -1
}
entity.NewBullet(position.X, position.Y, speedA, speedB)
creep.MovementTicks = int(m[2])
}
creep.Ticks = creep.FireRate
creep.MovementTicks--
}
creep.Ticks--
randVelocity := func() (float64, float64) {
for {
vx := creep.Rand.Float64()*0.5 + (0.5 - creep.Rand.Float64())
vy := creep.Rand.Float64()*0.5 + (0.5 - creep.Rand.Float64())
if vx > 0.5 || vx < -0.5 || vy > 0.5 || vy < -0.5 {
return vx, vy
}
}
}
if creep.FireTicks == 0 {
for i := 0; i < 8; i++ {
vx, vy := randVelocity()
if creep.Rand.Intn(2) == 0 {
vx *= -1
}
if creep.Rand.Intn(2) == 0 {
vy *= -1
}
entity.NewCreepBullet(position.X, position.Y, vx, vy)
}
creep.FireTicks = creep.FireRate
}
// TODO update colorM based on damageticks
creep.FireTicks--
return nil
}

57
system/input_fire.go Normal file
View File

@ -0,0 +1,57 @@
package system
import (
"code.rocketnine.space/tslocum/brownboxbatman/component"
"code.rocketnine.space/tslocum/brownboxbatman/entity"
"code.rocketnine.space/tslocum/brownboxbatman/world"
"code.rocketnine.space/tslocum/gohan"
"github.com/hajimehoshi/ebiten/v2"
)
const (
fireSpeed = 1.5
)
type playerFireSystem struct {
}
func NewplayerFireSystem() *playerFireSystem {
return &playerFireSystem{}
}
func (_ *playerFireSystem) Needs() []gohan.ComponentID {
return []gohan.ComponentID{
component.PositionComponentID,
component.VelocityComponentID,
component.WeaponComponentID,
component.SpriteComponentID,
}
}
func (_ *playerFireSystem) Uses() []gohan.ComponentID {
return nil
}
func (s *playerFireSystem) Update(ctx *gohan.Context) error {
if world.World.GameOver {
return nil
}
position := component.Position(ctx)
weapon := component.Weapon(ctx)
if ebiten.IsKeyPressed(ebiten.KeyZ) || ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
if weapon.NextFire == 0 {
entity.NewPlayerBullet(position.X-8, position.Y-8, 0, -weapon.BulletSpeed)
entity.NewPlayerBullet(position.X+8, position.Y-8, 0, -weapon.BulletSpeed)
weapon.NextFire = weapon.FireRate
}
}
if weapon.NextFire > 0 {
weapon.NextFire--
}
return nil
}
func (s *playerFireSystem) Draw(_ *gohan.Context, _ *ebiten.Image) error {
return gohan.ErrSystemWithoutDraw
}

View File

@ -75,10 +75,10 @@ func (s *playerMoveSystem) Update(ctx *gohan.Context) error {
return nil
}*/
pressLeft := ebiten.IsKeyPressed(ebiten.KeyA) || ebiten.IsKeyPressed(ebiten.KeyLeft)
pressRight := ebiten.IsKeyPressed(ebiten.KeyD) || ebiten.IsKeyPressed(ebiten.KeyRight)
pressUp := ebiten.IsKeyPressed(ebiten.KeyW) || ebiten.IsKeyPressed(ebiten.KeyUp)
pressDown := ebiten.IsKeyPressed(ebiten.KeyS) || ebiten.IsKeyPressed(ebiten.KeyDown)
pressLeft := ebiten.IsKeyPressed(ebiten.KeyLeft)
pressRight := ebiten.IsKeyPressed(ebiten.KeyRight)
pressUp := ebiten.IsKeyPressed(ebiten.KeyUp)
pressDown := ebiten.IsKeyPressed(ebiten.KeyDown)
if (pressLeft && !pressRight) ||
(pressRight && !pressLeft) {

View File

@ -113,21 +113,48 @@ func (s *MovementSystem) Update(ctx *gohan.Context) error {
}
}
// Check bullet collision.
// Check creepBullet collision.
if world.World.NoClip {
return nil
}
bullet := ECS.Component(ctx.Entity, component.BulletComponentID)
bulletSize := 8.0
if bullet != nil {
r := image.Rect(int(position.X), int(position.Y), int(position.X+bulletSize), int(position.Y+bulletSize))
bulletRect := image.Rect(int(position.X), int(position.Y), int(position.X+bulletSize), int(position.Y+bulletSize))
creepBullet := ECS.Component(ctx.Entity, component.CreepBulletComponentID)
playerBullet := ECS.Component(ctx.Entity, component.PlayerBulletComponentID)
// Check hazard collisions.
if creepBullet != nil || playerBullet != nil {
for _, hazardRect := range world.World.HazardRects {
if bulletRect.Overlaps(hazardRect) {
ctx.RemoveEntity()
return nil
}
}
}
if creepBullet != nil {
playerRect := image.Rect(int(world.World.PlayerX), int(world.World.PlayerY), int(world.World.PlayerX+world.World.PlayerWidth), int(world.World.PlayerY+world.World.PlayerHeight))
if playerRect.Overlaps(r) {
if bulletRect.Overlaps(playerRect) {
world.World.SetGameOver(velocity.X, velocity.Y)
return nil
}
return nil
}
if playerBullet != nil {
for i, creepRect := range world.World.CreepRects {
if bulletRect.Overlaps(creepRect) {
creep := ECS.Component(world.World.CreepEntities[i], component.CreepComponentID).(*component.CreepComponent)
if creep.Active {
creep.Health--
creep.DamageTicks = 144 / 2
ctx.RemoveEntity()
return nil
}
}
}
}
return nil

View File

@ -6,11 +6,10 @@ import (
"math/rand"
"path/filepath"
"code.rocketnine.space/tslocum/brownboxbatman/entity"
"code.rocketnine.space/tslocum/brownboxbatman/asset"
"code.rocketnine.space/tslocum/brownboxbatman/component"
. "code.rocketnine.space/tslocum/brownboxbatman/ecs"
"code.rocketnine.space/tslocum/brownboxbatman/entity"
"code.rocketnine.space/tslocum/gohan"
"github.com/hajimehoshi/ebiten/v2"
"github.com/lafriks/go-tiled"
@ -33,6 +32,7 @@ var World = &GameWorld{
CamMoving: true,
PlayerWidth: 8,
PlayerHeight: 32,
TileImages: make(map[uint32]*ebiten.Image),
}
type GameWorld struct {
@ -64,6 +64,8 @@ type GameWorld struct {
Map *tiled.Map
ObjectGroups []*tiled.ObjectGroup
HazardRects []image.Rectangle
CreepRects []image.Rectangle
CreepEntities []gohan.Entity
TriggerEntities []gohan.Entity
TriggerRects []image.Rectangle
TriggerNames []string
@ -71,6 +73,8 @@ type GameWorld struct {
NativeResolution bool
BrokenPieceA, BrokenPieceB gohan.Entity
TileImages map[uint32]*ebiten.Image
}
func SetMessage(message string) {
@ -112,10 +116,9 @@ func LoadMap(filePath string) {
// Load tiles.
tileCache := make(map[uint32]*ebiten.Image)
for i := uint32(0); i < uint32(tileset.TileCount); i++ {
rect := tileset.GetTileRect(i)
tileCache[i+tileset.FirstGID] = tilesetImg.SubImage(rect).(*ebiten.Image)
World.TileImages[i+tileset.FirstGID] = tilesetImg.SubImage(rect).(*ebiten.Image)
}
createTileEntity := func(t *tiled.LayerTile, x int, y int) gohan.Entity {
@ -128,7 +131,7 @@ func LoadMap(filePath string) {
})
sprite := &component.SpriteComponent{
Image: tileCache[t.Tileset.FirstGID+t.ID],
Image: World.TileImages[t.Tileset.FirstGID+t.ID],
HorizontalFlip: t.HorizontalFlip,
VerticalFlip: t.VerticalFlip,
DiagonalFlip: t.DiagonalFlip,
@ -147,21 +150,11 @@ func LoadMap(filePath string) {
continue // No tile at this position.
}
tileImg := tileCache[t.Tileset.FirstGID+t.ID]
tileImg := World.TileImages[t.Tileset.FirstGID+t.ID]
if tileImg == nil {
continue
}
e := createTileEntity(t, x, y)
if layer.Name == "CREEPS" {
creep := &component.CreepComponent{
Health: 1,
FireAmount: 8,
FireRate: 144 / 4,
Rand: rand.New(rand.NewSource(int64(t.ID))),
}
ECS.AddComponent(e, creep)
}
createTileEntity(t, x, y)
}
}
}
@ -197,7 +190,7 @@ func LoadMap(filePath string) {
Y: obj.Y - 32,
})
ECS.AddComponent(mapTile, &component.SpriteComponent{
Image: tileCache[obj.GID],
Image: World.TileImages[obj.GID],
})
World.TriggerNames = append(World.TriggerNames, obj.Name)
@ -208,6 +201,12 @@ func LoadMap(filePath string) {
for _, obj := range grp.Objects {
World.HazardRects = append(World.HazardRects, ObjectToRect(obj))
}
} else if grp.Name == "CREEPS" {
for _, obj := range grp.Objects {
c := NewCreep(component.CreepSnowGunner, int64(obj.ID), float64(obj.X), float64(obj.Y))
World.CreepRects = append(World.CreepRects, ObjectToRect(obj))
World.CreepEntities = append(World.CreepEntities, c)
}
}
}
}
@ -271,15 +270,55 @@ func (w *GameWorld) SetGameOver(vx, vy float64) {
ySpeedB = 1.5
}
w.BrokenPieceA = entity.NewBullet(position.X, position.Y, xSpeedA, ySpeedA)
w.BrokenPieceA = entity.NewCreepBullet(position.X, position.Y, xSpeedA, ySpeedA)
pieceASprite := &component.SpriteComponent{
Image: asset.ImgBatBroken1,
}
ECS.AddComponent(w.BrokenPieceA, pieceASprite)
w.BrokenPieceB = entity.NewBullet(position.X, position.Y, xSpeedB, ySpeedB)
w.BrokenPieceB = entity.NewCreepBullet(position.X, position.Y, xSpeedB, ySpeedB)
pieceBSprite := &component.SpriteComponent{
Image: asset.ImgBatBroken2,
}
ECS.AddComponent(w.BrokenPieceB, pieceBSprite)
}
// TODO move
func NewCreep(creepType int, creepID int64, x float64, y float64) gohan.Entity {
creep := ECS.NewEntity()
ECS.AddComponent(creep, &component.PositionComponent{
X: x,
Y: y,
})
if creepType == component.CreepSnowmanHead {
ECS.AddComponent(creep, &component.VelocityComponent{})
ECS.AddComponent(creep, &component.CreepComponent{
Health: 128,
FireAmount: 1,
FireRate: 144 * 1.5,
Rand: rand.New(rand.NewSource(creepID)),
})
} else {
ECS.AddComponent(creep, &component.CreepComponent{
Health: 64,
FireAmount: 8,
FireRate: 144 / 4,
Rand: rand.New(rand.NewSource(creepID)),
})
}
img := asset.ImgBat
if creepType == component.CreepSnowmanHead {
img = World.TileImages[8]
} else if creepType == component.CreepSnowGunner {
img = World.TileImages[50]
}
ECS.AddComponent(creep, &component.SpriteComponent{
Image: img,
})
return creep
}