mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Update doc gen
This commit is contained in:
parent
4b9c740ee8
commit
7d08acf695
@ -33,7 +33,7 @@ import (
|
||||
var license = ""
|
||||
|
||||
func init() {
|
||||
b, err := ioutil.ReadFile("../license.txt")
|
||||
b, err := ioutil.ReadFile("../LICENSE")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -53,8 +53,7 @@ pre {
|
||||
</p>
|
||||
|
||||
<h2>Install on Mac OS X</h2>
|
||||
<pre><code>:; brew install glfw3 # or homebrew/versions/glfw3
|
||||
:; go get github.com/hajimehoshi/ebiten</code></pre>
|
||||
<pre><code>:; go get github.com/hajimehoshi/ebiten</code></pre>
|
||||
<p>If you want to run your game on a web browser, execute this:</p>
|
||||
<pre><code>:; go get github.com/gopherjs/gopherjs
|
||||
:; go get github.com/gopherjs/webgl</code></pre>
|
||||
|
@ -40,13 +40,14 @@ pre {
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
"math"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/example/common"
|
||||
"github.com/hajimehoshi/ebiten/exp/audio"
|
||||
"image/color"
|
||||
"log"
|
||||
"math"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -73,8 +74,30 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
noteCache = map[int][]byte{}
|
||||
)
|
||||
|
||||
func toBytes(l, r []int16) []byte {
|
||||
if len(l) != len(r) {
|
||||
panic("len(l) must equal to len(r)")
|
||||
}
|
||||
b := make([]byte, len(l)*4)
|
||||
for i, _ := range l {
|
||||
b[4*i] = byte(l[i])
|
||||
b[4*i+1] = byte(l[i] >> 8)
|
||||
b[4*i+2] = byte(r[i])
|
||||
b[4*i+3] = byte(r[i] >> 8)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func addNote(freq float64, vol float64) {
|
||||
f := int(freq)
|
||||
if n, ok := noteCache[f]; ok {
|
||||
audio.Play(-1, n)
|
||||
return
|
||||
}
|
||||
length := len(pcm) * baseFreq / f
|
||||
l := make([]int16, length)
|
||||
r := make([]int16, length)
|
||||
@ -87,7 +110,9 @@ func addNote(freq float64, vol float64) {
|
||||
jj += f
|
||||
j = jj / baseFreq
|
||||
}
|
||||
audio.Play(-1, l, r)
|
||||
n := toBytes(l, r)
|
||||
noteCache[f] = n
|
||||
audio.Play(-1, n)
|
||||
}
|
||||
|
||||
var keys = []ebiten.Key{
|
||||
@ -127,6 +152,36 @@ func updateInput() {
|
||||
}
|
||||
}
|
||||
|
||||
var pianoImage *ebiten.Image
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
pianoImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
whiteKeys := []string{"A", "S", "D", "F", "G", "H", "J", "K", "L"}
|
||||
width := 24
|
||||
y := 48
|
||||
for i, k := range whiteKeys {
|
||||
x := i*width + 36
|
||||
height := 112
|
||||
pianoImage.DrawFilledRect(x, y, width-1, height, color.White)
|
||||
common.ArcadeFont.DrawText(pianoImage, k, x+8, y+height-16, 1, color.Black)
|
||||
}
|
||||
|
||||
blackKeys := []string{"Q", "W", "", "R", "T", "", "U", "I", "O"}
|
||||
for i, k := range blackKeys {
|
||||
if k == "" {
|
||||
continue
|
||||
}
|
||||
x := i*width + 24
|
||||
height := 64
|
||||
pianoImage.DrawFilledRect(x, y, width-1, height, color.Black)
|
||||
common.ArcadeFont.DrawText(pianoImage, k, x+8, y+height-16, 1, color.White)
|
||||
}
|
||||
}
|
||||
|
||||
func update(screen *ebiten.Image) error {
|
||||
updateInput()
|
||||
for i, key := range keys {
|
||||
@ -137,27 +192,7 @@ func update(screen *ebiten.Image) error {
|
||||
}
|
||||
|
||||
screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff})
|
||||
|
||||
whiteKeys := []string{"A", "S", "D", "F", "G", "H", "J", "K", "L"}
|
||||
width := 24
|
||||
y := 48
|
||||
for i, k := range whiteKeys {
|
||||
x := i*width + 36
|
||||
height := 112
|
||||
screen.DrawFilledRect(x, y, width-1, height, color.White)
|
||||
common.ArcadeFont.DrawText(screen, k, x+8, y+height-16, 1, color.Black)
|
||||
}
|
||||
|
||||
blackKeys := []string{"Q", "W", "", "R", "T", "", "U", "I", "O"}
|
||||
for i, k := range blackKeys {
|
||||
if k == "" {
|
||||
continue
|
||||
}
|
||||
x := i*width + 24
|
||||
height := 64
|
||||
screen.DrawFilledRect(x, y, width-1, height, color.Black)
|
||||
common.ArcadeFont.DrawText(screen, k, x+8, y+height-16, 1, color.White)
|
||||
}
|
||||
screen.DrawImage(pianoImage, nil)
|
||||
|
||||
ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()))
|
||||
return nil
|
||||
|
@ -81,8 +81,7 @@ pre {
|
||||
</p>
|
||||
|
||||
<h2>Install on Mac OS X</h2>
|
||||
<pre><code>:; brew install glfw3 # or homebrew/versions/glfw3
|
||||
:; go get github.com/hajimehoshi/ebiten</code></pre>
|
||||
<pre><code>:; go get github.com/hajimehoshi/ebiten</code></pre>
|
||||
<p>If you want to run your game on a web browser, execute this:</p>
|
||||
<pre><code>:; go get github.com/gopherjs/gopherjs
|
||||
:; go get github.com/gopherjs/webgl</code></pre>
|
||||
|
Loading…
Reference in New Issue
Block a user