Documentation ¶
Overview ¶
Package core includes all basic functions to generate and simulate the game world.
Index ¶
- Constants
- func CheckBorders(p Position, r, screenWidth, screenHeight int) bool
- func Distance(a, b Position) float64
- func IsCollided(pos1 Position, rad1 int, pos2 Position, rad2 int) bool
- func Length(x, y float64) float64
- func RelativeAngle(me Position, other Position) int
- type Position
- type Projectile
- func (p *Projectile) Angle() int
- func (p *Projectile) AoERadius() int
- func (p *Projectile) Collision() bool
- func (p *Projectile) Damage() int
- func (p *Projectile) Distance() int
- func (p *Projectile) EndPos() Position
- func (p *Projectile) Explode()
- func (p *Projectile) Exploded() bool
- func (p *Projectile) Parent() *Tank
- func (p *Projectile) Pos() Position
- func (p *Projectile) Remove()
- func (p *Projectile) Speed() int
- func (p *Projectile) StartPos() Position
- func (p *Projectile) TestInitialization(world *World, parent *Tank, pos, startPos, endPos Position, ...)
- func (p *Projectile) Update()
- type Tank
- func (t *Tank) ActiveMacro() bool
- func (t *Tank) Alive() bool
- func (t *Tank) Angle() int
- func (t *Tank) Armor() int
- func (t *Tank) Backward()
- func (t *Tank) Blocked() bool
- func (t *Tank) Command() int
- func (t *Tank) Fire(fireAngle, distance int) (success bool, txt string)
- func (t *Tank) FireAt(pos Position) (success bool, txt string)
- func (t *Tank) Forward()
- func (t *Tank) Health() int
- func (t *Tank) Hit(damage int)
- func (t *Tank) ID() string
- func (t *Tank) LastRotate() uint64
- func (t *Tank) Left() (success bool, status string)
- func (t *Tank) Moving() bool
- func (t *Tank) Owner() string
- func (t *Tank) Pos() Position
- func (t *Tank) Remove()
- func (t *Tank) Right() (success bool, status string)
- func (t *Tank) SetMacro(macro func(t *Tank))
- func (t *Tank) SetPosition(pos Position, angle int)
- func (t *Tank) Speed() int
- func (t *Tank) Status() (rdy bool, status string)
- func (t *Tank) Stop()
- func (t *Tank) TestInitialization(world *World, id, owner string, weapon *Weapon, health, armor, speed int, ...)
- func (t *Tank) Update()
- func (t *Tank) Weapon() *Weapon
- type Target
- type Weapon
- func (w *Weapon) AnyFireAngle() bool
- func (w *Weapon) AoERadius() int
- func (w *Weapon) Damage() int
- func (w *Weapon) Fire(vehiclePos Position, vehicleAngle, fireAngle, distance int) (success bool, status string)
- func (w *Weapon) LastFire() uint64
- func (w *Weapon) LastMove() uint64
- func (w *Weapon) PreparationTime() uint64
- func (w *Weapon) ProjectileCollision() bool
- func (w *Weapon) ProjectileSpeed() int
- func (w *Weapon) Range() int
- func (w *Weapon) ReloadTime() uint64
- func (w *Weapon) Status() (rdy bool, status string)
- func (w *Weapon) TestInitialization(world *World, parent *Tank, typ string, rng int, prepTime, reloadTime uint64, ...)
- func (w *Weapon) Type() string
- func (w *Weapon) Update(isMoving bool)
- type World
- func (w *World) AddTank(tank *Tank)
- func (w *World) BuyTank(tank *Tank) error
- func (w *World) CashStat() (cashRed, cashBlue int)
- func (w *World) Clear(prefix string)
- func (w *World) Freeze(status bool)
- func (w *World) IsFrozen() bool
- func (w *World) Iteration() uint64
- func (w *World) Projectiles() []*Projectile
- func (w *World) ScreenHeight() int
- func (w *World) ScreenWidth() int
- func (w *World) SetCash(cashRed, cashBlue int)
- func (w *World) Tanks() []*Tank
- func (w *World) TestInitialization(xWidth, yHeight int, iteration uint64, tanks []*Tank, ...)
- func (w *World) UnitCount() (red, blue int)
- func (w *World) Update()
- func (w *World) UpdateN(n int)
- func (w *World) XWidth() int
- func (w *World) YHeight() int
Constants ¶
const ( GameSpeed = 30 // iterations per second MovePerTick = 0.02 // percent of movement per tick WorldXWidth = 28 // world dimension X (28 * 64 = 1792pxl) WorldYHeight = 15 // world dimension Y (15 * 64 = 960pxl) BlockSize = 64 // image size of tanks, barriers, buildings, ... BlockRadius = BlockSize / 2 // radius of blocks (tanks) BallSize = 20 // size of projectiles BallRadius = BallSize / 2 // radius of projectiles )
game settings
const ( MacroAttackMove = "AttackMove" MacroFireAndManeuver = "FireAndManeuver" MacroFireWall = "FireWall" MacroGuardMode = "GuardMode" MacroReset = "nil" )
macros
const ( ShowExplosionIterations = 10 // duration of the explosion animation WeaponNone = "None" // no weapon for neutral objects (rock) WeaponCannon = "Tank" // weapon of a battle tank WeaponArtillery = "Artillery" // weapon of an artillery WeaponRockets = "RocketLauncher" // weapon of a rocket launcher )
weapons
const ( TankRotationDelay = 467 * GameSpeed / 1000 // rotation delay in iterations (~467 ms) TankBudget = 100 // max. points = armor + damage + speed TankMinSpeed = 25 // min. Speed (calc budget-armor-damage) TankMinArmor = 5 // min armor TankMaxArmor = 55 // max armor TankMinDamage = 15 // min damage TankMaxDamage = 70 // max damage )
tank attr
const ( North = 0 Northeast = 45 East = 90 Southeast = 135 South = 180 Southwest = 225 West = 270 Northwest = 315 )
tank angle (movement)
const ( StatusMoving = "Moving" // tank is moving and can't fire StatusPreparing = "Preparing" // tank prepare for fire after moving (see prepTime) StatusReady = "Ready" // tank can fire StatusReloading = "Reloading" // tank reload weapon after fire StatusNoWeapon = "NoWeapon" // error: no weapon or not alive )
tank status
const ( RedTank = "red" // player 1 (red) BlueTank = "blue" // player 2 (blue) )
player tanks
const ( NeutralRock = "neutral_rock" // rock, assigned to no player RedRock = "red_rock" // rock of gamer 1 (red) BlueRock = "blue_rock" // rock of gamer 2 (blue) RedBase = "red_base" // base of gamer 1 (red) BlueBase = "blue_base" // base of gamer 2 (blue) )
buildings
Variables ¶
This section is empty.
Functions ¶
func CheckBorders ¶
CheckBorders returns true if the object collide with the borders.
func IsCollided ¶
IsCollided return true if two objects touch.
func RelativeAngle ¶
RelativeAngle returns the relative position of OTHER as an angle. Return [0 ... 359]
North = 0 Northeast = 45 East = 90 Southeast = 135 South = 180 Southwest = 225 West = 270 Northwest = 315
Types ¶
type Position ¶
Position stores x and y as an int and as a float value. Update() work with the float value and round to int.
func CalcPosFromAngle ¶
CalcPosFromAngle returns the new coordinates with given angle and length. The angle is defined with North is 0° (see North, East, South, West, ...).
func NewPosition ¶
NewPosition return a position and set x,y float + int
type Projectile ¶
type Projectile struct {
// contains filtered or unexported fields
}
Projectile is created by a weapon. It moves in the world. It can collide with other objects and can explode.
func NewProjectile ¶
func NewProjectile(world *World, parent *Tank, pos Position, angle, distance, speed, damage, aoeRadius int, collision bool) *Projectile
NewProjectile create a new projectile. When created in a world, it interacts with other objects. Forward the parents, otherwise the projectile will explode at the start.
For parameter description see Projectile.Pos(), Projectile.Angle(), Projectile.Distance(), Projectile.Speed(), Projectile.Damage(), Projectile.AoERadius() and Projectile.Collision().
func (*Projectile) Angle ¶
func (p *Projectile) Angle() int
Angle is the start angle of the projectile. see North, South, East, ...
func (*Projectile) AoERadius ¶
func (p *Projectile) AoERadius() int
AoERadius determines how many objects are hit in an explosion. see Explode()
func (*Projectile) Collision ¶
func (p *Projectile) Collision() bool
Collision defines two types of projectiles:
true: the projectile flies until it hits a target or disappears after the maximum distance (WeaponCannon). false: the projectile flies without any interaction and explode after the maximum distance (WeaponArtillery).
func (*Projectile) Damage ¶
func (p *Projectile) Damage() int
Damage that is included in the calculation on a hit. see Tank.Hit()
func (*Projectile) Distance ¶
func (p *Projectile) Distance() int
Distance between start position and current position.
func (*Projectile) EndPos ¶
func (p *Projectile) EndPos() Position
EndPos returns the planned target position, but a collisions can happen earlier.
func (*Projectile) Explode ¶
func (p *Projectile) Explode()
Explode destroys the projectile at the current position. All objects in range (see AoERadius) are hit (see Tank.Hit).
func (*Projectile) Exploded ¶
func (p *Projectile) Exploded() bool
Exploded return true if the projectile is exploded.
func (*Projectile) Parent ¶
func (p *Projectile) Parent() *Tank
Parent returns the tank from which the projectile was fired.
func (*Projectile) Pos ¶
func (p *Projectile) Pos() Position
Pos is the current position of this projectile. Is changed by Update().
func (*Projectile) Remove ¶
func (p *Projectile) Remove()
Remove this projectile from the world list World.Projectiles.
func (*Projectile) Speed ¶
func (p *Projectile) Speed() int
Speed at which the bullet moves per tick.
func (*Projectile) StartPos ¶
func (p *Projectile) StartPos() Position
StartPos is the initial position of this projectile.
func (*Projectile) TestInitialization ¶
func (p *Projectile) TestInitialization(world *World, parent *Tank, pos, startPos, endPos Position, angle, distance, speed, damage, aoeRadius int, collision bool, exploded uint)
TestInitialization allows setting non-exported variables outside the core packet.
func (*Projectile) Update ¶
func (p *Projectile) Update()
Update move the projectile, remove exploded projectile, calculate collisions and enforce the max distance.
type Tank ¶
type Tank struct {
// contains filtered or unexported fields
}
Tank is an object in World. It can be a tank, a building, a rock, ...
func NewTank ¶
NewTank return a new tank. The tank must be added to the world manually (see World.AddTank()).
The attributes armor, damage and speed are related. Every unused budget point (see TankBudget) is converted into speed.
TankMinArmor < armor < TankMaxArmor TankMinDamage < damage < TankMaxDamage TankMinSpeed < speed
func (*Tank) ActiveMacro ¶
ActiveMacro returns if this tank is controlled by a macro. see SetMacro().
func (*Tank) Armor ¶
Armor reduces damage with each hit. Armor can be so high that no damage is dealt.
func (*Tank) Blocked ¶
Blocked return true if movement has ended because the path was blocked. Set by Update() and reset by Forward() and Backward().
func (*Tank) Command ¶
Command returns the current move command of the tank. 1 is forward; 0 is stop; -1 is backward
func (*Tank) FireAt ¶
FireAt is a wrapper for Fire() and convert the position to fireAngle and distance.
func (*Tank) Hit ¶
Hit calculate the damage on a direct hit. Reduce the damage by Armor(). Call Remove() for death tanks.
func (*Tank) LastRotate ¶
LastRotate returns at which iteration the last rotation was.
func (*Tank) SetMacro ¶
SetMacro sets a macro that is called with every update. Remove it with 'nil'.
func (*Tank) SetPosition ¶
SetPosition set a new tank position without collision check.
func (*Tank) Status ¶
Status returns the weapon status: (StatusMoving, StatusPreparing, StatusReloading, StatusReady or StatusNoWeapon). see Weapon.Status
func (*Tank) Stop ¶
func (t *Tank) Stop()
Stop the movement. Weapons can only build up when the tank is stationary see Command(). see Weapon.PreparationTime()
func (*Tank) TestInitialization ¶
func (t *Tank) TestInitialization(world *World, id, owner string, weapon *Weapon, health, armor, speed int, pos Position, command, angle int, isBlocked bool, lastRotate uint64, macro func(t *Tank))
TestInitialization allows setting non-exported variables outside the core packet.
type Target ¶
Target provide the tank, the distance and the relative angle to the tank. It is used by CloseTargets() and PossibleTargets(). see RelativeAngle().
func CloseTargets ¶
CloseTargets returns all objects in the world that are theoretical in weapon range. The weapon type is irrelevant (WeaponCannon or WeaponArtillery) and the angle of the tank is ignored. The list is sorted by distance (from the closest to the farthest).
func PossibleTargets ¶
PossibleTargets extends CloseTargets. It only returns objects that can actually be attacked,depending on the weapon type. However, it may be necessary for the battle tank to change its angle. The list is sorted by the rotation required to reach the target.
type Weapon ¶
type Weapon struct {
// contains filtered or unexported fields
}
Weapon can be mounted on vehicles or buildings. It generates bullets with Fire().
func NewWeaponArtillery ¶
NewWeaponArtillery return the weapon for an artillery. It's slow and can't collide with other tanks. Explode at the destination with big aoe but less damage (-10%).
func NewWeaponCannon ¶
NewWeaponCannon return the weapon for a battle tank. It's fast and collide with other tanks. The damage is very height on single target (+50%).
func NewWeaponRocketLauncher ¶
NewWeaponRocketLauncher return the weapon for a rocket launcher. It's like the artillery but the damage is used to reduce the reload time.
func (*Weapon) AnyFireAngle ¶
AnyFireAngle enables any launch direction. Otherwise, the projectile always fires in the tank direction.
func (*Weapon) AoERadius ¶
AoERadius is the area damage radius. Objects within the radius will be damaged even without a direct hit. see: Projectile.Explode() for calculation.
func (*Weapon) Damage ¶
Damage is the base damage on hits. Is reduced by armor. see Tank.Hit() for calculation.
func (*Weapon) Fire ¶
func (w *Weapon) Fire(vehiclePos Position, vehicleAngle, fireAngle, distance int) (success bool, status string)
Fire creates a new projectile. The attributes fireAngle and distance determine the direction and distance of the shot.
If AnyFireAngle() is false, attribute fireAngle is overridden by attribute vehicleAngle. If ProjectileCollision() is true, attribute distance is overridden by Range(). Attribute distance is limited by Range().
see NewProjectile()
func (*Weapon) LastFire ¶
LastFire returns at witch iteration the last fire was. see status StatusReloading
func (*Weapon) LastMove ¶
LastMove returns at witch iteration the last move was. see status StatusPreparing
func (*Weapon) PreparationTime ¶
PreparationTime is the time (=iteration ticks) the weapon has to build up after a movement. see status StatusPreparing
func (*Weapon) ProjectileCollision ¶
ProjectileCollision if is active, the projectile will be stopped by objects in the fly path and explodes. Otherwise, it will explode after the specified range.
true - only explodes on contact false - only explodes at the end of the distance
func (*Weapon) ProjectileSpeed ¶
ProjectileSpeed is the velocity of the bullet.
func (*Weapon) Range ¶
Range is the maximum range of the weapon. WeaponCannon disappear after the range. WeaponArtillery explode after the range.
see Projectile.Collision()
func (*Weapon) ReloadTime ¶
ReloadTime is the time (=iteration ticks) the weapon has to be reloaded after firing. see status StatusReloading
func (*Weapon) Status ¶
Status returns true if the weapon is ready to fire. Otherwise, the reason is returned (StatusMoving, StatusPreparing, StatusReloading or StatusReady). see: PreparationTime() and ReloadTime().
func (*Weapon) TestInitialization ¶
func (w *Weapon) TestInitialization(world *World, parent *Tank, typ string, rng int, prepTime, reloadTime uint64, projSpeed, damage, aoeRadius int, projCollision, anyFireAngle bool, lastMove, lastFire uint64)
TestInitialization allows setting non-exported variables outside the core packet.
type World ¶
type World struct {
// contains filtered or unexported fields
}
World is the game and holds all active objects on the map.
func NewWorld ¶
NewWorld create a new world. The attributes XWidth and YHeight are blocks (64x64). see WorldXWidth and WorldYHeight.
func (*World) AddTank ¶
AddTank adds a new tank to the world. Use Tank.SetPosition() to set the correct position.
func (*World) CashStat ¶
CashStat returns the current cash amount of the players. The amount is slowly generated by the home base.
see Update().
func (*World) Clear ¶
Clear all tanks (objects) with prefix from world. Kill a player like 'red' or 'blue'.
func (*World) Projectiles ¶
func (w *World) Projectiles() []*Projectile
Projectiles returns all flying bullets.
func (*World) ScreenHeight ¶
ScreenHeight is the GUI width (= YHeight * 64)
func (*World) ScreenWidth ¶
ScreenWidth is the GUI width (= XWidth * 64)
func (*World) TestInitialization ¶
func (w *World) TestInitialization(xWidth, yHeight int, iteration uint64, tanks []*Tank, projectiles []*Projectile, freeze bool, cashRed, cashBlue float64)
TestInitialization allows setting non-exported variables outside the core packet.
func (*World) UnitCount ¶
UnitCount returns the sum of all units. This number is used for the victory condition.