Documentation
¶
Overview ¶
Package ingame provides the classes that necessary for tower defense game implementation.
Index ¶
Constants ¶
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 ¶
Types ¶
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 ¶
NewEnemy creates a new entity of Enemy.
Panics if cfg.Color is not a correct hex-string of "#xxxxxx".
func (*Enemy) DealDamage ¶
DealDamage decreases the health of the enemy on dmg points. If health is less than dmg, health will become zero.
func (*Enemy) DealDamageToPlayer ¶
DealDamageToPlayer returns the final damage to the player.
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.
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.
type GameRule ¶
type GameRule []*Wave
GameRule is a set of waves.
func NewGameRule ¶
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 (*Map) AreThereAliveEnemies ¶
AreThereAliveEnemies returns true if there are alive enemies on the map.
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.
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.
type Strength ¶
type Strength struct { T general.TypeAttack DecDmg int }
Strength stores effects that are useful to the enemy
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 (*Tower) Launch ¶
func (t *Tower) Launch() *Projectile
Launch launches a projectile from 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 ¶
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 (*Wave) CallEnemies ¶
CallEnemies returns a slice of ids of enemies that are supposed to appear on the map next frame.