Add title screen

This commit is contained in:
Trevor Slocum 2021-12-28 17:21:15 -08:00
parent 04d855a92a
commit 06b7f9ef85
16 changed files with 138 additions and 36 deletions

View File

@ -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 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
asset/image/title1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
asset/image/title2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
asset/image/title3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -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 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,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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,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 @@
<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 @@
<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 @@
<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>

View File

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

View File

@ -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)

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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)

View File

@ -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
}

View File

@ -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
}

View File

@ -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 (
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 {
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
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
}

View File

@ -27,7 +27,6 @@ const (
)
var World = &GameWorld{
GameStarted: true, // TODO
CamScale: 1,
CamMoving: true,
PlayerWidth: 8,
@ -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) {
}
} 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 {
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{