Skip to content

Commit

Permalink
* Quick mode
Browse files Browse the repository at this point in the history
* Limit by distance
* Safer removal
* Shoot by default on mobile
* deprecation
* Mobile
  • Loading branch information
m110 committed Nov 2, 2024
1 parent 84cadf2 commit 5eb7ec5
Show file tree
Hide file tree
Showing 77 changed files with 1,511 additions and 309 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.test
*.out
vendor/
go.work
15 changes: 15 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'

tasks:
mobile:
dir: ./mobile
cmds:
- ebitenmobile bind -target ios -o Airplanes.xcframework .

mobile-deploy:
deps:
- mobile
dir: ./mobile
cmds:
- xcodebuild -scheme Airplanes -configuration Debug -sdk iphoneos -derivedDataPath build
- ios-deploy --bundle build/Build/Products/Debug-iphoneos/Airplanes.app --nostart --no-wifi
8 changes: 6 additions & 2 deletions archetype/bullet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/yohamta/donburi/features/math"
"github.com/yohamta/donburi/features/transform"
"github.com/yohamta/donburi/filter"
"github.com/yohamta/donburi/query"

"github.com/m110/airplanes/assets"
"github.com/m110/airplanes/component"
Expand Down Expand Up @@ -77,6 +76,7 @@ func newPlayerBullet(w donburi.World, position math.Vec2, localRotation float64)
component.Sprite,
component.Despawnable,
component.Collider,
component.DistanceLimit,
),
)

Expand Down Expand Up @@ -106,6 +106,10 @@ func newPlayerBullet(w donburi.World, position math.Vec2, localRotation float64)
Height: float64(height),
Layer: component.CollisionLayerPlayerBullets,
})

component.DistanceLimit.SetValue(bullet, component.DistanceLimitData{
MaxDistance: 200,
})
}

func NewEnemyBullet(w donburi.World, position math.Vec2, rotation float64) {
Expand Down Expand Up @@ -183,7 +187,7 @@ func NewEnemyMissile(w donburi.World, position math.Vec2, rotation float64) {
})

component.Follower.SetValue(missile, component.FollowerData{
Target: component.ClosestTarget(w, missile, query.NewQuery(filter.Contains(component.PlayerAirplane))),
Target: component.ClosestTarget(w, missile, donburi.NewQuery(filter.Contains(component.PlayerAirplane))),
FollowingSpeed: enemyMissileSpeed,
FollowingTimer: engine.NewTimer(3 * time.Second),
})
Expand Down
3 changes: 1 addition & 2 deletions archetype/camera.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/yohamta/donburi/features/math"
"github.com/yohamta/donburi/features/transform"
"github.com/yohamta/donburi/filter"
"github.com/yohamta/donburi/query"

"github.com/m110/airplanes/component"
"github.com/m110/airplanes/engine"
Expand All @@ -30,7 +29,7 @@ func NewCamera(w donburi.World, startPosition math.Vec2) *donburi.Entry {
}

func MustFindCamera(w donburi.World) *donburi.Entry {
camera, ok := query.NewQuery(filter.Contains(component.Camera)).First(w)
camera, ok := donburi.NewQuery(filter.Contains(component.Camera)).First(w)
if !ok {
panic("no camera found")
}
Expand Down
7 changes: 3 additions & 4 deletions archetype/enemy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/yohamta/donburi/features/math"
"github.com/yohamta/donburi/features/transform"
"github.com/yohamta/donburi/filter"
"github.com/yohamta/donburi/query"

"github.com/m110/airplanes/assets"
"github.com/m110/airplanes/component"
Expand Down Expand Up @@ -170,7 +169,7 @@ func NewEnemyTank(
})

component.Observer.SetValue(gun, component.ObserverData{
LookFor: query.NewQuery(filter.Contains(component.PlayerAirplane)),
LookFor: donburi.NewQuery(filter.Contains(component.PlayerAirplane)),
})

