Documentation
¶
Overview ¶
Package prototype implements the Prototype design pattern. NewCharacter represents the prototyped constructor of NPC in the abstract game, that creates the character based on the general behavior of the specified character and assigns additional optional properties to the new character.
Index ¶
Constants ¶
const ( Hostile uint16 = iota Friendly )
Behavioral constants enum
const ( Cube uint16 = iota Sphere Cylinder Cone Pyramid )
3D figures enum that represent the model used for character's shape
Variables ¶
var EnemyPrototype = Character{ Speed: 5.0, Shape: &Shape{ Head: ShapePart{ Color: "#000", model: Pyramid, Size: 1, Count: 1, }, Body: ShapePart{ Color: "#111", model: Cone, Size: 1.5, Count: 1, }, Legs: ShapePart{ Color: "#000", model: Cylinder, Size: 2, Count: 2, }, }, // contains filtered or unexported fields }
EnemyPrototype is an abstract enemy NPC prototype
var FriendPrototype = Character{ Speed: 8.5, Shape: &Shape{ Head: ShapePart{ Color: "#fff", model: Sphere, Size: 1, Count: 1, }, Body: ShapePart{ Color: "#eee", model: Cylinder, Size: 1.5, Count: 1, }, Legs: ShapePart{ Color: "#ddd", model: Cylinder, Size: 2, Count: 2, }, }, // contains filtered or unexported fields }
FriendPrototype is an abstract friend NPC prototype
Functions ¶
Types ¶
type Character ¶
type Character struct { Name string Speed float32 Shape *Shape // contains filtered or unexported fields }
Character is a complicated composed structure that represents a NPC in the game
func (*Character) Behavior ¶
Behavior is the human readable getter of the behavior property of the character
func (*Character) DeepClone ¶
func (ch *Character) DeepClone() (Prototyper, error)
DeepClone implements Prototyper interface and allows to create a deep copy of character through binary serialization
type Prototyper ¶
type Prototyper interface {
DeepClone() (Prototyper, error)
}
Prototyper is the interface that is implemented by Character to create the cloned struct based on the existing one
func NewCharacter ¶
func NewCharacter(behavior uint16, name string, speed float32, shape *Shape) Prototyper
NewCharacter is the Character constructor based on the prototypes selected by behavior
type ShapePart ¶
type ShapePart struct { Size float32 Color string Count uint16 // contains filtered or unexported fields }
ShapePart is the struct that encapsulates the data required to build the parts of the character's shape