example/blocks: Add comments

This commit is contained in:
Hajime Hoshi 2018-01-22 20:57:54 +09:00
parent 4e432ca816
commit 507fc7cbbb
2 changed files with 8 additions and 1 deletions

View File

@ -124,6 +124,8 @@ func (c *gamepadConfig) Scan(gamepadID int, b virtualGamepadButton) bool {
return false return false
} }
// IsButtonPressed returns a boolean value indicating whether
// the given virtual button b is pressed.
func (c *gamepadConfig) IsButtonPressed(b virtualGamepadButton) bool { func (c *gamepadConfig) IsButtonPressed(b virtualGamepadButton) bool {
c.initializeIfNeeded() c.initializeIfNeeded()
@ -131,6 +133,7 @@ func (c *gamepadConfig) IsButtonPressed(b virtualGamepadButton) bool {
if ok { if ok {
return ebiten.IsGamepadButtonPressed(0, bb) return ebiten.IsGamepadButtonPressed(0, bb)
} }
a, ok := c.axes[b] a, ok := c.axes[b]
if ok { if ok {
v := ebiten.GamepadAxis(0, a.id) v := ebiten.GamepadAxis(0, a.id)
@ -143,7 +146,7 @@ func (c *gamepadConfig) IsButtonPressed(b virtualGamepadButton) bool {
return false return false
} }
// Name returns the button's name. // Name returns the pysical button's name for the given virtual button.
func (c *gamepadConfig) ButtonName(b virtualGamepadButton) string { func (c *gamepadConfig) ButtonName(b virtualGamepadButton) string {
c.initializeIfNeeded() c.initializeIfNeeded()

View File

@ -20,6 +20,7 @@ import (
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
) )
// Input manages the input state including gamepads and keyboards.
type Input struct { type Input struct {
keyStates map[ebiten.Key]int keyStates map[ebiten.Key]int
anyGamepadButtonPressed bool anyGamepadButtonPressed bool
@ -27,6 +28,7 @@ type Input struct {
gamepadConfig gamepadConfig gamepadConfig gamepadConfig
} }
// StateForKey returns time length indicating how long the key is pressed.
func (i *Input) StateForKey(key ebiten.Key) int { func (i *Input) StateForKey(key ebiten.Key) int {
if i.keyStates == nil { if i.keyStates == nil {
return 0 return 0
@ -34,6 +36,8 @@ func (i *Input) StateForKey(key ebiten.Key) int {
return i.keyStates[key] return i.keyStates[key]
} }
// IsAnyGamepadButtonPressed returns a boolean value indicating
// whether any gamepad button is pressed.
func (i *Input) IsAnyGamepadButtonPressed() bool { func (i *Input) IsAnyGamepadButtonPressed() bool {
return i.anyGamepadButtonPressed return i.anyGamepadButtonPressed
} }