engine

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: 15 Imported by: 0

Documentation

Overview

VoV engine

VoV engine

VoV engine

VoV engine

VoV engine

Index

Constants

View Source
const (
	FONT_SMALL = iota
	FONT_SMALL_RED
	FONT_MEDIUM
	FONT_LARGE
)
View Source
const (

	// Export for window icon
	ImageIcon = "icon.png"
)

Variables

View Source
var (
	// Paused boolean
	Paused bool

	// Started boolean
	Started bool

	// WasPaused boolean
	WasPaused bool

	// The time when the timer started
	StartTicks uint32

	// The ticks stored when the timer was paused
	PausedTicks uint32
)
View Source
var (
	// Haptic device
	Haptic *sdl.Haptic
)

Functions

func GetTicks

func GetTicks() uint32

Returns timer's time

func Pause

func Pause()

Pauses timer

func StartTimer

func StartTimer()

Starts timer

func StopTimer

func StopTimer()

Stops timer

func Unpause

func Unpause()

Unpauses timer

Types

type Config

type Config struct {
	// Enable music
	MusicEnabled bool

	// Enable sounds
	SoundsEnabled bool

	// Enable accelerometer
	AccelerometerEnabled bool

	// Accelerometer threshold
	AccelThreshold float64

	// Touch threshold
	TouchThreshold float64

	// Enable haptic
	HapticEnabled bool

	// Show frames per second
	ShowFps bool

	// Maximum frames per second
	MaxFps int

	// Barrier speed
	BarrierSpeed float64

	// Ship bounciness from screen edges
	Bounciness float64

	// Number of rock prototypes
	NRocks int

	// Number of rock structs to allocate
	MaxRocks int

	// Number of powups structs to allocate
	MaxPowups int

	// How often to generate powups
	PowupsTimeout int

	// How much milliseconds powup lasts
	PowupStateTimeout float64

	// Scale powup text
	PowupTextScale float64

	// Powup text timeout
	PowupTextTimeout float64

	// Number of animation sprites
	NFrames uint32

	// Gamespeed
	GameSpeed float64

	// Initial rocks
	InitialRocks int

	// Final rocks
	FinalRocks int

	// 32s for a speed=1 rock to cross the screen horizontally
	KH float64
	// 24s for a speed=1 rock to cross the screen vertically
	KV float64
	// range for rock dx values (+/-)
	RDX float64
	// range for rock dy values (+/-)
	RDY float64

	// Dust color depth
	MaxDustDepth float64

	// Number of dust motes
	NDustMotes int

	// Number od dust arrays
	NDustArray int

	// Maximum ship engine dots
	MaxShipDots int

	// Number od ship dots arrays
	NShipDotsArray int

	// Maximum bang dots
	MaxBangDots int

	// Number od bang dots arrays
	NBangDotsArray int

	// Ship thruster strength
	ThrusterStrength float64

	// How many engine dots come out of each thruster
	EngineDots int

	// Dots heat colors
	W int
	M int

	// Determines how hard dots push the rocks. Set to 0 to disable pushing rocks
	DotMassUnit float64

	// Time (in 1/60ths of a seccond) between when you blow up, and when next ship appears
	DeadPauseLength float64

	// Time (in milliseconds) to be invincible after next ship appears
	InvinciblePauseLength float64

	// Game over state timeout
	GameOverLength float64

	// Time (in milliseconds) to show scores screen after hiscore/gameover
	ScoresLength float64

	// Number of scores
	NScores int

	// Window width
	WinWidth float64

	// Window height
	WinHeight float64

	// X scroll
	XScrollTo float64
	// Y scroll
	YScrollTo float64

	// Distance ahead
	DistAhead float64

	// Maximum distance ahead
	MaxDistAhead float64

	// Credits scroll speed
	ScrollSpeed float64
}

Configuration structure

func NewConfig

func NewConfig() (c *Config)

Returns new config

func (*Config) Default

func (c *Config) Default()

Sets default config

func (*Config) Exists

func (c *Config) Exists() bool

Checks if config file exists

func (*Config) Load

func (c *Config) Load()

Loads config from file

func (*Config) Save

func (c *Config) Save()

Saves config to file

type Engine

type Engine struct {
	// Config
	Cfg *Config

	// Game state
	State StateMachine

	// SDL Window
	Window *sdl.Window
	// SDL Renderer
	Renderer *sdl.Renderer

	// Game controller
	Controller *sdl.GameController

	// Joystick
	Joystick *sdl.Joystick

	// Boolean set to true until exit
	Running bool

	// Screen X distance
	ScreenDX float64
	// Screen Y distance
	ScreenDY float64

	// Frames counter
	Frames int
	// Frames per second
	Fps float64
	// Maximum fps in ms
	FrameMs uint32

	// Start of frame (milliseconds)
	StartTicks uint32
	// End of frame (milliseconds)
	EndTicks uint32
	// Delta time between frames
	FrameDelta uint32
	// Length of frame adjusted for gamespeed
	TFrame float64
}

