object

package
v0.0.0-...-c0736c2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GroupID0 = iota
	GroupID1
	GroupID2
	GroupID3
	GroupID4
	GroupID5
	GroupID6
	GroupID7
	GroupID8
	GroupID9
	GroupIDNone
)
View Source
const (
	// 顺时针
	RotateFlagClockwise = 1
	// 逆时针
	RotateFlagAnticlockwise = -1
)

Variables

View Source
var BulletImgWidthMap = map[string]int{}

Functions

func GetBulletImg

func GetBulletImg(btType BulletType, diameter int) *ebiten.Image

GetBulletImg 获取弹药图片

func GetImgWidth

func GetImgWidth(btName string, btType BulletType, diameter int) int

GetImgWidth 获取弹药图片宽度(虽然可能价值不大,总之先加一点缓存 :)

func GetShipCost

func GetShipCost(name string) (fundsCost int64, timeCost int64)

GetShipCost 获取战舰成本

func GetShipDesc

func GetShipDesc(name string) []string

GetShipDesc 获取战舰描述

func GetShipDisplayName

func GetShipDisplayName(name string) string

GetShipDisplayName 获取战舰展示用名称

Types

type BattleShip

type BattleShip struct {
	// 名称
	Name string `json:"name"`
	// 展示用名称
	DisplayName string `json:"displayName"`
	// 类别
	Type ShipType `json:"type"`
	// 类别缩写
	TypeAbbr string `json:"typeAbbr"`
	// 描述
	Description []string `json:"description"`

	// 初始生命值
	TotalHP float64 `json:"totalHP"`
	// 水平伤害减免(0.7 -> 仅受到击中的 70% 伤害)
	HorizontalDamageReduction float64 `json:"horizontalDamageReduction"`
	// 垂直伤害减免
	VerticalDamageReduction float64 `json:"verticalDamageReduction"`
	// 最大速度
	MaxSpeed float64 `json:"maxSpeed"`
	// 加速度
	Acceleration float64 `json:"acceleration"`
	// 转向速度(度)
	RotateSpeed float64 `json:"rotateSpeed"`
	// 战舰长度
	Length float64 `json:"length"`
	// 战舰宽度
	Width float64 `json:"width"`
	// 造价
	FundsCost int64 `json:"fundsCost"`
	// 耗时
	TimeCost int64 `json:"timeCost"`
	// 吨位
	Tonnage float64 `json:"tonnage"`
	// 武器
	Weapon Weapon `json:"weapon"`

	// 唯一标识
	Uid string
	// 当前生命值
	CurHP float64
	// 当前位置
	CurPos MapPos
	// 旋转角度
	CurRotation float64
	// 当前速度
	CurSpeed float64
	// 分组ID
	GroupID GroupID

	// 所属阵营(玩家)
	BelongPlayer faction.Player
}

BattleShip 战舰

func NewShip

func NewShip(
	uidGenerator *ShipUidGenerator, name string, pos MapPos, rotation float64, player faction.Player,
) *BattleShip

NewShip 新建战舰

func (*BattleShip) CanOnLand

func (s *BattleShip) CanOnLand() bool

CanOnLand 能在陆地上

func (*BattleShip) DisableWeapon

func (s *BattleShip) DisableWeapon(t WeaponType)

DisableWeapon 禁用武器

func (*BattleShip) EnableWeapon

func (s *BattleShip) EnableWeapon(t WeaponType)

EnableWeapon 启用武器

func (*BattleShip) Fire

func (s *BattleShip) Fire(enemy *BattleShip) []*Bullet

Fire 向指定目标发射武器

func (*BattleShip) GenTrails

func (s *BattleShip) GenTrails() []*Trail

GenTrails 生成尾流

func (*BattleShip) HurtBy

func (s *BattleShip) HurtBy(bullet *Bullet)

HurtBy 受到伤害

func (*BattleShip) MoveTo

func (s *BattleShip) MoveTo(mapCfg *mapcfg.MapCfg, targetPos MapPos, nearGoal bool) (arrive bool)

MoveTo 移动到指定位置 TODO 路线规划 -> 绕过陆地

