ingame

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package ingame provides the classes that necessary for tower defense game implementation.

Index

Constants

View Source
const (
	// First is a type of aim that represents the first enemy.
	First = Aim(iota)

	// Weakest is a type of aim that represents the weakest enemy.
	Weakest

	// Strongest is a type of aim that represents the strongest enemy.
	Strongest
)

Variables

This section is empty.

Functions

func CheckCollisionPath

func CheckCollisionPath(pos general.Point, path Path) bool

CheckCollisionPath checks if the path collides with the tower.

Types

type Aim

type Aim int

Aim is a type that represents the enemy that tower attacks.

type Enemy

type Enemy struct {
	// Name is a name of the enemy.
	Name string

	// State is a state of the enemy.
	State EnemyState

	// Path is a path of the enemy.
	Path Path

	// MaxHealth is a maximal health of the enemy.
	MaxHealth int

	// Vrms is a root mean square speed of the enemy.
	Vrms general.Coord

	// Damage is a damage of the enemy.
	Damage int

	// MoneyAward is a money award for killing the enemy.
	MoneyAward int

	// Weaknesses is a list of weaknesses of the enemy.
	Weaknesses map[general.TypeAttack]Weakness

	// Strengths is a list of strengths of the enemy.
	Strengths map[general.TypeAttack]Strength

	// Image is an image of the enemy.
	Image *ebiten.Image
}

Enemy is an entity moving on the Path and trying to achieve its end to deal damage to the Player.

In the beginning MaxHealth == State.Health.

func NewEnemy

func NewEnemy(cfg *config.Enemy, path Path) *Enemy

NewEnemy creates a new entity of Enemy.

Panics if cfg.Color is not a correct hex-string of "#xxxxxx".

func (*Enemy) DealDamage

func (e *Enemy) DealDamage(dmg int)

DealDamage decreases the health of the enemy on dmg points. If health is less than dmg, health will become zero.

func (*Enemy) DealDamageToPlayer

func (e *Enemy) DealDamageToPlayer() int

DealDamageToPlayer returns the final damage to the player.

func (*Enemy) Die

func (e *Enemy) Die()

Die marks the enemy dead.

func (*Enemy) Draw

func (e *Enemy) Draw(screen *ebiten.Image)

Draw draws the enemy on the screen.

func (*Enemy) FinalDamage

func (e *Enemy) FinalDamage(t general.TypeAttack, dmg int) int

FinalDamage returns the final damage depending on weaknesses and strengths of the enemy.

func (*Enemy) Update

func (e *Enemy) Update()

Update is a universal method for updating enemy's state by itself.

type EnemyState

type EnemyState struct {
	// CurrPoint is a current point in Path.
	CurrPoint int

	// Pos is a current position of the enemy.
	Pos general.Point

	// Vx is a velocity on X-axis.
	Vx general.Coord

	// Vy is a velocity on Y-axis.
	Vy general.Coord

	// Health is a current health of the enemy.
	Health int

	// TimeNextPointLeft is a time left to the next point.
	TimeNextPointLeft general.Frames

	// Dead is a flag that shows if the enemy is dead.
	Dead bool

	// PassPath is a flag that shows if the enemy has passed the path.
	PassPath bool

	// FinalDamage is a final damage to the player.
	FinalDamage int
}

EnemyState is a struct

type EnemySwarm

type EnemySwarm struct {
	// EnemyName is a name of the enemy.
	EnemyName string

	// Timeout is the time when the first enemy can be called.
	Timeout general.Frames

	// Interval is time between calls.
	Interval general.Frames

	// CurrTime is current time relatively the swarm's start.
	CurrTime general.Frames

	// MaxCalls is a maximal amount of enemies that can be called.
	MaxCalls int

	// CurCalls is the current amount of enemies called.
	CurCalls int
}

EnemySwarm contains the rules for calling the next enemy. Enemies are called in the same interval limited times. EnemySwarm can call only one type of the enemy.

