Documentation ¶
Index ¶
- Constants
- func CreateExplosion(s Sprite, c ExplosionCfg)
- func DetectCollision(r1 cwin.Rect, f1 Frame, r2 cwin.Rect, f2 Frame) bool
- func FrameRect(f Frame) cwin.Rect
- func FrameToWin(f Frame, w cwin.Win)
- func NewSimpleFrameProvider(frames Frames, t time.Duration, loop bool) *simpleFrameProvider
- func NewWaypointProviderSimple(wps []Waypoint) *waypointProviderSimple
- func NewWaypointProviderSimpleLoop(wps []Waypoint) *waypointProviderSimple
- type Animator
- type AnimatorCfgCommon
- type AnimatorFrame
- type AnimatorFrameCfg
- type AnimatorWaypoint
- type AnimatorWaypointCfg
- type Cell
- type CharPerSec
- type CharPerSecSec
- type CollidableRegistry
- type CollisionDetectionType
- type CollisionResponse
- type CollisionResponseType
- type Exchange
- type ExplosionCfg
- type Frame
- func CopyFrame(src Frame) Frame
- func FrameFromString(s string, attr cwin.Attr) Frame
- func FrameFromStringEx(s string, attr cwin.Attr, spaceEqualsTransparency bool) Frame
- func FrameFromWin(w cwin.Win) Frame
- func MultiColorFrameFromFile(filepath string, n int) (Frame, error)
- func MultiColorFrameFromString(s string, fg string, bg ...string) Frame
- func SetAttrInFrame(f Frame, attr cwin.Attr) Frame
- type FrameProvider
- type Frames
- type Game
- type InBoundsCheckResponse
- type InBoundsCheckResponseType
- type InBoundsCheckResult
- type InBoundsCheckType
- type SoundID
- type SoundManager
- func (sm *SoundManager) AvoidSameClipConcurrentPlaying()
- func (sm *SoundManager) Close()
- func (sm *SoundManager) Init() error
- func (sm *SoundManager) PauseAll()
- func (sm *SoundManager) PlayMP3(mp3FilePath string, vol float64, loop int) (SoundID, error)
- func (sm *SoundManager) ResumeAll()
- func (sm *SoundManager) Stop(id SoundID)
- type Sprite
- type SpriteBase
- func (sb *SpriteBase) AddAnimator(as ...Animator)
- func (sb *SpriteBase) Animators() []Animator
- func (sb *SpriteBase) Base() *SpriteBase
- func (sb *SpriteBase) DeleteAnimator(as ...Animator)
- func (sb *SpriteBase) Destroy()
- func (sb *SpriteBase) Frame() Frame
- func (sb *SpriteBase) Game() *Game
- func (sb *SpriteBase) IsDestroyed() bool
- func (sb *SpriteBase) Mgr() *SpriteManager
- func (sb *SpriteBase) Name() string
- func (sb *SpriteBase) ParentRect() cwin.Rect
- func (sb *SpriteBase) Rect() cwin.Rect
- func (sb *SpriteBase) SendToBottom()
- func (sb *SpriteBase) SendToTop()
- func (sb *SpriteBase) String() string
- func (sb *SpriteBase) This() Sprite
- func (sb *SpriteBase) Update(arg UpdateArg) bool
- type SpriteManager
- func (sm *SpriteManager) AddSprite(s Sprite)
- func (sm *SpriteManager) CheckCollision(collider Sprite, colliderR cwin.Rect, colliderF Frame) []Sprite
- func (sm *SpriteManager) CollidableRegistry() *CollidableRegistry
- func (sm *SpriteManager) DbgStats() string
- func (sm *SpriteManager) DeleteAll()
- func (sm *SpriteManager) DeleteSprite(s Sprite)
- func (sm *SpriteManager) Find(s Sprite) Sprite
- func (sm *SpriteManager) FindByName(name string) Sprite
- func (sm *SpriteManager) Process()
- func (sm *SpriteManager) Sprites() []Sprite
- func (sm *SpriteManager) TryFind(s Sprite) (Sprite, bool)
- func (sm *SpriteManager) TryFindByName(name string) (Sprite, bool)
- type UpdateArg
- type Waypoint
- type WaypointProvider
- type WaypointProviderAcceleration
- type WaypointProviderAccelerationCfg
Constants ¶
const ( InBoundsCheckPartiallyVisible = InBoundsCheckType(iota) InBoundsCheckFullyVisible InBoundsCheckNone )
const ( InBoundsCheckResultOK = InBoundsCheckResult(iota) InBoundsCheckResultN // breach to the north InBoundsCheckResultE // breach to the east InBoundsCheckResultS // breach to the south InBoundsCheckResultW // breach to the west )
const ( InBoundsCheckResponseAbandon = InBoundsCheckResponseType(iota) InBoundsCheckResponseJustDoIt )
const ( CollisionDetectionOn = CollisionDetectionType(iota) CollisionDetectionOff )
const ( CollisionResponseAbandon = CollisionResponseType(iota) CollisionResponseJustDoIt )
const (
CollidableRegistryMatchAll = "*"
)
const (
InvalidSoundID = SoundID(-1)
)
Variables ¶
This section is empty.
Functions ¶
func CreateExplosion ¶
func CreateExplosion(s Sprite, c ExplosionCfg)
func DetectCollision ¶
Be aware certain quirky situation: given this is a terminal/character based system it's possible to have two sprites actually cross/on top of each other without actually having any overlapping characters. Think the following simple example:
- sprite 1 looks like this: \ \
- sprite 2 looks like this: / /
They can be perfectly on top of each other/across, without causing an overlapping character situation:
\/ /\
Thus DetectCollision fails here. No good general solutions in mind yet, just need to be careful. For "enclosed" sprite, such as circle, one can fill the interior with characters not just TransparencyChx, that will alleviate the problem.
func FrameToWin ¶
func NewSimpleFrameProvider ¶
func NewWaypointProviderSimple ¶
func NewWaypointProviderSimple(wps []Waypoint) *waypointProviderSimple
func NewWaypointProviderSimpleLoop ¶
func NewWaypointProviderSimpleLoop(wps []Waypoint) *waypointProviderSimple
Types ¶
type AnimatorCfgCommon ¶
type AnimatorCfgCommon struct { InBoundsCheckType InBoundsCheckType // partially visible check by default CollisionDetectionType CollisionDetectionType // on by default KeepAliveWhenFinished bool AfterUpdate, AfterFinish func() }
type AnimatorFrame ¶
type AnimatorFrame struct {
// contains filtered or unexported fields
}
func NewAnimatorFrame ¶
func NewAnimatorFrame(s Sprite, c AnimatorFrameCfg) *AnimatorFrame
func (*AnimatorFrame) Animate ¶
func (af *AnimatorFrame) Animate()
func (*AnimatorFrame) Cfg ¶
func (af *AnimatorFrame) Cfg() AnimatorFrameCfg
type AnimatorFrameCfg ¶
type AnimatorFrameCfg struct { Frames FrameProvider AnimatorCfgCommon }
type AnimatorWaypoint ¶
type AnimatorWaypoint struct {
// contains filtered or unexported fields
}
func NewAnimatorWaypoint ¶
func NewAnimatorWaypoint(s Sprite, c AnimatorWaypointCfg) *AnimatorWaypoint
func (*AnimatorWaypoint) Animate ¶
func (aw *AnimatorWaypoint) Animate()
func (*AnimatorWaypoint) Cfg ¶
func (aw *AnimatorWaypoint) Cfg() AnimatorWaypointCfg
type AnimatorWaypointCfg ¶
type AnimatorWaypointCfg struct { Waypoints WaypointProvider // instead of a "continuous" move, after the specified T of a waypoint, the move will be // completed in one go. In most cases, we like the smooth movement; but in some case, like // for example in tetris, we do want the tetris piece to drop in a discrete manner SingleMovePerWaypoint bool AnimatorCfgCommon }
type CharPerSec ¶
type CharPerSec float64
type CharPerSecSec ¶
type CharPerSecSec float64
type CollidableRegistry ¶
type CollidableRegistry struct {
// contains filtered or unexported fields
}
func (*CollidableRegistry) Register ¶
func (cd *CollidableRegistry) Register(spriteName1, spriteName2 string) *CollidableRegistry
supported:
- name1, name2
- name, name
- name, * or *, name
- *, *
func (*CollidableRegistry) RegisterBulk ¶
func (cd *CollidableRegistry) RegisterBulk( spriteName1 string, otherSpriteNames []string) *CollidableRegistry
type CollisionDetectionType ¶
type CollisionDetectionType int
type CollisionResponse ¶
type CollisionResponse interface {
CollisionNotify(initiator bool, collidedWith []Sprite) CollisionResponseType
}
type CollisionResponseType ¶
type CollisionResponseType int
type ExplosionCfg ¶
type Frame ¶
type Frame []Cell
func FrameFromStringEx ¶
func FrameFromWin ¶
type Game ¶
type Game struct { WinSys *cwin.Sys MasterClock *cutil.Clock SpriteMgr *SpriteManager SoundMgr *SoundManager Exchange *Exchange // contains filtered or unexported fields }
func (*Game) HeapUsageInBytes ¶
func (*Game) IsGameOver ¶
func (*Game) Run ¶
func (g *Game) Run( gameOverKeys, pauseKeys []cterm.Event, gameEventHandler cwin.EventHandler, f ...cwin.EventLoopSleepDurationFunc)
type InBoundsCheckResponse ¶
type InBoundsCheckResponse interface {
InBoundsCheckNotify(result InBoundsCheckResult) InBoundsCheckResponseType
}
type InBoundsCheckResponseType ¶
type InBoundsCheckResponseType int
type InBoundsCheckResult ¶
type InBoundsCheckResult int
func InBoundsCheck ¶
func InBoundsCheck(checkType InBoundsCheckType, r cwin.Rect, f Frame, parentR cwin.Rect) InBoundsCheckResult
type InBoundsCheckType ¶
type InBoundsCheckType int
type SoundManager ¶
type SoundManager struct {
// contains filtered or unexported fields
}
func (*SoundManager) AvoidSameClipConcurrentPlaying ¶
func (sm *SoundManager) AvoidSameClipConcurrentPlaying()
func (*SoundManager) Close ¶
func (sm *SoundManager) Close()
func (*SoundManager) Init ¶
func (sm *SoundManager) Init() error
func (*SoundManager) PauseAll ¶
func (sm *SoundManager) PauseAll()
func (*SoundManager) ResumeAll ¶
func (sm *SoundManager) ResumeAll()
func (*SoundManager) Stop ¶
func (sm *SoundManager) Stop(id SoundID)
type Sprite ¶
type Sprite interface { Name() string // Base returns the embedded SpriteBase pointer for accessing its functionalities as well // as serving as an identity (by using its pointer address) Base() *SpriteBase // This returns the actual object that implements Sprite interface that is registered // with SpriteManager. Because SpriteBase implements Sprite interface, sometimes we go // into situation where a SpriteBase pointer is getting passed around but eventually // when deverloper wants to cast back to their own object (which embeds SpriteBase) they // get type assertion failure. As long as the object (that implements Sprite) passed into // SpriteManager.AddSprite is the "top-level" object, This() will always return that // registered object. Note if calling This() on a non SpriteManager managed (i.e. not // added with SpriteManager.AddSprite) object, it will panic. This() Sprite Mgr() *SpriteManager Game() *Game Rect() cwin.Rect ParentRect() cwin.Rect Frame() Frame Animators() []Animator Destroy() fmt.Stringer }
type SpriteBase ¶
type SpriteBase struct {
// contains filtered or unexported fields
}
func NewSpriteBase ¶
func NewSpriteBaseR ¶
func (*SpriteBase) AddAnimator ¶
func (sb *SpriteBase) AddAnimator(as ...Animator)
func (*SpriteBase) Animators ¶
func (sb *SpriteBase) Animators() []Animator
func (*SpriteBase) Base ¶
func (sb *SpriteBase) Base() *SpriteBase
func (*SpriteBase) DeleteAnimator ¶
func (sb *SpriteBase) DeleteAnimator(as ...Animator)
func (*SpriteBase) Destroy ¶
func (sb *SpriteBase) Destroy()
func (*SpriteBase) Frame ¶
func (sb *SpriteBase) Frame() Frame
func (*SpriteBase) Game ¶
func (sb *SpriteBase) Game() *Game
func (*SpriteBase) IsDestroyed ¶
func (sb *SpriteBase) IsDestroyed() bool
func (*SpriteBase) Mgr ¶
func (sb *SpriteBase) Mgr() *SpriteManager
func (*SpriteBase) Name ¶
func (sb *SpriteBase) Name() string
func (*SpriteBase) ParentRect ¶
func (sb *SpriteBase) ParentRect() cwin.Rect
func (*SpriteBase) Rect ¶
func (sb *SpriteBase) Rect() cwin.Rect
func (*SpriteBase) SendToBottom ¶
func (sb *SpriteBase) SendToBottom()
func (*SpriteBase) SendToTop ¶
func (sb *SpriteBase) SendToTop()
func (*SpriteBase) String ¶
func (sb *SpriteBase) String() string
func (*SpriteBase) This ¶
func (sb *SpriteBase) This() Sprite
func (*SpriteBase) Update ¶
func (sb *SpriteBase) Update(arg UpdateArg) bool
returns false if any of the tests (bounds, collision) fails; true otherwise. Important, do not call Update with IBC/CD turned on from your InBoundsCheckResponse.Notify or CollisionResponse.Notify or it might cause infinite recursion.
type SpriteManager ¶
type SpriteManager struct {
// contains filtered or unexported fields
}
func (*SpriteManager) AddSprite ¶
func (sm *SpriteManager) AddSprite(s Sprite)
func (*SpriteManager) CheckCollision ¶
func (sm *SpriteManager) CheckCollision( collider Sprite, colliderR cwin.Rect, colliderF Frame) []Sprite
CheckCollision does the collision detection with the collider against all the managed Sprites using the collider's Rect and Frame. Note that colliderR and colliderF are not necessarily the same as the collider's current position and frame.
func (*SpriteManager) CollidableRegistry ¶
func (sm *SpriteManager) CollidableRegistry() *CollidableRegistry
func (*SpriteManager) DbgStats ¶
func (sm *SpriteManager) DbgStats() string
func (*SpriteManager) DeleteAll ¶
func (sm *SpriteManager) DeleteAll()
func (*SpriteManager) DeleteSprite ¶
func (sm *SpriteManager) DeleteSprite(s Sprite)
func (*SpriteManager) Find ¶
func (sm *SpriteManager) Find(s Sprite) Sprite
Find returns the unique sprite managed by the SpriteManager that is identified by its SpriteBase. If no Sprite is found, panic.
func (*SpriteManager) FindByName ¶
func (sm *SpriteManager) FindByName(name string) Sprite
FindByName returns the first sprite managed by the SpriteManager that has the same name. If no match is found, panic.
func (*SpriteManager) Process ¶
func (sm *SpriteManager) Process()
func (*SpriteManager) Sprites ¶
func (sm *SpriteManager) Sprites() []Sprite
func (*SpriteManager) TryFind ¶
func (sm *SpriteManager) TryFind(s Sprite) (Sprite, bool)
TryFind returns the unique sprite managed by the SpriteManager that is identified by its SpriteBase.
func (*SpriteManager) TryFindByName ¶
func (sm *SpriteManager) TryFindByName(name string) (Sprite, bool)
TryFindByName returns the first sprite managed by the SpriteManager that has the same name.
type UpdateArg ¶
type UpdateArg struct { DXY *cwin.Point // update the sprite position by (dx,dy), if non nil. F Frame // If nil, no frame update; If empty (len=0), frame will be wiped clean IBC InBoundsCheckType // default to no in-bounds check. CD CollisionDetectionType // default to collision detection TestOnly bool // if true, do the tests only, no actual update or notifications }
type Waypoint ¶
From current position to (curX + DX, curY + DY) using time T. Note a trick here is to use DX=DY=0 to keep the sprite at the current location for time T.
type WaypointProvider ¶
type WaypointProviderAcceleration ¶
type WaypointProviderAcceleration struct {
// contains filtered or unexported fields
}
func NewWaypointProviderAcceleration ¶
func NewWaypointProviderAcceleration( cfg WaypointProviderAccelerationCfg) *WaypointProviderAcceleration
func (*WaypointProviderAcceleration) Cfg ¶
func (s *WaypointProviderAcceleration) Cfg() WaypointProviderAccelerationCfg
func (*WaypointProviderAcceleration) CurSpeed ¶
func (s *WaypointProviderAcceleration) CurSpeed() (xSpeed, ySpeed CharPerSec)
func (*WaypointProviderAcceleration) Next ¶
func (s *WaypointProviderAcceleration) Next() (Waypoint, bool)
type WaypointProviderAccelerationCfg ¶
type WaypointProviderAccelerationCfg struct { Clock *cutil.Clock InitXSpeed CharPerSec InitYSpeed CharPerSec AccX CharPerSecSec AccY CharPerSecSec DeltaT time.Duration // if 0, defaults to defaultDeltaT }