game

package
v0.0.0-...-cc4cc54 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2016 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

VoV game

VoV game

VoV game

VoV game

VoV game

VoV game

VoV game

VoV game

VoV game

VoV game

VoV game

VoV game

Index

Constants

View Source
const (
	BANGDOT = iota
	ENGINEDOT
)

Dot types

View Source
const (
	GamePlay = iota
	GameOver
	GamePause
	GameQuit
	DeadPause
)

Game states

View Source
const (
	LEFT = iota
	RIGHT
	UP
	DOWN
)

Directions

View Source
const (
	PLAIN = iota
	INVINCIBLE
	ENGINEBLAST
	SHIELDS
	ATTACK
	SLOWDOWN
)

Ship states

View Source
const (
	BASE = iota
	SHIP
	ROCK
	POWUP
)

Sprite types

View Source
const (
	MOVE    = 1
	DRAW    = 2
	COLLIDE = 4
)

Sprite flags

Variables

This section is empty.

Functions

This section is empty.

Types

type Button

type Button struct {
	Image     *Sprite
	Highlight *Sprite

	Active   bool
	Hovered  bool
	Clicked  bool
	Selected bool

	State engine.State
}

Menu button

func NewButton

func NewButton(e *engine.Engine, i *sdl.Texture, h *sdl.Texture, s engine.State, selected bool) (b *Button)

Returns new button

func (*Button) Draw

func (b *Button) Draw()

Draws button

type Credit

type Credit struct {
	Role *Sprite
	Name *Sprite
}

Credit structure

func NewCredit

func NewCredit(e *engine.Engine, r *sdl.Texture, n *sdl.Texture) (c *Credit)

Returns new credit

type Credits

type Credits struct {
	Engine   *engine.Engine
	Resource *engine.Resource

	Fog  *Fog
	Dust *Dust

	ScrollSpeed float64

	Credits []*Credit
}

Credits structure

func NewCredits

func NewCredits(e *engine.Engine, r *engine.Resource) (c *Credits)

Returns new credits

func (*Credits) Draw

func (c *Credits) Draw()

Draws credits

func (*Credits) HandleEvent

func (c *Credits) HandleEvent(event sdl.Event)

Handles input event

func (*Credits) HandleEvents

func (c *Credits) HandleEvents()

Handles input events

func (*Credits) OnInit

func (c *Credits) OnInit() bool

Initializes state

func (*Credits) OnQuit

func (c *Credits) OnQuit() bool

Quits state

func (*Credits) String

func (c *Credits) String() string

Returns state string

func (*Credits) Update

func (c *Credits) Update()

Updates credits

type Direction

type Direction struct {
	X1     float32
	Y1     float32
	X2     float32
	Y2     float32
	Motion bool
	State  []bool
}

Input directions

func (*Direction) SetStates

func (d *Direction) SetStates(state bool)

Sets all direction states to state

func (*Direction) StateEnabled

func (d *Direction) StateEnabled() bool

Checks if any of direction states is enabled

type Dot

type Dot struct {
	Game *Game

	X      float64
	Y      float64
	DX     float64
	DY     float64
	Mass   float64
	Decay  float64 // Rate at which to reduce mass
	Type   int
	Active bool
}

Dot structure

func (*Dot) Collide

func (d *Dot) Collide(b *Sprite) bool

Checks for dot collision

func (*Dot) Collisions

func (d *Dot) Collisions()

Checks dot collisions

func (*Dot) Move

func (d *Dot) Move()

Moves dot

type Dots

type Dots struct {
	Game *Game
	Cfg  *engine.Config

	Bd int
	S  [4]float64

	// Slice of heat colors
	HeatColors []sdl.Color

	ShipDots []*Dot
	BangDots []*Dot

	ShipDotsColors []sdl.Color
	BangDotsColors []sdl.Color

	ShipDotsPoints map[int][]sdl.Point
	BangDotsPoints map[int][]sdl.Point
}

Dots structure

func NewDots

func NewDots(g *Game) (d *Dots)

Returns new dots

func (*Dots) Draw

func (d *Dots) Draw()

Draws dots

func (*Dots) Init

func (d *Dots) Init()

Initializes dots

func (*Dots) InitColors

func (d *Dots) InitColors()

Initialize colors

func (*Dots) NewBangDots

func (d *Dots) NewBangDots(s *Sprite)

