Documentation ¶
Overview ¶
Package game provides the cat-o-licious game.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = Config{
FPS: 30,
Width: 800,
Height: 600,
PlayerSpeed: 20,
}
DefaultConfig is the game's default configuration.
var DefaultPlayerHitSquare = struct{ X, Y, W, H, FlipOffset float32 }{
X: .4,
Y: .8,
W: .3,
H: .15,
FlipOffset: .1,
}
DefaultPlayerHitSquare defines the hit square within the player image, in percentages.
var DefaultPlayerSide = Right
DefaultPlayerSide configures the default facing side of the player.
var Version = "tip"
Version is the version of the game engine.
Functions ¶
Types ¶
type Config ¶
type Config struct { // FPS is the rendering rate of the game. It cannot be changed. FPS int // Width is the initial width for the game window. Width int // Height is the initial height of the game window. Height int // PlayerSpeed is the speed of the player's lateral movement. PlayerSpeed int }
Config is the game configuration.
type Drop ¶
type Drop interface { // Pos returns the position of the drop in the viewport. Pos() sdl.Rect // Points returns delta points for the drop. Good drops // return positive numbers while bad drops return negative. Points() int64 }
Drop is a single drop of rain.
type Engine ¶
type Engine interface {
// Run runs the engine. Blocks until Q is pressed.
Run()
}
Engine is the game engine.
type Image ¶
type Image interface { // Size returns the image size. Size() (w, h int32) // Texture returns the SDL image texture. Texture() *sdl.Texture }
Image is a wrapper for SDL images.
func NewImageFromFile ¶
NewImageFromFile loads an image from file.
type Player ¶
type Player interface { // Move moves the player. Move(d Direction, steps int32) // Hit returns true when the given drop's area intersects // with the player's hit area. This is when you make points. Hit(d Drop) bool // Draw draws the player. Draw(viewport *sdl.Rect) }
Player is a game player.
type Rain ¶
type Rain interface { // SetRate sets the rate of drops per second. SetRate(n int) // Drops returns all raindrops from the rain. Drops() []Drop // Draw draws the rain. Draw(now time.Time, viewport *sdl.Rect) }
Rain makes objects (raindrops) fall from the top of the viewport all the way to the bottom.
type Scene ¶
type Scene interface { // Player returns the game player so callers can control // its lateral movement. Player() Player // Draw draws the scene. Draw(now time.Time, viewport *sdl.Rect) }
Scene is the game scene. It contains the background image, scoreboard, player, rain, and sound.
type Scoreboard ¶
type Scoreboard interface { // Add adds the given delta to the player's score. Add(delta int64) // Points returns the current player's points. Points() int64 // Draw draws the scoreboard. Draw(viewport *sdl.Rect) }
Scoreboard tracks the player's score and draws the scoreboard.
func NewScoreboard ¶
func NewScoreboard(r *sdl.Renderer) (Scoreboard, error)
NewScoreboard creates and initializes a new scoreboard.