func NewEnemySwarm

func NewEnemySwarm(config *config.EnemySwarm) *EnemySwarm

NewEnemySwarm returns a new EnemySwarm.

func (*EnemySwarm) Ended

func (s *EnemySwarm) Ended() bool

Ended returns true if maximum calls amount exceeded.

func (*EnemySwarm) Update

func (s *EnemySwarm) Update(t general.Frames) string

Update increases time of EnemySwarm and returns a new enemy id if it's time for it.

type GameRule

type GameRule []*Wave

GameRule is a set of waves.

func NewGameRule

func NewGameRule(config []config.Wave) GameRule

NewGameRule returns a new GameRule.

type Map

type Map struct {
	// Towers on the map now.
	Towers []*Tower

	// Enemies on the map now.
	Enemies []*Enemy

	// Projectiles on the map now.
	Projectiles []*Projectile

	// Path is a path of the map.
	Path Path

	// Image is an image of the map.
	Image *ebiten.Image
}

Map is a struct that represents a map.

func NewMap

func NewMap(config *config.Map) *Map

NewMap creates a new entity of Map.

func (*Map) AreThereAliveEnemies

func (m *Map) AreThereAliveEnemies() bool

AreThereAliveEnemies returns true if there are alive enemies on the map.

func (*Map) Draw

func (m *Map) Draw(screen *ebiten.Image)

Draw draws the map.

func (*Map) Update

func (m *Map) Update()

Update updates the map.

type Path

type Path []general.Point

Path is a struct that represents a path.

func (Path) Draw

func (p Path) Draw(screen *ebiten.Image)

Draw draws the path.

type PlayerMapState

type PlayerMapState struct {
	// Health is a player's health.
	Health int

	// Money is a player's money.
	Money int
}

PlayerMapState is a state of the player during the game.

func (*PlayerMapState) Dead

func (s *PlayerMapState) Dead() bool

Dead returns true if player's health is equal to zero.

type PlayerState

type PlayerState struct {
	// LevelsComplete is a set of levels that player has completed.
	LevelsComplete map[int]struct{} `json:"levels_complete"`
}

PlayerState is a struct that represents a state of the player.

func (*PlayerState) Valid

func (ps *PlayerState) Valid(levels map[string]*config.Level) error

Valid returns an error if the player's state is not valid.

type Projectile

type Projectile struct {
	// Pos is a position of the projectile.
	Pos general.Point

	// Vrms is a root mean square speed of the projectile.
	Vrms general.Coord

	// Vx is a speed of the projectile on the X axis.
	Vx general.Coord

	// Vy is a speed of the projectile on the Y axis.
	Vy general.Coord

	// Type is a type of the projectile.
	Type general.TypeAttack

	// Damage is a damage of the projectile.
	Damage int

	// TTL is a time to live of the projectile.
	TTL general.Frames

	// TargetEnemy is an enemy that the projectile is flying to.
	TargetEnemy *Enemy

	// Image is an image of the projectile.
	Image *ebiten.Image
	// contains filtered or unexported fields
}

Projectile is an entity generated by towers that flies to the enemy and deals the damage to it. Projectiles never misses the enemy and achieves the aim when TTL is equal to zero.

func (*Projectile) Draw

func (p *Projectile) Draw(screen *ebiten.Image)

Draw draws the projectile.

func (*Projectile) EnemyHit

func (p *Projectile) EnemyHit()

EnemyHit checks if the projectile hit the enemy and returns true if it is.

func (*Projectile) Update

func (p *Projectile) Update()

Update updates the projectile.

type Strength

type Strength struct {
	T      general.TypeAttack
	DecDmg int
}

Strength stores effects that are useful to the enemy

func (Strength) DecDamage

func (w Strength) DecDamage(damage int) int

DecDamage returns decreased damage.

type Tower