Generates new bang dots

func (*Dots) NewShipBangDots

func (d *Dots) NewShipBangDots()

Generates new bang dots

func (*Dots) NewShipDots

func (d *Dots) NewShipDots()

Generates new ship engine dots

func (*Dots) Update

func (d *Dots) Update()

Updates dots

type Dust

type Dust struct {
	Engine *engine.Engine
	Cfg    *engine.Config

	// Dust motes
	Motes map[sdl.Color][]*DustMote

	// Motes points
	MotesPoints map[sdl.Color][]sdl.Point
}

Dust structure

func NewDust

func NewDust(e *engine.Engine) (d *Dust)

Returns new dust

func (*Dust) Draw

func (d *Dust) Draw()

Draws dust

func (*Dust) Init

func (d *Dust) Init()

Initializes dust

func (*Dust) Update

func (d *Dust) Update()

Updates dust

type DustMote

type DustMote struct {
	X float64
	Y float64
	Z float64
}

Dust mote structure

type Fog

type Fog struct {
	Sprite

	Engine   *engine.Engine
	Resource *engine.Resource

	ScrollOffset float64

	Backgrounds map[int]*sdl.Texture
}

Fog structure

func NewFog

func NewFog(e *engine.Engine, r *engine.Resource) *Fog

Returns new fog

func (*Fog) Draw

func (b *Fog) Draw()

Draws fog

func (*Fog) Init

func (b *Fog) Init()

Initializes fog

func (*Fog) Update

func (b *Fog) Update()

Updates fog

type Game

type Game struct {
	Engine   *engine.Engine
	Cfg      *engine.Config
	Resource *engine.Resource

	Life *Sprite

	FpsText  *Sprite
	TimeText *Sprite

	ShieldsText     *Sprite
	AttackText      *Sprite
	InvincibleText  *Sprite
	EngineBlastText *Sprite
	SlowdownText    *Sprite

	PausedText   *Sprite
	GameOverText *Sprite

	Fog    *Fog
	Dust   *Dust
	Dots   *Dots
	Ship   *Ship
	Rocks  *Rocks
	Powups *Powups

	State        int
	LastState    int
	StateTimeout float64

	Direction *Direction

	Score int
}

Game structure

func NewGame

func NewGame(e *engine.Engine, r *engine.Resource) (g *Game)

Returns new game

func (*Game) Draw

func (g *Game) Draw()

Draws game

func (*Game) DrawFPS

func (g *Game) DrawFPS()

Draws fps

func (*Game) DrawLives

func (g *Game) DrawLives()

Draws lives

func (*Game) DrawScore

func (g *Game) DrawScore()

Draws score

func (*Game) DrawState

func (g *Game) DrawState()

Draws ship state timeout

func (*Game) HandleEvent

func (g *Game) HandleEvent(event sdl.Event)

Handles input event

func (*Game) HandleEvents

func (g *Game) HandleEvents()

Handles input events

func (*Game) OnInit

func (g *Game) OnInit() bool

Initializes game state

func (*Game) OnQuit

func (g *Game) OnQuit() bool

Quits game state

func (*Game) String

func (g *Game) String() string

Returns state string

func (*Game) TogglePause

func (g *Game) TogglePause()

Toggles paused state

func (*Game) Update

func (g *Game) Update()

Updates game

func (*Game) UpdateState

func (g *Game) UpdateState()

Updates game state

type Menu struct {
	Engine   *engine.Engine
	Resource *engine.Resource

	Fog  *Fog
	Dust *Dust

	Buttons      []*Button
	ButtonActive int

	TitleText *Sprite

	FadeTimer float64
}

Menu structure

func NewMenu

func NewMenu(e *engine.Engine, r *engine.Resource) (m *Menu)

Returns new menu

func (m *Menu) Draw()

Draws menu

func (m *Menu) HandleEvent(event sdl.Event)

Handles input event

func (m *Menu) HandleEvents()

Handles input events

func (m *Menu) OnInit() bool

Initializes menu state

func (m *Menu) OnQuit() bool

Quits game state

func (m *Menu) String() string

Returns state string

func (m *Menu) Update()

Updates menu

type Options

type Options struct {
	Engine   *engine.Engine
	Resource *engine.Resource

	Fog  *Fog
	Dust *Dust

	Buttons      []*Button
	ButtonActive int

	YesText *Sprite
	NoText  *Sprite

	FadeTimer float64
}