type Bullet

type Bullet struct {
	// 弹药名称
	Name string `json:"name"`
	// 弹药类型
	Type BulletType `json:"type"`
	// 口径
	Diameter int `json:"diameter"`
	// 伤害数值
	Damage float64 `json:"damage"`
	// 暴击概率(理论上口径越大越容易被暴击,但是暴击率不应该太高)
	CriticalRate float64 `json:"criticalRate"`
	// 生命(前进太多要消亡)
	Life int

	// 唯一标识
	Uid string
	// 当前位置
	CurPos MapPos
	// 目标位置
	TargetPos MapPos
	// 旋转角度
	Rotation float64
	// 速度
	Speed float64
	// 射击方式
	ShotType BulletShotType
	// 前进周期数
	ForwardAge int

	// 所属战舰
	BelongShip string
	// 所属阵营(玩家)
	BelongPlayer faction.Player

	// 实际造成的伤害
	RealDamage float64
	// 造成暴击类型
	CriticalType CriticalType
	// 击中的对象类型
	HitObjectType HitObjectType
}

火炮 / 鱼雷弹药

func NewBullets

func NewBullets(
	name string,
	curPos, targetPos MapPos,
	shotType BulletShotType,
	speed float64,
	life int,
	shipUid string,
	player faction.Player,
) *Bullet

NewBullets 新建弹药

func (*Bullet) Forward

func (b *Bullet) Forward()

Forward 弹药前进

func (*Bullet) GenTrails

func (b *Bullet) GenTrails() []*Trail

GenTrail 生成尾流

type BulletShotType

type BulletShotType int
const (
	// BulletShotTypeDirect 直射
	BulletShotTypeDirect BulletShotType = iota
	// BulletShotTypeArcing 曲射(抛物线射击)
	BulletShotTypeArcing
)

type BulletType

type BulletType string
const (
	// BulletTypeShell 火炮炮弹
	BulletTypeShell BulletType = "shell"
	// BulletTypeTorpedo 鱼雷
	BulletTypeTorpedo BulletType = "torpedo"
)

type CriticalType

type CriticalType int
const (
	// CriticalTypeNone 没有暴击
	CriticalTypeNone CriticalType = iota
	// CriticalTypeThreeTimes 三倍暴击
	CriticalTypeThreeTimes
	// CriticalTypeTenTimes 十倍暴击
	CriticalTypeTenTimes
)

type FiringArc

type FiringArc struct {
	Start float64 `json:"start"`
	End   float64 `json:"end"`
}

FiringArc 火炮射界

func (*FiringArc) Contains

func (f *FiringArc) Contains(angle float64) bool

Contains 是否在射界内

type GroupID

type GroupID int

战舰编组 ID

type Gun

type Gun struct {
	// 火炮名称
	Name string `json:"name"`
	// 炮弹类型
	BulletName string `json:"bulletName"`
	// 单次抛射炮弹数量
	BulletCount int `json:"bulletCount"`
	// 装填时间(单位: s)
	ReloadTime float64 `json:"reloadTime"`
	// 射程
	Range float64 `json:"range"`
	// 炮弹散布
	BulletSpread int `json:"bulletSpread"`
	// 炮弹速度
	BulletSpeed float64 `json:"bulletSpeed"`
	// 相对位置
	// 0.35 -> 从中心往舰首 35% 舰体长度
	// -0.3 -> 从中心往舰尾 30% 舰体长度
	PosPercent float64
	// 左射界 (180, 360]
	LeftFiringArc FiringArc
	// 右射界 (0, 180]
	RightFiringArc FiringArc

	// 当前火炮是否可用(如战损 / 禁用)
	Disable bool
	// 装填开始时间(毫秒时间戳)
	ReloadStartAt int64
}

Gun 火炮

func (*Gun) CanFire

func (g *Gun) CanFire(shipCurRotation float64, curPos, targetPos MapPos) bool

CanFire 是否可发射

func (*Gun) Fire

func (g *Gun) Fire(ship, enemy *BattleShip) []*Bullet

Fire 发射

func (*Gun) Reloaded

