public void initialize(Vector2 position, float rotation, Texture2D texture, int tileX, int tileY, string objectID, TileMap map) { this.texture = texture; this.animationCount = 0; this.objectID = objectID; this.map = map; this.tileX = tileX; this.tileY = tileY; this.map.mapCell[tileX, tileY].AddObject(objectID); destination = new Rectangle( (int)position.X - frameStartX / 2, (int)position.Y - frameStartY / 2, frameWidth, frameHeight ); source = new Rectangle( frameStartX, frameStartY + frameSkipY * frameCount, frameWidth, frameHeight ); boundingBox = new Rectangle( (int)position.X - (source.Width/2), (int)position.Y - (source.Height/2), frameWidth, frameHeight ); }
public int winGoal; // winning door index #endregion Fields #region Constructors public Level(TileMap[] maps, Point[] goal, Point[] start, int mapIndex, int win) { this.currentMapIndex = mapIndex; this.maps = maps; this.currentMap = maps[mapIndex]; this.goal = goal; currentGoal = this.goal[mapIndex]; this.start = start; guards = new List<List<Npc>>(); this.winGoal = win; }
public void initialize(TileMap map,int x, int y, int offsetX, int offsetY, Texture2D texture, string objectID) { this.originalOffsetX = offsetX; this.originalOffsetY = offsetY; this.texture = texture; this.map = map; this.objectID = objectID; this.currentTile.X = x; this.currentTile.Y = y; this.rotation = 0; map.mapCell[x,y].AddObject(objectID); source = new Rectangle( frameStartX, frameStartY + frameSkipY * frameCount, frameWidth, frameHeight ); }
public void Update(TileMap myMap, int squaresAcross, int squaresDown, GameTime gameTime) { KeyboardState ks = Keyboard.GetState (); if (ks.IsKeyDown (Keys.Left)) { this.Location.X = MathHelper.Clamp (this.Location.X - 2, 0, (myMap.MapWidth - squaresAcross) * 64); } if (ks.IsKeyDown (Keys.Right)) { this.Location.X = MathHelper.Clamp (this.Location.X + 2, 0, (myMap.MapWidth - squaresAcross) * 64); } if (ks.IsKeyDown (Keys.Up)) { this.Location.Y = MathHelper.Clamp (this.Location.Y - 2, 0, (myMap.MapHeight - squaresDown) * 64); } if (ks.IsKeyDown (Keys.Down)) { this.Location.Y = MathHelper.Clamp (this.Location.Y + 2, 0, (myMap.MapHeight - squaresDown) * 64); } base.Update(gameTime); }
public void Update(TileMap myMap, int squaresAcross, int squaresDown, GameTime gameTime) { KeyboardState ks = Keyboard.GetState (); /* MouseState ms = Mouse.GetState(); Vector2 mouseLoc = new Vector2(ms.X, ms.Y); Vector2 direction = (Location - mouseLoc).Angle(); this.rotation = (float)(Math.Atan2(direction.Y, direction.X));*/ int xCount; int yCount; if (ks.IsKeyDown(Keys.Left)) { // this.rotation = (float)Math.PI / 2; this.animationCount += 1; this.Location.X = MathHelper.Clamp(this.Location.X - acceleration, 0, (myMap.MapWidth - squaresAcross) * 64); } if (ks.IsKeyDown(Keys.Right)) { // this.rotation = (float)(3 * Math.PI / 2); ; this.animationCount += 1; this.Location.X = MathHelper.Clamp(this.Location.X + acceleration, 0, (myMap.MapWidth - squaresAcross) * 64); } if (ks.IsKeyDown(Keys.Up)) { // this.rotation = (float)Math.PI; this.animationCount += 1; this.Location.Y = MathHelper.Clamp(this.Location.Y - acceleration, 0, (myMap.MapHeight - squaresDown) * 64); } if (ks.IsKeyDown(Keys.Down)) { // this.rotation = 0; this.animationCount += 1; this.Location.Y = MathHelper.Clamp(this.Location.Y + acceleration, 0, (myMap.MapHeight - squaresDown) * 64); } xCount = (int)this.Location.X / 64 + squaresAcross / 2; yCount = (int)this.Location.Y / 64 + squaresDown / 2; this.updateTilePosition(xCount, yCount); UpdateAnimation(); base.Update(gameTime); }
public void initialize(TileMap map, int x, int y, int offsetX, int offsetY, Texture2D texture, string objectID, Point[] patrolTiles, int speed) { this.patrolTiles = patrolTiles; this.originalOffsetX = offsetX; //offset in current tile this.originalOffsetY = offsetY; //offset in current tile this.speed = speed; this.texture = texture; this.map = map; this.objectID = objectID; this.currentTile = new Point(x, y); this.moveByX = speed; this.moveByY = speed; this.itr = 1; //index of next tile to move to, guard initially drawn at tile 0 it patrolTiles, so start itr at 1 this.moveTo = new Point(-1, -1); this.length = 0; this.init = true; this.ISeeYou = false; map.mapCell[x, y].AddObject(objectID); source = new Rectangle( frameStartX, frameStartY + frameSkipY * frameCount, frameWidth, frameHeight ); }
public void initialize(TileMap map, int x, int y, int offsetX, int offsetY, Texture2D texture, string objectID, Point[] patrolTiles, int[] directions, int speed) { this.patrolTiles = patrolTiles; this.originalOffsetX = offsetX; //offset in current tile this.originalOffsetY = offsetY; //offset in current tile this.speed = speed; this.texture = texture; this.map = map; this.objectID = objectID; this.currentTile = new Point(x, y); this.moveByX = speed; this.moveByY = speed; this.chase = 2; this.itr = 1; //index of next tile to move to, guard initially drawn at tile 0 it patrolTiles, so start itr at 1 this.moveTo = new Point(-1, -1); this.ableToMove = true; this.ISeeYou = false; this.wait = false; this.waitTime = 0; this.direction = 4; this.directions = directions; this.time = 1000; this.timeAtGold = 0; this.lastSpot = new Point(0, 0); tilesInRange = new ArrayList(); this.guardPath = new LinkedList<Point>(); this.setPath = false; this.nextPoint = new Point(0, 0); map.mapCell[x, y].AddObject(objectID); source = new Rectangle( frameStartX, frameStartY + frameSkipY * frameCount, frameWidth, frameHeight ); }
/// <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() { timer = 0; this.IsMouseVisible = true; //TileMap TileMap[] lvl1 = new TileMap[3]; lvl1[0] = new TileMap(1,1); lvl1[1] = new TileMap(1,2); lvl1[2] = new TileMap(1, 3); //Level Point[] goal = new Point[3]; goal[0].X = 27; goal[0].Y = 4; goal[1].X = 25; goal[1].Y = 4; goal[2].X = 40; goal[2].Y = 4; Point[] starts = new Point[3]; starts[0].X = 19; starts[0].Y = 30; starts[1].X = 11; starts[1].Y = 21; starts[2].X = 10; starts[2].Y = 13; currentLevel = new Level(lvl1 , goal, starts, 0,3); pauseFont = Content.Load<SpriteFont>("SpriteFont2"); //Audio sound.normalMusic = Content.Load<Song>("hero"); sound.Alert = Content.Load<Song>("emergence"); sound.coinSound = Content.Load<SoundEffect>("coinbag"); sound.fallSound = Content.Load<SoundEffect>("fall"); sound.weakScreamSound = Content.Load<SoundEffect>("weakScream"); SpriteFont font = Content.Load<SpriteFont>("SpriteFont1"); blackTexture = new Texture2D(GraphicsDevice, 1, 1); blackTexture.SetData(new[] { Color.White }); credits = new Credits(this); credits.initialize(font, blackTexture); Texture2D torchTexture = Content.Load<Texture2D> ("torch"); gameOverFont = Content.Load<SpriteFont>("GameOver"); Texture2D timerTexture = Content.Load<Texture2D>("hud"); Texture2D viewTexture = Content.Load<Texture2D>("view"); //Menu arrow = Content.Load<Texture2D>("arrow"); menu = new Menu(this); menu.initialize(blackTexture, arrow, font, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); // +2 to compensate for tiles off screen squaresAcross = 13 ; squaresDown = 9 ; //hud hud = new hud(this); hud.initializeTimer(timerTexture, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, GraphicsDevice.Viewport.Width - 50, GraphicsDevice.Viewport.Height - 50,font); hud.initializeView(viewTexture, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); drawnRectangles = new Rectangle[squaresAcross, squaresDown]; dot = Content.Load<Texture2D>("whitedot"); minimap = Content.Load<Texture2D>("minimap"); //Load guards loadGuards("lvl1map" + (currentLevel.currentMapIndex + 1) + "guards.csv"); //Load Gold loadGold("lvl1map" + (currentLevel.currentMapIndex + 1) + "gold.csv"); MediaPlayer.Volume = 0.25f; start = new Vector2(GraphicsDevice.Viewport.Width/2, GraphicsDevice.Viewport.Height/2); timTexture = Content.Load<Texture2D>("sprite"); player = new Player(this); player.initialize(start, (float)Math.PI, timTexture,currentLevel.start[0].X,currentLevel.start[0].Y, "Player", currentLevel.currentMap); base.Initialize (); }
public void initialize(Vector2 position, float rotation, Texture2D texture, int tileX, int tileY, string objectID, TileMap map) { this.texture = texture; this.animationCount = 0; this.objectID = objectID; this.map = map; this.tileX = tileX; this.tileY = tileY; this.position = position; this.Location.X = tileSize * tileX - (6 * tileSize); this.Location.Y = tileSize * tileY - (4 * tileSize); this.numGold = 3; this.goldKeyPressed = false; this.rotation = rotation; this.whereOnTile.Y = Location.Y % tileSize; this.whereOnTile.X = Location.X % tileSize; this.map.mapCell[tileX, tileY].AddObject(objectID); destination = new Rectangle( (int)position.X - frameStartX / 2, (int)position.Y - frameStartY / 2, frameWidth, frameHeight ); source = new Rectangle( frameStartX, frameStartY + frameSkipY * frameCount, frameWidth, frameHeight ); boundingBox = new Rectangle( (int)position.X - (source.Width/2), (int)position.Y - (source.Height/2), frameWidth, frameHeight ); }
public void Update(TileMap myMap, int squaresAcross, int squaresDown, GameTime gameTime, Rectangle[,] drawnRectangles) { GamePadState gps = GamePad.GetState(PlayerIndex.One); KeyboardState ks = Keyboard.GetState (); MouseState ms = Mouse.GetState(); Vector2 mouseLoc = new Vector2(ms.X, ms.Y); Vector2 direction; direction.X = mouseLoc.X - position.X; direction.Y = mouseLoc.Y - position.Y; if (gps.IsConnected) { direction.X = gps.ThumbSticks.Left.X; direction.Y = gps.ThumbSticks.Left.Y * -1; } if (direction.X + direction.Y != 0) this.rotation = (float)(Math.Atan2(direction.Y, direction.X)) - (float)Math.PI/2; //Console.WriteLine(nextTileX); //Console.WriteLine(myMap.obstacleTiles.Last.Value); if (direction.X < 0) nextTileX = tileX - 1; if (direction.X > 0) nextTileX = tileX + 1; if (direction.Y > 0) nextTileY = tileY + 1; if (direction.Y < 0) nextTileY = tileY - 1; int xCount; int yCount; if (ks.IsKeyDown(Keys.W) || (gps.IsConnected && (direction.X + direction.Y != 0))) { this.animationCount += 1; if (myMap.obstacleTiles.Contains(new Point(tileX, nextTileY)) && direction.Y > 0) { if (whereOnTile.Y < 60) this.Location.Y = MathHelper.Clamp(this.Location.Y + (float)Math.Cos(this.rotation) * acceleration, 0, (myMap.MapHeight - squaresDown) * tileSize); } else if (!myMap.obstacleTiles.Contains(new Point(tileX, nextTileY))) this.Location.Y = MathHelper.Clamp(this.Location.Y + (float)Math.Cos(this.rotation) * acceleration, 0, (myMap.MapHeight - squaresDown) * tileSize); if (myMap.obstacleTiles.Contains(new Point(nextTileX, tileY)) && direction.X > 0) { if (whereOnTile.X < 60) this.Location.X = MathHelper.Clamp(this.Location.X - (float)Math.Sin(this.rotation) * acceleration, 0, (myMap.MapWidth - squaresAcross) * tileSize); } else if (!myMap.obstacleTiles.Contains(new Point(nextTileX, tileY))) this.Location.X = MathHelper.Clamp(this.Location.X - (float)Math.Sin(this.rotation) * acceleration, 0, (myMap.MapWidth - squaresAcross) * tileSize); } /* if (ks.IsKeyDown(Keys.Left)) { // this.rotation = (float)Math.PI / 2; this.animationCount += 1; this.Location.X = MathHelper.Clamp(this.Location.X - acceleration, 0, (myMap.MapWidth - squaresAcross) * 64); } if (ks.IsKeyDown(Keys.Right)) { // this.rotation = (float)(3 * Math.PI / 2); ; this.animationCount += 1; this.Location.X = MathHelper.Clamp(this.Location.X + acceleration, 0, (myMap.MapWidth - squaresAcross) * 64); } if (ks.IsKeyDown(Keys.Up)) { // this.rotation = (float)Math.PI; this.animationCount += 1; this.Location.Y = MathHelper.Clamp(this.Location.Y - acceleration, 0, (myMap.MapHeight - squaresDown) * 64); } if (ks.IsKeyDown(Keys.Down)) { // this.rotation = 0; this.animationCount += 1; this.Location.Y = MathHelper.Clamp(this.Location.Y + acceleration, 0, (myMap.MapHeight - squaresDown) * 64); }*/ if (ks.IsKeyDown(Keys.E) || gps.Buttons.A == ButtonState.Pressed) { if (numGold > 0 && !goldKeyPressed) { myMap.mapCell[tileX, tileY].AddBaseTile(229); myMap.mapCell[tileX, tileY].AddObject("Gold"); sound.coinSound.Play(); numGold--; goldKeyPressed = true; } } if (ks.IsKeyUp(Keys.E) && gps.Buttons.A == ButtonState.Released) { goldKeyPressed = false; } xCount = (int)(this.Location.X) / tileSize + (squaresAcross ) / 2 ; yCount = (int)(this.Location.Y) / tileSize + (squaresDown) / 2; // Console.WriteLine(xCount + " " + yCount); this.updateTilePosition(xCount, yCount); UpdateAnimation(); base.Update(gameTime); }