2014-12-09 15:16:04 +01:00
|
|
|
/*
|
|
|
|
Copyright 2014 Hajime Hoshi
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-12-08 17:35:35 +01:00
|
|
|
package blocks
|
2013-12-18 19:21:25 +01:00
|
|
|
|
|
|
|
import (
|
2014-12-09 14:09:22 +01:00
|
|
|
"github.com/hajimehoshi/ebiten"
|
2013-12-18 19:21:25 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Input struct {
|
2014-12-09 14:09:22 +01:00
|
|
|
states map[ebiten.Key]int
|
2013-12-18 19:21:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewInput() *Input {
|
2014-12-09 14:09:22 +01:00
|
|
|
states := map[ebiten.Key]int{}
|
|
|
|
for key := ebiten.Key(0); key < ebiten.KeyMax; key++ {
|
2013-12-18 19:21:25 +01:00
|
|
|
states[key] = 0
|
|
|
|
}
|
|
|
|
return &Input{
|
|
|
|
states: states,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-09 14:09:22 +01:00
|
|
|
func (i *Input) StateForKey(key ebiten.Key) int {
|
2013-12-18 19:21:25 +01:00
|
|
|
return i.states[key]
|
|
|
|
}
|
|
|
|
|
2014-12-10 17:06:38 +01:00
|
|
|
func (i *Input) Update(g ebiten.GameContext) {
|
2014-12-06 14:56:57 +01:00
|
|
|
for key := range i.states {
|
2014-12-10 17:06:38 +01:00
|
|
|
if !g.IsKeyPressed(key) {
|
2013-12-18 19:21:25 +01:00
|
|
|
i.states[key] = 0
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
i.states[key] += 1
|
|
|
|
}
|
|
|
|
}
|