SDL engine structure

func NewEngine

func NewEngine(c *Config) (e *Engine)

Returns new engine

func (*Engine) Clear

func (e *Engine) Clear()

Clears screen

func (*Engine) CloseController

func (e *Engine) CloseController()

Closes game controller

func (*Engine) Destroy

func (e *Engine) Destroy()

Destroys SDL and releases the memory

func (*Engine) EndFrame

func (e *Engine) EndFrame()

Calculates end frame

func (*Engine) Fullscreen

func (e *Engine) Fullscreen()

Toggles fullscreen

func (*Engine) GetDimensions

func (e *Engine) GetDimensions() (width, height int)

Gets window dimensions based on display aspect ratio

func (*Engine) Init

func (e *Engine) Init() (err error)

Initializes engine

func (*Engine) Quit

func (e *Engine) Quit()

Quits game loop

func (*Engine) SetAccelerometer

func (e *Engine) SetAccelerometer()

Sets android accelerometer

func (*Engine) SetController

func (e *Engine) SetController(mappings []string)

Initializes game controller

func (*Engine) SetHaptic

func (e *Engine) SetHaptic()

Sets joystick haptic

func (*Engine) SetIcon

func (e *Engine) SetIcon(icon *sdl.Surface)

Sets window icon

func (*Engine) StartFrame

func (e *Engine) StartFrame()

Calculates start frame

func (*Engine) UpdateDimensions

func (e *Engine) UpdateDimensions()

Updates window dimensions

type Glyph

type Glyph struct {
	Image  *sdl.Texture
	Width  float64
	Height float64
}

Text glyph

func (*Glyph) Query

func (g *Glyph) Query()

Queries glyph texture dimensions

type Resource

type Resource struct {
	Engine *Engine

	DataDir string

	Mappings []string

	FontMain   *ttf.Font
	FontSmall  *ttf.Font
	FontTitle  *ttf.Font
	FontMedium *ttf.Font

	SoundClick      *mix.Chunk
	SoundBounce     *mix.Chunk
	SoundEngine1    *mix.Chunk
	SoundEngine2    *mix.Chunk
	SoundEngine3    *mix.Chunk
	SoundPowup0     *mix.Chunk
	SoundPowup1     *mix.Chunk
	SoundPowup2     *mix.Chunk
	SoundPowup3     *mix.Chunk
	SoundPowup4     *mix.Chunk
	SoundPowup5     *mix.Chunk
	SoundExplosion1 *mix.Chunk
	SoundExplosion2 *mix.Chunk

	MusicMenu *mix.Music
	MusicGame *mix.Music

	Ship     *sdl.Texture
	ShipSurf *sdl.Surface
	ShipGlow *sdl.Texture

	Powup     *sdl.Texture
	PowupSurf *sdl.Surface
	PowupGlow *sdl.Texture

	Life        *sdl.Texture
	Background1 *sdl.Texture
	Background2 *sdl.Texture
	Background3 *sdl.Texture
	Explosion1  *sdl.Texture
	Explosion2  *sdl.Texture

	LoadingText      *sdl.Texture
	TitleText        *sdl.Texture
	HiScoreText      *sdl.Texture
	HiScoreEnterText *sdl.Texture

	StartText     *sdl.Texture
	StartTextHi   *sdl.Texture
	ScoresText    *sdl.Texture
	ScoresTextHi  *sdl.Texture
	OptionsText   *sdl.Texture
	OptionsTextHi *sdl.Texture
	CreditsText   *sdl.Texture
	CreditsTextHi *sdl.Texture

	ProgrammingText          *sdl.Texture
	ProgrammingCreditText    *sdl.Texture
	MusicAndSoundsText       *sdl.Texture
	MusicAndSoundsCreditText *sdl.Texture
	GraphicsText             *sdl.Texture
	GraphicsCreditText       *sdl.Texture
	FontText                 *sdl.Texture
	FontCreditText           *sdl.Texture
	BasedText                *sdl.Texture
	BasedCreditText          *sdl.Texture
	SDLText                  *sdl.Texture
	SDLCreditText            *sdl.Texture
	GoText                   *sdl.Texture
	GoCreditText             *sdl.Texture
	VoVText                  *sdl.Texture
	VoVCreditText            *sdl.Texture

	MusicText           *sdl.Texture
	MusicTextHi         *sdl.Texture
	SoundsText          *sdl.Texture
	SoundsTextHi        *sdl.Texture
	AccelerometerText   *sdl.Texture
	AccelerometerTextHi *sdl.Texture
	HapticText          *sdl.Texture
	HapticTextHi        *sdl.Texture
	ShowFpsText         *sdl.Texture
	ShowFpsTextHi       *sdl.Texture

	YesText *sdl.Texture
	NoText  *sdl.Texture

	FpsText  *sdl.Texture
	TimeText *sdl.Texture

	ShieldsText     *sdl.Texture
	AttackText      *sdl.Texture
	InvincibleText  *sdl.Texture
	EngineBlastText *sdl.Texture
	SlowdownText    *sdl.Texture

	LifePowText        *sdl.Texture
	ShieldsPowText     *sdl.Texture
	AttackPowText      *sdl.Texture
	InvinciblePowText  *sdl.Texture
	EngineBlastPowText *sdl.Texture
	SlowdownPowText    *sdl.Texture

	PausedText   *sdl.Texture
	GameOverText *sdl.Texture

	Rocks     []*sdl.Texture
	RocksSurf []*sdl.Surface

	Glyphs           []string
	GlyphMapSmall    map[string]*Glyph
	GlyphMapSmallRed map[string]*Glyph
	GlyphMapMedium   map[string]*Glyph
	GlyphMapLarge    map[string]*Glyph
}

