/// <summary> /// Make a boom sprite if boomn size == 0 then default size is used /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="boomKind"></param> /// <param name="boomSize"></param> /// <returns></returns> public Sprite3 makeBoom(int x, int y, int boomKind, float boomSize) { //Texture2DSequence fs = new Texture2DSequence(boomSpriteSheets[boomKind]); //fs.setAnimationSequence(frameSeqs[boomKind].firstFrame,frameSeqs[boomKind].lastFrame,frameSeqs[boomKind].ticksBetweenFrames); Sprite3 boom = new Sprite3(true, boomImages[boomKind], x, y); GCG_SpriteSheet ss = boomSpriteSheets[boomKind]; boom.setXframes(ss.getXframes()); boom.setYframes(ss.getYframes()); int q = ss.getXframes() * ss.getYframes(); Vector2[] animSeq = new Vector2[q]; int ctr = 0; for (int yy = 0; yy < ss.getYframes(); yy++) { for (int xx = 0; xx < ss.getXframes(); xx++) { animSeq[ctr].X = xx; animSeq[ctr].Y = yy; ctr++; } } boom.setAnimationSequence(animSeq, 0, q - 1, 4); //boom.setFrameSource(boomSpriteSheets[boomKind], true); if (boomSize > 0) { boom.setWidthHeight(boomSize, boomSize); } boom.animationStart(); //boom.animInfo = fs; boom.setAnimFinished(2); return(boom); }
//Creates blood splatter animation when player or enemy gets hit public void Blood(float x, float y, bool isHorse) { Sprite3 blood = new Sprite3(true, texBlood, x - 10, y - 20); blood.setYframes(6); if (isHorse) { blood.setWidthHeight(texBlood.Width * 0.2f, texBlood.Height / 6 * 0.2f); } else { blood.setWidthHeight(texBlood.Width * 0.1f, texBlood.Height / 6 * 0.1f); } Vector2[] animBlood = new Vector2[6]; for (int h = 0; h < animBlood.Length; h++) { animBlood[h].Y = h; } blood.setAnimationSequence(animBlood, 0, 5, 5); blood.setAnimFinished(2); blood.animationStart(); bloodSplat.addSpriteReuse(blood); }
//Adds explosion to particle list public void AddExplosion(int x, int y) { float scale = 0.6f; float xOffset = -10; float yOffset = -5; Sprite3 newExplosion = new Sprite3(true, explosionTex, x + xOffset, y + yOffset); newExplosion.setXframes(7); newExplosion.setYframes(3); newExplosion.setWidthHeight(896 / 7 * scale, 384 / 3 * scale); Vector2[] anim = new Vector2[21]; anim[0].X = 0; anim[0].Y = 0; anim[1].X = 1; anim[1].Y = 0; anim[2].X = 2; anim[2].Y = 0; anim[3].X = 3; anim[3].Y = 0; anim[4].X = 4; anim[4].Y = 0; anim[5].X = 5; anim[5].Y = 0; anim[6].X = 6; anim[6].Y = 0; anim[7].X = 0; anim[7].Y = 1; anim[8].X = 1; anim[8].Y = 1; anim[9].X = 2; anim[9].Y = 1; anim[10].X = 3; anim[10].Y = 1; anim[11].X = 4; anim[11].Y = 1; anim[12].X = 5; anim[12].Y = 1; anim[13].X = 6; anim[13].Y = 1; anim[14].X = 0; anim[14].Y = 2; anim[15].X = 1; anim[15].Y = 2; anim[16].X = 2; anim[16].Y = 2; anim[17].X = 3; anim[17].Y = 2; anim[18].X = 4; anim[18].Y = 2; anim[19].X = 5; anim[19].Y = 2; anim[20].X = 6; anim[20].Y = 2; newExplosion.setAnimationSequence(anim, 0, 20, 2); newExplosion.setAnimFinished(2); // make it inactive and invisible newExplosion.animationStart(); particleList.addSpriteReuse(newExplosion); soundExplosionLimit.playSoundIfOk(); }
void createExplosion(int x, int y) { float scale = 0.99f; int xoffset = -2; int yoffset = -20; Sprite3 s = new Sprite3(true, texBoom, x + xoffset, y + yoffset); s.setXframes(7); s.setYframes(3); s.setWidthHeight(896 / 7 * scale, 384 / 3 * scale); Vector2[] anim = new Vector2[21]; anim[0].X = 0; anim[0].Y = 0; anim[1].X = 1; anim[1].Y = 0; anim[2].X = 2; anim[2].Y = 0; anim[3].X = 3; anim[3].Y = 0; anim[4].X = 4; anim[4].Y = 0; anim[5].X = 5; anim[5].Y = 0; anim[6].X = 6; anim[6].Y = 0; anim[7].X = 0; anim[7].Y = 1; anim[8].X = 1; anim[8].Y = 1; anim[9].X = 2; anim[9].Y = 1; anim[10].X = 3; anim[10].Y = 1; anim[11].X = 4; anim[11].Y = 1; anim[12].X = 5; anim[12].Y = 1; anim[13].X = 6; anim[13].Y = 1; anim[14].X = 0; anim[14].Y = 2; anim[15].X = 1; anim[15].Y = 2; anim[16].X = 2; anim[16].Y = 2; anim[17].X = 3; anim[17].Y = 2; anim[18].X = 4; anim[18].Y = 2; anim[19].X = 5; anim[19].Y = 2; anim[20].X = 6; anim[20].Y = 2; s.setAnimationSequence(anim, 0, 20, 4); s.setAnimFinished(2); // make it inactive and invisible s.animationStart(); booms.addSpriteReuse(s); // add the sprite }
//This function starts the movement and animation of the player public void StartMovement(int horseSpeed) { horse.setAnimationSequence(anim, 0, 7, horseSpeed); horse.setAnimFinished(0); horse.animationStart(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { //Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); mainCamera = new Camera(); //Load all the textures and fonts gameOverText = Content.Load <SpriteFont>("MedievalFont"); directions = Content.Load <SpriteFont>("Gold"); font = Content.Load <SpriteFont>("MedievalFont"); difficultySelectText = Content.Load <SpriteFont>("MedievalFont"); startText = Content.Load <SpriteFont>("Gold"); texStartBanner = Util.texFromFile(GraphicsDevice, dir + "startBanner.png"); texGoldBanner = Util.texFromFile(GraphicsDevice, dir + "goldBanner.png"); texBook = Util.texFromFile(GraphicsDevice, dir + "openBookWithText.png"); texHorseRun = Util.texFromFile(GraphicsDevice, dir + "horseRun.png"); texEnemy = Util.texFromFile(GraphicsDevice, dir + "Enemy.png"); texBlood = Util.texFromFile(GraphicsDevice, dir + "bloodSide.png"); texArrow = Util.texFromFile(GraphicsDevice, dir + "Arrow.png"); texWorldMap = Util.texFromFile(GraphicsDevice, dir + "FantasyWorldMap_2.png"); //Define playarea playArea = new Rectangle(lhs, top, rhs - lhs, bot - top); // width and height //Load sprites and change size if necessary worldMap = new Sprite3(true, texWorldMap, -2000, -1000); worldMap.setWidthHeight(6400, 4800); book = new Sprite3(true, texBook, 50, 50); book.setWidthHeight(700, 500); startBanner = new Sprite3(true, texStartBanner, 0, 0); startBanner.setWidthHeight(800, 600); goldBanner = new Sprite3(true, texGoldBanner, 15, 15); goldBanner.setWidthHeight(130, 40); horse = new Sprite3(true, texHorseRun, xx, yy); //Load some empty spritelists enemies = new SpriteList(); bloodSplat = new SpriteList(); horseRun = new SpriteList(); quiver = new SpriteList(); for (int a = 0; a < 5; a++) { arrow = new Sprite3(false, texArrow, 0, 0); arrow.setWidthHeight(arrow.getWidth() * 0.09f, arrow.getHeight() * 0.09f); quiver.addSpriteReuse(arrow); } //Used to change size of sprites float scale = 0.5f; //Player animation setup horse.setXframes(8); horse.setWidthHeight(1568 / 8 * scale, texHorseRun.Height * scale); horse.setBB(30, 10, (horse.getWidth() / scale) - 60, horse.getHeight() / scale - 20); for (int h = 0; h < anim.Length; h++) { anim[h].X = h; } horseRun.addSpriteReuse(horse); //enemy.setBBToTexture(); //Enemy animation setup for (int k = 0; k < 100; k++) { enemy = new Sprite3(false, texEnemy, 850, 400); enemy.setXframes(10); enemy.setYframes(5); enemy.setWidthHeight(320 / 10, 160 / 5); enemy.setBB(0, 0, enemy.getWidth(), enemy.getHeight()); int count = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 10; j++) { animEnemy[count].X = j; animEnemy[count].Y = i; count++; } } enemy.setAnimationSequence(animEnemy, 20, 29, 15); enemy.setAnimFinished(0); enemy.animationStart(); enemy.setVisible(false); enemies.addSpriteReuse(enemy); } //Load scrolling background images scrolling1 = new Scrolling(Util.texFromFile(GraphicsDevice, dir + "GPT Background 800x600.png"), new Rectangle(0, 0, 800, 600), scrollingSpeed); scrolling2 = new Scrolling(Util.texFromFile(GraphicsDevice, dir + "GPT Background2 800x600.png"), new Rectangle(800, 0, 800, 600), scrollingSpeed); }
public override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(graphicsDevice); weaponList = new SpriteList(20); playerXLocation = Dir.rnd.Next(0, 1000); playerYLocation = 880; enemyXLocation = -20; enemyYLocation = Dir.rnd.Next(213, 600); enemy2XLocation = Dir.rnd.Next(Dir.rightBoundary - 300, Dir.rightBoundary); anchorXLocation = Dir.rnd.Next(Dir.leftBoundary + 100, Dir.rightBoundary - 100); anchorYLocation = 175; texBackgroundLevel2 = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Sea04.png"); texPlayer = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\ship-md.png"); texEnemy1 = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Merchant1.png"); texEnemy2 = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Merchant2.png"); texMissile = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Torpedo5up.png"); texMissileSmoke = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Particle1.png"); texExplostionAnimation = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\explodeWater1024x64.png"); texMineExplostion = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\explode1.png"); texMouse = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Mouse.png"); texAnchor = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\anchor-th.png"); texLife = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\life-preserver-th.png"); texMine = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\water_mine.png"); scoreFont = Content.Load <SpriteFont>("display"); helpFont = Content.Load <SpriteFont>("helpText"); explostionSound = Content.Load <SoundEffect>("bazooka_fire"); exLimSound = new LimitSound(explostionSound, 3); backgroundLevel2 = new ImageBackground(texBackgroundLevel2, Color.White, graphicsDevice); player = new Sprite3(true, texPlayer, playerXLocation, playerYLocation); enemy1 = new Sprite3(true, texEnemy1, enemyXLocation, enemyYLocation); enemy2 = new Sprite3(true, texEnemy2, enemy2XLocation, enemyYLocation); explosionAnimation = new Sprite3(true, texExplostionAnimation, 0, playerYLocation); mineExplostionAnimation = new Sprite3(true, texMineExplostion, 0, playerYLocation); mine = new Sprite3(true, texMine, 0, 0); mine.setHSoffset(new Vector2(296, 313)); weaponList.addSpriteReuse(mine); life = new Sprite3(true, texLife, Dir.rnd.Next(Dir.leftBoundary + 200, Dir.rightBoundary - 200), Dir.rnd.Next(300, 600)); life.setActiveAndVisible(false); for (int i = 1; i < 3; i++) { anchor = new Sprite3(true, texAnchor, anchorXLocation, anchorYLocation); anchor.setWidthHeight(50, 50); weaponList.addSpriteReuse(anchor); } for (int m = 1; m < 6; m++) { missile = new Sprite3(true, texMissile, playerXLocation, playerYLocation); missile.setWidthHeight(missile.getWidth() / 2, missile.getHeight() / 2); weaponList.addSpriteReuse(missile); } player.setColor(Color.Red); // Adjusting sprite image sizes to suit my taste player.setWidthHeight(210, 64); enemy1.setWidthHeight(256, 64); enemy2.setWidthHeight(enemy1.getWidth() / 2, 64); life.setWidthHeight(48, 48); mine.setWidthHeight(40, 45); // animation for torpedo explosion explosionAnimation.setWidthHeightOfTex(1024, 64); explosionAnimation.setXframes(16); explosionAnimation.setYframes(1); explosionAnimation.setWidthHeight(80, 80); for (int moveX = 0; moveX <= 15; moveX++) { anim[moveX].X = moveX; anim[moveX].Y = 0; } explosionAnimation.setAnimationSequence(anim, 0, 15, 3); explosionAnimation.setAnimFinished(0); explosionAnimation.animationStart(); // animation for mine explostion mineExplostionAnimation.setWidthHeightOfTex(1024, 64); mineExplostionAnimation.setXframes(16); mineExplostionAnimation.setYframes(1); mineExplostionAnimation.setWidthHeight(80, 80); for (int moveX = 0; moveX <= 15; moveX++) { mineAnim[moveX].X = moveX; mineAnim[moveX].Y = 0; } mineExplostionAnimation.setAnimationSequence(mineAnim, 0, 15, 4); mineExplostionAnimation.setAnimFinished(0); mineExplostionAnimation.animationStart(); HealthBarAttached h1 = new HealthBarAttached(Color.Aquamarine, Color.Green, Color.Red, 9, true); h1.offset = new Vector2(0, -1); // one pixel above the bounding box h1.gapOfbar = 2; enemy1.hitPoints = 10; enemy1.maxHitPoints = 10; enemy1.attachedRenderable = h1; HealthBarAttached h2 = new HealthBarAttached(Color.Aquamarine, Color.Green, Color.Red, 9, true); h2.offset = new Vector2(0, -1); // one pixel above the bounding box h2.gapOfbar = 2; enemy2.hitPoints = 20; enemy2.maxHitPoints = 20; enemy2.attachedRenderable = h2; HealthBarAttached playerHP = new HealthBarAttached(Color.Aquamarine, Color.Green, Color.Red, 9, true); playerHP.offset = new Vector2(0, -1); // one pixel above the bounding box playerHP.gapOfbar = 2; player.hitPoints = 50; player.maxHitPoints = 50; player.attachedRenderable = playerHP; drawSmoke(); }
public override void LoadContent() { enemyList = new SpriteList(20); playerXLocation = Dir.rnd.Next(0, 1000); playerYLocation = 880; enemyXLocation = -20; enemyYLocation = Dir.rnd.Next(213, 600); enemy2XLocation = Dir.rnd.Next(Dir.rightBoundary - 300, Dir.rightBoundary); enemy3YLocation = enemyYLocation + Dir.rnd.Next(100, 200); // Image Locations Dir.texBackground = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Sea04.png"); texPlayer = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\ship-md.png"); texEnemy1 = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Merchant1.png"); texEnemy2 = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Merchant2.png"); texMissile = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Torpedo5up.png"); texMissileSmoke = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\Particle1.png"); texExplostionAnimation = Util.texFromFile(graphicsDevice, Dir.dir + @"Art\explode1.png"); scoreFont = Content.Load <SpriteFont>("display"); helpFont = Content.Load <SpriteFont>("helpText"); explostionSound = Content.Load <SoundEffect>("bazooka_fire"); exLimSound = new LimitSound(explostionSound, 3); // Set Sprites Dir.background = new ImageBackground(Dir.texBackground, Color.White, graphicsDevice); player = new Sprite3(true, texPlayer, playerXLocation, playerYLocation); enemy1 = new Sprite3(true, texEnemy1, enemyXLocation, enemyYLocation); enemy2 = new Sprite3(true, texEnemy2, enemy2XLocation, enemyYLocation); enemy3 = new Sprite3(true, texEnemy1, enemyXLocation, enemy3YLocation); missile = new Sprite3(true, texMissile, playerXLocation, playerYLocation); explosionAnimation = new Sprite3(true, texExplostionAnimation, 0, playerYLocation); // Adjusting sprite image sizes to suit my taste player.setWidthHeight(210, 64); enemy1.setWidthHeight(256, 64); enemy2.setWidthHeight(enemy1.getWidth() / 2, 64); enemy3.setWidthHeight(256, 64); missile.setWidthHeight(missile.getWidth() / 2, missile.getHeight() / 2); HealthBarAttached h1 = new HealthBarAttached(Color.Aquamarine, Color.Green, Color.Red, 9, true); h1.offset = new Vector2(0, -1); // one pixel above the bounding box h1.gapOfbar = 2; enemy1.hitPoints = 10; enemy1.maxHitPoints = 10; enemy1.attachedRenderable = h1; HealthBarAttached h2 = new HealthBarAttached(Color.Aquamarine, Color.Green, Color.Red, 9, true); h2.offset = new Vector2(0, -1); // one pixel above the bounding box h2.gapOfbar = 2; enemy2.hitPoints = 20; enemy2.maxHitPoints = 20; enemy2.attachedRenderable = h2; HealthBarAttached h3 = new HealthBarAttached(Color.Aquamarine, Color.Green, Color.Red, 9, true); h3.offset = new Vector2(0, -1); // one pixel above the bounding box h3.gapOfbar = 2; enemy3.hitPoints = 10; enemy3.maxHitPoints = 10; enemy3.attachedRenderable = h3; // Add to sprite list enemyList.addSpriteReuse(enemy1); enemyList.addSpriteReuse(enemy2); enemyList.addSpriteReuse(enemy3); explosionAnimation.setWidthHeightOfTex(1024, 64); explosionAnimation.setXframes(16); explosionAnimation.setYframes(1); explosionAnimation.setWidthHeight(90, 90); for (int moveX = 0; moveX <= 15; moveX++) { anim[moveX].X = moveX; anim[moveX].Y = 0; } explosionAnimation.setAnimationSequence(anim, 0, 15, 4); explosionAnimation.setAnimFinished(0); explosionAnimation.animationStart(); drawSmoke(); }