mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
Refactoring
This commit is contained in:
parent
79a68a425b
commit
71606b78a9
@ -11,7 +11,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Sprite struct {
|
type Sprite struct {
|
||||||
texture graphics.Texture
|
width int
|
||||||
|
height int
|
||||||
ch chan bool
|
ch chan bool
|
||||||
x int
|
x int
|
||||||
y int
|
y int
|
||||||
@ -19,12 +20,12 @@ type Sprite struct {
|
|||||||
vy int
|
vy int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSprite(screenWidth, screenHeight int,
|
func NewSprite(screenWidth, screenHeight, width, height int) *Sprite {
|
||||||
texture graphics.Texture) *Sprite {
|
maxX := screenWidth - width
|
||||||
maxX := screenWidth - texture.Width
|
maxY := screenHeight - height
|
||||||
maxY := screenHeight - texture.Height
|
|
||||||
sprite := &Sprite{
|
sprite := &Sprite{
|
||||||
texture: texture,
|
width: width,
|
||||||
|
height: height,
|
||||||
ch: make(chan bool),
|
ch: make(chan bool),
|
||||||
x: rand.Intn(maxX),
|
x: rand.Intn(maxX),
|
||||||
y: rand.Intn(maxY),
|
y: rand.Intn(maxY),
|
||||||
@ -36,8 +37,8 @@ func NewSprite(screenWidth, screenHeight int,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sprite *Sprite) update(screenWidth, screenHeight int) {
|
func (sprite *Sprite) update(screenWidth, screenHeight int) {
|
||||||
maxX := screenWidth - sprite.texture.Width
|
maxX := screenWidth - sprite.width
|
||||||
maxY := screenHeight - sprite.texture.Height
|
maxY := screenHeight - sprite.height
|
||||||
for {
|
for {
|
||||||
<-sprite.ch
|
<-sprite.ch
|
||||||
sprite.x += sprite.vx
|
sprite.x += sprite.vx
|
||||||
@ -91,7 +92,8 @@ func (game *Sprites) Init(tf graphics.TextureFactory) {
|
|||||||
sprite := NewSprite(
|
sprite := NewSprite(
|
||||||
game.ScreenWidth(),
|
game.ScreenWidth(),
|
||||||
game.ScreenHeight(),
|
game.ScreenHeight(),
|
||||||
game.ebitenTexture)
|
game.ebitenTexture.Width,
|
||||||
|
game.ebitenTexture.Height)
|
||||||
game.sprites = append(game.sprites, sprite)
|
game.sprites = append(game.sprites, sprite)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user