public bool CheckBounds(Squared.Tiled.Object obj) { bool check = false; Rectangle playrec = new Rectangle( obj.X, obj.Y, obj.Width, obj.Height ); for (int x = 0; x < map.Width; x++) { for (int y = 0; y < map.Height; y++) { if (collision.GetTile(x, y) != 0) { Rectangle tile = new Rectangle( (int)x * tilepixel, (int)y * tilepixel, tilepixel, tilepixel ); if (playrec.Intersects(tile)) { check = true; } } } } return(check); }
public bool CheckEnemy(Squared.Tiled.Object obj, Enemy e) { bool check = false; Rectangle playrec = new Rectangle( obj.X, obj.Y, obj.Width, obj.Height ); foreach (Enemy E in EnemyList) { if (E != e) { Rectangle enemyrec = new Rectangle( (int)E.Position.X, (int)E.Position.Y, (int)32, (int)32 ); if (playrec.Intersects(enemyrec)) { check = true; } } } return(check); }
public void Init(string mapname, Game1 game, GraphicsDeviceManager man, string layer, string obj) { parent = game; g = man; map = Map.Load(Path.Combine(game.Content.RootDirectory, mapname), game.Content); cameraObject = map.ObjectGroups[layer].Objects[obj]; }
static void spawnRoundCactus(Squared.Tiled.Object obj) { GameObject2d enemy = GameObject2d.Initialize(); enemy.sprite = new Sprite(content.Load <Texture2D>("cactusRound")); //enemy.sprite.Scale *= 1; enemy.sprite.LayerDepth = 0.4f; enemy.addBehavior(new grazeEnemy()); enemy.addBehavior(new enemyHealth()); enemy.addBehavior(new BasicShootEnemy()); enemy.sprite.Position = new Vector2(obj.X, obj.Y); BulletSpawner b = new BulletSpawner(); b.bulletSpeed = 2; b.bulletAmount = 6; b.bulletfrequency = 0.5f; // ms b.spin = 0f; b.bulletSprite = content.Load <Texture2D>("needleBullet"); b.facing = true; b.scale = Vector2.One * 0.7f; enemy.addBehavior(b); }
static void spawnSun(Squared.Tiled.Object obj) { GameObject2d spawner = GameObject2d.Initialize(); //TEMP Texture2D bulletSprite = content.Load <Texture2D>("bullet_1"); spawner.sprite = new AnimatedSprite(content.Load <Texture2D>("sunSprite"), 3, 1000, 1000, true, 0); spawner.sprite.Scale *= 1; spawner.sprite.collisionBox *= 0.85f; spawner.sprite.LayerDepth = 0.4f; spawner.addBehavior(new grazeEnemy()); BulletSpawner b = new BulletSpawner(); spawner.sprite.Position = new Vector2(obj.X, obj.Y); b.bulletSpeed = 2; b.bulletAmount = 3; b.bulletfrequency = 0.05f; // ms b.spin = 0.3f; b.Wave = 0.2f; b.bulletSprite = bulletSprite; b.scale = Vector2.One * 0.4f; spawner.addBehavior(b); // Bar Vector2 barscale = Vector2.One * 0.29f; Vector2 barPos = new Vector2(300, 45); ProgressBar bar = ProgressBar.Initialize() as ProgressBar; bar.sprite = new Sprite(content.Load <Texture2D>("bar")); bar.sprite.Position = barPos; bar.sprite.Scale = barscale; bar.sprite.LayerDepth = 0.01f; bar.sprite.enableCam = false; bar.innerSprite = new Sprite(content.Load <Texture2D>("inner")); bar.innerSprite.Position = barPos; bar.innerSprite.Color = Color.DarkRed; bar.innerSprite.Scale = barscale; bar.innerSprite.enableCam = false; bar.value = 100; // more boss stuff? BossController boss = new BossController(); boss.healthbar = bar; spawner.addBehavior(boss); var h = new enemyHealth(); h.max = 20000; spawner.addBehavior(h); }
// constructor to pass everything to sprite bas class public Projectile(Texture2D texture, Texture2D blank, Vector2 pos, Vector2 move, Squared.Tiled.Object obj, bool en) : base(texture, null) { active = true; Blank = blank; Velocity = move; Position = pos; mapobj = obj; deathtimer = new Timer(); deathtimer.Interval = 3000; deathtimer.Elapsed += new ElapsedEventHandler(OnFireTimedEvent); deathtimer.Enabled = true; enemy = en; }
static void SwapMap(Squared.Tiled.Object obj) { fixForScreenSize(obj); string mapfilename = obj.Name + ".tmx"; Vector2 spawnLocation = fixForScreenSize(new Vector2(Int32.Parse(obj.Properties["playerLocationX"]), Int32.Parse(obj.Properties["playerLocationY"]))); void switchMap(PlayerObject p) => MainGameplayScreen.currentGame.loadMap(mapfilename, spawnLocation); GameObject2d g = GameObject2d.Initialize(); g.sprite.visible = false; g.addBehavior(new eventLocation(switchMap, new Vector2(obj.X, obj.Y), 32)); }
public void ProcessMovement(KeyboardState keyState, GamePadState gamePadState) { //detect key press and xy scroll values int scrollx = 0, scrolly = 0, moveSpeed = 2; if (keyState.IsKeyDown(Keys.Left)) { scrollx = -1; } if (keyState.IsKeyDown(Keys.Right)) { scrollx = 1; } if (keyState.IsKeyDown(Keys.Up)) { scrolly = 1; } if (keyState.IsKeyDown(Keys.Down)) { scrolly = -1; } if (keyState.IsKeyDown(Keys.Space)) { Squared.Tiled.Object temp = new Squared.Tiled.Object(); temp.X = (int)Position.X; temp.Y = (int)Position.Y; temp.Width = 30; temp.Height = 30; temp.Texture = projTexture; temp.Type = "proj"; if (_sprites[0].Fire(Position, temp, blankTexture)) { map.ObjectGroups["Objects"].Objects.Add("proj" + projcount, temp); projcount++; } } // get game pad input scrollx += (int)gamePadState.ThumbSticks.Left.X; scrolly += (int)gamePadState.ThumbSticks.Left.Y; // move player in the map map.ObjectGroups["Objects"].Objects["Player"].X += (scrollx * moveSpeed); map.ObjectGroups["Objects"].Objects["Player"].Y -= (scrolly * moveSpeed); }
public bool Fire(Vector2 Position, Squared.Tiled.Object obj, Texture2D blank) { if (!firetimer.Enabled) { Projectile Temp = new Projectile(projtexture, blank, Position, OldVelocity * 5, obj, false); PlayerProjectiles.Add(Temp); firetimer = new Timer(); firetimer.Interval = 500; firetimer.Elapsed += new ElapsedEventHandler(OnFireTimedEvent); firetimer.Enabled = true; return(true); } else { return(false); } }
// checks for the bounds of the map with a given object public bool CheckBounds(Squared.Tiled.Object obj) { bool check = false; // creates rectangle Rectangle objrec = new Rectangle( obj.X, obj.Y, obj.Width, obj.Height ); int startx = ((int)obj.X / 16) - 5; int starty = ((int)obj.Y / 16) - 5; // cycles through each tile on the map for (int x = startx; x < startx + 10; x++) { for (int y = starty; y < starty + 10; y++) { // if the tile is in the collision layer if (collision.GetTile(x, y) != 0) { // create rectangle for the tile Rectangle tile = new Rectangle( (int)x * tilepixel, (int)y * tilepixel, tilepixel, tilepixel ); // check if the object intersects the tile if (objrec.Intersects(tile)) { check = true; } } } } return(check); }
// First event for enemy spawns this is probably most of what will be here static void SpawnEnemy(Squared.Tiled.Object obj) { fixForScreenSize(obj); switch (obj.Name) { case "Sun": spawnSun(obj); break; case "RoundCactus": spawnRoundCactus(obj); break; case "Susumu": spawnSusumu(obj); break; default: // Put something here to indicate a load error on map break; } }
// used to check the enemy collision with an object // returns true if collision false if not // enemy e is to stop collision with itself public bool CheckEnemy(Squared.Tiled.Object obj, Enemy e) { bool check = false; // get rectangle for object Rectangle objrec = new Rectangle( obj.X, obj.Y, obj.Width, obj.Height ); // cycles through each enemy foreach (Enemy E in EnemyList) { // the enemy can't collide with itself if (E != e) { // creates rectangle for enemy Rectangle enemyrec = new Rectangle( (int)E.Position.X, (int)E.Position.Y, (int)32, (int)32 ); // checks for collision if (objrec.Intersects(enemyrec)) { check = true; } } } return(check); }
public void LoadContent(ContentManager content, int stageNum) { map = Map.Load(Path.Combine(content.RootDirectory, tmxFile), content); //background = content.Load<Texture2D>("background" + ((stageNum / 3) + 1) + ".jpg"); background = content.Load <Texture2D>("background1.jpg"); width = map.Width; height = map.Height; int tempID; //Add all collidable obstacles obstacles = map.ObjectGroups["obstacles"].Objects; foreach (Squared.Tiled.Object o in obstacles.Values) { tempID = cm.addEntity(); cm.addCollide(tempID, new Rectangle(o.X, o.Y, o.Width, o.Height), false, false); } //Add all collidable platforms platforms = map.ObjectGroups["platforms"].Objects; int platformNum = 0; foreach (Squared.Tiled.Object o in platforms.Values) { int x = o.X + o.Width / 2; int y = o.Y + o.Height / 2; tempID = cm.addEntity(); Rectangle crateHitBox = new Rectangle(o.X, o.Y, o.Width, o.Height); cm.addCollide(tempID, crateHitBox, true); List <Vector2> waypoints = new List <Vector2>(); if (tmxFile.Equals("stage4.tmx")) { waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x, y - 300)); cm.addPatrol(tempID, waypoints, 3); } else if (tmxFile.Equals("stage6.tmx")) { waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x, y + 350)); cm.addPatrol(tempID, waypoints, 3); } else if (tmxFile.Equals("stage9.tmx")) { if (platformNum % 2 == 0) { waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x + 200, y)); cm.addPatrol(tempID, waypoints, 2); } else { waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x - 200, y)); cm.addPatrol(tempID, waypoints, 2); } } else if (tmxFile.Equals("stage10.tmx")) { if (platformNum == 0) { waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x + 168, y)); cm.addPatrol(tempID, waypoints, 2); } else if (platformNum == 1) { waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x - 132, y)); cm.addPatrol(tempID, waypoints, 2); } else if (platformNum == 2) { waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x + 168, y)); cm.addPatrol(tempID, waypoints, 2); } else { waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x - 200, y)); cm.addPatrol(tempID, waypoints, 2); } } else if (tmxFile.Equals("stage12.tmx")) { waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x + 200, y)); cm.addPatrol(tempID, waypoints, 2); } else { waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x, y + 300)); cm.addPatrol(tempID, waypoints, 2); } cm.addSprite(tempID, o.Width, o.Height, content.Load <Texture2D>("crate.png"), crateHitBox, false); platformNum++; } //int shackleBoxID = 0; //Add shackleable objects shackleables = map.ObjectGroups["shackleables"].Objects; foreach (Squared.Tiled.Object o in shackleables.Values) { tempID = cm.addEntity(); cm.addCollide(tempID, new Rectangle(o.X, o.Y, o.Width, o.Height), false, true); preExistingShackleIDs.Add(tempID); } //ADD ENEMIES enemies = map.ObjectGroups["enemies"].Objects; int enemy0ID = 0; int enemy1ID = 0; int enemy2ID = 0; int enemy3ID = 0; int enemycount = 0; foreach (Squared.Tiled.Object o in enemies.Values) { int x = o.X + o.Width / 2; int y = o.Y + o.Height / 2; tempID = cm.addEntity(); //HARD CODED ENEMY MOVEMENTS IN, need to change later based on stage List <Vector2> waypoints = new List <Vector2>(); Rectangle enemySpriteBox = new Rectangle(o.X, o.Y, o.Width, o.Height); Rectangle enemyHitBox = new Rectangle(o.X, o.Y, o.Width, o.Height); if (tmxFile.Equals("stage3.tmx")) { if (enemycount == 0) { cm.addCollide(tempID, enemyHitBox, true, true); waypoints.Add(new Vector2(x, y - 100)); waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x + 100, y - 100)); } else if (enemycount == 1) { cm.addCollide(tempID, enemyHitBox, true, true); waypoints.Add(new Vector2(x, y + 230)); waypoints.Add(new Vector2(x, y)); } else if (enemycount == 2) { cm.addCollide(tempID, enemyHitBox, true, true, true); waypoints.Add(new Vector2(x + 200, y)); waypoints.Add(new Vector2(x, y)); } cm.addPatrol(tempID, waypoints, 3); } else if (tmxFile.Equals("stage4.tmx")) { cm.addCollide(tempID, enemyHitBox, true, true); waypoints.Add(new Vector2(x, y + 250)); waypoints.Add(new Vector2(x + 100, y + 250)); waypoints.Add(new Vector2(x + 100, y)); waypoints.Add(new Vector2(x, y)); cm.addPatrol(tempID, waypoints, 2); } else if (tmxFile.Equals("stage5.tmx")) { cm.addCollide(tempID, enemyHitBox, true, true); waypoints.Add(new Vector2(x, y - 100)); waypoints.Add(new Vector2(x, y + 20)); waypoints.Add(new Vector2(x, y)); cm.addPatrol(tempID, waypoints, 2); } else if (tmxFile.Equals("stage6.tmx")) { if (enemycount == 0) { cm.addCollide(tempID, enemyHitBox, true, true, 1, false); waypoints.Add(new Vector2(x, y + 300)); waypoints.Add(new Vector2(x, y)); //Connect pre-existing shackle int shackleTemp = cm.addEntity(); cm.addShackle(shackleTemp, tempID, preExistingShackleIDs[enemycount], false); //Calculate hitbox for shackle Rectangle tempRect1 = cm.getCollides()[tempID].hitbox; Rectangle tempRect2 = cm.getCollides()[preExistingShackleIDs[enemycount]].hitbox; int rectX = Math.Min(tempRect1.X + (int)(tempRect1.Width / 2.0), tempRect2.X + (int)(tempRect2.Width / 2.0)); int rectY = Math.Min(tempRect1.Y + (int)(tempRect1.Height / 2.0), tempRect2.Y + (int)(tempRect2.Height / 2.0)); int rectWidth = Math.Max(tempRect1.X + (int)(tempRect1.Width / 2.0), tempRect2.X + (int)(tempRect2.Width / 2.0)) - rectX; int rectHeight = Math.Max(tempRect1.Y + (int)(tempRect1.Height / 2.0), tempRect2.Y + (int)(tempRect2.Height / 2.0)) - rectY; //Add collide for shackle cm.addCollide(shackleTemp, new Rectangle(rectX, rectY, rectWidth, rectHeight), false, false); } else if (enemycount == 1) { cm.addCollide(tempID, enemyHitBox, true, true); waypoints.Add(new Vector2(x, y - 300)); waypoints.Add(new Vector2(x, y)); } cm.addPatrol(tempID, waypoints, 2); } else if (tmxFile.Equals("stage7.tmx")) { if (enemycount == 0) { cm.addCollide(tempID, enemyHitBox, true, true, 2, false); waypoints.Add(new Vector2(x, y - 100)); waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x, y + 80)); //Connect pre-existing shackle int shackleTemp = cm.addEntity(); cm.addShackle(shackleTemp, tempID, preExistingShackleIDs[0], false); //Calculate hitbox for shackle Rectangle tempRect1 = cm.getCollides()[tempID].hitbox; Rectangle tempRect2 = cm.getCollides()[preExistingShackleIDs[0]].hitbox; int rectX = Math.Min(tempRect1.X + (int)(tempRect1.Width / 2.0), tempRect2.X + (int)(tempRect2.Width / 2.0)); int rectY = Math.Min(tempRect1.Y + (int)(tempRect1.Height / 2.0), tempRect2.Y + (int)(tempRect2.Height / 2.0)); int rectWidth = Math.Max(tempRect1.X + (int)(tempRect1.Width / 2.0), tempRect2.X + (int)(tempRect2.Width / 2.0)) - rectX; int rectHeight = Math.Max(tempRect1.Y + (int)(tempRect1.Height / 2.0), tempRect2.Y + (int)(tempRect2.Height / 2.0)) - rectY; //Add collide for shackle cm.addCollide(shackleTemp, new Rectangle(rectX, rectY, rectWidth, rectHeight), false, false); enemy0ID = tempID; } else if (enemycount == 1) { cm.addCollide(tempID, enemyHitBox, true, true, 2, false); waypoints.Add(new Vector2(x + 100, y - 200)); waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x - 50, y + 100)); enemy1ID = tempID; } else if (enemycount == 2) { cm.addCollide(tempID, enemyHitBox, true, true, 2, false); waypoints.Add(new Vector2(x - 30, y - 30)); waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x + 30, y + 30)); enemy2ID = tempID; } else if (enemycount == 3) { cm.addCollide(tempID, enemyHitBox, true, true, 2, false); waypoints.Add(new Vector2(x, y + 150)); waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x, y - 80)); //Connect pre-existing shackle int shackleTemp = cm.addEntity(); cm.addShackle(shackleTemp, tempID, preExistingShackleIDs[1], false); //Calculate hitbox for shackle Rectangle tempRect1 = cm.getCollides()[tempID].hitbox; Rectangle tempRect2 = cm.getCollides()[preExistingShackleIDs[1]].hitbox; int rectX = Math.Min(tempRect1.X + (int)(tempRect1.Width / 2.0), tempRect2.X + (int)(tempRect2.Width / 2.0)); int rectY = Math.Min(tempRect1.Y + (int)(tempRect1.Height / 2.0), tempRect2.Y + (int)(tempRect2.Height / 2.0)); int rectWidth = Math.Max(tempRect1.X + (int)(tempRect1.Width / 2.0), tempRect2.X + (int)(tempRect2.Width / 2.0)) - rectX; int rectHeight = Math.Max(tempRect1.Y + (int)(tempRect1.Height / 2.0), tempRect2.Y + (int)(tempRect2.Height / 2.0)) - rectY; //Add collide for shackle cm.addCollide(shackleTemp, new Rectangle(rectX, rectY, rectWidth, rectHeight), false, false); enemy3ID = tempID; } cm.addPatrol(tempID, waypoints, 2); } else if (tmxFile.Equals("stage8.tmx")) { if (enemycount == 0) { cm.addCollide(tempID, enemyHitBox, true, true); waypoints.Add(new Vector2(x, y - 100)); waypoints.Add(new Vector2(x, y)); } else { cm.addCollide(tempID, enemyHitBox, true, true); waypoints.Add(new Vector2(x, y + 100)); waypoints.Add(new Vector2(x, y)); } cm.addPatrol(tempID, waypoints, 2); } else if (tmxFile.Equals("stage12.tmx")) { if (o.Name.Equals("enemy1")) { cm.addCollide(tempID, enemyHitBox, true, true); waypoints.Add(new Vector2(x, y + 100)); waypoints.Add(new Vector2(x, y)); } else if (o.Name.Equals("enemy3")) { cm.addCollide(tempID, enemyHitBox, true, true); waypoints.Add(new Vector2(x, y + 150)); waypoints.Add(new Vector2(x, y)); } else if (o.Name.Equals("enemy2")) { cm.addCollide(tempID, enemyHitBox, true, true); waypoints.Add(new Vector2(x, y - 100)); waypoints.Add(new Vector2(x, y)); } else if (o.Name.Equals("enemy14")) { cm.addCollide(tempID, enemyHitBox, true, true); waypoints.Add(new Vector2(x + 500, y)); waypoints.Add(new Vector2(x, y)); } else { cm.addCollide(tempID, enemyHitBox, true, true); } cm.addPatrol(tempID, waypoints, 2); } cm.addSprite(tempID, o.Width, o.Height, content.Load <Texture2D>("birdsheet.png"), enemySpriteBox, true); enemycount++; } //Add shackles between birbs if (tmxFile.Equals("stage7.tmx")) { //Connect pre-existing shackle 1 int shackleTemp = cm.addEntity(); cm.addShackle(shackleTemp, enemy0ID, enemy1ID, false); //Calculate hitbox for shackle Rectangle tempRect1 = cm.getCollides()[enemy0ID].hitbox; Rectangle tempRect2 = cm.getCollides()[enemy1ID].hitbox; int rectX = Math.Min(tempRect1.X + (int)(tempRect1.Width / 2.0), tempRect2.X + (int)(tempRect2.Width / 2.0)); int rectY = Math.Min(tempRect1.Y + (int)(tempRect1.Height / 2.0), tempRect2.Y + (int)(tempRect2.Height / 2.0)); int rectWidth = Math.Max(tempRect1.X + (int)(tempRect1.Width / 2.0), tempRect2.X + (int)(tempRect2.Width / 2.0)) - rectX; int rectHeight = Math.Max(tempRect1.Y + (int)(tempRect1.Height / 2.0), tempRect2.Y + (int)(tempRect2.Height / 2.0)) - rectY; //Add collide for shackle cm.addCollide(shackleTemp, new Rectangle(rectX, rectY, rectWidth, rectHeight), false, false); //Connect pre-existing shackle 2 shackleTemp = cm.addEntity(); cm.addShackle(shackleTemp, enemy1ID, enemy2ID, false); //Calculate hitbox for shackle tempRect1 = cm.getCollides()[enemy1ID].hitbox; tempRect2 = cm.getCollides()[enemy2ID].hitbox; rectX = Math.Min(tempRect1.X + (int)(tempRect1.Width / 2.0), tempRect2.X + (int)(tempRect2.Width / 2.0)); rectY = Math.Min(tempRect1.Y + (int)(tempRect1.Height / 2.0), tempRect2.Y + (int)(tempRect2.Height / 2.0)); rectWidth = Math.Max(tempRect1.X + (int)(tempRect1.Width / 2.0), tempRect2.X + (int)(tempRect2.Width / 2.0)) - rectX; rectHeight = Math.Max(tempRect1.Y + (int)(tempRect1.Height / 2.0), tempRect2.Y + (int)(tempRect2.Height / 2.0)) - rectY; //Add collide for shackle cm.addCollide(shackleTemp, new Rectangle(rectX, rectY, rectWidth, rectHeight), false, false); //Connect pre-existing shackle 2 shackleTemp = cm.addEntity(); cm.addShackle(shackleTemp, enemy2ID, enemy3ID, false); //Calculate hitbox for shackle tempRect1 = cm.getCollides()[enemy2ID].hitbox; tempRect2 = cm.getCollides()[enemy3ID].hitbox; rectX = Math.Min(tempRect1.X + (int)(tempRect1.Width / 2.0), tempRect2.X + (int)(tempRect2.Width / 2.0)); rectY = Math.Min(tempRect1.Y + (int)(tempRect1.Height / 2.0), tempRect2.Y + (int)(tempRect2.Height / 2.0)); rectWidth = Math.Max(tempRect1.X + (int)(tempRect1.Width / 2.0), tempRect2.X + (int)(tempRect2.Width / 2.0)) - rectX; rectHeight = Math.Max(tempRect1.Y + (int)(tempRect1.Height / 2.0), tempRect2.Y + (int)(tempRect2.Height / 2.0)) - rectY; //Add collide for shackle cm.addCollide(shackleTemp, new Rectangle(rectX, rectY, rectWidth, rectHeight), false, false); } //Add all PINECONES pinecones = map.ObjectGroups["pinecones"].Objects; int pineconeCount = 0; foreach (Squared.Tiled.Object o in pinecones.Values) { int x = o.X + o.Width / 2; int y = o.Y + o.Height / 2; tempID = cm.addEntity(); Rectangle pineconeHitBox = new Rectangle(o.X, o.Y, o.Width, o.Height); Rectangle pineconeSpriteBox = new Rectangle(o.X, o.Y, o.Width, o.Height); cm.addCollide(tempID, pineconeHitBox, true, false, false, false); List <Vector2> waypoints = new List <Vector2>(); if (tmxFile.Equals("stage12.tmx")) { if (pineconeCount == 0) { waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x, y + 300)); cm.addPatrol(tempID, waypoints, 2, false); } else { waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x, y + 240)); cm.addPatrol(tempID, waypoints, 3, false); } } else { if (pineconeCount % 2 == 0) { waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x, y + 500)); cm.addPatrol(tempID, waypoints, 4, false); } else { waypoints.Add(new Vector2(x, y)); waypoints.Add(new Vector2(x, y + 600)); cm.addPatrol(tempID, waypoints, 4, false); } } cm.addProjectile(tempID, true, Math.PI / 2, 1, o.X, o.Y); cm.addSprite(tempID, o.Width, o.Height, content.Load <Texture2D>("pinecone.png"), pineconeSpriteBox, false); pineconeCount++; } //Add player at start start = map.ObjectGroups["startFinish"].Objects["start"]; tempID = cm.addEntity(); cm.addPlayer(tempID); Rectangle playerHitBox = new Rectangle(start.X + 10, start.Y, 40, 62); //Change dis Rectangle playerSpriteBox = new Rectangle(start.X, start.Y, 60, 62); cm.addCollide(tempID, playerHitBox, false, false); cm.addSprite(tempID, 60, 62, content.Load <Texture2D>("BBHood.png"), playerSpriteBox, true); //add tutorial text if (tmxFile.Equals("stage1.tmx")) { int temp = cm.addEntity(); cm.addText(temp, cm.font, new Vector2(100, 10), "Press A or D to move.", false); cm.addCollide(temp, new Rectangle(start.X, start.Y, start.Width, start.Height), false); temp = cm.addEntity(); cm.addText(temp, cm.font, new Vector2(100, 35), "Press W to jump.", false); cm.addCollide(temp, new Rectangle(start.X + 100, start.Y, start.Width, start.Height), false); temp = cm.addEntity(); cm.addText(temp, cm.font, new Vector2(100, 60), "Press P to pause a level.", false); cm.addCollide(temp, new Rectangle(start.X + 500, start.Y - 100, start.Width, start.Height * 5), false); temp = cm.addEntity(); cm.addText(temp, cm.font, new Vector2(100, 85), "Press R to reset a level.", false); cm.addCollide(temp, new Rectangle(start.X + 500, start.Y - 100, start.Width, start.Height * 5), false); } if (tmxFile.Equals("stage2.tmx")) { int temp = cm.addEntity(); cm.addText(temp, cm.font, new Vector2(100, 10), "Left click to a shoot a shackle. Shackles will create a platform between two objects.", false); cm.addCollide(temp, new Rectangle(start.X, start.Y, start.Width, start.Height), false); temp = cm.addEntity(); cm.addText(temp, cm.font, new Vector2(100, 35), "Right click to shoot an arrow. Arrows destroy shackle platforms and some enemies.", false); cm.addCollide(temp, new Rectangle(start.X + 350, start.Y - 300, start.Width, start.Height * 10), false); temp = cm.addEntity(); cm.addText(temp, cm.font, new Vector2(100, 60), "Note that you can only use 3 shackles and 3 arrows at a time.", false); cm.addCollide(temp, new Rectangle(start.X + 500, start.Y - 400, start.Width * 2, start.Height * 10), false); temp = cm.addEntity(); cm.addText(temp, cm.font, new Vector2(100, 85), "You also have only 3 lives for the entire game.", false); cm.addCollide(temp, new Rectangle(start.X + 500, start.Y - 400, start.Width, start.Height * 10), false); } //Add finish collidable finish = map.ObjectGroups["startFinish"].Objects["finish"]; tempID = cm.addEntity(); cm.addCollide(tempID, new Rectangle(finish.X, finish.Y, finish.Width, finish.Height), false, false, false, true); }
protected override void Update(GameTime gameTime) { if (currentScreen == Menu.Play) { if (songplaying == false) { backsong = Content.Load <Song>("Game of Thrones"); MediaPlayer.Play(backsong); songplaying = true; } else if (MediaPlayer.State == MediaState.Stopped) { songplaying = false; } if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } clean(); // get player input GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); KeyboardState keyState = Keyboard.GetState(); // record current position before movement int tempx = map.ObjectGroups["Objects"].Objects["Player"].X; int tempy = map.ObjectGroups["Objects"].Objects["Player"].Y; Position = new Vector2(map.ObjectGroups["Objects"].Objects["Player"].X, map.ObjectGroups["Objects"].Objects["Player"].Y); // process movement input move player object ProcessMovement(keyState, gamePadState); //now we have moved checkbounds if (CheckBounds(map.ObjectGroups["Objects"].Objects["Player"])) { map.ObjectGroups["Objects"].Objects["Player"].X = tempx; map.ObjectGroups["Objects"].Objects["Player"].Y = tempy; } // check for player interaction with coins and exits within the game var p = map.ObjectGroups["Objects"].Objects["Player"]; Rectangle playerRec = new Rectangle(p.X, p.Y, p.Width, p.Height); CheckCoins(playerRec); CheckExits(playerRec); CheckKey(playerRec); CheckEnd(playerRec); CheckDoor(playerRec); // update player object with position and viewport Vector2 Test = (viewportPosition + new Vector2(0, 100) - new Vector2((graphics.PreferredBackBufferWidth / 2), (graphics.PreferredBackBufferHeight / 2))); foreach (var sprite in _sprites) { sprite.Update(gameTime, Position, Test); foreach (Projectile P in sprite.PlayerProjectiles) { Rectangle proj = new Rectangle((int)P.Position.X, (int)P.Position.Y, P.mapobj.Width, P.mapobj.Height); foreach (Enemy E in EnemyList) { Rectangle Erec = new Rectangle((int)E.mapobj.X, (int)E.mapobj.Y, E.mapobj.Width, E.mapobj.Height); if (proj.Intersects(Erec) && P.active) { E.Health -= 1; P.mapobj.Texture = P.Blank; P.active = false; Console.WriteLine("shot: " + proj + " -- " + Erec + " -- " + E.Health); } } } sprite.Position = new Vector2(map.ObjectGroups["Objects"].Objects["Player"].X, map.ObjectGroups["Objects"].Objects["Player"].Y); } // update each enemy int i = 1; foreach (Enemy E in EnemyList) { if (E.Health > 0) { // get position of enemy Vector2 temp = E.Position; // update the enemy to move E.Update(gameTime, Position); foreach (Projectile P in E.PlayerProjectiles) { Rectangle proj = new Rectangle((int)P.Position.X, (int)P.Position.Y, P.mapobj.Width, P.mapobj.Height); Squared.Tiled.Object obj = map.ObjectGroups["Objects"].Objects["Player"]; Rectangle objrec = new Rectangle( obj.X, obj.Y, obj.Width, obj.Height ); if (proj.Intersects(objrec) && P.active) { _sprites[0].Health -= 1; P.mapobj.Texture = P.Blank; P.active = false; } } // check for enemy collision between the bounds and other enemies if (CheckBounds(map.ObjectGroups["Objects"].Objects["Enemy" + i]) || CheckEnemy(map.ObjectGroups["Objects"].Objects["Enemy" + i], E)) { // collision so set position back to temp value E.Position = temp; } else { // no collision so update the enemy position in map map.ObjectGroups["Objects"].Objects["Enemy" + i].X = (int)E.Position.X; map.ObjectGroups["Objects"].Objects["Enemy" + i].Y = (int)E.Position.Y; if (true) { Squared.Tiled.Object tempp = new Squared.Tiled.Object(); tempp.X = (int)E.Position.X; tempp.Y = (int)E.Position.Y; tempp.Width = 30; tempp.Height = 30; tempp.Type = "proj"; tempp.Texture = projTexture; if (E.Fire(E.Position, tempp, blankTexture)) { map.ObjectGroups["Objects"].Objects.Add("proj" + projcount, tempp); projcount++; } } } i++; } } viewportPosition = new Vector2(map.ObjectGroups["Objects"].Objects["Player"].X, map.ObjectGroups["Objects"].Objects["Player"].Y); KeyboardState keys = Keyboard.GetState(); if (_sprites[0].Health <= 0) { currentScreen = Menu.Main; LoadContent(); } // Takes to main menu or inventory if (keys.IsKeyDown(Keys.Tab)) { currentScreen = Menu.Main; } else if (keys.IsKeyDown(Keys.I)) { currentScreen = Menu.Inventory; string temp = "No"; if (key_collected) { temp = "Yes"; } inventory = new SimpleTextUI(this, big, new[] { "Coins: " + coin_collected, "Key: " + temp, "Back" }) { TextColor = Color.Black, SelectedElement = new TextElement(">", Color.White), Align = Alignment.Left }; current = inventory; } } // code for the controlling menu screens else if (currentScreen == Menu.Main) { KeyboardState keys = Keyboard.GetState(); bool change = true; if (!keytimer.Enabled) { if (keys.IsKeyDown(Keys.Up)) { current.Move(Direction.Up); } else if (keys.IsKeyDown(Keys.Down)) { current.Move(Direction.Down); } else if (keys.IsKeyDown(Keys.Left)) { current.Move(Direction.Left); if (current.GetCurrentCaption() == "Video") { graphics.IsFullScreen = (current.GetCurrentValue() == "FullScreen"); graphics.ApplyChanges(); } } else if (keys.IsKeyDown(Keys.Right)) { current.Move(Direction.Right); if (current.GetCurrentCaption() == "Video") { graphics.IsFullScreen = (current.GetCurrentValue() == "FullScreen"); graphics.ApplyChanges(); } } else if (keys.IsKeyDown(Keys.Enter)) { string test = current.GetCurrentCaption(); if (current == menu) { if (test == "Exit") { Exit(); } else if (test == "Options") { current = options; } else if (test == "Continue") { currentScreen = Menu.Play; } else if (test == "Credits") { current = credits; } } else if (current == credits) { if (test == "Back") { current = menu; } } else if (current == options) { if (test == "Back") { current = menu; } } } else { change = false; } if (change) { keytimer = new Timer(); keytimer.Interval = 200; keytimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); keytimer.Enabled = true; } } } else if (currentScreen == Menu.Inventory) { KeyboardState keys = Keyboard.GetState(); bool change = true; if (!keytimer.Enabled) { if (keys.IsKeyDown(Keys.Up)) { current.Move(Direction.Up); } else if (keys.IsKeyDown(Keys.Down)) { current.Move(Direction.Down); } else if (keys.IsKeyDown(Keys.Enter)) { string test = current.GetCurrentCaption(); if (current == inventory) { if (test == "Back") { currentScreen = Menu.Play; } } } } else { change = false; } if (change) { keytimer = new Timer(); keytimer.Interval = 200; keytimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); keytimer.Enabled = true; } } base.Update(gameTime); }
// constructor to pass everything to sprite bas class public Enemy(Dictionary <string, Animation> animations2, bool health, Squared.Tiled.Object obj) : base(animations2, health, null, true) { mapobj = obj; }
static void fixForScreenSize(Squared.Tiled.Object obj) { obj.X -= MainGameplayScreen.PreferredBackBufferWidth / 2; obj.Y -= MainGameplayScreen.PreferredBackBufferHeight / 2; }