mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
doc: Update: changed the path for the script location
This commit is contained in:
parent
6db96f5442
commit
fb65fe1fee
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = '{{.Example.Name}}.js';
|
var src = '{{.Example.Name}}.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 1.8 KiB |
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'alphablending.js';
|
var src = 'alphablending.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -48,26 +48,6 @@ var (
|
|||||||
ebitenImage *ebiten.Image
|
ebitenImage *ebiten.Image
|
||||||
)
|
)
|
||||||
|
|
||||||
type imageParts struct {
|
|
||||||
diff float64
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *imageParts) Src(i int) (int, int, int, int) {
|
|
||||||
w, h := ebitenImage.Size()
|
|
||||||
return 0, 0, w, h
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *imageParts) Dst(i int) (int, int, int, int) {
|
|
||||||
x := int(float64(i%10)*p.diff + 15)
|
|
||||||
y := int(float64(i/10)*p.diff + 20)
|
|
||||||
w, h := ebitenImage.Size()
|
|
||||||
return x, y, x + w, y + h
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *imageParts) Len() int {
|
|
||||||
return 10 * 10
|
|
||||||
}
|
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
func update(screen *ebiten.Image) error {
|
||||||
count++
|
count++
|
||||||
count %= ebiten.FPS * 10
|
count %= ebiten.FPS * 10
|
||||||
@ -84,10 +64,13 @@ func update(screen *ebiten.Image) error {
|
|||||||
screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff})
|
screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff})
|
||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
|
op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
|
||||||
op.ImageParts = &imageParts{
|
for i := 0; i < 10*10; i++ {
|
||||||
diff: diff,
|
op.GeoM.Reset()
|
||||||
}
|
x := float64(i%10)*diff + 15
|
||||||
|
y := float64(i/10)*diff + 20
|
||||||
|
op.GeoM.Translate(x, y)
|
||||||
screen.DrawImage(ebitenImage, op)
|
screen.DrawImage(ebitenImage, op)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'audio.js';
|
var src = 'audio.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'blocks.js';
|
var src = 'blocks.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'font.js';
|
var src = 'font.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'gamepad.js';
|
var src = 'gamepad.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'hsv.js';
|
var src = 'hsv.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'hue.js';
|
var src = 'hue.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'infinitescroll.js';
|
var src = 'infinitescroll.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'keyboard.js';
|
var src = 'keyboard.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -56,12 +56,20 @@ func init() {
|
|||||||
var keyNames = map[ebiten.Key]string{
|
var keyNames = map[ebiten.Key]string{
|
||||||
ebiten.KeyBackspace: "BS",
|
ebiten.KeyBackspace: "BS",
|
||||||
ebiten.KeyComma: ",",
|
ebiten.KeyComma: ",",
|
||||||
ebiten.KeyDelete: "Del",
|
|
||||||
ebiten.KeyEnter: "Enter",
|
ebiten.KeyEnter: "Enter",
|
||||||
ebiten.KeyEscape: "Esc",
|
ebiten.KeyEscape: "Esc",
|
||||||
ebiten.KeyPeriod: ".",
|
ebiten.KeyPeriod: ".",
|
||||||
ebiten.KeySpace: "Space",
|
ebiten.KeySpace: "Space",
|
||||||
ebiten.KeyTab: "Tab",
|
ebiten.KeyTab: "Tab",
|
||||||
|
ebiten.KeyMinus: "-",
|
||||||
|
ebiten.KeyEqual: "=",
|
||||||
|
ebiten.KeyBackslash: "\\",
|
||||||
|
ebiten.KeyGraveAccent: "`",
|
||||||
|
ebiten.KeyLeftBracket: "[",
|
||||||
|
ebiten.KeyRightBracket: "]",
|
||||||
|
ebiten.KeySemicolon: ";",
|
||||||
|
ebiten.KeyApostrophe: "'",
|
||||||
|
ebiten.KeySlash: "/",
|
||||||
|
|
||||||
// Arrows
|
// Arrows
|
||||||
ebiten.KeyDown: "Down",
|
ebiten.KeyDown: "Down",
|
||||||
@ -75,26 +83,10 @@ var keyNames = map[ebiten.Key]string{
|
|||||||
ebiten.KeyAlt: "Alt",
|
ebiten.KeyAlt: "Alt",
|
||||||
}
|
}
|
||||||
|
|
||||||
type pressedKeysParts []string
|
|
||||||
|
|
||||||
func (p pressedKeysParts) Len() int {
|
|
||||||
return len(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p pressedKeysParts) Dst(i int) (x0, y0, x1, y1 int) {
|
|
||||||
k := p[i]
|
|
||||||
r, ok := keyboard.KeyRect(k)
|
|
||||||
if !ok {
|
|
||||||
return 0, 0, 0, 0
|
|
||||||
}
|
|
||||||
return r.Min.X, r.Min.Y, r.Max.X, r.Max.Y
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p pressedKeysParts) Src(i int) (x0, y0, x1, y1 int) {
|
|
||||||
return p.Dst(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
func update(screen *ebiten.Image) error {
|
||||||
|
if ebiten.IsRunningSlowly() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
const offsetX, offsetY = 24, 40
|
const offsetX, offsetY = 24, 40
|
||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
op.GeoM.Translate(offsetX, offsetY)
|
op.GeoM.Translate(offsetX, offsetY)
|
||||||
@ -123,11 +115,18 @@ func update(screen *ebiten.Image) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op = &ebiten.DrawImageOptions{
|
op = &ebiten.DrawImageOptions{}
|
||||||
ImageParts: pressedKeysParts(pressed),
|
for _, p := range pressed {
|
||||||
|
op.GeoM.Reset()
|
||||||
|
r, ok := keyboard.KeyRect(p)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
op.GeoM.Translate(float64(r.Min.X), float64(r.Min.Y))
|
||||||
op.GeoM.Translate(offsetX, offsetY)
|
op.GeoM.Translate(offsetX, offsetY)
|
||||||
|
op.SourceRect = &r
|
||||||
screen.DrawImage(keyboardImage, op)
|
screen.DrawImage(keyboardImage, op)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'life.js';
|
var src = 'life.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'masking.js';
|
var src = 'masking.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'mosaic.js';
|
var src = 'mosaic.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'noise.js';
|
var src = 'noise.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'paint.js';
|
var src = 'paint.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'perspective.js';
|
var src = 'perspective.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image"
|
||||||
_ "image/jpeg"
|
_ "image/jpeg"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
@ -46,39 +47,25 @@ var (
|
|||||||
gophersImage *ebiten.Image
|
gophersImage *ebiten.Image
|
||||||
)
|
)
|
||||||
|
|
||||||
type parts struct {
|
|
||||||
image *ebiten.Image
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p parts) Len() int {
|
|
||||||
_, h := p.image.Size()
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p parts) Dst(i int) (x0, y0, x1, y1 int) {
|
|
||||||
w, h := p.image.Size()
|
|
||||||
width := w + i*3/4
|
|
||||||
x := ((h - i) * 3 / 4) / 2
|
|
||||||
return x, i, x + width, i + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p parts) Src(i int) (x0, y0, x1, y1 int) {
|
|
||||||
w, _ := p.image.Size()
|
|
||||||
return 0, i, w, i + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
func update(screen *ebiten.Image) error {
|
||||||
if ebiten.IsRunningSlowly() {
|
if ebiten.IsRunningSlowly() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
op := &ebiten.DrawImageOptions{
|
op := &ebiten.DrawImageOptions{}
|
||||||
ImageParts: &parts{gophersImage},
|
|
||||||
}
|
|
||||||
w, h := gophersImage.Size()
|
w, h := gophersImage.Size()
|
||||||
maxWidth := float64(w) + float64(h)*0.75
|
for i := 0; i < h; i++ {
|
||||||
|
op.GeoM.Reset()
|
||||||
|
width := w + i*3/4
|
||||||
|
x := ((h - i) * 3 / 4) / 2
|
||||||
|
op.GeoM.Scale(float64(width)/float64(w), 1)
|
||||||
|
op.GeoM.Translate(float64(x), float64(i))
|
||||||
|
maxWidth := float64(w) + float64(h)*3/4
|
||||||
op.GeoM.Translate(-maxWidth/2, -float64(h)/2)
|
op.GeoM.Translate(-maxWidth/2, -float64(h)/2)
|
||||||
op.GeoM.Translate(screenWidth/2, screenHeight/2)
|
op.GeoM.Translate(screenWidth/2, screenHeight/2)
|
||||||
|
r := image.Rect(0, i, w, i+1)
|
||||||
|
op.SourceRect = &r
|
||||||
screen.DrawImage(gophersImage, op)
|
screen.DrawImage(gophersImage, op)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'piano.js';
|
var src = 'piano.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'rotate.js';
|
var src = 'rotate.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -16,7 +16,7 @@ window.addEventListener('load', function() {
|
|||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
var src = 'sprites.js';
|
var src = 'sprites.js';
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/1.4/' + src;
|
src = 'https://hajimehoshi.github.io/ebiten.pagestorage/latest/' + src;
|
||||||
}
|
}
|
||||||
s.src = src;
|
s.src = src;
|
||||||
s.onload = function() {
|
s.onload = function() {
|
||||||
|
@ -33,6 +33,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
@ -42,12 +43,11 @@ import (
|
|||||||
const (
|
const (
|
||||||
screenWidth = 320
|
screenWidth = 320
|
||||||
screenHeight = 240
|
screenHeight = 240
|
||||||
|
maxAngle = 256
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ebitenImage *ebiten.Image
|
ebitenImage *ebiten.Image
|
||||||
ebitenImageWidth = 0
|
|
||||||
ebitenImageHeight = 0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Sprite struct {
|
type Sprite struct {
|
||||||
@ -57,6 +57,7 @@ type Sprite struct {
|
|||||||
y int
|
y int
|
||||||
vx int
|
vx int
|
||||||
vy int
|
vy int
|
||||||
|
angle int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sprite) Update() {
|
func (s *Sprite) Update() {
|
||||||
@ -76,6 +77,8 @@ func (s *Sprite) Update() {
|
|||||||
s.y = 2*(screenHeight-s.imageHeight) - s.y
|
s.y = 2*(screenHeight-s.imageHeight) - s.y
|
||||||
s.vy = -s.vy
|
s.vy = -s.vy
|
||||||
}
|
}
|
||||||
|
s.angle++
|
||||||
|
s.angle %= maxAngle
|
||||||
}
|
}
|
||||||
|
|
||||||
type Sprites struct {
|
type Sprites struct {
|
||||||
@ -89,31 +92,15 @@ func (s *Sprites) Update() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sprites) Len() int {
|
|
||||||
return s.num
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Sprites) Dst(i int) (x0, y0, x1, y1 int) {
|
|
||||||
if s.num <= i {
|
|
||||||
return 0, 0, 0, 0
|
|
||||||
}
|
|
||||||
ss := s.sprites[i]
|
|
||||||
return ss.x, ss.y, ss.x + ebitenImageWidth, ss.y + ebitenImageHeight
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Sprites) Src(i int) (x0, y0, x1, y1 int) {
|
|
||||||
if s.num <= i {
|
|
||||||
return 0, 0, 0, 0
|
|
||||||
}
|
|
||||||
return 0, 0, ebitenImageWidth, ebitenImageHeight
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MinSprites = 0
|
MinSprites = 0
|
||||||
MaxSprites = 50000
|
MaxSprites = 50000
|
||||||
)
|
)
|
||||||
|
|
||||||
var sprites = &Sprites{make([]*Sprite, MaxSprites), 500}
|
var (
|
||||||
|
sprites = &Sprites{make([]*Sprite, MaxSprites), 500}
|
||||||
|
op = &ebiten.DrawImageOptions{}
|
||||||
|
)
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
func update(screen *ebiten.Image) error {
|
||||||
if ebiten.IsKeyPressed(ebiten.KeyLeft) {
|
if ebiten.IsKeyPressed(ebiten.KeyLeft) {
|
||||||
@ -133,29 +120,41 @@ func update(screen *ebiten.Image) error {
|
|||||||
if ebiten.IsRunningSlowly() {
|
if ebiten.IsRunningSlowly() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
op := &ebiten.DrawImageOptions{
|
w, h := ebitenImage.Size()
|
||||||
ImageParts: sprites,
|
for i := 0; i < sprites.num; i++ {
|
||||||
}
|
s := sprites.sprites[i]
|
||||||
op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
|
op.GeoM.Reset()
|
||||||
|
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
|
||||||
|
op.GeoM.Rotate(2 * math.Pi * float64(s.angle) / maxAngle)
|
||||||
|
op.GeoM.Translate(float64(w)/2, float64(h)/2)
|
||||||
|
op.GeoM.Translate(float64(s.x), float64(s.y))
|
||||||
screen.DrawImage(ebitenImage, op)
|
screen.DrawImage(ebitenImage, op)
|
||||||
|
}
|
||||||
msg := fmt.Sprintf(`FPS: %0.2f
|
msg := fmt.Sprintf(`FPS: %0.2f
|
||||||
Num of sprites: %d
|
Num of sprites: %d
|
||||||
Press <- or -> to change the number of sprites`, ebiten.CurrentFPS(), sprites.Len())
|
Press <- or -> to change the number of sprites`, ebiten.CurrentFPS(), sprites.num)
|
||||||
ebitenutil.DebugPrint(screen, msg)
|
if err := ebitenutil.DebugPrint(screen, msg); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest)
|
img, _, err := ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
ebitenImageWidth, ebitenImageHeight = ebitenImage.Size()
|
w, h := img.Size()
|
||||||
|
ebitenImage, _ = ebiten.NewImage(w, h, ebiten.FilterNearest)
|
||||||
|
op := &ebiten.DrawImageOptions{}
|
||||||
|
op.ColorM.Scale(1, 1, 1, 0.5)
|
||||||
|
ebitenImage.DrawImage(img, op)
|
||||||
for i := range sprites.sprites {
|
for i := range sprites.sprites {
|
||||||
w, h := ebitenImage.Size()
|
w, h := ebitenImage.Size()
|
||||||
x, y := rand.Intn(screenWidth-w), rand.Intn(screenHeight-h)
|
x, y := rand.Intn(screenWidth-w), rand.Intn(screenHeight-h)
|
||||||
vx, vy := 2*rand.Intn(2)-1, 2*rand.Intn(2)-1
|
vx, vy := 2*rand.Intn(2)-1, 2*rand.Intn(2)-1
|
||||||
|
a := rand.Intn(maxAngle)
|
||||||
sprites.sprites[i] = &Sprite{
|
sprites.sprites[i] = &Sprite{
|
||||||
imageWidth: w,
|
imageWidth: w,
|
||||||
imageHeight: h,
|
imageHeight: h,
|
||||||
@ -163,6 +162,7 @@ func main() {
|
|||||||
y: y,
|
y: y,
|
||||||
vx: vx,
|
vx: vx,
|
||||||
vy: vy,
|
vy: vy,
|
||||||
|
angle: a,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Sprites (Ebiten Demo)"); err != nil {
|
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Sprites (Ebiten Demo)"); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user