mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-13 20:16:41 -05:00
Started work on gameplay scene. (#153)
This commit is contained in:
parent
4fa66988d4
commit
a8171145f9
@ -126,6 +126,7 @@ const (
|
|||||||
|
|
||||||
// --- GAME UI ---
|
// --- GAME UI ---
|
||||||
|
|
||||||
|
PentSpin = "/data/global/ui/CURSOR/pentspin.DC6"
|
||||||
MinipanelSmall = "/data/global/ui/PANEL/minipanel_s.dc6"
|
MinipanelSmall = "/data/global/ui/PANEL/minipanel_s.dc6"
|
||||||
MinipanelButton = "/data/global/ui/PANEL/minipanelbtn.DC6"
|
MinipanelButton = "/data/global/ui/PANEL/minipanelbtn.DC6"
|
||||||
|
|
||||||
|
@ -113,6 +113,7 @@ func (v *CharacterSelect) Load() []func() {
|
|||||||
func() {
|
func() {
|
||||||
v.okButton = d2ui.CreateButton(d2ui.ButtonTypeMedium, v.fileProvider, d2common.TranslateString("#971"))
|
v.okButton = d2ui.CreateButton(d2ui.ButtonTypeMedium, v.fileProvider, d2common.TranslateString("#971"))
|
||||||
v.okButton.MoveTo(625, 537)
|
v.okButton.MoveTo(625, 537)
|
||||||
|
v.okButton.OnActivated(func() { v.onOkButtonClicked() })
|
||||||
v.uiManager.AddWidget(&v.okButton)
|
v.uiManager.AddWidget(&v.okButton)
|
||||||
},
|
},
|
||||||
func() {
|
func() {
|
||||||
@ -302,3 +303,7 @@ func (v *CharacterSelect) refreshGameStates() {
|
|||||||
v.moveSelectionBox()
|
v.moveSelectionBox()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *CharacterSelect) onOkButtonClicked() {
|
||||||
|
v.sceneProvider.SetNextScene(CreateGame(v.fileProvider, v.sceneProvider, v.uiManager, v.soundManager, v.gameStates[v.selectedCharacter]))
|
||||||
|
}
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
package d2scene
|
package d2scene
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image/color"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2audio"
|
"github.com/OpenDiablo2/OpenDiablo2/d2audio"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2core"
|
"github.com/OpenDiablo2/OpenDiablo2/d2core"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2data/d2datadict"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2render"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2render/d2ui"
|
"github.com/OpenDiablo2/OpenDiablo2/d2render/d2ui"
|
||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
)
|
)
|
||||||
@ -14,6 +20,9 @@ type Game struct {
|
|||||||
soundManager *d2audio.Manager
|
soundManager *d2audio.Manager
|
||||||
fileProvider d2interface.FileProvider
|
fileProvider d2interface.FileProvider
|
||||||
sceneProvider d2interface.SceneProvider
|
sceneProvider d2interface.SceneProvider
|
||||||
|
pentSpinLeft d2render.Sprite
|
||||||
|
pentSpinRight d2render.Sprite
|
||||||
|
testLabel d2ui.Label
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateGame(
|
func CreateGame(
|
||||||
@ -36,7 +45,23 @@ func CreateGame(
|
|||||||
func (v *Game) Load() []func() {
|
func (v *Game) Load() []func() {
|
||||||
return []func(){
|
return []func(){
|
||||||
func() {
|
func() {
|
||||||
|
v.pentSpinLeft = d2render.CreateSprite(v.fileProvider.LoadFile(d2resource.PentSpin), d2datadict.Palettes[d2enum.Sky])
|
||||||
|
v.pentSpinLeft.Animate = true
|
||||||
|
v.pentSpinLeft.AnimateBackwards = true
|
||||||
|
v.pentSpinLeft.SpecialFrameTime = 475
|
||||||
|
v.pentSpinLeft.MoveTo(100, 300)
|
||||||
|
},
|
||||||
|
func() {
|
||||||
|
v.pentSpinRight = d2render.CreateSprite(v.fileProvider.LoadFile(d2resource.PentSpin), d2datadict.Palettes[d2enum.Sky])
|
||||||
|
v.pentSpinRight.Animate = true
|
||||||
|
v.pentSpinRight.SpecialFrameTime = 475
|
||||||
|
v.pentSpinRight.MoveTo(650, 300)
|
||||||
|
},
|
||||||
|
func() {
|
||||||
|
v.testLabel = d2ui.CreateLabel(v.fileProvider, d2resource.Font42, d2enum.Units)
|
||||||
|
v.testLabel.Alignment = d2ui.LabelAlignCenter
|
||||||
|
v.testLabel.SetText("Soon :tm:")
|
||||||
|
v.testLabel.MoveTo(400, 250)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,7 +71,10 @@ func (v *Game) Unload() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v Game) Render(screen *ebiten.Image) {
|
func (v Game) Render(screen *ebiten.Image) {
|
||||||
|
screen.Fill(color.Black)
|
||||||
|
v.pentSpinLeft.Draw(screen)
|
||||||
|
v.pentSpinRight.Draw(screen)
|
||||||
|
v.testLabel.Draw(screen)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Game) Update(tickTime float64) {
|
func (v *Game) Update(tickTime float64) {
|
||||||
|
@ -217,7 +217,7 @@ func (v *Engine) Update() {
|
|||||||
// Draw draws the game
|
// Draw draws the game
|
||||||
func (v Engine) Draw(screen *ebiten.Image) {
|
func (v Engine) Draw(screen *ebiten.Image) {
|
||||||
if v.loadingProgress < 1.0 {
|
if v.loadingProgress < 1.0 {
|
||||||
v.LoadingSprite.Frame = uint8(d2helper.Max(0, d2helper.Min(uint32(len(v.LoadingSprite.Frames)-1), uint32(float64(len(v.LoadingSprite.Frames)-1)*v.loadingProgress))))
|
v.LoadingSprite.Frame = int16(d2helper.Max(0, d2helper.Min(uint32(len(v.LoadingSprite.Frames)-1), uint32(float64(len(v.LoadingSprite.Frames)-1)*v.loadingProgress))))
|
||||||
v.LoadingSprite.Draw(screen)
|
v.LoadingSprite.Draw(screen)
|
||||||
} else {
|
} else {
|
||||||
if v.CurrentScene == nil {
|
if v.CurrentScene == nil {
|
||||||
|
@ -107,7 +107,7 @@ func (v *Font) Draw(x, y int, text string, color color.Color, target *ebiten.Ima
|
|||||||
for _, ch := range line {
|
for _, ch := range line {
|
||||||
char := uint8(ch)
|
char := uint8(ch)
|
||||||
metric := v.metrics[char]
|
metric := v.metrics[char]
|
||||||
v.fontSprite.Frame = char
|
v.fontSprite.Frame = int16(char)
|
||||||
v.fontSprite.MoveTo(xPos, y+int(v.fontSprite.Frames[char].Height))
|
v.fontSprite.MoveTo(xPos, y+int(v.fontSprite.Frames[char].Height))
|
||||||
v.fontSprite.Draw(target)
|
v.fontSprite.Draw(target)
|
||||||
xPos += int(metric.Width)
|
xPos += int(metric.Width)
|
||||||
|
@ -22,9 +22,10 @@ type Sprite struct {
|
|||||||
atlas *ebiten.Image
|
atlas *ebiten.Image
|
||||||
Frames []SpriteFrame
|
Frames []SpriteFrame
|
||||||
SpecialFrameTime int
|
SpecialFrameTime int
|
||||||
|
AnimateBackwards bool // Because why not
|
||||||
StopOnLastFrame bool
|
StopOnLastFrame bool
|
||||||
X, Y int
|
X, Y int
|
||||||
Frame, Direction uint8
|
Frame, Direction int16
|
||||||
Blend bool
|
Blend bool
|
||||||
LastFrameTime time.Time
|
LastFrameTime time.Time
|
||||||
Animate bool
|
Animate bool
|
||||||
@ -65,6 +66,7 @@ func CreateSprite(data []byte, palette d2datadict.PaletteRec) Sprite {
|
|||||||
SpecialFrameTime: -1,
|
SpecialFrameTime: -1,
|
||||||
StopOnLastFrame: false,
|
StopOnLastFrame: false,
|
||||||
valid: false,
|
valid: false,
|
||||||
|
AnimateBackwards: false,
|
||||||
}
|
}
|
||||||
dataPointer := uint32(24)
|
dataPointer := uint32(24)
|
||||||
totalFrames := result.Directions * result.FramesPerDirection
|
totalFrames := result.Directions * result.FramesPerDirection
|
||||||
@ -235,14 +237,25 @@ func (v *Sprite) updateAnimation() {
|
|||||||
}
|
}
|
||||||
for time.Since(v.LastFrameTime) >= timePerFrame {
|
for time.Since(v.LastFrameTime) >= timePerFrame {
|
||||||
v.LastFrameTime = v.LastFrameTime.Add(timePerFrame)
|
v.LastFrameTime = v.LastFrameTime.Add(timePerFrame)
|
||||||
|
if !v.AnimateBackwards {
|
||||||
v.Frame++
|
v.Frame++
|
||||||
if v.Frame >= uint8(v.FramesPerDirection) {
|
if v.Frame >= int16(v.FramesPerDirection) {
|
||||||
if v.StopOnLastFrame {
|
if v.StopOnLastFrame {
|
||||||
v.Frame = uint8(v.FramesPerDirection) - 1
|
v.Frame = int16(v.FramesPerDirection) - 1
|
||||||
} else {
|
} else {
|
||||||
v.Frame = 0
|
v.Frame = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
v.Frame--
|
||||||
|
if v.Frame < 0 {
|
||||||
|
if v.StopOnLastFrame {
|
||||||
|
v.Frame = 0
|
||||||
|
} else {
|
||||||
|
v.Frame = int16(v.FramesPerDirection) - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +265,7 @@ func (v *Sprite) ResetAnimation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v Sprite) OnLastFrame() bool {
|
func (v Sprite) OnLastFrame() bool {
|
||||||
return v.Frame == uint8(v.FramesPerDirection-1)
|
return v.Frame == int16(v.FramesPerDirection-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFrameSize returns the size of the specific frame
|
// GetFrameSize returns the size of the specific frame
|
||||||
|
Loading…
Reference in New Issue
Block a user