Browse Source

Add title screen

main
Trevor Slocum 5 months ago
parent
commit
06b7f9ef85
  1. 6
      asset/asset.go
  2. BIN
      asset/image/snowflake.png
  3. BIN
      asset/image/title1.png
  4. BIN
      asset/image/title2.png
  5. BIN
      asset/image/title3.png
  6. 79
      asset/map/m1.tmx
  7. 2
      component/creep.go
  8. 2
      game/game.go
  9. 2
      system/camera.go
  10. 2
      system/creep.go
  11. 2
      system/input_fire.go
  12. 11
      system/input_move.go
  13. 2
      system/movement.go
  14. 2
      system/rail.go
  15. 52
      system/render.go
  16. 10
      world/world.go

6
asset/asset.go

@ -22,9 +22,15 @@ var ImgWhiteSquare = ebiten.NewImage(8, 8) @@ -22,9 +22,15 @@ var ImgWhiteSquare = ebiten.NewImage(8, 8)
var ImgBlackSquare = ebiten.NewImage(8, 8)
var (
ImgTitle1 = LoadImage("image/title1.png")
ImgTitle2 = LoadImage("image/title2.png")
ImgTitle3 = LoadImage("image/title3.png")
ImgBat = LoadImage("image/bat.png")
ImgBatBroken1 = LoadImage("image/bat_broken1.png")
ImgBatBroken2 = LoadImage("image/bat_broken2.png")
ImgSnowflake = LoadImage("image/snowflake.png")
)
var (

BIN
asset/image/snowflake.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
asset/image/title1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
asset/image/title2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
asset/image/title3.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

79
asset/map/m1.tmx

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
<?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" backgroundcolor="#181818" nextlayerid="7" nextobjectid="80">
<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="129">
<tileset firstgid="1" name="tileset" tilewidth="32" tileheight="32" tilecount="72" columns="9">
<image source="../image/tileset/tileset.png" width="288" height="256"/>
</tileset>
@ -172,25 +172,25 @@ @@ -172,25 +172,25 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
49,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
58,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
67,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,68,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,59,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3,0,0,0,54,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,61,62,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,13,0,0,0,0,0,0,
0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,23,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@ -255,11 +255,8 @@ @@ -255,11 +255,8 @@
<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"/>
@ -271,6 +268,38 @@ @@ -271,6 +268,38 @@
<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"/>
<object id="80" gid="50" x="128" y="2144" width="32" height="32"/>
<object id="94" gid="52" x="32" y="544" width="32" height="32"/>
<object id="95" gid="52" x="64" y="576" width="32" height="32"/>
<object id="96" gid="52" x="32" y="608" width="32" height="32"/>
<object id="97" gid="50" x="608" y="768" width="32" height="32"/>
<object id="98" gid="50" x="544" y="768" width="32" height="32"/>
<object id="99" gid="50" x="544" y="832" width="32" height="32"/>
<object id="100" gid="50" x="608" y="832" width="32" height="32"/>
<object id="101" gid="50" x="416" y="192" width="32" height="32"/>
<object id="102" gid="50" x="480" y="256" width="32" height="32"/>
<object id="103" gid="50" x="576" y="320" width="32" height="32"/>
<object id="104" gid="50" x="352" y="96" width="32" height="32"/>
<object id="105" gid="50" x="320" y="32" width="32" height="32"/>
<object id="106" gid="52" x="0" y="288" width="32" height="32"/>
<object id="107" gid="52" x="96" y="256" width="32" height="32"/>
<object id="108" gid="52" x="160" y="192" width="32" height="32"/>
<object id="109" gid="52" x="224" y="128" width="32" height="32"/>
<object id="110" gid="52" x="256" y="64" width="32" height="32"/>
<object id="114" gid="50" x="544" y="192" width="32" height="32"/>
<object id="115" gid="50" x="448" y="128" width="32" height="32"/>
<object id="116" gid="50" x="480" y="64" width="32" height="32"/>
<object id="117" gid="50" x="576" y="128" width="32" height="32"/>
<object id="119" gid="50" x="608" y="32" width="32" height="32"/>
<object id="120" gid="52" x="0" y="32" width="32" height="32"/>
<object id="121" gid="52" x="0" y="96" width="32" height="32"/>
<object id="122" gid="52" x="64" y="64" width="32" height="32"/>
<object id="123" gid="52" x="0" y="192" width="32" height="32"/>
<object id="124" gid="52" x="64" y="128" width="32" height="32"/>
<object id="125" gid="52" x="128" y="96" width="32" height="32"/>
<object id="126" gid="52" x="160" y="32" width="32" height="32"/>
<object id="127" gid="50" x="416" y="32" width="32" height="32"/>
<object id="128" gid="50" x="544" y="64" width="32" height="32"/>
</objectgroup>
<objectgroup color="#ce0003" id="5" name="HAZARDS">
<object id="1" x="486" y="3392" width="16" height="27"/>
@ -319,5 +348,17 @@ @@ -319,5 +348,17 @@
<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"/>
<object id="82" x="0" y="1376" width="7" height="64"/>
<object id="83" x="38" y="1376" width="17" height="28"/>
<object id="84" x="66" y="1453" width="21" height="33"/>
<object id="85" x="37" y="1508" width="14" height="14"/>
<object id="86" x="9" y="1607" width="11" height="15"/>
<object id="87" x="40" y="1760" width="12" height="19"/>
<object id="88" x="45" y="1574" width="8" height="17"/>
<object id="89" x="75" y="1557" width="8" height="17"/>
<object id="90" x="422" y="1714" width="15" height="27"/>
<object id="91" x="390" y="1952" width="17" height="27"/>
<object id="92" x="451" y="1898" width="22" height="16"/>
<object id="93" x="617" y="1863" width="11" height="15"/>
</objectgroup>
</map>

2
component/creep.go

@ -25,7 +25,7 @@ type CreepComponent struct { @@ -25,7 +25,7 @@ type CreepComponent struct {
}
const (
CreepSnowGunner = iota + 1
CreepSnowblower = iota + 1
CreepSnowmanHead
)

2
game/game.go

@ -149,8 +149,6 @@ func (g *game) Update() error { @@ -149,8 +149,6 @@ func (g *game) Update() error {
}
func (g *game) Draw(screen *ebiten.Image) {
screen.Fill(color.RGBA{100, 100, 100, 255})
err := ECS.Draw(screen)
if err != nil {
panic(err)

2
system/camera.go

@ -29,7 +29,7 @@ func (_ *CameraSystem) Uses() []gohan.ComponentID { @@ -29,7 +29,7 @@ func (_ *CameraSystem) Uses() []gohan.ComponentID {
}
func (s *CameraSystem) Update(ctx *gohan.Context) error {
if world.World.MessageVisible || world.World.GameOver {
if world.World.MessageVisible || !world.World.GameStarted || world.World.GameOver {
return nil
}

2
system/creep.go

@ -31,7 +31,7 @@ func (_ *CreepSystem) Uses() []gohan.ComponentID { @@ -31,7 +31,7 @@ func (_ *CreepSystem) Uses() []gohan.ComponentID {
}
func (s *CreepSystem) Update(ctx *gohan.Context) error {
if world.World.MessageVisible {
if world.World.MessageVisible || !world.World.GameStarted {
return nil
}

2
system/input_fire.go

@ -33,7 +33,7 @@ func (_ *playerFireSystem) Uses() []gohan.ComponentID { @@ -33,7 +33,7 @@ func (_ *playerFireSystem) Uses() []gohan.ComponentID {
}
func (s *playerFireSystem) Update(ctx *gohan.Context) error {
if world.World.GameOver {
if !world.World.GameStarted || world.World.GameOver {
return nil
}

11
system/input_move.go

@ -68,12 +68,19 @@ func (s *playerMoveSystem) Update(ctx *gohan.Context) error { @@ -68,12 +68,19 @@ func (s *playerMoveSystem) Update(ctx *gohan.Context) error {
return nil
}
/*if world.World.MessageVisible {
if !world.World.GameStarted {
if ebiten.IsKeyPressed(ebiten.KeyEnter) || ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
world.World.GameStarted = true
}
return nil
}
if world.World.MessageVisible {
if inpututil.IsKeyJustPressed(ebiten.KeyEnter) {
world.World.MessageVisible = false
}
return nil
}*/
}
pressLeft := ebiten.IsKeyPressed(ebiten.KeyLeft)
pressRight := ebiten.IsKeyPressed(ebiten.KeyRight)

2
system/movement.go

@ -59,7 +59,7 @@ func (_ *MovementSystem) Uses() []gohan.ComponentID { @@ -59,7 +59,7 @@ func (_ *MovementSystem) Uses() []gohan.ComponentID {
}
func (s *MovementSystem) Update(ctx *gohan.Context) error {
if world.World.MessageVisible {
if !world.World.GameStarted || world.World.MessageVisible {
return nil
}

2
system/rail.go

@ -27,7 +27,7 @@ func (_ *RailSystem) Uses() []gohan.ComponentID { @@ -27,7 +27,7 @@ func (_ *RailSystem) Uses() []gohan.ComponentID {
}
func (s *RailSystem) Update(ctx *gohan.Context) error {
if world.World.MessageVisible || world.World.GameOver || !world.World.CamMoving {
if !world.World.GameStarted || world.World.MessageVisible || world.World.GameOver || !world.World.CamMoving {
return nil
}

52
system/render.go

@ -4,6 +4,10 @@ import ( @@ -4,6 +4,10 @@ import (
_ "image/png"
"time"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"code.rocketnine.space/tslocum/brownboxbatman/asset"
"code.rocketnine.space/tslocum/brownboxbatman/component"
. "code.rocketnine.space/tslocum/brownboxbatman/ecs"
"code.rocketnine.space/tslocum/brownboxbatman/world"
@ -25,7 +29,9 @@ const ( @@ -25,7 +29,9 @@ const (
type RenderSystem struct {
ScreenW int
ScreenH int
op *ebiten.DrawImageOptions
img *ebiten.Image
op *ebiten.DrawImageOptions
camScale float64
@ -35,6 +41,7 @@ type RenderSystem struct { @@ -35,6 +41,7 @@ type RenderSystem struct {
func NewRenderSystem() *RenderSystem {
s := &RenderSystem{
renderer: ECS.NewEntity(),
img: ebiten.NewImage(320, 100),
op: &ebiten.DrawImageOptions{},
camScale: 1,
ScreenW: 640,
@ -119,6 +126,49 @@ func (s *RenderSystem) renderSprite(x float64, y float64, offsetx float64, offse @@ -119,6 +126,49 @@ func (s *RenderSystem) renderSprite(x float64, y float64, offsetx float64, offse
func (s *RenderSystem) Draw(ctx *gohan.Context, screen *ebiten.Image) error {
if !world.World.GameStarted {
if ctx.Entity == world.World.Player {
world.World.GameStartedTicks++
pct := float64(world.World.GameStartedTicks) / (144 * 1)
if pct > 1 {
pct = 1
}
s.op.GeoM.Reset()
s.op.ColorM.Reset()
s.op.ColorM.Scale(1, 1, 1, pct)
screen.DrawImage(asset.ImgTitle1, s.op)
s.op.ColorM.Reset()
if world.World.GameStartedTicks > 144*2 {
pct = float64(world.World.GameStartedTicks-(144*2)) / (144 * 1.5)
if pct > 1 {
pct = 1
}
s.op.ColorM.Reset()
s.op.ColorM.Scale(1, 1, 1, pct)
screen.DrawImage(asset.ImgTitle2, s.op)
}
if world.World.GameStartedTicks > 144*4 {
pct = float64(world.World.GameStartedTicks-(144*4)) / (144 * 0.5)
if pct > 1 {
pct = 1
}
s.op.ColorM.Reset()
s.op.ColorM.Scale(1, 1, 1, pct)
screen.DrawImage(asset.ImgTitle3, s.op)
if world.World.GameStartedTicks > 144*6 && world.World.GameStartedTicks%(144*2) < 144*1.5 {
s.img.Clear()
ebitenutil.DebugPrint(s.img, "PRESS <ENTER> OR <START> OR <LMB>")
s.op.GeoM.Scale(2, 2)
s.op.GeoM.Translate(120, 387)
screen.DrawImage(s.img, s.op)
}
}
s.op.ColorM.Reset()
}
return nil
}

10
world/world.go

@ -27,7 +27,6 @@ const ( @@ -27,7 +27,6 @@ const (
)
var World = &GameWorld{
GameStarted: true, // TODO
CamScale: 1,
CamMoving: true,
PlayerWidth: 8,
@ -47,8 +46,9 @@ type GameWorld struct { @@ -47,8 +46,9 @@ type GameWorld struct {
Debug int
NoClip bool
GameStarted bool
GameOver bool
GameStarted bool
GameStartedTicks int
GameOver bool
MessageVisible bool
@ -203,7 +203,7 @@ func LoadMap(filePath string) { @@ -203,7 +203,7 @@ func LoadMap(filePath string) {
}
} else if grp.Name == "CREEPS" {
for _, obj := range grp.Objects {
c := NewCreep(component.CreepSnowGunner, int64(obj.ID), float64(obj.X), float64(obj.Y))
c := NewCreep(component.CreepSnowblower, int64(obj.ID), float64(obj.X), float64(obj.Y))
World.CreepRects = append(World.CreepRects, ObjectToRect(obj))
World.CreepEntities = append(World.CreepEntities, c)
}
@ -313,7 +313,7 @@ func NewCreep(creepType int, creepID int64, x float64, y float64) gohan.Entity { @@ -313,7 +313,7 @@ func NewCreep(creepType int, creepID int64, x float64, y float64) gohan.Entity {
img := asset.ImgBat
if creepType == component.CreepSnowmanHead {
img = World.TileImages[8]
} else if creepType == component.CreepSnowGunner {
} else if creepType == component.CreepSnowblower {
img = World.TileImages[50]
}
ECS.AddComponent(creep, &component.SpriteComponent{

Loading…
Cancel
Save