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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
using System.Collections.Generic;
using Celesteia.Game.Components;
using Celesteia.Game.ECS;
using Celesteia.Game.Items;
using Celesteia.Graphics.Lighting;
using Celesteia.Resources.Types;
using Celesteia.Resources.Types.Builders;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended.TextureAtlases;
/*
A collection of resources for the base game.
*/
namespace Celesteia.Resources.Collections {
public class BaseCollection : IResourceCollection
{
public NamespacedKey GetKey(string index) => NamespacedKey.Base(index);
private ContentManager _content;
public BaseCollection(ContentManager Content) {
_content = Content;
}
public Dictionary<NamespacedKey, BlockType> GetBlocks() => LoadBlocks();
private Dictionary<NamespacedKey, BlockType> blocks;
private Dictionary<NamespacedKey, BlockType> LoadBlocks(int pixelSize = 8) {
if (blocks != null) return blocks;
void AddBlock(string index, BlockType type) => blocks.Add(GetKey(index), type);
TextureAtlas _atlas = TextureAtlas.Create("blocks", _content.Load<Texture2D>("sprites/blocks"), pixelSize, pixelSize);
BlockTypeBuilder builder = new BlockTypeBuilder(_atlas);
blocks = new Dictionary<NamespacedKey, BlockType>();
AddBlock("air", builder.WithName("Air").Invisible().Get());
AddBlock("grown_soil", builder.WithName("Grown Soil").Full().Frames(0).Properties(
strength: 5,
drop: GetKey("soil")
).Get());
AddBlock("soil", builder.WithName("Soil").Full().Frames(1).Properties(
strength: 5,
drop: GetKey("soil")
).Get());
AddBlock("stone", builder.WithName("Stone").Full().Frames(2).Properties(
strength: 7,
drop: GetKey("stone")
).Get());
AddBlock("deepstone", builder.WithName("Deepstone").Full().Frames(3).Properties(
strength: -1,
drop: GetKey("deepstone")
).Get());
AddBlock("log", builder.WithName("Wooden Log").Full().Frames(10).Properties(
strength: 2,
drop: GetKey("log")
).Get());
AddBlock("leaves", builder.WithName("Leaves").Walkthrough().Frames(11).Properties(
translucent: true,
strength: 1,
light: new BlockLightProperties(LightColor.black, 0, false)
).Get());
AddBlock("iron_ore", builder.WithName("Iron Ore").Full().Frames(8).Properties(
strength: 15,
drop: GetKey("iron_ore")
).Get());
AddBlock("copper_ore", builder.WithName("Copper Ore").Full().Frames(7).Properties(
strength: 10,
drop: GetKey("copper_ore")
).Get());
AddBlock("coal_ore", builder.WithName("Coal Ore").Full().Frames(14).Properties(
strength: 10,
drop: GetKey("coal")
).Get());
AddBlock("wooden_planks", builder.WithName("Wooden Planks").Full().Frames(4).Properties(
strength: 4,
drop: GetKey("wooden_planks")
).Get());
AddBlock("torch", builder.WithName("Torch").Walkthrough().Frames(9).Properties(
translucent: true,
strength: 1,
drop: GetKey("wooden_torch"),
light: new BlockLightProperties(LightColor.white, 6, false)
).Get());
AddBlock("stone_bricks", builder.WithName("Stone Bricks").Frames(6).Full().Properties(
strength: 7,
drop: GetKey("stone_bricks")
).Get());
AddBlock("unyx_bricks", builder.WithName("Unyx Bricks").Frames(12).Full().Properties(
strength: 10,
drop: GetKey("unyx_bricks")
).Get());
AddBlock("unyx_eyestone", builder.WithName("Unyx Eyestone").Frames(13).Full().Properties(
strength: 10,
drop: GetKey("unyx_eyestone"),
light: new BlockLightProperties(new LightColor(230f, 74f, 255f), 5, true)
).Get());
AddBlock("scorched_soil", builder.WithName("Scorched Soil").Frames(15).Full().Properties(
strength: -1
).Get());
AddBlock("blue_flower", builder.WithName("Morning Stars").Frames(16).Walkthrough().Properties(
strength: 1,
drop: GetKey("blue_flower_bundle"),
light: new BlockLightProperties(LightColor.black, 0, false)
).Get());
AddBlock("red_flower", builder.WithName("Red Tears").Frames(17).Walkthrough().Properties(
strength: 1,
drop: GetKey("red_flower_bundle"),
light: new BlockLightProperties(LightColor.black, 0, false)
).Get());
AddBlock("violet_flower", builder.WithName("Colupria").Frames(18).Walkthrough().Properties(
strength: 1,
drop: GetKey("violet_flower_bundle"),
light: new BlockLightProperties(LightColor.black, 0, false)
).Get());
AddBlock("grass", builder.WithName("Grass").Frames(19).Walkthrough().Properties(
strength: 1,
light: new BlockLightProperties(LightColor.black, 0, false)
).Get());
AddBlock("crashed_capsule_base", builder.WithName("Crashed Capsule").UniqueFrames(
TextureAtlas.Create("cc", _content.Load<Texture2D>("sprites/crashed_capsule"), pixelSize * 3, pixelSize * 3), 0, 1,
new Vector2(pixelSize * 1, pixelSize * 2)
).Walkthrough().Properties(
translucent: true,
strength: -1,
light: new BlockLightProperties(LightColor.black, 0, false)
).Get());
AddBlock("crashed_capsule_frame", builder.WithName("Crashed Capsule").Invisible().Properties(
translucent: true,
strength: -1,
light: new BlockLightProperties(LightColor.black, 0, false)
).Get());
return blocks;
}
public Dictionary<NamespacedKey, ItemType> GetItems() => LoadItems();
private Dictionary<NamespacedKey, ItemType> items;
private Dictionary<NamespacedKey, ItemType> LoadItems(int pixelSize = 16) {
if (items != null) return items;
void AddItem(string index, ItemType type) => items.Add(GetKey(index), type);
TextureAtlas _atlas = TextureAtlas.Create("items", _content.Load<Texture2D>("sprites/items"), pixelSize, pixelSize);
ItemTypeBuilder builder = new ItemTypeBuilder(_atlas);
items = new Dictionary<NamespacedKey, ItemType>();
if (blocks != null) {
foreach (KeyValuePair<NamespacedKey, BlockType> pair in blocks) {
if (pair.Value.Frames == null) continue;
AddItem(pair.Key.Index, builder.WithName(pair.Value.Name).Block(pair.Key).Frame(pair.Value.Frames.GetFrame(0).GetRegion()).Get());
}
}
AddItem("iron_pickaxe", builder.WithName("Iron Pickaxe").Pickaxe(4).Frame(0).Get());
AddItem("wooden_log", builder.WithName("Wooden Log").Frame(1).Block(NamespacedKey.Base("log")).Get());
AddItem("coal", builder.WithName("Coal Lump").Frame(2).Get());
AddItem("plank", builder.WithName("Plank").Frame(3).Get());
AddItem("copper_ingot", builder.WithName("Copper Ingot").Frame(4).Get());
AddItem("iron_ingot", builder.WithName("Iron Ingot").Frame(5).Get());
AddItem("fuel_tank", builder.WithName("Fuel Tank").Frame(6).Upgrade(EntityAttribute.JumpFuel, 0.5f, 5f).Get());
AddItem("wooden_torch", builder.WithName("Wooden Torch").Template(new ItemTypeTemplate(1000, true))
.Frame(7).Actions(new TorchItemActions(NamespacedKey.Base("torch"))).Get());
AddItem("blue_flower_bundle", builder.WithName("Morning Stars").Template(new ItemTypeTemplate(1000, true))
.Frame(10).Actions(new FoliageItemActions(NamespacedKey.Base("blue_flower"))).Get());
AddItem("red_flower_bundle", builder.WithName("Red Tears").Template(new ItemTypeTemplate(1000, true))
.Frame(11).Actions(new FoliageItemActions(NamespacedKey.Base("red_flower"))).Get());
AddItem("violet_flower_bundle", builder.WithName("Colupria").Template(new ItemTypeTemplate(1000, true))
.Frame(12).Actions(new FoliageItemActions(NamespacedKey.Base("violet_flower"))).Get());
return items;
}
public Dictionary<NamespacedKey, Recipe> GetRecipes() => LoadRecipes();
private Dictionary<NamespacedKey, Recipe> recipes;
private Dictionary<NamespacedKey, Recipe> LoadRecipes() {
if (recipes != null) return recipes;
void AddRecipe(string index, Recipe type) => recipes.Add(GetKey(index), type);
recipes = new Dictionary<NamespacedKey, Recipe>();
AddRecipe("plank_ingredient", new Recipe(new Part(GetKey("plank"), 4), new Part(GetKey("log"), 1)));
AddRecipe("plank_block", new Recipe(new Part(GetKey("wooden_planks"), 1), new Part(GetKey("plank"), 2)));
AddRecipe("copper_smelt", new Recipe(new Part(GetKey("copper_ingot"), 1), new Part(GetKey("copper_ore"), 1)));
AddRecipe("iron_smelt", new Recipe(new Part(GetKey("iron_ingot"), 1), new Part(GetKey("iron_ore"), 1)));
AddRecipe("fuel_tank", new Recipe(new Part(GetKey("fuel_tank"), 1), new Part(GetKey("iron_ingot"), 10), new Part(GetKey("copper_ingot"), 5)));
AddRecipe("torches", new Recipe(new Part(GetKey("wooden_torch"), 4), new Part(GetKey("plank"), 1), new Part(GetKey("coal"), 1)));
AddRecipe("stone_brick", new Recipe(new Part(GetKey("stone_bricks"), 4), new Part(GetKey("stone"), 4)));
return recipes;
}
public Dictionary<NamespacedKey, EntityType> GetEntities() => LoadEntities();
private Dictionary<NamespacedKey, EntityType> entities;
private Dictionary<NamespacedKey, EntityType> LoadEntities() {
if (entities != null) return entities;
void AddEntity(string index, EntityType type) => entities.Add(GetKey(index), type);
entities = new Dictionary<NamespacedKey, EntityType>();
AddEntity("player", new EntityType((e) => EntityFactory.BuildPlayer(e, _content.Load<Texture2D>("sprites/entities/player/astronaut"))));
return entities;
}
}
}
|