func (g *Gun) Reloaded() bool

Reloaded 是否已装填完成

type HitObjectType

type HitObjectType int
const (
	// HitObjectTypeNone 无
	HitObjectTypeNone HitObjectType = iota
	// HitObjectTypeShip 战舰
	HitObjectTypeShip
	// HitObjectTypeWater 水面
	HitObjectTypeWater
	// HitObjectTypeLand 陆地
	HitObjectTypeLand
)

type LoadingOilShip

type LoadingOilShip struct {
	CurPos MapPos
	// 资金产量
	FundYield int
	// 装载耗时
	TimeCost int64
	// 开始的时间戳
	StartedAt int64
	// 进度
	Progress float64
}

LoadingOilShip 装载石油的货轮

func (*LoadingOilShip) Update

func (s *LoadingOilShip) Update() (finished bool)

Update ...

type MapPos

type MapPos struct {
	// 地图位置(用于通用计算,如小地图等)
	MX, MY int
	// 真实位置(用于计算屏幕位置,如不需要可不初始化)
	RX, RY float64
}

MapPos 位置

func NewMapPos

func NewMapPos(mx, my int) MapPos

NewMapPos 使用 MX,MY 新建 MapPos

func NewMapPosR

func NewMapPosR(rx, ry float64) MapPos

NewMapPosR 使用 RX,RY 新建 MapPos

func (*MapPos) AddMx

func (p *MapPos) AddMx(mx int)

AddMx 修改 Rx,同时计算 Mx

func (*MapPos) AddMy

func (p *MapPos) AddMy(my int)

AddMy 修改 Ry,同时计算 My

func (*MapPos) AddRx

func (p *MapPos) AddRx(rx float64)

AddRx 修改 Rx,同时计算 Mx

func (*MapPos) AddRy

func (p *MapPos) AddRy(ry float64)

AddRy 修改 Ry,同时计算 My

func (*MapPos) AssignMxy

func (p *MapPos) AssignMxy(mx, my int)

AssignMxy 重新赋值 MX,MY,同时计算 RX,RY

func (*MapPos) AssignRxy

func (p *MapPos) AssignRxy(rx, ry float64)

AssignRxy 重新赋值 RX,RY,并计算 MX,MY

func (*MapPos) Copy

func (p *MapPos) Copy() MapPos

Copy 复制 MapPos 对象

func (*MapPos) EnsureBorder

func (p *MapPos) EnsureBorder(borderX, borderY float64)

EnsureBorder 边界检查

func (*MapPos) MEqual

func (p *MapPos) MEqual(other MapPos) bool

MEqual 判断位置是否相等(用地图位置判断,RX,RY 太准确一直没法到)

func (*MapPos) Near

func (p *MapPos) Near(other MapPos, distance float64) bool

Near 判断位置是否在指定范围内

func (*MapPos) OnBorder

func (p *MapPos) OnBorder(borderX, borderY float64) bool

OnBorder 判断是否在边界上

func (*MapPos) String

func (p *MapPos) String() string

String ...

func (*MapPos) SubMx

func (p *MapPos) SubMx(mx int)

SubMx 修改 Rx,同时计算 Mx

func (*MapPos) SubMy

func (p *MapPos) SubMy(my int)

SubMy 修改 My,同时计算 Ry

func (*MapPos) SubRx

func (p *MapPos) SubRx(rx float64)

SubRx 修改 Rx,同时计算 Mx

func (*MapPos) SubRy

func (p *MapPos) SubRy(ry float64)

SubRy 修改 Ry,同时计算 My

type Mark

type Mark struct {
	ID   MarkID
	Pos  MapPos
	Img  *ebiten.Image
	Life int
}

Mark 标记(如目标地点等,会存在一定时间后消失)

func NewImgMark

func NewImgMark(pos MapPos, img *ebiten.Image, life int) *Mark

NewImgMark ...

func NewTextMark

func NewTextMark(pos MapPos, text string, fontSize float64, clr color.Color, life int) *Mark

NewTextMark ...

type MarkID

type MarkID string
const (
	// MarkIDTarget 目标标记
	MarkIDTarget MarkID = "target"
)

