physics

package
Version: v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StarshipAgent string = "starship"
	AsteroidAgent string = "asteroid"
	RubbleAgent   string = "rubble"
	BulletAgent   string = "bullet"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentRegister

type AgentRegister func(Physic)

AgentRegister is a function to register an agent

type AgentUnregister

type AgentUnregister func(string, string)

AgentUnregister is a function to unregister an agent

type Block

type Block struct {
	Position
	Size
}

Block is a dimension and position helper structure.

type Physic

type Physic interface {
	// Draw draws the agent on screen.
	Draw(*ebiten.Image)
	// Update proceeds the agent state.
	Update()
	// Init initializes the physic body.
	Init()
	// ID displays physic body unique ID.
	ID() string
	// String displays physic body information as a string.
	String() string
	// Intersect returns true if the physical body collide another one.
	// Collision is computed based on Axis-Aligned Bounding Boxes.
	// https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection
	Intersect(Physic) bool
	// IntersectMultiple checks if multiple physical bodies are colliding with the first
	IntersectMultiple(map[string]Physic) (string, bool)
	// Dimensions returns physical body dimensions.
	Dimension() Block
	// Type returns physical body agent type as a string.
	Type() string
	// Explode proceeds the agent explosion and termination.
	Explode()
}

type PhysicBody

type PhysicBody struct {
	Position
	AgentType string

	Log         *logrus.Logger
	Orientation float64 // theta (radian)
	Size        float64

	PhysicWidth  float64
	PhysicHeight float64
	ScreenWidth  float64
	ScreenHeight float64

	Velocity     Vector
	Acceleration Vector

	Register   AgentRegister
	Unregister AgentUnregister
	Image      *ebiten.Image

	Debug bool
	// contains filtered or unexported fields
}

func (*PhysicBody) Dimension

func (pb *PhysicBody) Dimension() Block

Dimensions returns physical body dimensions.

func (*PhysicBody) Draw

func (pb *PhysicBody) Draw(screen *ebiten.Image)

Draw draws the agent. Draw is called every frame (typically 1/60[s] for 60Hz display).

func (*PhysicBody) DrawBodyBoundaryBox

func (pb *PhysicBody) DrawBodyBoundaryBox(screen *ebiten.Image)

func (*PhysicBody) Explode

func (pb *PhysicBody) Explode()

Explode proceeds the agent explosion and termination.

func (*PhysicBody) ID

func (pb *PhysicBody) ID() string

ID displays physic body unique ID.

func (*PhysicBody) Init

func (pb *PhysicBody) Init()

Init initializes the physic body

func (*PhysicBody) Intersect

func (pb *PhysicBody) Intersect(p Physic) bool

Intersect returns true if the physical body collide another one. Collision is computed based on Axis-Aligned Bounding Boxes. https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection

func (*PhysicBody) IntersectMultiple

func (pb *PhysicBody) IntersectMultiple(physics map[string]Physic) (string, bool)

IntersectMultiple checks if multiple physical bodies are colliding with the first

func (*PhysicBody) Rotate

func (pb *PhysicBody) Rotate(rotationAngle float64)

func (*PhysicBody) String

func (pb *PhysicBody) String() string

String displays physic body information as a string.

func (*PhysicBody) Type

func (pb *PhysicBody) Type() string

Type returns physical body agent type as a string.

func (*PhysicBody) Update

func (pb *PhysicBody) Update()

Update proceeds the game state. Update is called every tick (1/60 [s] by default).

func (*PhysicBody) UpdateAcceleration

func (pb *PhysicBody) UpdateAcceleration(i float64)

type Position

type Position struct {
	X float64
	Y float64
}

Size represents coordonnates (X, Y) of a physical body.

type Size

type Size struct {
	H float64
	W float64
}

Size represents height and width of a physical body.

type Vector

type Vector struct {
	X float64
	Y float64
}

Vector represents a vector composantes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to