1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-09 01:10:43 +00:00

Started work on gameplay scene. (#153)

This commit is contained in:
Tim Sarbin 2019-11-13 00:31:52 -05:00 committed by GitHub
parent 4fa66988d4
commit a8171145f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 10 deletions

View File

@ -126,6 +126,7 @@ const (
// --- GAME UI ---
PentSpin = "/data/global/ui/CURSOR/pentspin.DC6"
MinipanelSmall = "/data/global/ui/PANEL/minipanel_s.dc6"
MinipanelButton = "/data/global/ui/PANEL/minipanelbtn.DC6"

View File

@ -113,6 +113,7 @@ func (v *CharacterSelect) Load() []func() {
func() {
v.okButton = d2ui.CreateButton(d2ui.ButtonTypeMedium, v.fileProvider, d2common.TranslateString("#971"))
v.okButton.MoveTo(625, 537)
v.okButton.OnActivated(func() { v.onOkButtonClicked() })
v.uiManager.AddWidget(&v.okButton)
},
func() {
@ -302,3 +303,7 @@ func (v *CharacterSelect) refreshGameStates() {
v.moveSelectionBox()
}
func (v *CharacterSelect) onOkButtonClicked() {
v.sceneProvider.SetNextScene(CreateGame(v.fileProvider, v.sceneProvider, v.uiManager, v.soundManager, v.gameStates[v.selectedCharacter]))
}

View File

@ -1,9 +1,15 @@
package d2scene
import (
"image/color"
"github.com/OpenDiablo2/OpenDiablo2/d2audio"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core"
"github.com/OpenDiablo2/OpenDiablo2/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2render/d2ui"
"github.com/hajimehoshi/ebiten"
)
@ -14,6 +20,9 @@ type Game struct {
soundManager *d2audio.Manager
fileProvider d2interface.FileProvider
sceneProvider d2interface.SceneProvider
pentSpinLeft d2render.Sprite
pentSpinRight d2render.Sprite
testLabel d2ui.Label
}
func CreateGame(
@ -36,7 +45,23 @@ func CreateGame(
func (v *Game) Load() []func() {
return []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) {
screen.Fill(color.Black)
v.pentSpinLeft.Draw(screen)
v.pentSpinRight.Draw(screen)
v.testLabel.Draw(screen)
}
func (v *Game) Update(tickTime float64) {

View File

@ -217,7 +217,7 @@ func (v *Engine) Update() {
// Draw draws the game
func (v Engine) Draw(screen *ebiten.Image) {
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)
} else {
if v.CurrentScene == nil {

View File

@ -107,7 +107,7 @@ func (v *Font) Draw(x, y int, text string, color color.Color, target *ebiten.Ima
for _, ch := range line {
char := uint8(ch)
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.Draw(target)
xPos += int(metric.Width)

View File

@ -22,9 +22,10 @@ type Sprite struct {
atlas *ebiten.Image
Frames []SpriteFrame
SpecialFrameTime int
AnimateBackwards bool // Because why not
StopOnLastFrame bool
X, Y int
Frame, Direction uint8
Frame, Direction int16
Blend bool
LastFrameTime time.Time
Animate bool
@ -65,6 +66,7 @@ func CreateSprite(data []byte, palette d2datadict.PaletteRec) Sprite {
SpecialFrameTime: -1,
StopOnLastFrame: false,
valid: false,
AnimateBackwards: false,
}
dataPointer := uint32(24)
totalFrames := result.Directions * result.FramesPerDirection
@ -235,12 +237,23 @@ func (v *Sprite) updateAnimation() {
}
for time.Since(v.LastFrameTime) >= timePerFrame {
v.LastFrameTime = v.LastFrameTime.Add(timePerFrame)
v.Frame++
if v.Frame >= uint8(v.FramesPerDirection) {
if !v.AnimateBackwards {
v.Frame++
if v.Frame >= int16(v.FramesPerDirection) {
if v.StopOnLastFrame {
v.Frame = int16(v.FramesPerDirection) - 1
} else {
v.Frame = 0
}
}
continue
}
v.Frame--
if v.Frame < 0 {
if v.StopOnLastFrame {
v.Frame = uint8(v.FramesPerDirection) - 1
} else {
v.Frame = 0
} else {
v.Frame = int16(v.FramesPerDirection) - 1
}
}
}
@ -252,7 +265,7 @@ func (v *Sprite) ResetAnimation() {
}
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