state

package
v0.0.0-...-5062497 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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 NewAsteroid(id uint32, initialPosition *types.Point, initialVelocity *types.Vector) *Asteroid

func (*Asteroid) AddToProtoSpace

func (asteroid *Asteroid) AddToProtoSpace(space *pb.Space)

func (*Asteroid) CollideWith

func (asteroid *Asteroid) CollideWith(other Object)

func (*Asteroid) CollideWithProjectile

func (asteroid *Asteroid) CollideWithProjectile(projectile *Projectile)

func (*Asteroid) DamageValue

func (asteroid *Asteroid) DamageValue() uint32

func (*Asteroid) ObjectDestroyed

func (asteroid *Asteroid) ObjectDestroyed(destroyedObject Object)

func (*Asteroid) ToProto

func (asteroid *Asteroid) ToProto() *pb.Asteroid

ToProto returns protobuf representation

type Direction

type Direction int

Direction is a type describing user input on spaceship rotation.

const (
	NONE Direction = iota
	RIGHT
	LEFT
)

Constants 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 NewObjectState(ID uint32, position *types.Point, velocity *types.Vector, initialHp uint32) *ObjectState

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 NewSpace

func NewSpace() *Space

NewSpace initializes new Space.

func (*Space) AddAsteroid

func (space *Space) AddAsteroid(asteroid *Asteroid)

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

func (space *Space) AddSpaceship(clientID uint32, spaceship *Spaceship)

AddSpaceship adds new spaceship to the space.

func (*Space) NewSpaceship

func (space *Space) NewSpaceship(clientID uint32) *Spaceship

NewSpaceship creates a new spaceship and adds it to the space.

func (*Space) NextProjectileID

func (space *Space) NextProjectileID() uint32

NextProjectileID returns next unused projectile ID.

func (*Space) RemoveAsteroid

func (space *Space) RemoveAsteroid(id uint32)

RemoveAsteroid removes spaceship from the space.

func (*Space) RemoveObject

func (space *Space) RemoveObject(id uint32)

RemoveAsteroid removes spaceship from the space.

func (*Space) RemoveProjectile

func (space *Space) RemoveProjectile(projectile *Projectile)

RemoveProjectile removes projectile from the space.

func (*Space) RemoveSpaceship

func (space *Space) RemoveSpaceship(id uint32)

RemoveSpaceship removes spaceship from the space.

func (*Space) ToMessage

func (space *Space) ToMessage(fullUpdate bool) *pb.Message

ToMessage returns protobuffer Message object with Space set.

func (*Space) ToProto

func (space *Space) ToProto(fullUpdate bool) *pb.Space

ToProto returns protobuf representation

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 NewSpaceship

func NewSpaceship(clientId uint32, initialPosition *types.Point) *Spaceship

func (*Spaceship) AddToProtoSpace

func (s *Spaceship) AddToProtoSpace(space *pb.Space)

func (*Spaceship) ApplyAngularFriction

func (s *Spaceship) ApplyAngularFriction()

func (*Spaceship) BoostIfPossible

func (s *Spaceship) BoostIfPossible() (canBoost bool)

func (*Spaceship) CollideWith

func (s *Spaceship) CollideWith(other Object)

func (*Spaceship) CollideWithProjectile

func (s *Spaceship) CollideWithProjectile(projectile *Projectile)

func (*Spaceship) DamageValue

func (s *Spaceship) DamageValue() uint32

func (*Spaceship) IsFiring

func (s *Spaceship) IsFiring() bool

func (*Spaceship) LeftTurn

func (s *Spaceship) LeftTurn()

func (*Spaceship) LimitAngularVelocityDelta

func (s *Spaceship) LimitAngularVelocityDelta()

func (*Spaceship) NotifyAboutNewFrame

func (s *Spaceship) NotifyAboutNewFrame()

func (*Spaceship) ObjectDestroyed

func (s *Spaceship) ObjectDestroyed(destroyedObject Object)

func (*Spaceship) ProjectileHitOtherObject

func (s *Spaceship) ProjectileHitOtherObject(other Object)

func (*Spaceship) RightTurn

func (s *Spaceship) RightTurn()

func (*Spaceship) ShootIfPossible

func (s *Spaceship) ShootIfPossible() (canShoot bool)

func (*Spaceship) String

func (s *Spaceship) String() string

String function returns string representation.

func (*Spaceship) ToProto

func (s *Spaceship) ToProto() *pb.Spaceship

ToProto returns protobuf representation

func (*Spaceship) TurnToTarget

func (s *Spaceship) TurnToTarget()

func (*Spaceship) UpdateTargetAngle

func (s *Spaceship) UpdateTargetAngle(angle float64)

func (*Spaceship) UpdateUserInput

func (s *Spaceship) UpdateUserInput(userInput pb.UserInput)

Jump to

Keyboard shortcuts

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