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:
| using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media;
namespace AncientMagic { public static class World { public static int[,] WorldArray; public static List<Tile> TileList = new List<Tile>(); public static List<Enemy> EnemyList = new List<Enemy>(); public static List<Bullet> BulletList = new List<Bullet>();
public static void Load() { bool saveData = false; TileList.RemoveAll(c => c.Position.X > int.MinValue); EnemyList.RemoveAll(c => c.Position.X > int.MinValue); BulletList.RemoveAll(c => c.Position.X > int.MinValue); if (Player.LoadedWorld == new Vector2(0,0)) { WorldArray = new int[,] { {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 3, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0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*50, x*50), 4)); TileList.Add(new Tile(new Vector2(y * 50, x * 50), 0)); } else TileList.Add(new Tile(new Vector2(y*50,x*50), WorldArray[x,y])); } } } }
public static void Update(GameTime gameTime) { foreach(var item in EnemyList) { item.Update(gameTime); }
try { foreach (var item in BulletList) item.Update(gameTime); } catch { } }
public static void Draw(SpriteBatch spriteBatch) { for (int i = 0; i < 3; i++ ) { foreach (var item in TileList.Where(c => c.Layer == i)) spriteBatch.Draw(item.Texture, item.Position, Color.White); if (i == 1) { Player.Draw(spriteBatch);
foreach (var item in EnemyList) { item.Draw(spriteBatch); }
foreach (var item in BulletList) { item.Draw(spriteBatch); }
} }
} } } |