prototype

package
v0.0.0-...-a75cf63 Latest Latest
Warning

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

Go to latest
Published: May 13, 2025 License: Unlicense Imports: 3 Imported by: 0

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

View Source
const (
	Hostile uint16 = iota
	Friendly
)

Behavioral constants enum

View Source
const (
	Cube uint16 = iota
	Sphere
	Cylinder
	Cone
	Pyramid
)

3D figures enum that represent the model used for character's shape

Variables

View Source
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

View Source
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

func Run

func Run()

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

func (ch *Character) Behavior() string

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

func (*Character) String

func (ch *Character) String() string

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 Shape

type Shape struct {
	Head ShapePart
	Body ShapePart
	Legs ShapePart
}

Shape is the struct that represents the shape of the Character

func (*Shape) String

func (s *Shape) String() string

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

func (*ShapePart) Model

func (sp *ShapePart) Model() string

Model is the human readable getter of the model property of the shape part

func (*ShapePart) String

func (sp *ShapePart) String() string

Jump to

Keyboard shortcuts

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