-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresources.go
96 lines (87 loc) · 3.15 KB
/
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package kar
import (
"image"
"kar/items"
"kar/res"
"kar/tilemap"
"github.com/setanarut/anim"
"github.com/setanarut/kamera/v2"
)
// ECS Resources
var (
GameDataRes *GameData
TileMapRes *tilemap.TileMap
CraftingTableRes *items.CraftTable
InventoryRes *items.Inventory
AnimPlayerDataRes *AnimPlayerData
CameraRes *kamera.Camera
)
func init() {
GameDataRes = &GameData{CraftingState: false, CraftingState4: false}
CraftingTableRes = items.NewCraftTable()
InventoryRes = items.NewInventory()
TileMapRes = tilemap.MakeTileMap(512, 512, 20, 20)
CameraRes = kamera.NewCamera(0, 0, ScreenW, ScreenH)
PlayerAnimPlayer = 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},
)
PlayerAnimPlayer.NewState("idleRight", 0, 0, 16, 16, 1, false, false, 1)
PlayerAnimPlayer.NewState("idleUp", 208, 0, 16, 16, 1, false, false, 1)
PlayerAnimPlayer.NewState("idleDown", 224, 0, 16, 16, 1, false, false, 1)
PlayerAnimPlayer.NewState("walkRight", 16, 0, 16, 16, 4, false, false, 15)
PlayerAnimPlayer.NewState("jump", 16*5, 0, 16, 16, 1, false, false, 15)
PlayerAnimPlayer.NewState("skidding", 16*6, 0, 16, 16, 1, false, false, 15)
PlayerAnimPlayer.NewState("attackDown", 16*7, 0, 16, 16, 2, false, false, 8)
PlayerAnimPlayer.NewState("attackRight", 144, 0, 16, 16, 2, false, false, 8)
PlayerAnimPlayer.NewState("attackWalk", 0, 16, 16, 16, 4, false, false, 8)
PlayerAnimPlayer.NewState("attackUp", 16*11, 0, 16, 16, 2, false, false, 8)
PlayerAnimPlayer.CurrentState = "idleRight"
AnimPlayerDataRes = NewAnimPlayerData(PlayerAnimPlayer)
}
type GameData struct {
CraftingState bool
CraftingState4 bool
TargetBlockCoord image.Point
}
func NewAnimPlayerData(ap *anim.AnimationPlayer) *AnimPlayerData {
return &AnimPlayerData{
CurrentState: ap.CurrentState,
CurrentAtlas: ap.CurrentAtlas,
Paused: ap.Paused,
Tick: ap.Tick,
CurrentIndex: ap.CurrentIndex,
}
}
func FetchAnimPlayerData(ap *anim.AnimationPlayer, data *AnimPlayerData) {
data.CurrentState = ap.CurrentState
data.CurrentAtlas = ap.CurrentAtlas
data.Paused = ap.Paused
data.Tick = ap.Tick
data.CurrentIndex = ap.CurrentIndex
}
func SetAnimPlayerData(ap *anim.AnimationPlayer, data *AnimPlayerData) {
ap.CurrentState = data.CurrentState
ap.CurrentAtlas = data.CurrentAtlas
ap.Paused = data.Paused
ap.Tick = data.Tick
ap.CurrentIndex = data.CurrentIndex
}
type AnimPlayerData struct {
CurrentState string
CurrentAtlas string
Paused bool
Tick float64
CurrentIndex int
}