type Tower struct {
	// Name is a name of the tower.
	Name string

	// Damage is a damage of the tower.
	Damage int

	// Type is a type of the tower.
	Type general.TypeAttack

	// Price is a price of the tower.
	Price int

	// Image is an image of the tower.
	Image *ebiten.Image

	// Radius is a radius of the tower.
	Radius general.Coord

	// State is a state of the tower.
	State TowerState

	// SpeedAttack is a speed of the tower's attack.
	SpeedAttack general.Frames

	// ProjectileVrms is a root mean square speed of the tower's projectile.
	ProjectileVrms general.Coord

	// ProjectileImage is an image of the tower's projectile.
	ProjectileImage *ebiten.Image

	// Upgrades is a list of upgrades of the tower.
	Upgrades []*Upgrade

	// UpgradesBought is a number of upgrades bought.
	UpgradesBought int

	// Chosen is a flag that shows if the tower is chosen.
	Chosen bool

	// Sold is a flag that shows if the tower is sold.
	Sold bool
}

Tower is a struct that represents a tower.

func NewTower

func NewTower(config *config.Tower, pos general.Point, path Path) *Tower

NewTower creates a new entity of Tower.

func (*Tower) Draw

func (t *Tower) Draw(screen *ebiten.Image)

Draw draws the tower.

func (*Tower) IsClicked

func (t *Tower) IsClicked() bool

func (*Tower) Launch

func (t *Tower) Launch() *Projectile

Launch launches a projectile from the tower.

func (*Tower) TakeAim

func (t *Tower) TakeAim(e1 []*Enemy)

TakeAim takes aim at the enemy.

func (*Tower) Update

func (t *Tower) Update()

Update updates the tower.

func (*Tower) Upgrade

func (t *Tower) Upgrade(complete map[int]struct{}) bool

Upgrade upgrades the tower.

type TowerState

type TowerState struct {
	// AimType is a type of aim.
	AimType Aim

	// IsTurnedOn is a flag that shows if the tower is turned on.
	IsTurnedOn bool

	// CoolDown is a cool down of the tower.
	CoolDown general.Frames

	// Pos is a position of the tower.
	Pos general.Point

	// Aim is an enemy that the tower is aiming at.
	Aim *Enemy
}

TowerState is a struct that represents the state of a tower.

type UI

type UI map[string]*ebiten.Image

UI is a type that represents the UI. It is a map of string to ebiten.Image.

type Upgrade

type Upgrade struct {
	// Price is a price of the upgrade.
	Price int

	// DeltaDamage is a delta of the damage.
	DeltaDamage int

	// DeltaSpeedAttack is a delta of the speed of the attack.
	DeltaSpeedAttack general.Frames

	// DeltaRadius is a delta of the radius.
	DeltaRadius general.Coord

	// OpenLevel is a level when the upgrade is opened.
	OpenLevel int
}

Upgrade is an entity stores useful effects for towers.

func NewUpgrade

func NewUpgrade(config *config.Upgrade) *Upgrade

NewUpgrade returns a new upgrade.

type Wave

type Wave struct {
	// Swarms is a set of the enemy swarms.
	Swarms []*EnemySwarm

	// Time is a current time of the wave.
	Time general.Frames
}

Wave is a set of the enemies.

func NewWave

func NewWave(config *config.Wave) *Wave

NewWave returns a new Wave.

func (*Wave) CallEnemies

func (w *Wave) CallEnemies() []string

CallEnemies returns a slice of ids of enemies that are supposed to appear on the map next frame.

func (*Wave) Ended

func (w *Wave) Ended() bool

Ended returns true if all the swarms are ended.

type Weakness

type Weakness struct {
	T      general.TypeAttack
	IncDmg int
}

Weakness stores effects that are detrimental to the enemy

func (Weakness) IncDamage

func (w Weakness) IncDamage(damage int) int

IncDamage returns increased damage.

Jump to

Keyboard shortcuts

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