Options structure

func NewOptions

func NewOptions(e *engine.Engine, r *engine.Resource) (m *Options)

Returns new options

func (*Options) Draw

func (m *Options) Draw()

Draws menu

func (*Options) HandleEvent

func (m *Options) HandleEvent(event sdl.Event)

Handles input event

func (*Options) HandleEvents

func (m *Options) HandleEvents()

Handles input events

func (*Options) OnInit

func (m *Options) OnInit() bool

Initializes menu state

func (*Options) OnQuit

func (m *Options) OnQuit() bool

Quits game state

func (*Options) String

func (m *Options) String() string

Returns state string

func (*Options) Update

func (m *Options) Update()

Updates menu

func (*Options) UpdateConfig

func (m *Options) UpdateConfig()

Updates config

type Powups

type Powups struct {
	Game   *Game
	Engine *engine.Engine

	Powups []*Sprite

	Glow *Sprite

	Timeout int

	SpeedMin [4]float64
	SpeedMax [4]float64
}

Powups structure

func NewPowups

func NewPowups(g *Game) (r *Powups)

Returns new powups

func (*Powups) Collisions

func (r *Powups) Collisions()

Checks powups collisions

func (*Powups) Draw

func (r *Powups) Draw()

Draws powups

func (*Powups) DrawGlow

func (r *Powups) DrawGlow(i int)

Draws powup glow

func (*Powups) Init

func (r *Powups) Init()

Initializes powups

func (*Powups) New

func (r *Powups) New()

Generates new powup

func (*Powups) Sides

func (r *Powups) Sides()

Computes the speed ranges of powups coming from each side

func (*Powups) Update

func (r *Powups) Update()

Updates powups

type Rocks

type Rocks struct {
	Engine   *engine.Engine
	Cfg      *engine.Config
	Resource *engine.Resource

	Rocks      []*Sprite
	Prototypes []*Sprite

	Nrocks         int
	InitialRocks   int
	FinalRocks     int
	NrocksTimer    float64
	NrocksIncTicks float64
	CurrentRock    int

	Ti       [4]float64
	Rtimers  [4]float64
	SpeedMin [4]float64
	SpeedMax [4]float64
}

Rocks structure

func NewRocks

func NewRocks(e *engine.Engine, res *engine.Resource) (r *Rocks)

Returns new rocks

func (*Rocks) Collisions

func (r *Rocks) Collisions()

Checks rocks collisions

func (*Rocks) Draw

func (r *Rocks) Draw()

Draws rocks

func (*Rocks) Init

func (r *Rocks) Init()

Initializes rocks

func (*Rocks) New

func (r *Rocks) New()

Generates new rocks

func (*Rocks) Reset

func (r *Rocks) Reset()

Resets rocks

func (*Rocks) Sides

func (r *Rocks) Sides()

Computes the number of rocks/tick that should be coming from each side, and the speed ranges of rocks coming from each side

func (*Rocks) Update

func (r *Rocks) Update()

Updates rocks

type Score

type Score struct {
	Name      string
	Time      int
	X         float64
	Y         float64
	Width     float64
	Height    float64
	Formatted string
}

Score structure

type Scores

type Scores struct {
	Engine   *engine.Engine
	Resource *engine.Resource

	Fog  *Fog
	Dust *Dust

	// Current score
	Current int

	// String from input
	TextInput string

	// Is passed score highscore
	IsHighScore bool

	// Continue to menu state after timeout if true
	Continue bool

	// If scores are loaded
	Loaded bool

	// New hiscore text
	HiScoreText      *Sprite
	HiScoreEnterText *Sprite

	// Loading text
	LoadingText *Sprite

	// List of scores
	Scores []Score

	// Timers
	FadeTimer  float64
	StateTimer float64
}

Scores structure

func NewScores

func NewScores(e *engine.Engine, r *engine.Resource, score int, cont bool) (s *Scores)

Returns new scores

func (*Scores) Default

func (s *Scores) Default()

Adds default scores

func (*Scores) Draw

func (s *Scores) Draw()

Draws scores

func (*Scores) Exists

func (s *Scores) Exists() bool

Checks if scores file exists

func (*Scores) Format

func (s *Scores) Format()

