Documentation ¶
Index ¶
- type Asteroid
- func (asteroid *Asteroid) AddToProtoSpace(space *pb.Space)
- func (asteroid *Asteroid) CollideWith(other Object)
- func (asteroid *Asteroid) CollideWithProjectile(projectile *Projectile)
- func (asteroid *Asteroid) DamageValue() uint32
- func (asteroid *Asteroid) ObjectDestroyed(destroyedObject Object)
- func (asteroid *Asteroid) ToProto() *pb.Asteroid
- type Direction
- type Object
- type ObjectState
- func (objectState *ObjectState) AngularVelocity() float64
- func (objectState *ObjectState) AngularVelocityDelta() float64
- func (object *ObjectState) DetectCollision(other Object) bool
- func (objectState *ObjectState) Dirty() bool
- func (objectState *ObjectState) Facing() float64
- func (objectState *ObjectState) HandleDirtyTimeout()
- func (objectState *ObjectState) Hp() uint32
- func (objectState *ObjectState) Id() uint32
- func (objectState *ObjectState) MarkClean()
- func (objectState *ObjectState) MarkDirty()
- func (objectState *ObjectState) NotifyAboutNewFrame()
- func (objectState *ObjectState) Position() *types.Point
- func (objectState *ObjectState) SetAngularVelocity(angularVelocity float64)
- func (objectState *ObjectState) SetAngularVelocityDelta(angularVelocityDelta float64)
- func (objectState *ObjectState) SetFacing(facing float64)
- func (objectState *ObjectState) SetHp(hp uint32)
- func (objectState *ObjectState) SetPosition(position *types.Point)
- func (objectState *ObjectState) SetVelocity(velocity *types.Vector)
- func (objectState *ObjectState) SpawnTimestamp() time.Time
- func (objectState *ObjectState) Velocity() *types.Vector
- type Projectile
- type Space
- func (space *Space) AddAsteroid(asteroid *Asteroid)
- func (space *Space) AddProjectile(projectile *Projectile)
- func (space *Space) AddSpaceship(clientID uint32, spaceship *Spaceship)
- func (space *Space) NewSpaceship(clientID uint32) *Spaceship
- func (space *Space) NextProjectileID() uint32
- func (space *Space) RemoveAsteroid(id uint32)
- func (space *Space) RemoveObject(id uint32)
- func (space *Space) RemoveProjectile(projectile *Projectile)
- func (space *Space) RemoveSpaceship(id uint32)
- func (space *Space) ToMessage(fullUpdate bool) *pb.Message
- func (space *Space) ToProto(fullUpdate bool) *pb.Space
- type Spaceship
- func (s *Spaceship) AddToProtoSpace(space *pb.Space)
- func (s *Spaceship) ApplyAngularFriction()
- func (s *Spaceship) BoostIfPossible() (canBoost bool)
- func (s *Spaceship) CollideWith(other Object)
- func (s *Spaceship) CollideWithProjectile(projectile *Projectile)
- func (s *Spaceship) DamageValue() uint32
- func (s *Spaceship) IsFiring() bool
- func (s *Spaceship) LeftTurn()
- func (s *Spaceship) LimitAngularVelocityDelta()
- func (s *Spaceship) NotifyAboutNewFrame()
- func (s *Spaceship) ObjectDestroyed(destroyedObject Object)
- func (s *Spaceship) ProjectileHitOtherObject(other Object)
- func (s *Spaceship) RightTurn()
- func (s *Spaceship) ShootIfPossible() (canShoot bool)
- func (s *Spaceship) String() string
- func (s *Spaceship) ToProto() *pb.Spaceship
- func (s *Spaceship) TurnToTarget()
- func (s *Spaceship) UpdateTargetAngle(angle float64)
- func (s *Spaceship) UpdateUserInput(userInput pb.UserInput)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Asteroid ¶
type Asteroid struct {
ObjectState
}
func NewAsteroid ¶
func (*Asteroid) AddToProtoSpace ¶
func (*Asteroid) CollideWith ¶
func (*Asteroid) CollideWithProjectile ¶
func (asteroid *Asteroid) CollideWithProjectile(projectile *Projectile)
func (*Asteroid) DamageValue ¶
func (*Asteroid) ObjectDestroyed ¶
type Direction ¶
type Direction int
Direction is a type describing user input on spaceship rotation.
type Object ¶
type Object interface { Id() uint32 Position() *types.Point Velocity() *types.Vector Facing() float64 AngularVelocity() float64 AngularVelocityDelta() float64 Hp() uint32 SetPosition(*types.Point) SetVelocity(*types.Vector) SetFacing(float64) SetAngularVelocity(float64) SetAngularVelocityDelta(float64) Dirty() bool MarkDirty() MarkClean() DetectCollision(other Object) bool CollideWithProjectile(*Projectile) CollideWith(other Object) ObjectDestroyed(other Object) DamageValue() uint32 NotifyAboutNewFrame() AddToProtoSpace(*pb.Space) }
type ObjectState ¶
type ObjectState struct {
// contains filtered or unexported fields
}
func NewObjectState ¶
func (*ObjectState) AngularVelocity ¶
func (objectState *ObjectState) AngularVelocity() float64
func (*ObjectState) AngularVelocityDelta ¶
func (objectState *ObjectState) AngularVelocityDelta() float64
func (*ObjectState) DetectCollision ¶
func (object *ObjectState) DetectCollision(other Object) bool
DetectCollision returns true if receiver object collides with other object.
func (*ObjectState) Dirty ¶
func (objectState *ObjectState) Dirty() bool
func (*ObjectState) Facing ¶
func (objectState *ObjectState) Facing() float64
func (*ObjectState) HandleDirtyTimeout ¶
func (objectState *ObjectState) HandleDirtyTimeout()
func (*ObjectState) Hp ¶
func (objectState *ObjectState) Hp() uint32
func (*ObjectState) Id ¶
func (objectState *ObjectState) Id() uint32
func (*ObjectState) MarkClean ¶
func (objectState *ObjectState) MarkClean()
func (*ObjectState) MarkDirty ¶
func (objectState *ObjectState) MarkDirty()
func (*ObjectState) NotifyAboutNewFrame ¶
func (objectState *ObjectState) NotifyAboutNewFrame()
func (*ObjectState) Position ¶
func (objectState *ObjectState) Position() *types.Point
func (*ObjectState) SetAngularVelocity ¶
func (objectState *ObjectState) SetAngularVelocity(angularVelocity float64)
func (*ObjectState) SetAngularVelocityDelta ¶
func (objectState *ObjectState) SetAngularVelocityDelta(angularVelocityDelta float64)
func (*ObjectState) SetFacing ¶
func (objectState *ObjectState) SetFacing(facing float64)
func (*ObjectState) SetHp ¶
func (objectState *ObjectState) SetHp(hp uint32)
func (*ObjectState) SetPosition ¶
func (objectState *ObjectState) SetPosition(position *types.Point)
func (*ObjectState) SetVelocity ¶
func (objectState *ObjectState) SetVelocity(velocity *types.Vector)
func (*ObjectState) SpawnTimestamp ¶
func (objectState *ObjectState) SpawnTimestamp() time.Time
func (*ObjectState) Velocity ¶
func (objectState *ObjectState) Velocity() *types.Vector
type Projectile ¶
type Projectile struct { ID uint32 ClientID uint32 Spaceship *Spaceship FrameID uint32 Facing float32 Origin *types.Point Velocity *types.Vector Position *types.Point TTL uint32 }
Projectile struct holds players' shots data.
func NewProjectile ¶
func NewProjectile(ID, frameID uint32, spaceship *Spaceship) *Projectile
NewProjectile returns new instance of Projectile
func (*Projectile) DetectCollision ¶
func (projectile *Projectile) DetectCollision(object Object) (bool, *types.Point)
func (*Projectile) ToHitMessage ¶
func (projectile *Projectile) ToHitMessage() *pb.Message
func (*Projectile) ToMessage ¶
func (projectile *Projectile) ToMessage() *pb.Message
func (*Projectile) ToProto ¶
func (projectile *Projectile) ToProto() *pb.ProjectileFired
ToProto returns protobuf representation
type Space ¶
type Space struct { Objects map[uint32]Object Spaceships map[uint32]*Spaceship Asteroids map[uint32]*Asteroid Projectiles map[*Projectile]bool PhysicsFrameID uint32 NextProjectileIDValue uint32 }
Space struct holds entire game state.
func (*Space) AddAsteroid ¶
AddAsteroid adds new spaceship to the space.
func (*Space) AddProjectile ¶
func (space *Space) AddProjectile(projectile *Projectile)
AddProjectile adds projectile to the space.“
func (*Space) AddSpaceship ¶
AddSpaceship adds new spaceship to the space.
func (*Space) NewSpaceship ¶
NewSpaceship creates a new spaceship and adds it to the space.
func (*Space) NextProjectileID ¶
NextProjectileID returns next unused projectile ID.
func (*Space) RemoveAsteroid ¶
RemoveAsteroid removes spaceship from the space.
func (*Space) RemoveObject ¶
RemoveAsteroid removes spaceship from the space.
func (*Space) RemoveProjectile ¶
func (space *Space) RemoveProjectile(projectile *Projectile)
RemoveProjectile removes projectile from the space.
func (*Space) RemoveSpaceship ¶
RemoveSpaceship removes spaceship from the space.
type Spaceship ¶
type Spaceship struct { ObjectState InputThrust bool InputBoost bool InputDirection Direction TargetAngle *float64 StraightFire bool TurretFire bool LastShotTime time.Time MaxHP uint32 Energy uint32 MaxEnergy uint32 AutoRepairDelay uint32 Hits uint32 HitsReceived uint32 ProjectilesFired uint32 Kills uint32 DestroyedAsteroids uint32 }
Spaceship struct describes a spaceship.
func (*Spaceship) AddToProtoSpace ¶
func (*Spaceship) ApplyAngularFriction ¶
func (s *Spaceship) ApplyAngularFriction()
func (*Spaceship) BoostIfPossible ¶
func (*Spaceship) CollideWith ¶
func (*Spaceship) CollideWithProjectile ¶
func (s *Spaceship) CollideWithProjectile(projectile *Projectile)
func (*Spaceship) DamageValue ¶
func (*Spaceship) LimitAngularVelocityDelta ¶
func (s *Spaceship) LimitAngularVelocityDelta()
func (*Spaceship) NotifyAboutNewFrame ¶
func (s *Spaceship) NotifyAboutNewFrame()
func (*Spaceship) ObjectDestroyed ¶
func (*Spaceship) ProjectileHitOtherObject ¶
func (*Spaceship) ShootIfPossible ¶
func (*Spaceship) TurnToTarget ¶
func (s *Spaceship) TurnToTarget()