Resource structure

func NewResource

func NewResource(e *Engine, d string) (r *Resource)

Returns new resource

func (*Resource) DrawText

func (r *Resource) DrawText(text string, x, y int32, font int)

Draws text from glyph map

func (*Resource) Free

func (r *Resource) Free()

Frees resources

func (*Resource) FreeGlyphs

func (r *Resource) FreeGlyphs()

Frees glyphs

func (*Resource) FreeRocks

func (r *Resource) FreeRocks()

Frees rocks

func (*Resource) Load

func (r *Resource) Load()

Loads resources

func (*Resource) LoadFont

func (r *Resource) LoadFont(filename string, size int) (font *ttf.Font)

Loads ttf font

func (*Resource) LoadGlyphs

func (r *Resource) LoadGlyphs()

Loads glyphs

func (*Resource) LoadMappings

func (r *Resource) LoadMappings()

Loads controllers mappings

func (*Resource) LoadMusic

func (r *Resource) LoadMusic(filename string) (music *mix.Music)

Loads music

func (*Resource) LoadRocks

func (r *Resource) LoadRocks()

Loads rocks

func (*Resource) LoadSound

func (r *Resource) LoadSound(filename string) (sound *mix.Chunk)

Loads sound

func (*Resource) LoadSurface

func (r *Resource) LoadSurface(filename string) (image *sdl.Surface)

Loads surface

func (*Resource) LoadTexture

func (r *Resource) LoadTexture(filename string) (image *sdl.Texture)

Loads texture

func (*Resource) PlayMusic

func (r *Resource) PlayMusic(music *mix.Music, loops int)

Plays music

func (*Resource) PlaySound

func (r *Resource) PlaySound(sound *mix.Chunk, channel int, loops int)

Plays sound

func (*Resource) PlaySoundTimed

func (r *Resource) PlaySoundTimed(sound *mix.Chunk, channel int, loops int, ticks int)

Plays sound timed

func (*Resource) RenderText

func (r *Resource) RenderText(font *ttf.Font, text string, color sdl.Color, blended bool, outline int) (image *sdl.Texture)

Creates sdl texture from ttf font

type State

type State interface {
	OnInit() bool
	OnQuit() bool

	String() string

	HandleEvents()
	Update()
	Draw()
}

Game state interface

type StateMachine

type StateMachine struct {
	// contains filtered or unexported fields
}

State machine

func (*StateMachine) Change

func (g *StateMachine) Change(state State)

Change state

func (*StateMachine) Draw

func (g *StateMachine) Draw()

Draws state

func (*StateMachine) HandleEvents

func (g *StateMachine) HandleEvents()

Handles state events

func (*StateMachine) Pop

func (g *StateMachine) Pop()

Pop state

func (*StateMachine) Push

func (g *StateMachine) Push(state State)

Push state

func (*StateMachine) Size

func (g *StateMachine) Size() int

Returns size

func (*StateMachine) State

func (g *StateMachine) State() int

Returns state

func (*StateMachine) Update

func (g *StateMachine) Update()

Updates state

Jump to

Keyboard shortcuts

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