Formats scores and gets text dimensions

func (*Scores) HandleEvent

func (s *Scores) HandleEvent(event sdl.Event)

Handles input event

func (*Scores) HandleEvents

func (s *Scores) HandleEvents()

Handles input events

func (*Scores) HighScore

func (s *Scores) HighScore() bool

Checks if score is highscore

func (*Scores) Insert

func (s *Scores) Insert()

Inserts new score

func (*Scores) Load

func (s *Scores) Load()

Loads scores from file

func (*Scores) OnInit

func (s *Scores) OnInit() bool

Initializes state

func (*Scores) OnQuit

func (s *Scores) OnQuit() bool

Quits state

func (*Scores) Rank

func (s *Scores) Rank() int

Returns score rank

func (*Scores) Save

func (s *Scores) Save()

Saves scores to file

func (*Scores) String

func (s *Scores) String() string

Returns state string

func (*Scores) Update

func (s *Scores) Update()

Updates scores

func (*Scores) UpdateState

func (s *Scores) UpdateState()

Updates state

type Ship

type Ship struct {
	Sprite

	Game *Game
	Cfg  *engine.Config

	Glow *Sprite

	Moving      bool
	Transparent bool

	StateTimeout  float64
	TranspTimeout float64

	LifePowText        *Sprite
	ShieldsPowText     *Sprite
	AttackPowText      *Sprite
	InvinciblePowText  *Sprite
	EngineBlastPowText *Sprite
	SlowdownPowText    *Sprite

	PowupTextScale   float64
	PowupTextTimeout float64
	PowupCurrent     int
	PowupTextActive  bool
}

Ship structure

func NewShip

func NewShip(g *Game) *Ship

Returns new ship

func (*Ship) Collisions

func (s *Ship) Collisions()

Checks ship collisions

func (*Ship) Draw

func (s *Ship) Draw()

Draws ship

func (*Ship) DrawPowupText

func (s *Ship) DrawPowupText()

Draws powup text

func (*Ship) FadeSound

func (s *Ship) FadeSound()

Fades engine sound

func (*Ship) Init

func (s *Ship) Init()

Initialize ship

func (*Ship) Kill

func (s *Ship) Kill()

Kills ship

func (*Ship) PlaySound

func (s *Ship) PlaySound()

Plays engine sound

func (*Ship) Update

func (s *Ship) Update()

Updates ship

func (*Ship) UpdateState

func (s *Ship) UpdateState()

Updates ship state

func (*Ship) UpdateTransp

func (s *Ship) UpdateTransp()

Updates ship transparency

type Sprite

type Sprite struct {
	Engine *engine.Engine

	Type   int
	Flags  int
	X      float64
	Y      float64
	DX     float64
	DY     float64
	Width  float64
	Height float64
	Frame  uint32
	Active bool

	Texture *sdl.Texture
	Surface *sdl.Surface

	// Explosion
	Exp1      *Sprite
	Exp2      *Sprite
	ExpActive bool
	ExpFrame  int

	// Rock extras
	Life      int
	Direction int

	// Ship extras
	Lives int
	Jets  int
	State int
}

Sprite structure

func NewSprite

func NewSprite(e *engine.Engine, texture *sdl.Texture) (s *Sprite)

Returns new sprite

func (*Sprite) Bounce

func (s *Sprite) Bounce(b *Sprite)

Bounces sprites

func (*Sprite) Collide

func (s *Sprite) Collide(b *Sprite) bool

Checks for sprite collision

func (*Sprite) Collides

func (s *Sprite) Collides() bool

Checks collide flag

func (*Sprite) Draw

func (s *Sprite) Draw()

Draws sprite

func (*Sprite) Explode

func (s *Sprite) Explode()

Explodes sprite

func (*Sprite) Kill

func (s *Sprite) Kill()

Kills sprite

func (*Sprite) Mass

func (s *Sprite) Mass() (m float64)

Returns mass of sprite

func (*Sprite) Quad

func (s *Sprite) Quad() int

Returns sprite quadrant

func (*Sprite) Query

func (s *Sprite) Query()

Queries sprite texture dimensions

func (*Sprite) Rect

func (s *Sprite) Rect() *sdl.Rect

Returns sprite rect

func (*Sprite) Update

func (s *Sprite) Update()

Updates sprite

Jump to

Keyboard shortcuts

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