-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathecs_resources.go
82 lines (73 loc) · 2.8 KB
/
ecs_resources.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package kar
import (
"image"
"kar/items"
"kar/res"
"kar/tilemap"
"github.com/mlange-42/ark/ecs"
"github.com/setanarut/anim"
"github.com/setanarut/kamera/v2"
)
// ECS Resources
var (
animPlayer *anim.AnimationPlayer
animDefaultPlaybackData anim.PlaybackData
cameraRes *kamera.Camera
craftingTableRes *items.CraftTable
gameDataRes *gameData
inventoryRes *items.Inventory
tileMapRes *tilemap.TileMap
mapResAnimPlaybackData = ecs.NewResource[anim.PlaybackData](&world)
mapResCamera = ecs.NewResource[kamera.Camera](&world)
mapRescraftingtable = ecs.NewResource[items.CraftTable](&world)
mapResgameData = ecs.NewResource[gameData](&world)
mapResinventory = ecs.NewResource[items.Inventory](&world)
mapRestilemap = ecs.NewResource[tilemap.TileMap](&world)
)
// GameplayStates
const (
Playing int = iota
CraftingTable3x3
Crafting2x2
Furnace1x2
)
type gameData struct {
GameplayState int
TargetBlockCoord image.Point
IsRayHit bool
BlockHealth float64
}
func init() {
gameDataRes = &gameData{GameplayState: Playing}
craftingTableRes = items.NewCraftTable()
inventoryRes = items.NewInventory()
tileMapRes = tilemap.MakeTileMap(512, 512, 20, 20)
cameraRes = kamera.NewCamera(0, 0, ScreenSize.X, ScreenSize.Y)
animPlayer = anim.NewAnimationPlayer(
&anim.Atlas{"Default", res.Player},
&anim.Atlas{"WoodenAxe", res.PlayerWoodenAxeAtlas},
&anim.Atlas{"StoneAxe", res.PlayerStoneAxeAtlas},
&anim.Atlas{"IronAxe", res.PlayerIronAxeAtlas},
&anim.Atlas{"DiamondAxe", res.PlayerDiamondAxeAtlas},
&anim.Atlas{"WoodenPickaxe", res.PlayerWoodenPickaxeAtlas},
&anim.Atlas{"StonePickaxe", res.PlayerStonePickaxeAtlas},
&anim.Atlas{"IronPickaxe", res.PlayerIronPickaxeAtlas},
&anim.Atlas{"DiamondPickaxe", res.PlayerDiamondPickaxeAtlas},
&anim.Atlas{"WoodenShovel", res.PlayerWoodenShovelAtlas},
&anim.Atlas{"StoneShovel", res.PlayerStoneShovelAtlas},
&anim.Atlas{"IronShovel", res.PlayerIronShovelAtlas},
&anim.Atlas{"DiamondShovel", res.PlayerDiamondShovelAtlas},
)
animPlayer.NewAnim("idleRight", 0, 0, 16, 16, 1, false, false, 1)
animPlayer.NewAnim("idleUp", 208, 0, 16, 16, 1, false, false, 1)
animPlayer.NewAnim("idleDown", 224, 0, 16, 16, 1, false, false, 1)
animPlayer.NewAnim("walkRight", 16, 0, 16, 16, 4, false, false, 15)
animPlayer.NewAnim("jump", 16*5, 0, 16, 16, 1, false, false, 15)
animPlayer.NewAnim("skidding", 16*6, 0, 16, 16, 1, false, false, 15)
animPlayer.NewAnim("attackDown", 16*7, 0, 16, 16, 2, false, false, 8)
animPlayer.NewAnim("attackRight", 144, 0, 16, 16, 2, false, false, 8)
animPlayer.NewAnim("attackWalk", 0, 16, 16, 16, 4, false, false, 8)
animPlayer.NewAnim("attackUp", 16*11, 0, 16, 16, 2, false, false, 8)
animPlayer.SetAnim("idleRight")
animDefaultPlaybackData = *animPlayer.Data
}