/
WarpManager.cs
106 lines (99 loc) · 4.42 KB
/
WarpManager.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
namespace GameBuild.Game
{
public class WarpManager
{
List<WarpItem> warps;
int warpFileCount;//number of files in folder
string[] warpFiles;//file names
public WarpManager()
{
warpFileCount = Directory.GetFiles(@"Content\Warp\").Length;
warps = new List<WarpItem>();
}
public void UpdateList(string mapName)
{
warps.Clear();
warpFiles = new string[warpFileCount];//initialize the string[] with the amount of files
for (int i = 0; i < warpFileCount; i++)//add a warp item for every file
{
warpFiles[i] = Directory.GetFiles(@"Content\Warp\")[i];
StreamReader reader = new StreamReader(warpFiles[i]);
WarpItem warp = new WarpItem(reader.ReadLine(), int.Parse(reader.ReadLine()), int.Parse(reader.ReadLine()), int.Parse(reader.ReadLine()),
int.Parse(reader.ReadLine()), reader.ReadLine(), int.Parse(reader.ReadLine()), int.Parse(reader.ReadLine()), reader.ReadLine());
reader.Close();
if (warp.isOnMap)
{
warps.Add(warp);
}
}
//for (int i = 0; i < warps.Count; i++)
//{
// Console.WriteLine(warps[i].sourceMap);
// WarpItem w = new WarpItem(reader.ReadLine(), int.Parse(reader.ReadLine()), int.Parse(reader.ReadLine()), int.Parse(reader.ReadLine()),
// int.Parse(reader.ReadLine()), reader.ReadLine(), int.Parse(reader.ReadLine()), int.Parse(reader.ReadLine()), reader.ReadLine());
// reader.Close();
// Console.WriteLine(w.sourceMap);
// if (w.sourceMap == mapName.Remove(mapName.Length-1))
// {
// warps.Add(w);
// Console.WriteLine("Added warp mofo");
// }
//}
}
public void Warp(WarpItem warp, string key, int targetX, int targetY, string map, Game1 game)//the key to unlock the door, targeted x coordinate, targeted y coordinate, targeted map
{
//UpdateList(Game1.map.mapName);
for (int x = 0; x < Game1.character.inventory.width; x++)//player inventory slots
{
for (int y = 0; y < Game1.character.inventory.height; y++)
{
if ((Game1.character.inventory.inventorySlot[x, y].item == key || key == "."))//checks if the player has the key or if the key is ".", aka no key required
{
Game1.map = game.Content.Load<H_Map.TileMap>(@"Map\" + map);
Game1.map.tileset = game.Content.Load<Texture2D>(@"Game\tileset");
if (warp.targetX != -1)//warp the X value if it isnt -1(tha player's X value)
{
Game1.character.position.X = warp.targetX;
}
if (warp.targetY != -1)//warp the Y value if it isnt -1(tha player's Y value)
{
Game1.character.position.Y = warp.targetY;
}
break;
}
else
{
Console.WriteLine("locked");
break;
}
}
}
}
public void Update(Game1 game)
{
UpdateList(Game1.map.mapName);
for (int i = 0; i < warps.Count; i++)
{
if (Game1.character.attackRectangle.Intersects(warps[i].warpField))
{
Warp(warps[i], warps[i].key, warps[i].targetX, warps[i].targetY, warps[i].targetMap, game);
}
}
}
public void Draw(SpriteBatch spriteBatch, Game1 game)
{
for (int i = 0; i < warps.Count; i++)
{
spriteBatch.Draw(game.screenTexture, warps[i].warpField, new Color(100, 100, 100, 100));
spriteBatch.DrawString(game.spriteFont, warps[i].targetMap, new Vector2(warps[i].warpField.X, warps[i].warpField.Y), Color.Red);
}
}
}
}