/// <summary> /// Creates a new instance of engine for the game /// </summary> private Engine() { engineState = new PlayState(); TimerManager.RegisterTimer("Can Act", .25f); GameAction invoke = new GameAction( this, this.GetType().GetMethod("Select"), new object[0]); InputManager.AddToKeyboardMap(Keys.Enter, invoke); InputManager.AddToKeyboardMap(Keys.LeftShift, invoke); }
/// <summary> /// Creates an Effect which invokes a GameAction /// </summary> /// <param name="gameAction">The GameAction to invoke</param> public Effect(GameAction gameAction) { this.gameAction = gameAction; }
/// <summary> /// Sets up the input for the player /// </summary> public void SetUpInput() { GameAction up = new GameAction( this, this.GetType().GetMethod("Up"), new object[0]); InputManager.AddToKeyboardMap(Keys.Up, up); InputManager.AddToKeyboardMap(Keys.W, up); GameAction down = new GameAction( this, this.GetType().GetMethod("Down"), new object[0]); InputManager.AddToKeyboardMap(Keys.Down, down); InputManager.AddToKeyboardMap(Keys.S, down); GameAction left = new GameAction( this, this.GetType().GetMethod("Left"), new object[0]); InputManager.AddToKeyboardMap(Keys.Left, left); InputManager.AddToKeyboardMap(Keys.A, left); GameAction right = new GameAction( this, this.GetType().GetMethod("Right"), new object[0]); InputManager.AddToKeyboardMap(Keys.Right, right); InputManager.AddToKeyboardMap(Keys.D, right); object[] plusDrugParameters = { 0.1m }; GameAction plusDrug = new GameAction( this, this.GetType().GetMethod("Drug"), plusDrugParameters); InputManager.AddToKeyboardMap(Keys.P, plusDrug); object[] minusDrugParameters = { -0.1m }; GameAction minusDrug = new GameAction( this, this.GetType().GetMethod("Drug"), minusDrugParameters); InputManager.AddToKeyboardMap(Keys.O, minusDrug); GameAction use = new GameAction( this, this.GetType().GetMethod("Use", new Type[0]), new object[0]); InputManager.AddToKeyboardMap(Keys.Space, use); InputManager.AddToKeyboardMap(Keys.NumPad0, use); GameAction nextItem = new GameAction( this, this.GetType().GetMethod("NextItem"), new object[0]); InputManager.AddToKeyboardMap(Keys.E, nextItem); GameAction prevItem = new GameAction( this, this.GetType().GetMethod("PrevItem"), new object[0]); InputManager.AddToKeyboardMap(Keys.Q, prevItem); // there has GOT to be a better way to do this // also, the number 1 doesnt work for some reason Keys[] numKeys = { Keys.D1, Keys.D2, Keys.D3, Keys.D4, Keys.D5, Keys.D6, Keys.D7, Keys.D8, Keys.D9 }; Keys[] numPadKeys = { Keys.NumPad1, Keys.NumPad2, Keys.NumPad3, Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, Keys.NumPad8, Keys.NumPad9 }; for (int i = 0; i < Math.Min(9, Inventory.NUM_SLOTS); i++) { object[] parameters = { i }; Type[] types = { i.GetType() }; GameAction select = new GameAction( this, this.GetType().GetMethod("Use",types), parameters); InputManager.AddToKeyboardMap(numKeys[i], select); InputManager.AddToKeyboardMap(numPadKeys[i], select); } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { Vector2 screenSize = new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); // engine intialization GameAction debug = new GameAction( null, Engine.GetInstance().GetType().GetMethod("Debug"), new object[0]); InputManager.AddToKeyboardMap(Keys.OemQuestion, debug); Dictionary<string, string> gameFiles = new Dictionary<string, string>(); gameFiles.Add("playersFile", ""); gameFiles.Add("itemsFile", ""); gameFiles.Add("blocksFile", ""); gameFiles.Add("enemiesFile", ""); gameFiles.Add("levelsFile", ""); StreamReader reader = new StreamReader("Content/LRE/rob_game.txt"); rootPath = reader.ReadLine().Split(delimeter, StringSplitOptions.RemoveEmptyEntries)[1] + "/"; Content.RootDirectory = rootPath; while (reader.Peek() >= 0) { string[] line = reader.ReadLine().Split(delimeter, StringSplitOptions.RemoveEmptyEntries); if(gameFiles.ContainsKey(line[0])) { gameFiles[line[0]] = rootPath + line[1]; } } // player manager intialization PlayerManager.AddPlayer(Content.Load<Texture2D>("Players/player1"), 24, 24, Content.Load<Texture2D>("HUD/selected"), Content.Load<Texture2D>("HUD/unselected")); // item manager intialization LoadItems(gameFiles["itemsFile"]); // level intialization LoadBlocks(gameFiles["blocksFile"]); LoadLevels(gameFiles["levelsFile"]); // load first level Level.GetInstance().LoadLevel(0); // HUD intialization HUD.GetInstance().setInventory(ItemManager.inventories[0]); HUD.GetInstance().setScreenSize(screenSize); SpriteFont font = Content.Load<SpriteFont>("Arial"); HUD.GetInstance().setScoreData(new Vector2(0, 0), font); HUD.GetInstance().setTimerData(new Vector2(0, 20), font); HUD.GetInstance().setFont(font); HUD.GetInstance().overlay = new Sprite(Content.Load<Texture2D>("HUD/overlay"), new Vector2(screenSize.X/2, screenSize.Y/2)); base.Initialize(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { Vector2 screenSize = new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); // engine intialization GameAction skip = new GameAction( null, Level.GetInstance().GetType().GetMethod("NextLevel"), new object[0]); InputManager.AddToKeyboardMap(Keys.I, skip); Dictionary<string, string> gameFiles = new Dictionary<string, string>(); gameFiles.Add("playersFile", ""); gameFiles.Add("itemsFile", ""); gameFiles.Add("blocksFile", ""); gameFiles.Add("enemiesFile", ""); gameFiles.Add("levelsFile", ""); StreamReader reader = new StreamReader("Content/LRE_game.txt"); rootPath = reader.ReadLine().Split(delimeter, StringSplitOptions.RemoveEmptyEntries)[1] + "/"; Content.RootDirectory = rootPath; while (reader.Peek() >= 0) { string[] line = reader.ReadLine().Split(delimeter, StringSplitOptions.RemoveEmptyEntries); if(gameFiles.ContainsKey(line[0])) { gameFiles[line[0]] = rootPath + line[1]; } } // sound initialization //SoundManager.effects.Add("playerHit", Content.Load<SoundEffect>("RecievedDamage")); //SoundManager.effects.Add("itemCollected", Content.Load<SoundEffect>("ObtainedItem")); //SoundManager.effects.Add("playerDied", Content.Load<SoundEffect>("Death")); //SoundManager.effects.Add("itemUsed", Content.Load<SoundEffect>("UsedItem")); //SoundManager.effects.Add("doorUnlocked", Content.Load<SoundEffect>("UnlockADoor")); //SoundManager.songs.Add("mainMenu", Content.Load<Song>("StartScreenAudioLoop")); //SoundManager.songs.Add("winLevelMenu", Content.Load<Song>("LevelCompleteSplash")); //SoundManager.songs.Add("winGameMenu", Content.Load<Song>("YouWin(thegame)")); //SoundManager.songs.Add("dieMenu", Content.Load<Song>("YouHaveDiedSplash")); //SoundManager.songs.Add("game", Content.Load<Song>("Kalimba(InGameAudio)")); // player manager intialization PlayerManager.AddPlayer(Content.Load<Texture2D>("Players/whiterat"), 40, 40, Content.Load<Texture2D>("HUD/selected"), Content.Load<Texture2D>("HUD/unselected"), Content.Load<Texture2D>("HUD/inventory"), screenSize); // item manager intialization LoadItems(gameFiles["itemsFile"]); // Enemy initialization List<Effect> hazmatEffects = new List<Effect>(); hazmatEffects.Add(new Effect("drugIntensity", new Modifier("+", ".33"))); EnemyManager.possibleEnemies.Add("enemy", new Enemy(Content.Load<Texture2D>("Enemies/hazmat"), 56, 56, new Vector2(0, 0), new DoNothingAI(), new TeleportToHomeAI(), new BeelineAI(250), hazmatEffects, 256, 1024)); List<Effect> brainEffects = new List<Effect>(); brainEffects.Add(new Effect("drugIntensity", new Modifier("=", ".99"))); EnemyManager.possibleEnemies.Add("brain", new Enemy(Content.Load<Texture2D>("Enemies/brains"), 60, 60, new Vector2(0, 0), new TeleportToHomeAI(), new TeleportToHomeAI(), new BeelineAI(300), brainEffects, 256, 1024)); // HUD intialization HUD.GetInstance().setInventory(ItemManager.inventories[0]); HUD.GetInstance().setScreenSize(screenSize); SpriteFont font = Content.Load<SpriteFont>("Arial"); SpriteFont small = Content.Load<SpriteFont>("Small"); HUD.GetInstance().setScoreData(new Vector2(0, 0), font); HUD.GetInstance().setTimerData(new Vector2(0, 20), font); HUD.GetInstance().setFont(font); HUD.GetInstance().setSmallFont(small); HUD.GetInstance().overlay = new Sprite(Content.Load<Texture2D>("HUD/overlay"), new Vector2(screenSize.X/2, screenSize.Y/2)); // level intialization LoadBlocks(gameFiles["blocksFile"]); LoadLevels(gameFiles["levelsFile"]); // load first level Level.GetInstance().LoadLevel(0); GameAction startGame = new GameAction( this, Engine.GetInstance().GetType().GetMethod("Play"), new object[0]); GameAction exitGame = new GameAction( this, this.GetType().GetMethod("Exit"), new object[0]); GameAction restartGame = new GameAction( Engine.GetInstance(), Engine.GetInstance().GetType().GetMethod("Reset"), new object[0]); List<MenuItem> startMenuItems = new List<MenuItem>(); startMenuItems.Add(new MenuItem("Press Enter to Play!", startGame)); startMenuItems.Add(new MenuItem("Press Enter to Exit!", exitGame)); Menu mainMenu = new Menu(Content.Load<Texture2D>("Menu/Splash"), screenSize, font, "mainMenu", "Press Space to Begin", startMenuItems, Color.Red, Color.White); mainMenu.setUp(); Engine.GetInstance().mainMenu = mainMenu; List<MenuItem> pauseMenuItems = new List<MenuItem>(); pauseMenuItems.Add(new MenuItem("Resume", startGame)); pauseMenuItems.Add(new MenuItem("Main Menu", restartGame)); pauseMenuItems.Add(new MenuItem("Quit", exitGame)); Menu pauseMenu = new Menu(Content.Load<Texture2D>("Menu/Splash"), screenSize, font, "pauseMenu", "Press Space to Begin", pauseMenuItems, Color.Red, Color.White); pauseMenu.setUp(); Engine.GetInstance().pauseMenu = pauseMenu; List<MenuItem> dieMenuItems = new List<MenuItem>(); dieMenuItems.Add(new MenuItem("Retry", startGame)); dieMenuItems.Add(new MenuItem("Main Menu", restartGame)); dieMenuItems.Add(new MenuItem("Quit", exitGame)); Menu dieMenu = new Menu(Content.Load<Texture2D>("Menu/LabRat-Dead"), screenSize, font, "dieMenu", "Press Space to Begin", dieMenuItems, Color.Red, Color.White); dieMenu.setUp(); Engine.GetInstance().dieMenu = dieMenu; List<MenuItem> winLevelMenuItems = new List<MenuItem>(); winLevelMenuItems.Add(new MenuItem("Continue", startGame)); winLevelMenuItems.Add(new MenuItem("Main Menu", restartGame)); winLevelMenuItems.Add(new MenuItem("Quit", exitGame)); Menu winLevel = new Menu(Content.Load<Texture2D>("Menu/LabRat-Level"), screenSize, font, "winLevelMenu", "Press Space to Begin", winLevelMenuItems, Color.Red, Color.White); winLevel.setUp(); Engine.GetInstance().winLevelMenu = winLevel; List<MenuItem> winGameMenuItems = new List<MenuItem>(); winGameMenuItems.Add(new MenuItem("Main Menu", restartGame)); winGameMenuItems.Add(new MenuItem("Quit", exitGame)); Menu winGameMenu = new Menu(Content.Load<Texture2D>("Menu/LabRat-Won"), screenSize, font, "winGameMenu", "Press Space to Begin", winGameMenuItems, Color.Red, Color.White); winGameMenu.setUp(); Engine.GetInstance().winGameMenu = winGameMenu; List<MenuItem> cheeseMenuItems = new List<MenuItem>(); cheeseMenuItems.Add(new MenuItem("Main Menu", restartGame)); cheeseMenuItems.Add(new MenuItem("Quit", exitGame)); Menu cheeseMenu = new Menu(Content.Load<Texture2D>("Menu/LabRat-WonCheese"), screenSize, font, "cheeseMenu", "Press Space to Begin", cheeseMenuItems, Color.Red, Color.White); cheeseMenu.setUp(); Engine.GetInstance().cheeseMenu = cheeseMenu; Engine.Menu(Engine.GetInstance().mainMenu); base.Initialize(); }
/// <summary> /// Sets up the menu /// </summary> public void setUp() { Vector2 position = menuItemStartPosition; foreach (MenuItem menuItem in menuItems) { position.Y += font.MeasureString("M").Y; menuItem.setMessage(position, font, unselected); } menuItems[0].changeIsSelected(); GameAction next = new GameAction( this, this.GetType().GetMethod("Next"), new object[0]); InputManager.AddToKeyboardMap(Keys.Down, next); InputManager.AddToKeyboardMap(Keys.E, next); GameAction previous = new GameAction( this, this.GetType().GetMethod("Previous"), new object[0]); InputManager.AddToKeyboardMap(Keys.Up, previous); InputManager.AddToKeyboardMap(Keys.Q, previous); }
/// <summary> /// Makes a new MenuItem /// </summary> /// <param name="message">Message for the MenuItem to display</param> /// <param name="action">Action to perform when selected</param> public MenuItem(string message, GameAction action) { this.message = message; this.action = action; this.isSelected = false; }
/// <summary> /// Makes a new MenuItem /// </summary> /// <param name="message">Message for the MenuItem to display</param> /// <param name="action">Action to perform when selected</param> public MenuItem(string message, GameAction action) { }