object

package
v0.0.0-...-c5f8cbb Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: MIT Imports: 20 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

This section is empty.

Functions

This section is empty.

Types

type BattleShip

type BattleShip struct {
	// 名称
	Name string `json:"name"`
	// 展示用名称
	DisplayName string `json:"displayName"`
	// 类别
	Type string `json:"type"`

	// 初始生命值
	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"`
	// 武器
	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(name string, pos MapPos, rotation float64, player faction.Player) *BattleShip

NewShip 新建战舰

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

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

Hurt 收到伤害

func (*BattleShip) MoveTo

func (s *BattleShip) MoveTo(mapCfg *mapcfg.MapCfg, targetPos MapPos) (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 弹药前进

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 发射

type HitObjectType

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

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) 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 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 发射

type Trail

type Trail struct {
	Pos   MapPos
	Shape texture.TrailShape
	// 当前尺寸 & 尺寸扩散速度
	CurSize       float64
	DiffusionRate float64
	// 当前生命值 & 生命值衰减速度
	CurLife           float64
	LifeReductionRate float64
	// 延迟时间
	Delay float64
	// 旋转角度
	Rotation float64
}

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

func NewTrail

func NewTrail(
	pos MapPos,
	Shape texture.TrailShape,
	size, diffusionRate float64,
	life, lifeReductionRate float64,
	delay, rotation float64,
) *Trail

NewTrail ...

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 武器系统

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