type OilPlatform

type OilPlatform struct {
	Uid             string
	Pos             MapPos
	Radius          int
	Yield           int
	LoadingOilShips map[string]*LoadingOilShip
}

OilPlatform 油井

func NewOilPlatform

func NewOilPlatform(pos MapPos, radius int, yield int) *OilPlatform

NewOilPlatform ...

func (*OilPlatform) AddShip

func (p *OilPlatform) AddShip(ship *BattleShip)

AddShip 添加货轮

func (*OilPlatform) RemoveShip

func (p *OilPlatform) RemoveShip(shipUid string)

RemoveShip 移除货轮

type OncomingShip

type OncomingShip struct {
	Name      string
	FundsCost int64
	TimeCost  int64
	// 开始的时间戳
	StartedAt int64
	// 进度
	Progress float64
}

OncomingShip 增援中的战舰

func (*OncomingShip) Update

func (s *OncomingShip) Update() (finished bool)

Update ...

type ReinforcePoint

type ReinforcePoint struct {
	Uid      string
	Pos      MapPos
	Rotation float64
	// 集结点 FIXME 支持自定义集结点
	RallyPos MapPos
	// 所属阵营(玩家)
	BelongPlayer faction.Player
	// 当前被选中的战舰索引
	CurSelectedShipIndex int
	// 提供的战舰类型
	ProvidedShipNames []string
	// 最大增援进度数量
	MaxOncomingShip int
	// 增援进度
	OncomingShips []*OncomingShip
}

ReinforcePoint 增援点

func NewReinforcePoint

func NewReinforcePoint(
	pos MapPos,
	rotation float64,
	rallyPos MapPos,
	belongPlayer faction.Player,
	maxOncomingShip int,
	providedShipNames []string,
) *ReinforcePoint

NewReinforcePoint ...

func (*ReinforcePoint) Progress

func (p *ReinforcePoint) Progress() int

Progress 获取进度

func (*ReinforcePoint) Summon

func (p *ReinforcePoint) Summon(shipName string)

Summon 召唤增援

func (*ReinforcePoint) Update

func (p *ReinforcePoint) Update(
	shipUidGenerator *ShipUidGenerator, curFunds int64,
) *BattleShip

Update ...

type ShipType

type ShipType string
const (
	// ShipTypeDefault 默认
	ShipTypeDefault ShipType = "default"
	// ShipTypeBattleShip 战列舰
	ShipTypeBattleShip ShipType = "battleship"
	// ShipTypeCruiser 巡洋舰
	ShipTypeCruiser ShipType = "cruiser"
	// ShipTypeDestroyer 驱逐舰
	ShipTypeDestroyer ShipType = "destroyer"
	// ShipTypeTorpedoBoat 鱼雷艇
	ShipTypeTorpedoBoat ShipType = "torpedo_boat"
	// ShipTypeCargo 货轮
	ShipTypeCargo ShipType = "cargo"
)

type ShipUidGenerator

type ShipUidGenerator struct {
	// contains filtered or unexported fields
}

ShipUidGenerator 战舰 Uid 生成器

func NewShipUidGenerator

func NewShipUidGenerator(player faction.Player) *ShipUidGenerator

NewShipUidGenerator ...

func (*ShipUidGenerator) Gen

func (g *ShipUidGenerator) Gen(typeAbbr string) string

Gen 生成战舰 Uid

type TorpedoLauncher

type TorpedoLauncher struct {
	// 发射器名称
	Name string `json:"name"`
	// 鱼雷类型
	BulletName string `json:"bulletName"`
	// 鱼雷数量
	BulletCount int `json:"bulletCount"`
	// 发射间隔(单位: s)
	ShotInterval float64 `json:"shotInterval"`
	// 装填时间(单位: s)
	ReloadTime float64 `json:"reloadTime"`
	// 射程
	Range float64 `json:"range"`
	// 鱼雷速度
	BulletSpeed float64 `json:"bulletSpeed"`
	// 相对位置
	// 0.35 -> 从中心往舰首 35% 舰体长度
	// -0.3 -> 从中心往舰尾 30% 舰体长度
	PosPercent float64
	// 左射界 (180, 360]
	LeftFiringArc FiringArc
	// 右射界 (0, 180]
	RightFiringArc FiringArc

	// 动态参数
	// 当前鱼雷是否可用(如战损 / 禁用)
	Disable bool
	// 开始装填时间(时间戳)
	ReloadStartAt int64
	// 最近发射时间(时间戳)
	LatestFireAt int64
	// 本次装填鱼雷已发射数量
	ShotCountBeforeReload int
}