component.Shooter.SetValue(gun, component.ShooterData{
Expand Down Expand Up @@ -211,7 +210,7 @@ func NewEnemyTurretBeam(
})

component.Observer.SetValue(gun, component.ObserverData{
LookFor: query.NewQuery(filter.Contains(component.PlayerAirplane)),
LookFor: donburi.NewQuery(filter.Contains(component.PlayerAirplane)),
})

component.Shooter.SetValue(gun, component.ShooterData{
Expand Down Expand Up @@ -252,7 +251,7 @@ func NewEnemyTurretMissiles(
})

component.Observer.SetValue(gun, component.ObserverData{
LookFor: query.NewQuery(filter.Contains(component.PlayerAirplane)),
LookFor: donburi.NewQuery(filter.Contains(component.PlayerAirplane)),
})

component.Shooter.SetValue(gun, component.ShooterData{
Expand Down
39 changes: 39 additions & 0 deletions archetype/joystick.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package archetype

import (
"github.com/yohamta/donburi"
"github.com/yohamta/donburi/features/math"
"github.com/yohamta/donburi/features/transform"

"github.com/m110/airplanes/assets"
"github.com/m110/airplanes/component"
)

func NewJoystick(w donburi.World, pos math.Vec2) {
joystick := w.Entry(w.Create(
transform.Transform,
component.Joystick,
component.Sprite,
))
component.Sprite.SetValue(joystick, component.SpriteData{
Image: assets.JoystickBase,
Layer: component.SpriteLayerUI,
Pivot: component.SpritePivotCenter,
})
t := transform.Transform.Get(joystick)
t.LocalPosition = pos
t.LocalScale = math.Vec2{X: 0.5, Y: 0.5}

knob := w.Entry(w.Create(
transform.Transform,
component.Joystick,
component.Sprite,
))

component.Sprite.SetValue(knob, component.SpriteData{
Image: assets.JoystickKnob,
Layer: component.SpriteLayerUI,
Pivot: component.SpritePivotCenter,
})
transform.AppendChild(joystick, knob, false)
}
3 changes: 1 addition & 2 deletions archetype/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/yohamta/donburi/features/math"
"github.com/yohamta/donburi/features/transform"
"github.com/yohamta/donburi/filter"
"github.com/yohamta/donburi/query"

"github.com/m110/airplanes/assets"
"github.com/m110/airplanes/component"
Expand Down Expand Up @@ -230,7 +229,7 @@ func NewPlayerAirplane(w donburi.World, player component.PlayerData, faction com

func MustFindPlayerByNumber(w donburi.World, playerNumber int) *component.PlayerData {
var foundPlayer *component.PlayerData
query.NewQuery(filter.Contains(component.Player)).Each(w, func(e *donburi.Entry) {
donburi.NewQuery(filter.Contains(component.Player)).Each(w, func(e *donburi.Entry) {
player := component.Player.Get(e)
if player.PlayerNumber == playerNumber {
foundPlayer = player
Expand Down
11 changes: 11 additions & 0 deletions assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ var (
//go:embed tiles/airplane_shield.png
airplaneShieldData []byte

//go:embed tiles/joystick-base.png
joystickBaseData []byte
//go:embed tiles/joystick-knob.png
joystickKnobData []byte

//go:embed fonts/kenney-future.ttf
normalFontData []byte
//go:embed fonts/kenney-future-narrow.ttf
Expand Down Expand Up @@ -55,6 +60,9 @@ var (
AirplaneShield *ebiten.Image
Crosshair *ebiten.Image

JoystickBase *ebiten.Image
JoystickKnob *ebiten.Image

AirBase AirBaseLevel
Levels []Level

Expand Down Expand Up @@ -158,6 +166,9 @@ func MustLoadAssets() {

AirplaneShield = mustNewEbitenImage(airplaneShieldData)
Crosshair = loader.MustFindTile(TilesetClassTiles, "crosshair")

JoystickBase = mustNewEbitenImage(joystickBaseData)
JoystickKnob = mustNewEbitenImage(joystickKnobData)
}

func mustLoadFont(data []byte, size int) font.Face {
Expand Down
Binary file added assets/tiles/joystick-base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/tiles/joystick-knob.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions component/destroyed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package component

import "github.com/yohamta/donburi"

type DestroyedData struct{}

var Destroyed = donburi.NewComponentType[DestroyedData]()

func Destroy(e *donburi.Entry) {
if !e.Valid() {
return
}
if !e.HasComponent(Destroyed) {
e.AddComponent(Destroyed)
}
}
16 changes: 16 additions & 0 deletions component/distancelimit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package component

import (
"github.com/yohamta/donburi"
"github.com/yohamta/donburi/features/math"
)

type DistanceLimitData struct {
MaxDistance float64

DistanceTraveled float64
PreviousPosition math.Vec2
Initialized bool
}

var DistanceLimit = donburi.NewComponentType[DistanceLimitData]()
3 changes: 1 addition & 2 deletions component/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package component
import (
"github.com/yohamta/donburi"
"github.com/yohamta/donburi/filter"
"github.com/yohamta/donburi/query"
)

type GameData struct {
Expand All @@ -25,7 +24,7 @@ type Settings struct {
var Game = donburi.NewComponentType[GameData]()

func MustFindGame(w donburi.World) *GameData {
game, ok := query.NewQuery(filter.Contains(Game)).First(w)
game, ok := donburi.NewQuery(filter.Contains(Game)).First(w)
if !ok {
panic("game not found")
}
Expand Down
8 changes: 8 additions & 0 deletions component/joystick.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package component

import "github.com/yohamta/donburi"

type JoystickData struct {
}

var Joystick = donburi.NewComponentType[JoystickData]()
3 changes: 1 addition & 2 deletions component/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package component
import (
"github.com/yohamta/donburi"
"github.com/yohamta/donburi/filter"
"github.com/yohamta/donburi/query"

"github.com/m110/airplanes/engine"
)
Expand All @@ -17,7 +16,7 @@ type LevelData struct {
var Level = donburi.NewComponentType[LevelData]()

func MustFindLevel(w donburi.World) *donburi.Entry {
level, ok := query.NewQuery(filter.Contains(Level)).First(w)
level, ok := donburi.NewQuery(filter.Contains(Level)).First(w)
if !ok {
panic("no level found")
}
Expand Down
5 changes: 2 additions & 3 deletions component/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ package component
import (
"github.com/yohamta/donburi"
"github.com/yohamta/donburi/features/transform"
"github.com/yohamta/donburi/query"
)

type ObserverData struct {
LookFor *query.Query
LookFor *donburi.Query
Target *donburi.Entry
}

var Observer = donburi.NewComponentType[ObserverData]()

func ClosestTarget(w donburi.World, entry *donburi.Entry, lookFor *query.Query) *donburi.Entry {
func ClosestTarget(w donburi.World, entry *donburi.Entry, lookFor *donburi.Query) *donburi.Entry {
pos := transform.WorldPosition(entry)

var closestDistance float64
Expand Down
1 change: 1 addition & 0 deletions component/sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
SpriteLayerFallingWrecks
SpriteLayerAirUnits
SpriteLayerIndicators
SpriteLayerUI
)

type SpritePivot int
Expand Down
13 changes: 13 additions & 0 deletions component/timetolive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package component

import (
"github.com/yohamta/donburi"

"github.com/m110/airplanes/engine"
)

type TimeToLiveData struct {
Timer *engine.Timer
}

var TimeToLive = donburi.NewComponentType[TimeToLiveData]()
1 change: 1 addition & 0 deletions engine/input/input.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package input
7 changes: 7 additions & 0 deletions engine/input/touch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !android && !ios

package input

func IsTouchPrimaryInput() bool {
return false
}
7 changes: 7 additions & 0 deletions engine/input/touch_mobile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build android || ios

package input

func IsTouchPrimaryInput() bool {
return true
}
Loading

0 comments on commit 5eb7ec5

Please sign in to comment.