forked from OpenDiablo2/OpenDiablo2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for missiles (OpenDiablo2#308)
* WIP: Add support for missiles Break AnimatedEntity into two parts to support single and composite animations. Summon misssiles on right click. * Break animated entity down further Move npc only logic to npc struct, reduce duplication in map entities * Change a bunch of int32s to int
- Loading branch information
1 parent
2953d21
commit bdfdeda
Showing
17 changed files
with
461 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package d2common | ||
|
||
type Path struct { | ||
X int32 | ||
Y int32 | ||
Action int32 | ||
X int | ||
Y int | ||
Action int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package d2map | ||
|
||
import ( | ||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict" | ||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" | ||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset" | ||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render" | ||
) | ||
|
||
// AnimatedComposite represents a composite of animations that can be projected onto the map. | ||
type AnimatedComposite struct { | ||
mapEntity | ||
animationMode string | ||
composite *d2asset.Composite | ||
direction int | ||
} | ||
|
||
// CreateAnimatedComposite creates an instance of AnimatedComposite | ||
func CreateAnimatedComposite(x, y int, object *d2datadict.ObjectLookupRecord, palettePath string) (*AnimatedComposite, error) { | ||
composite, err := d2asset.LoadComposite(object, palettePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
entity := &AnimatedComposite{ | ||
mapEntity: createMapEntity(x, y), | ||
composite: composite, | ||
} | ||
entity.mapEntity.directioner = entity.rotate | ||
return entity, nil | ||
} | ||
|
||
func (ac *AnimatedComposite) SetAnimationMode(animationMode string) error { | ||
return ac.composite.SetMode(animationMode, ac.weaponClass, ac.direction) | ||
} | ||
|
||
// SetMode changes the graphical mode of this animated entity | ||
func (ac *AnimatedComposite) SetMode(animationMode, weaponClass string, direction int) error { | ||
ac.animationMode = animationMode | ||
ac.direction = direction | ||
|
||
err := ac.composite.SetMode(animationMode, weaponClass, direction) | ||
if err != nil { | ||
err = ac.composite.SetMode(animationMode, "HTH", direction) | ||
ac.weaponClass = "HTH" | ||
} | ||
|
||
return err | ||
} | ||
|
||
// Render draws this animated entity onto the target | ||
func (ac *AnimatedComposite) Render(target d2render.Surface) { | ||
target.PushTranslation( | ||
ac.offsetX+int((ac.subcellX-ac.subcellY)*16), | ||
ac.offsetY+int(((ac.subcellX+ac.subcellY)*8)-5), | ||
) | ||
defer target.Pop() | ||
ac.composite.Render(target) | ||
} | ||
|
||
// rotate sets direction and changes animation | ||
func (ac *AnimatedComposite) rotate(angle float64) { | ||
// TODO: Check if is in town and if is player. | ||
newAnimationMode := ac.animationMode | ||
if !ac.IsAtTarget() { | ||
newAnimationMode = d2enum.AnimationModeMonsterWalk.String() | ||
} | ||
|
||
if newAnimationMode != ac.animationMode { | ||
ac.SetMode(newAnimationMode, ac.weaponClass, ac.direction) | ||
} | ||
|
||
newDirection := angleToDirection(angle, ac.composite.GetDirectionCount()) | ||
if newDirection != ac.direction { | ||
ac.SetMode(ac.animationMode, ac.weaponClass, newDirection) | ||
} | ||
} | ||
|
||
func (ac *AnimatedComposite) Advance(elapsed float64) { | ||
ac.composite.Advance(elapsed) | ||
} |
Oops, something went wrong.