func (*TorpedoLauncher) CanFire

func (lc *TorpedoLauncher) CanFire(shipCurRotation float64, curPos, targetPos MapPos) bool

CanFire 是否可发射

func (*TorpedoLauncher) Fire

func (lc *TorpedoLauncher) Fire(ship, enemy *BattleShip) []*Bullet

Fire 发射

func (*TorpedoLauncher) Reloaded

func (lc *TorpedoLauncher) Reloaded() bool

Reloaded 是否在重新装填 / 发射间隔

type Trail

type Trail struct {
	Pos   MapPos
	Shape textureImg.TrailShape
	// 当前尺寸 & 尺寸扩散速度
	CurSize       float64
	DiffusionRate float64
	// 当前生命值 & 生命值衰减速度
	CurLife           float64
	LifeReductionRate float64
	// 延迟时间
	Delay float64
	// 旋转角度
	Rotation float64
	// 颜色(nil 为默认白色)
	Color color.Color
}

Trail 尾流(战舰,鱼雷,炮弹)

func (*Trail) IsActive

func (t *Trail) IsActive() bool

IsActive ...

func (*Trail) IsAlive

func (t *Trail) IsAlive() bool

IsAlive ...

func (*Trail) Update

func (t *Trail) Update()

Update ...

type Weapon

type Weapon struct {
	// 主炮元数据
	MainGunsMD []WeaponMetadata `json:"mainGuns"`
	// 副炮元数据
	SecondaryGunsMD []WeaponMetadata `json:"secondaryGuns"`
	// 鱼雷元数据
	TorpedoesMD []WeaponMetadata `json:"torpedoes"`
	// 主炮
	MainGuns []*Gun
	// 副炮
	SecondaryGuns []*Gun
	// 鱼雷
	Torpedoes []*TorpedoLauncher
	// 最大射程(各类武器射程最大值)
	MaxRange float64
	// 拥有的武器情况
	HasMainGun      bool
	HasSecondaryGun bool
	HasTorpedo      bool
	// 武器禁用情况
	MainGunDisabled      bool
	SecondaryGunDisabled bool
	TorpedoDisabled      bool
}

Weapon 武器系统

func (*Weapon) MainGunReloaded

func (w *Weapon) MainGunReloaded() bool

MainGunReloaded 主炮是否已装填

func (*Weapon) SecondaryGunReloaded

func (w *Weapon) SecondaryGunReloaded() bool

SecondaryGunReloaded 副炮是否已装填

func (*Weapon) TorpedoLauncherReloaded

func (w *Weapon) TorpedoLauncherReloaded() bool

TorpedoLauncherReloaded 鱼雷是否已装填

type WeaponMetadata

type WeaponMetadata struct {
	Name string `json:"name"`
	// 相对位置
	// 0.35 -> 从中心往舰首 35% 舰体长度
	// -0.3 -> 从中心往舰尾 30% 舰体长度
	PosPercent float64 `json:"posPercent"`
	// 左射界
	LeftFiringArc [2]float64 `json:"leftFiringArc"`
	// 右射界
	RightFiringArc [2]float64 `json:"rightFiringArc"`
}

type WeaponType

type WeaponType string
const (
	// 所有
	WeaponTypeAll WeaponType = "all"
	// 主炮
	WeaponTypeMainGun WeaponType = "mainGun"
	// 副炮
	WeaponTypeSecondaryGun WeaponType = "secondaryGun"
	// 鱼雷
	WeaponTypeTorpedo WeaponType = "torpedo"
	// 导弹
	WeaponTypeMissile WeaponType = "missile"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL