gamepad

package
v0.0.0-...-79996cc Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package gamepad provides game controller logic for the game.

Controls

The gamepad controls are currently hard-coded for Xbox 360 style controllers, and the controller mappings vary depending on the "mode" of control.

N Style and X Style

If the gamepad control is set to "NStyle" then the A/B and X/Y buttons will be swapped to match the labels of a Nintendo style controller. Since the game has relatively few inputs needed now, this module maps them to a PrimaryButton and a SecondaryButton, defined as:

PrimaryButton: A or X button SecondaryButton: B or Y button

Mouse Mode

- Left stick moves the mouse cursor (a cursor sprite is drawn on screen) - Right stick scrolls the level (title screen or level editor) - PrimaryButton emulates a left click. - SecondaryButton emulates a right click. - Left Shoulder emulates a middle click. - Left Trigger (L2) closes the top-most window in the Editor (Backspace key) - Right Shoulder toggles between Mouse Mode and other scene-specific mode.

Gameplay Mode

- Left stick moves the player character (left/right only). - D-Pad also moves the player character (left/right only). - PrimaryButton is to "Use" - SecondaryButton is to "Jump" - If the player has antigravity, up/down controls on left stick or D-Pad work too. - Right Shoulder toggles between GameplayMode and MouseMode.

Index

Constants

This section is empty.

Variables

View Source
var (
	// PlayScene tells us whether antigravity is on, so directional controls work all directions.
	PlayModeAntigravity bool
	SceneName           string // Set by doodle.Goto() so we know what scene name we're on.

)

Global state variables for gamepad support.

Functions

func Draw

func Draw(e render.Engine)

Draw the cursor on screen if the game controller is emulating a mouse.

func Loop

func Loop(ev *event.State)

Loop hooks the render events on each game tick.

func PrimaryButton

func PrimaryButton(ctrl event.GameController) bool

PrimaryButton returns whether the A or X button is pressed.

func SecondaryButton

func SecondaryButton(ctrl event.GameController) bool

SecondaryButton returns whether the B or Y button is pressed.

func SetControllerIndex

func SetControllerIndex(index int)

SetControllerIndex sets which gamepad will be "Player One"

func SetMode

func SetMode(m Mode)

SetMode sets the controller mode.

func SetStyle

func SetStyle(s Style)

SetStyle sets the controller button style.

func UnsetController

func UnsetController()

UnsetController detaches the Player One controller.

Types

type Mode

type Mode int

Mode of controller behavior (Player One)

const (
	// MouseMode: the joystick moves a mouse cursor around and
	// the face buttons emulate mouse click events.
	MouseMode Mode = iota

	// GameplayMode: to control the player character during Play Mode.
	GameplayMode

	// EditorMode: to support the Level Editor.
	EditorMode
)

Controller mode options.

type Style

type Style int

Style of controller (Player One)

const (
	XStyle      Style = iota // Xbox 360 layout (A button on bottom)
	NStyle                   // Nintendo style (A button on right)
	CustomStyle              // Custom style (TODO)
)

Controller style options.

Jump to

Keyboard shortcuts

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