Beispiel #1
0
func (i *Input) Update() {
	if i.keyStates == nil {
		i.keyStates = map[ebiten.Key]int{}
	}
	for key := ebiten.Key(0); key <= ebiten.KeyMax; key++ {
		if !ebiten.IsKeyPressed(ebiten.Key(key)) {
			i.keyStates[key] = 0
			continue
		}
		i.keyStates[key]++
	}

	const gamepadID = 0
	if i.gamepadButtonStates == nil {
		i.gamepadButtonStates = map[ebiten.GamepadButton]int{}
	}
	for b := ebiten.GamepadButton(0); b <= ebiten.GamepadButtonMax; b++ {
		if !ebiten.IsGamepadButtonPressed(gamepadID, b) {
			i.gamepadButtonStates[b] = 0
			continue
		}
		i.gamepadButtonStates[b]++
	}

	if i.gamepadAbstractButtonStates == nil {
		i.gamepadAbstractButtonStates = map[abstractButton]int{}
	}
	for _, b := range gamepadAbstractButtons {
		if !i.gamepadConfig.IsButtonPressed(gamepadID, b) {
			i.gamepadAbstractButtonStates[b] = 0
			continue
		}
		i.gamepadAbstractButtonStates[b]++
	}
}
Beispiel #2
0
func (i *Input) Update() {
	for key := range i.keyStates {
		if !ebiten.IsKeyPressed(ebiten.Key(key)) {
			i.keyStates[key] = 0
			continue
		}
		i.keyStates[key]++
	}

	const gamepadID = 0
	for b := range i.gamepadButtonStates {
		if !ebiten.IsGamepadButtonPressed(gamepadID, ebiten.GamepadButton(b)) {
			i.gamepadButtonStates[b] = 0
			continue
		}
		i.gamepadButtonStates[b]++
	}

	for _, b := range gamepadStdButtons {
		if !i.gamepadConfig.IsButtonPressed(gamepadID, b) {
			i.gamepadStdButtonStates[b] = 0
			continue
		}
		i.gamepadStdButtonStates[b]++
	}
}
Beispiel #3
0
func update(screen *ebiten.Image) error {
	const offsetX, offsetY = 24, 40
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(offsetX, offsetY)
	op.ColorM.Scale(0.5, 0.5, 0.5, 1)
	if err := screen.DrawImage(keyboardImage, op); err != nil {
		return err
	}

	pressed := []string{}
	for i := 0; i <= 9; i++ {
		if ebiten.IsKeyPressed(ebiten.Key(i) + ebiten.Key0) {
			pressed = append(pressed, string(i+'0'))
		}
	}
	for c := 'A'; c <= 'Z'; c++ {
		if ebiten.IsKeyPressed(ebiten.Key(c) - 'A' + ebiten.KeyA) {
			pressed = append(pressed, string(c))
		}
	}
	for i := 1; i <= 12; i++ {
		if ebiten.IsKeyPressed(ebiten.Key(i) + ebiten.KeyF1 - 1) {
			pressed = append(pressed, "F"+strconv.Itoa(i))
		}
	}
	for key, name := range keyNames {
		if ebiten.IsKeyPressed(key) {
			pressed = append(pressed, name)
		}
	}

	op = &ebiten.DrawImageOptions{
		ImageParts: pressedKeysParts(pressed),
	}
	op.GeoM.Translate(offsetX, offsetY)
	if err := screen.DrawImage(keyboardImage, op); err != nil {
		return err
	}

	return nil
}