/*World cordinates for the boss area are 4150x to 4350x -50z to 150z * "barrel throw kill zone" is 4275 - 4310 */ public void update(double time, PlayState playstate, Vector3 playerposn, bool enable3d) { if (active) { if (barrelDelayed) { delayTimer = delayTimer + time; if (delayTimer > delayTime) { delayTimer = 0; barrelDelayed = false; } } else { //throw barrels int inverseHP = (6 - boss.health) + 1; // used as a multiplier, the lower the bosses health gets, the higher this value becomes. for (int i = 0; i < inverseHP + 2; i++) { // throw at least 3 barrels + more the weaker boss gets Vector3 Target = new Vector3(rng.Next(4275, 4310), 75, rng.Next(-50, 150)); spawnProjectile(Target); } //set delaytime based on health delayTime = 1 + (2 / inverseHP); barrelDelayed = true; } } for(int i = barrels.Count - 1; i >= 0; i--) { Projectile cur = barrels[i]; if(cur.location.X <= 4100.0f) { ps.objList.Remove(cur); ps.renderList.Remove(cur); ps.collisionList.Remove(cur); ps.physList.Remove(cur); ps.combatList.Remove(cur); barrels.RemoveAt(i); } } }
public LoadScreenState(GameEngine engine, PlayState playstate, int lvl) { eng = engine; this.playstate = playstate; this.lvl = lvl; doneLoading = false; lookat = new Vector3(0, 0, 2); eye = new Vector3(0, 0, 5); screens = new Texture[8]; for(int i = 0; i < 8; i++) { screens[i] = eng.StateTextureManager.GetTexture("load" + (i + 1)); } // Set the current image to be displayed at 0 which is the first in the sequence curFrame = 0.0; //Free up any old textures so we have more VRAM available to load new stuff for(int i = SpriteSheet.allSprites.Count - 1; i >= 0; i-- ) { SpriteSheet.allSprites[i].releaseTexture(); } foreach(int i in SpriteSheet.texIDsToRemove) { GL.DeleteTexture(i); } SpriteSheet.texIDsToRemove.Clear(); GC.Collect(); //Start loading in separate thread Thread loaderThread = new Thread(new ThreadStart(loadLevel)); loaderThread.Start(); }
public ZookeeperAI(Player player, PlayState ps) { //Load all resources required for all subclasses here so there is only one copy of each in memory SpriteSheet zookeeperSprite = LoadLevel.parseSpriteFile("zoo_keeper_sprite.dat"); SpriteSheet ropeSprite = LoadLevel.parseSpriteFile("zoo_keeper_rope.dat"); //TODO: Change to rope when available ProjectileProperties invisProj = LoadLevel.parseProjectileFile("invisible_projectile.dat", ps); invisProj.cbox = new Vector3(24.8f, 0.1f, 24.8f); invisProj.pbox = new Vector3(24.8f, 0.1f, 24.8f); invisProj.speed = 200; List<Vector3> locs = new List<Vector3>(); for( int i = 0; i < 4; i++){ for (int k = 0; k < 4; k++) { locs.Add(new Vector3(4175 + (50 * i), maxHeight, (-25 + (50 * k)))); } } List<Obstacle> boxObstacles = LoadLevel.parseSingleObstacleFile("zoo_keeper_crate.dat", locs); List<Obstacle> groundObstacles = LoadLevel.parseSingleObstacleFile("zookeeper_boss_ground.dat", locs); List<Obstacle> ropeObstacles = LoadLevel.parseSingleObstacleFile("zookeeper_boss_rope.dat", locs); rng = new Random(System.DateTime.Now.Millisecond); //initialize arrays of crates + boss(FallingBox) boxes = new FallingBox[16]; currentBossIndex = 9; /* looking at it from the top down * 0 4 8 12 * 1 5 9 13 * 2 6 10 14 * 3 7 11 15 * */ for(int i=0; i<16; i++) { Obstacle box = boxObstacles[i]; FallingBox newcrate; if(i != currentBossIndex) { newcrate = new Crate(player, ps, new Vector3(box.location), maxHeight, invisProj, box, groundObstacles[i], ropeObstacles[i]); } else { newcrate = bossobject = new ZooBoss(player, ps, new Vector3(box.location), maxHeight, invisProj, box, groundObstacles[i], ropeObstacles[i], zookeeperSprite); ps.combatList.Add(bossobject); ps.renderList.Add(bossobject); } boxes[i] = newcrate; ps.objList.Add(newcrate); ps.physList.Add(newcrate); ps.collisionList.Add(newcrate); //ps.renderList.Add(newcrate); } }
public Camera(int width, int height, Player p, PlayState ps) { this.width = width; this.height = height; player = p; playstate = ps; this.viewport = new int[] { ps.eng.ClientRectangle.X, ps.eng.ClientRectangle.Y, ps.eng.ClientRectangle.Width, ps.eng.ClientRectangle.Height }; eye = new Vector3(); lookat = new Vector3(); fov = (float)(Math.PI / 5); playerYPos = p.location.Y; movingInY = false; trackingPlayer = false; switchedBillboards = true; bossMode = false; isInTransition = false; Set2DCamera(); }
List<Projectile> barrels; //keep this so we can delete barrels when they're offscreen public GorillaAI(Player player, PlayState ps) { this.ps = ps; rng = new Random(System.DateTime.Now.Millisecond); SpriteSheet gorillaSprite = LoadLevel.parseSpriteFile("gorilla_sprite.dat"); barrelProp = LoadLevel.parseProjectileFile("barrel_projectile.dat", ps); Vector3 location = new Vector3(4370,162.5f,51); Vector3 scale = new Vector3(50.0f, 50.0f, 50.0f); Vector3 pbox = new Vector3(6, 6, 6); Vector3 cbox = new Vector3(6, 6, 6); boss = new GorillaBossobject(player, location, pbox, cbox, scale, true, true, 6, 2, 1, gorillaSprite); ps.objList.Add(boss); ps.physList.Add(boss); ps.collisionList.Add(boss); ps.renderList.Add(boss); ps.combatList.Add(boss); barrels = new List<Projectile>(); delayTime = 3; delayTimer = 0; barrelDelayed = true; }
/// <summary> /// Peeks at the AI on the top of the AI stack and runs its update method /// </summary> /// <param name="time"></param> /// <param name="playstate"></param> /// <param name="playerposn"></param> /// <param name="enable3d"></param> /// <param name="physList"></param> public void aiUpdate(double time, PlayState playstate, Vector3 playerposn, bool enable3d, List<PhysicsObject> physList) { CurrentAI.Peek().update(time, playstate, playerposn, this, enable3d, physList); }
public void update(double time, PlayState playstate, Vector3 playerposn, Enemy me, bool enable3d, List<PhysicsObject> physList) { //update current animation me.cycleNumber = (int)(enable3d ? KidAnim.stand3d : KidAnim.stand2d); //Flip scale if necessary if(!enable3d) { if((me.location.X < playerposn.X && me.scale.X > 0) || (me.location.X > playerposn.X && me.scale.X < 0)) { me.scale = new Vector3(-me.scale.X, me.scale.Y, me.scale.Z); } } else { // 3D if(me.scale.X < 0) { me.scale = new Vector3(-me.scale.X, me.scale.Y, me.scale.Z); } } if (!me.frozen) { if (VectorUtil.dist(playerposn, me.location) <= 90) { if (me.attackdelayed) me.attacktimer = me.attacktimer + time; if (me.attacktimer > me.attackspeed) { me.attackdelayed = false; me.attacktimer = 0; } if (!me.attackdelayed) { Vector3 dir = VectorUtil.getdir(playerposn, me.location); //throw icecream Vector3 projlocation = me.location; Vector3 direction = VectorUtil.getdir(playerposn, me.location); if (!enable3d) { projlocation.Z += 0.001f; //break the rendering tie between enemy and projectile, or else they flicker } else { direction.Z = 0.0f; direction.NormalizeFast(); } Projectile shot = new Projectile(projlocation, direction, false, me.projectile, playstate.player); //Projectile shot = new Projectile(projlocation, direction, new Vector3(12.5f, 12.5f, 12.5f), new Vector3(6.25f, 6.25f, 6.25f), new Vector3(6.25f, 6.25f, 6.25f), true, true, playstate.enable3d, me.damage, 150, false, false, me.projectileSprite); playstate.objList.Add(shot); playstate.renderList.Add(shot); playstate.collisionList.Add(shot); playstate.physList.Add(shot); playstate.combatList.Add(shot); me.attackdelayed = true; } } else me.ChangeState(new Kidmoveto()); } }
public static void Load(int level_to_load, PlayState ps) { ps.objList = new List<GameObject>(); ps.renderList = new List<RenderObject>(); ps.aiList = new List<AIObject>(); ps.combatList = new List<CombatObject>(); ps.physList = new List<PhysicsObject>(); ps.collisionList = new List<PhysicsObject>(); ps.backgroundList = new List<Background>(); /** * This next section of code will read in a level file and create an array of Enemy files to be parsed. * */ Assembly assembly = Assembly.GetExecutingAssembly(); string file = "U5Designs.Resources.Data.Levels.level_" + level_to_load.ToString() + ".dat"; Stream fstream = assembly.GetManifestResourceStream(file); XmlDocument doc = new XmlDocument(); XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true; XmlReader reader = XmlReader.Create(fstream, settings); doc.Load(reader); XmlNode bossRegion = doc.GetElementsByTagName("bossRegion")[0]; XmlNode endRegion = doc.GetElementsByTagName("endRegion")[0]; XmlNode bossAreaCenter = doc.GetElementsByTagName("bossAreaCenter")[0]; XmlNode bossAreaBounds = doc.GetElementsByTagName("bossAreaBounds")[0]; XmlNode bossSpawn = doc.GetElementsByTagName("bossSpawn")[0]; XmlNodeList _b_list = doc.GetElementsByTagName("background"); XmlNodeList _e_list = doc.GetElementsByTagName("enemy"); XmlNodeList _o_list = doc.GetElementsByTagName("obstaclelist")[0].ChildNodes; XmlNodeList _d_list = doc.GetElementsByTagName("decorationlist")[0].ChildNodes; XmlNodeList _a_list = doc.GetElementsByTagName("audiofile"); XmlNodeList bossObstacleList = doc.GetElementsByTagName("bosslist")[0].ChildNodes; XmlNodeList bossRemoveList = doc.GetElementsByTagName("bossremovelist")[0].ChildNodes; fstream.Close(); //Regions and Boss Area ps.bossRegion = parseRegion(bossRegion); ps.endRegion = parseRegion(endRegion); ps.bossAreaCenter = parseVector3(bossAreaCenter); ps.bossAreaBounds = parseVector3(bossAreaBounds); ps.bossSpawn = parseVector3(bossSpawn); XmlNode aud = _a_list[0]; ps.levelMusic = new AudioFile(assembly.GetManifestResourceStream("U5Designs.Resources.Music." + aud.InnerText)); //Player List<ProjectileProperties> playerProjectiles = new List<ProjectileProperties>(); playerProjectiles.Add(parseProjectileFile("banana_projectile.dat", ps)); playerProjectiles.Add(parseProjectileFile("coconut_grenade_projectile.dat", ps)); ps.player = new Player(parseSpriteFile("player_sprite.dat"), parseSpriteFile("player_arm_sprite.dat"), playerProjectiles, ps); ps.player.marker = parseSpriteFile("marker_sprite.dat"); GameEngine ge = ps.eng; ps.player.p_state.setName(ge._player_name); ps.physList.Add(ps.player); ps.renderList.Add(ps.player); ps.crosshair = parseSpriteFile("crosshair_sprite.dat"); //Various GameObjects List<Enemy> _elist = parseEnemyFiles(_e_list, ps.player, ps); foreach(Enemy e in _elist) { ps.objList.Add(e); ps.physList.Add(e); ps.collisionList.Add(e); ps.renderList.Add(e); ps.aiList.Add(e); ps.combatList.Add(e); } List<Obstacle> _olist = parseObstacleFiles(_o_list); foreach(Obstacle o in _olist) { ps.objList.Add(o); ps.physList.Add(o); ps.renderList.Add(o); } List<Background> _blist = parseBackgroundFile(_b_list); foreach(Background b in _blist) { ps.objList.Add(b); ps.renderList.Add(b); ps.backgroundList.Add(b); } List<Decoration> _dlist = parseDecorationFile(_d_list); foreach(Decoration d in _dlist) { ps.objList.Add(d); ps.renderList.Add(d); } ps.bossList = parseObstacleFiles(bossObstacleList); ps.bossRemoveList = parseDecorationFile(bossRemoveList); ps.objList.AddRange(ps.bossRemoveList); ps.renderList.AddRange(ps.bossRemoveList); if ( level_to_load == 0) ps.bossAI = new ZookeeperAI(ps.player, ps); if (level_to_load == 1) ps.bossAI = new GorillaAI(ps.player, ps); SpriteSheet.quad = new ObjMesh(assembly.GetManifestResourceStream("U5Designs.Resources.Geometry.quad.obj")); //HUD Stamina Bar ps.staminaBack = parseSpriteFile("stamina_back.dat"); ps.staminaBar = parseSpriteFile("stamina_bar.dat"); ps.staminaFrame = parseSpriteFile("stamina_frame.dat"); // Auto Save autoSave(ps.player, level_to_load); }
public void update(double time, PlayState playstate, Vector3 playerposn, bool enable3d) { if (active) { //do Ai code, update the list of crates //tmp: pass update to the just the lone boss object for now if (bossobject.idle && switchdelaytimer > switchtime) { //time to swap the boss with something else and make him fall int index = rng.Next(0, 16); while (index == currentBossIndex || !boxes[index].idle) { index = rng.Next(0, 16); } //Swap boss/box code Vector3 temp = new Vector3(boxes[index].location.X, maxHeight, boxes[index].location.Z); boxes[index].setPosition(new Vector3(bossobject.centerLoc.X, maxHeight, bossobject.centerLoc.Z)); bossobject.setPosition(temp); boxes[currentBossIndex] = boxes[index]; currentBossIndex = index; boxes[index] = bossobject; switchdelaytimer = 0; //end swap code //Choose random facing for boss bossobject.setFacing(rng.Next(2) == 1); if (gethealth() == 5) { //first stage, only drop the boss bossobject.fall(); } if (gethealth() == 4) { // second stage, drop boss + either his row or column of boxes int rows = rng.Next(0, 2); if (rows == 0) { //row for (int i = 0; i < 4; i++) { if (currentBossIndex == 0 + i) { boxes[4 + i].fall(); boxes[8 + i].fall(); boxes[12 + i].fall(); } if (currentBossIndex == 4 + i) { boxes[0 + i].fall(); boxes[8 + i].fall(); boxes[12 + i].fall(); } if (currentBossIndex == 8 + i) { boxes[0 + i].fall(); boxes[4 + i].fall(); boxes[12 + i].fall(); } if (currentBossIndex == 12 + i) { boxes[0 + i].fall(); boxes[4 + i].fall(); boxes[8 + i].fall(); } } } else { //column for (int i = 0; i < 4; i++) { if (currentBossIndex >= i * 4 && currentBossIndex <= (i * 4) + 3) { for (int k = 0; k < 4; k++) { if ((i * 4) + k != currentBossIndex) boxes[(i * 4) + k].fall(); } } } } bossobject.fall(); } if (gethealth() == 3) { //third, drop both his row and column //row for (int i = 0; i < 4; i++) { if (currentBossIndex == 0 + i) { boxes[4 + i].fall(); boxes[8 + i].fall(); boxes[12 + i].fall(); } if (currentBossIndex == 4 + i) { boxes[0 + i].fall(); boxes[8 + i].fall(); boxes[12 + i].fall(); } if (currentBossIndex == 8 + i) { boxes[0 + i].fall(); boxes[4 + i].fall(); boxes[12 + i].fall(); } if (currentBossIndex == 12 + i) { boxes[0 + i].fall(); boxes[4 + i].fall(); boxes[8 + i].fall(); } } //column for (int i = 0; i < 4; i++) { if (currentBossIndex >= i * 4 && currentBossIndex <= (i * 4) + 3) { for (int k = 0; k < 4; k++) { if ((i * 4) + k != currentBossIndex) boxes[(i * 4) + k].fall(); } } } bossobject.fall(); } if (gethealth() == 2) { //specific pattern int pattern = rng.Next(0, 3); if (pattern == 0) { //checkers pattern if (currentBossIndex == 0 || currentBossIndex == 2 || currentBossIndex == 5 || currentBossIndex == 7 || currentBossIndex == 8 || currentBossIndex == 10 || currentBossIndex == 13 || currentBossIndex == 15) { boxes[0].fall(); boxes[2].fall(); boxes[5].fall(); boxes[7].fall(); boxes[8].fall(); boxes[10].fall(); boxes[13].fall(); boxes[15].fall(); } else { boxes[1].fall(); boxes[3].fall(); boxes[4].fall(); boxes[6].fall(); boxes[9].fall(); boxes[11].fall(); boxes[12].fall(); boxes[14].fall(); } bossobject.fall(); } if (pattern == 1) {// cross pattern boxes[0].fall(); boxes[12].fall(); boxes[5].fall(); boxes[9].fall(); boxes[6].fall(); boxes[10].fall(); boxes[3].fall(); boxes[15].fall(); bossobject.fall(); } if (pattern == 2) {//box pattern boxes[0].fall(); boxes[1].fall(); boxes[2].fall(); boxes[3].fall(); boxes[4].fall(); boxes[7].fall(); boxes[8].fall(); boxes[11].fall(); boxes[12].fall(); boxes[13].fall(); boxes[14].fall(); boxes[15].fall(); bossobject.fall(); } } if (gethealth() == 1) { //all but one box int stayup = rng.Next(0, 16); while (stayup == currentBossIndex) { stayup = rng.Next(0, 16); } for (int i = 0; i < 16; i++) { if (i != stayup) boxes[i].fall(); } } } else if (bossobject.idle) { switchdelaytimer = switchdelaytimer + time; } for (int i = 0; i < 16; i++) { if (i != currentBossIndex) { boxes[i].update(time, playstate, playerposn, enable3d); } else { bossobject.update(time, playstate, playerposn, enable3d);// always pass control to update } } } }
internal ZooBoss(Player player, PlayState ps, Vector3 location, int maxheight, ProjectileProperties invisProj, Obstacle crate, Obstacle ground, Obstacle rope, SpriteSheet bossSprite) : base(player, ps, location, maxheight, invisProj, crate, ground, rope) { //animation _sprite = bossSprite; _cycleNum = 0; _frameNum = 0; _animDirection = 1; //combat stuff _cbox = new Vector3(6, 6, 6); _health = 5; _damage = 1; _speed = 1; _alive = true; _hascbox = true; _type = 3; //Type 3 means this is the boss //Offset boss location centerLoc = new Vector3(_location); _location.X += 8.0f; _location.Z -= 0.01f; in3d = false; bb = Billboarding.Lock2d; invincible = false; }
public Effect(PlayState ps, Vector3 location, Vector3 scale, bool existsIn2d, bool existsIn3d, Billboarding bb, SpriteSheet sprite) : base(location, scale, existsIn2d, existsIn3d, bb, sprite) { this.playstate = ps; timeElapsed = 0.0; }
/// <summary> /// Called by mouse or keyboard handlers when the user picked a button (by clicking or hitting enter) /// </summary> internal void handleButtonPress() { // Go to next page switch (cur_page) { case 3: PlayState ps = new PlayState(eng, menu, 0); LoadScreenState ls = new LoadScreenState(eng, ps, 0); eng.ChangeState(ls); break; } }
public Player(SpriteSheet sprite, SpriteSheet arms, List<ProjectileProperties> projectiles, PlayState ps) : base(Int32.MaxValue) //player always has largest ID for rendering purposes { p_state = new PlayerState("TEST player"); //p_state.setSpeed(130); this.playstate = ps; _speed = runSpeed; _location = new Vector3(25, 12.5f, 50); _scale = new Vector3(25f, 25f, 25f); _pbox = new Vector3(5f, 11.0f, 5f); _cbox = new Vector3(4f, 10.0f, 4f); spinSize = 12; //?? experiment with this, TODO: change it to match the sprites size velocity = new Vector3(0, 0, 0); accel = new Vector3(0, 0, 0); kbspeed = new Vector3(70, 100, 70); jumpspeed = 250.0f; _cycleNum = 0; _frameNum = 0; _sprite = sprite; _hascbox = true; _type = 0; //type 0 is the player and only the player _existsIn2d = true; _existsIn3d = true; onGround = true; //arms this.arms = new Decoration(_location + new Vector3(0.005f, 0.0f, 0.005f), _scale, true, true, Billboarding.Yes, arms); ps.renderList.Add(this.arms); //combat things _damage = 1; spinDamage = 2; maxHealth = _health = 7; stamina = 5.0; maxStamina = 5.0; spaceDown = false; eDown = false; pDown = false; isMobile = true; Invincible = false; HasControl = true; Invincibletimer = 0.0; NoControlTimer = 0.0; fallTimer = 0.0; viewSwitchJumpTimer = 0.0; projectileTimer = 0.0; spinTimer = 0.0; lookDownTimer = -1.0; squishTimer = -1.0; lastPosOnGround = new Vector3(_location); _animDirection = 1; this.projectiles = projectiles; curProjectile = projectiles[0]; curProjectile.damage = _damage; markerList = new List<Decoration>(); Assembly assembly = Assembly.GetExecutingAssembly(); jumpSound = new AudioFile(assembly.GetManifestResourceStream("U5Designs.Resources.Sound.jump_sound.ogg")); bananaSound = new AudioFile(assembly.GetManifestResourceStream("U5Designs.Resources.Sound.banana2.ogg")); HurtSound = new AudioFile(assembly.GetManifestResourceStream("U5Designs.Resources.Sound.hurt.ogg")); HitSound = new AudioFile(assembly.GetManifestResourceStream("U5Designs.Resources.Sound.hit.ogg")); SpinSound = new AudioFile(assembly.GetManifestResourceStream("U5Designs.Resources.Sound.spin.ogg")); }
/** * This method parses a single Effect .dat file and returns the Effect * */ public static Effect parseEffectFile(string path, PlayState ps) { Assembly assembly = Assembly.GetExecutingAssembly(); Stream fstream = assembly.GetManifestResourceStream("U5Designs.Resources.Data.Effects." + path); XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true; XmlReader reader = XmlReader.Create(fstream, settings); XmlDocument doc = new XmlDocument(); doc.Load(reader); Vector3 scale = parseVector3(doc.GetElementsByTagName("scale")[0]); bool _draw2 = Convert.ToBoolean(doc.GetElementsByTagName("draw2")[0].InnerText); bool _draw3 = Convert.ToBoolean(doc.GetElementsByTagName("draw3")[0].InnerText); SpriteSheet ss = parseSpriteFile(doc.GetElementsByTagName("sprite")[0].InnerText); Billboarding bb = Billboarding.Yes; //Have to put something here for it to compile switch(doc.GetElementsByTagName("billboards")[0].InnerText) { case "yes": case "Yes": bb = Billboarding.Yes; break; case "lock2d": case "Lock2d": bb = Billboarding.Lock2d; break; case "lock3d": case "Lock3d": bb = Billboarding.Lock3d; break; default: Console.WriteLine("Bad obstacle file: " + path); Environment.Exit(1); break; } fstream.Close(); return new Effect(ps, Vector3.Zero, scale, _draw2, _draw3, bb, ss); }
/** * This method will take an XMLNodeList that contains all the Enemy objects that need to be created * for the current level being loaded. It will parse the XML .dat files, create an Enemy object, and add it * to a List<> which will be returned. * */ public static List<Enemy> parseEnemyFiles(XmlNodeList EList, Player player, PlayState ps) { // Instantiate the list List<Enemy> _e = new List<Enemy>(); Assembly assembly = Assembly.GetExecutingAssembly(); XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true; // Loop over the string list containing all the Enemy.dat files associated with the current Level being loaded. // For every Enemy.dat file parse the file, and create an Enemy, then add it to the List. When you're done with // the list of Enemies to parse, return the List<Enemy> for(int i = 0; i < EList.Count; i++) { string _e_path = "U5Designs.Resources.Data.Enemies." + EList[i].FirstChild.InnerText; Stream fstream = assembly.GetManifestResourceStream(_e_path); XmlDocument doc = new XmlDocument(); XmlReader reader = XmlReader.Create(fstream, settings); doc.Load(reader); Vector3 scale = parseVector3(doc.GetElementsByTagName("scale")[0]); Vector3 pbox = parseVector3(doc.GetElementsByTagName("pbox")[0]); Vector3 cbox = parseVector3(doc.GetElementsByTagName("cbox")[0]); bool draw_2d = Convert.ToBoolean(doc.GetElementsByTagName("draw2")[0].InnerText); bool draw_3d = Convert.ToBoolean(doc.GetElementsByTagName("draw3")[0].InnerText); int _health = Convert.ToInt32(doc.GetElementsByTagName("health")[0].InnerText); int _damage = Convert.ToInt32(doc.GetElementsByTagName("damage")[0].InnerText); float _speed = Convert.ToSingle(doc.GetElementsByTagName("speed")[0].InnerText); int _AI = Convert.ToInt32(doc.GetElementsByTagName("AI")[0].InnerText); string _sprite_path = doc.GetElementsByTagName("sprite")[0].InnerText; string _death_path = doc.GetElementsByTagName("death")[0].InnerText; XmlNodeList _proj = doc.GetElementsByTagName("proj"); fstream.Close(); SpriteSheet ss = parseSpriteFile(_sprite_path); Effect death = parseEffectFile(_death_path, ps); if(_proj.Count == 0) { // Create the Enemies for(int j = 1; j < EList[i].ChildNodes.Count; j++) { Vector3 loc = parseVector3(EList[i].ChildNodes[j]); _e.Add(new Enemy(player, loc, scale, pbox, cbox, draw_2d, draw_3d, _health, _damage, _speed, _AI, ss, death)); } } else { ProjectileProperties proj = parseProjectileFile(_proj[0].InnerText, ps); // Create the Enemies for(int j = 1; j < EList[i].ChildNodes.Count; j++) { Vector3 loc = parseVector3(EList[i].ChildNodes[j]); _e.Add(new Enemy(player, loc, scale, pbox, cbox, draw_2d, draw_3d, _health, _damage, _speed, _AI, ss, death, proj)); } } } // Return list of Enemies return _e; }
public static ProjectileProperties parseProjectileFile(String path, PlayState ps) { Assembly assembly = Assembly.GetExecutingAssembly(); Stream fstream = assembly.GetManifestResourceStream("U5Designs.Resources.Data.Projectiles." + path); XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true; XmlReader reader = XmlReader.Create(fstream, settings); XmlDocument doc = new XmlDocument(); doc.Load(reader); Vector3 scale = parseVector3(doc.GetElementsByTagName("scale")[0]); Vector3 pbox = parseVector3(doc.GetElementsByTagName("pbox")[0]); Vector3 cbox = parseVector3(doc.GetElementsByTagName("cbox")[0]); bool draw2 = Convert.ToBoolean(doc.GetElementsByTagName("draw2")[0].InnerText); bool draw3 = Convert.ToBoolean(doc.GetElementsByTagName("draw3")[0].InnerText); int damage = Convert.ToInt32(doc.GetElementsByTagName("damage")[0].InnerText); float speed = Convert.ToSingle(doc.GetElementsByTagName("speed")[0].InnerText); bool grav = Convert.ToBoolean(doc.GetElementsByTagName("gravity")[0].InnerText); SpriteSheet ss = parseSpriteFile(doc.GetElementsByTagName("sprite")[0].InnerText); XmlNodeList staminaCost = doc.GetElementsByTagName("staminaCost"); XmlNodeList duration = doc.GetElementsByTagName("duration"); XmlNodeList deathList = doc.GetElementsByTagName("death"); fstream.Close(); Effect deathAnim = null; if(deathList.Count > 0) { deathAnim = parseEffectFile(deathList[0].InnerText, ps); } bool hasStamina = staminaCost.Count != 0; bool hasDuration = duration.Count != 0; if(!hasStamina && !hasDuration) { return new ProjectileProperties(scale, pbox, cbox, draw2, draw3, damage, speed, grav, ss, deathAnim); } else if(!hasDuration) { return new ProjectileProperties(scale, pbox, cbox, draw2, draw3, damage, speed, grav, ss, deathAnim, Convert.ToDouble(staminaCost[0].InnerText)); } else if(!hasStamina) { return new ProjectileProperties(scale, pbox, cbox, draw2, draw3, damage, speed, grav, ss, deathAnim, 0.0, Convert.ToDouble(duration[0].InnerText)); } else { //has both return new ProjectileProperties(scale, pbox, cbox, draw2, draw3, damage, speed, grav, ss, deathAnim, Convert.ToDouble(staminaCost[0].InnerText), Convert.ToDouble(duration[0].InnerText)); } }
internal FallingBox(Player player, PlayState ps, Vector3 location, int maxheight, ProjectileProperties invisProj, Obstacle crate, Obstacle ground, Obstacle rope) : base() { //physics stuff velocity = new Vector3(0, 0, 0); accel = new Vector3(0, 0, 0); doesGravity = false; _scale = new Vector3(30.0f, 33.84f, 30.0f); _pbox = new Vector3(15.0f, 16.92f, 0.0f); _existsIn3d = true; _existsIn2d = true; maxHeight = maxheight; falling = false; rising = false; prefalling = false; idle = true; //animation _sprite = null; _cycleNum = 0; _frameNum = 0; _animDirection = 1; //timers downtime = 3; pretime = 1.5; shadowtimer = 0; //setup the sub-objects of the boss projectile = invisProj; mybox = crate; ps.objList.Add(mybox); ps.physList.Add(mybox); ps.renderList.Add(mybox); myGround = ground; ps.objList.Add(myGround); ps.physList.Add(myGround); ps.renderList.Add(myGround); myRope = rope; ps.objList.Add(myRope); ps.renderList.Add(myRope); //initialize everything's location based on the seed location mybox.canSquish = true; mybox.location = location + new Vector3(0, mybox.pbox.Y, 0); _location = location + new Vector3(0, (mybox.pbox.Y * 2) + pbox.Y, 0); myRope.location = location + new Vector3(0, (mybox.pbox.Y * 2) + pbox.Y + ropeOffset, 0);//rope sprite myGround.location = new Vector3(myGround.location.X, 100.0f, myGround.location.Z); minHeight = 125; preHeight = 210; }
public virtual void update(double time, PlayState playstate, Vector3 playerposn, bool enable3d) { if(prefalling) { if((mybox.location.Y - mybox.pbox.Y) <= preHeight) { setPosition(new Vector3(mybox.location.X, preHeight, mybox.location.Z)); velocity = mybox.velocity = myRope.velocity = new Vector3(0, 0, 0); pretimer = pretimer + time; if(pretimer >= pretime) { pretimer = 0; falling = true; prefalling = false; velocity = mybox.velocity = myRope.velocity = new Vector3(0, -200, 0); Projectile shot = new Projectile(new Vector3(mybox.location.X, preHeight - 0.12f, mybox.location.Z), new Vector3(0, -1, 0), false, projectile, playstate.player); // spawn the actual projectile shot.type = (int)CombatType.squish; // add projectile to appropriate lists playstate.objList.Add(shot); playstate.renderList.Add(shot); playstate.collisionList.Add(shot); playstate.physList.Add(shot); playstate.combatList.Add(shot); } } } if(falling) { if(mybox.velocity.Y == 0.0f) { //Wait for physics to stop the crate setPosition(new Vector3(mybox.location.X, minHeight, mybox.location.Z)); velocity = mybox.velocity = myRope.velocity = new Vector3(0, 0, 0); downtimer = downtimer + time; if(downtimer >= downtime) { downtimer = 0; falling = false; rising = true; velocity = mybox.velocity = myRope.velocity = new Vector3(0, 80, 0); shadowtimer = 1.25; } } } if(rising) { if(mybox.location.Y - mybox.pbox.Y >= maxHeight) { setPosition(new Vector3(mybox.location.X, maxHeight, mybox.location.Z)); velocity = mybox.velocity = myRope.velocity = new Vector3(0, 0, 0); rising = false; idle = true; } } //Update shadow if(prefalling || falling) { //Shadow increasing shadowtimer += time; myGround.frame3d = Math.Min((int)(shadowtimer * 22.0), 11); } else if(rising) { //Shadow decreasing shadowtimer -= time; myGround.frame3d = Math.Min((int)(shadowtimer * 22.0), 11); } else { //No shadow myGround.frame3d = 0; } }
/// <summary> /// Called by mouse or keyboard handlers when the user picked a button (by clicking or hitting enter) /// </summary> internal void handleButtonPress() { if (lvl == eng.max_level) { MainMenuState ms = new MainMenuState(eng); eng.ChangeState(ms); } else { // Go to next level MainMenuState ms = new MainMenuState(eng); PlayState ps = new PlayState(eng, ms, lvl); LoadScreenState ls = new LoadScreenState(eng, ps, lvl); eng.ChangeState(ls); } }
internal Crate(Player player, PlayState ps, Vector3 location, int maxheight, ProjectileProperties invisProj, Obstacle crate, Obstacle ground, Obstacle rope) : base(player, ps, location, maxheight, invisProj, crate, ground, rope) { }
public void update(double time, PlayState playstate, Vector3 playerposn, Enemy me, bool enable3d, List<PhysicsObject> physList) { me.cycleNumber = (int)(enable3d ? BirdAnim.fly3d : BirdAnim.fly2d); //Flip scale if necessary if(enable3d) { if(me.scale.X < 0) { me.scale = new Vector3(-me.scale.X, me.scale.Y, me.scale.Z); } } else { //2D if((me.velocity.X < 0 && me.scale.X < 0) || (me.velocity.X > 0 && me.scale.X > 0)) { me.scale = new Vector3(-me.scale.X, me.scale.Y, me.scale.Z); } } me.attackspeed = 1; // not used in the same way as other attack speeds. This is used to time out the swoop if it gets stuck if (!me.frozen) { if (dist2d(playerposn, me.location) > 60) { Vector3 dir = VectorUtil.getdir(playerposn, me.location); dir.Y = 0.0f; if (!enable3d) { dir.Z = 0.0f; } dir.NormalizeFast(); me.velocity.X = dir.X * me.speed; me.velocity.Z = dir.Z * me.speed; } else { me.velocity.X = 0; me.velocity.Z = 0; me.PushState(new BirdDive(me.location, playerposn)); } } }
public void killBoss(PlayState ps) { //TODO: whatever happens when the boss dies ps.objList.Remove(boss); ps.physList.Remove(boss); ps.collisionList.Remove(boss); ps.renderList.Remove(boss); ps.combatList.Remove(boss); active = false; }
internal void loadPlayState(int lvl) { PlayState ps = new PlayState(eng, menu, lvl); LoadScreenState ls = new LoadScreenState(eng, ps, lvl); eng.ChangeState(ls); }
public void update(double time, PlayState playstate, Vector3 playerposn, Enemy me, bool enable3d, List<PhysicsObject> physList) { if (!me.frozen) { if (!finished) { if (diving) { me.cycleNumber = (int)(enable3d ? BirdAnim.attack3d : BirdAnim.attack2d); //Flip scale if necessary //TODO: These are specific to 2D, add 3D case if((me.velocity.X < 0 && me.scale.X < 0) || (me.velocity.X > 0 && me.scale.X > 0)) { me.scale = new Vector3(-me.scale.X, me.scale.Y, me.scale.Z); } me.attacktimer = me.attacktimer + time; // do a fake gravity to simulate diving down if (startplayer.Y > startingposn.Y) me.accel.Y += (float)(200 * time); else me.accel.Y -= (float)(200 * time); dir.Y = 0.0f; if (!enable3d) { dir.Z = 0.0f; } dir.NormalizeFast(); me.velocity.X = dir.X * (me.speed); me.velocity.Z = dir.Z * (me.speed); // if dove to lowest point, or to much time has passed(we got suck), stop diving if ((Math.Abs(me.location.Y - startplayer.Y) < 10) || me.attacktimer > me.attackspeed) { me.velocity.Y = 0; me.attacktimer = 0; diving = false; } } else { me.cycleNumber = (int)(enable3d ? BirdAnim.fly3d : BirdAnim.fly2d); //Flip scale if necessary if(enable3d) { if(me.scale.X < 0) { me.scale = new Vector3(-me.scale.X, me.scale.Y, me.scale.Z); } } else { //2D if((me.velocity.X < 0 && me.scale.X < 0) || (me.velocity.X > 0 && me.scale.X > 0)) { me.scale = new Vector3(-me.scale.X, me.scale.Y, me.scale.Z); } } me.attacktimer = me.attacktimer + time; // do a reverse gravity to simulate flying back up if (startplayer.Y > startingposn.Y) me.accel.Y -= (float)(200 * time); else me.accel.Y += (float)(200 * time); dir.Y = 0.0f; if (!enable3d) { dir.Z = 0.0f; } dir.NormalizeFast(); me.velocity.X = dir.X * (me.speed); me.velocity.Z = dir.Z * (me.speed); //if back to original height, or to much time has passed(we got suck), just finish if (startplayer.Y > startingposn.Y) { if ((me.location.Y <= startingposn.Y) || me.attacktimer > me.attackspeed) { finished = true; me.velocity.X = 0; me.velocity.Y = 0; me.velocity.Z = 0; } } else { if ((me.location.Y >= startingposn.Y) || me.attacktimer > me.attackspeed) { finished = true; me.velocity.X = 0; me.velocity.Y = 0; me.velocity.Z = 0; } } } } else { me.attacktimer = 0; me.velocity.X = 0; me.velocity.Y = 0; me.velocity.Z = 0; me.PopState(); } } }
public GameOverState(MainMenuState prvstate, GameEngine engine, PlayState ps) { eng = engine; menu = prvstate; _ps = ps; _old_state = OpenTK.Input.Keyboard.GetState(); lookat = new Vector3(0, 0, 2); eye = new Vector3(0, 0, 5); xf = 1.0f; yf = 1.0f; // TO DO: CHANGE THE GAME OVER SCREEN eng.StateTextureManager.RenderSetup(); Assembly audAssembly = Assembly.GetExecutingAssembly(); eng.StateTextureManager.LoadTexture("go", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.gameover.png")); goBackground = eng.StateTextureManager.GetTexture("go"); /* eng.StateTextureManager.LoadTexture("arrow", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.arrow.png")); arrow = eng.StateTextureManager.GetTexture("arrow"); eng.StateTextureManager.LoadTexture("back2menu", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.btn_backtomenu.png")); mainmenu = eng.StateTextureManager.GetTexture("back2menu"); eng.StateTextureManager.LoadTexture("back2menupress", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.btn_backtomenu_hover.png")); menu_pressed = eng.StateTextureManager.GetTexture("back2menupress"); eng.StateTextureManager.LoadTexture("restartlevel", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.btn_restart.png")); restart = eng.StateTextureManager.GetTexture("restartlevel"); eng.StateTextureManager.LoadTexture("restartlevelpress", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.btn_restart_hover.png")); restart_pressed = eng.StateTextureManager.GetTexture("restartlevelpress"); eng.StateTextureManager.LoadTexture("exitgame", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.btn_exit.png")); exit = eng.StateTextureManager.GetTexture("exitgame"); eng.StateTextureManager.LoadTexture("exitpress", audAssembly.GetManifestResourceStream("U5Designs.Resources.Textures.GameOverTextures.btn_exit_hover.png")); exit_pressed = eng.StateTextureManager.GetTexture("exitpress"); * */ // QFont //Assembly assembly = Assembly.GetExecutingAssembly(); //eng.StateTextureManager.LoadTexture("menu", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.menu.png")); //bg = eng.StateTextureManager.GetTexture("menu"); _buttons = new List<String>(); _buttons.Add("Restart Level ??"); _buttons.Add("Return to Main Menu"); _buttons.Add("Quit"); button = QFont.FromQFontFile("Fonts/myHappySans.qfont", new QFontLoaderConfiguration(true)); button.Options.DropShadowActive = true; //title = QFont.FromQFontFile("myHappySans.qfont", new QFontLoaderConfiguration(true)); title = QFont.FromQFontFile("Fonts/myRock.qfont", new QFontLoaderConfiguration(true)); title.Options.DropShadowActive = false; buttonHighlight = QFont.FromQFontFile("Fonts/myHappySans2.qfont", new QFontLoaderConfiguration(true)); buttonHighlight.Options.DropShadowActive = true; //QFont.CreateTextureFontFiles("Fonts/Rock.TTF", 48, "myRock"); // Use this to create new Fonts that you will texture // End QFonts //restart_btn = eng.StateTextureManager.GetTexture("restart"); //quit_btn = eng.StateTextureManager.GetTexture("quit_button"); arX = -200.0f; b1Y = -50.0f; b2Y = -100.0f; b3Y = -150.0f; timeTillNextState = 4; }
/** This loads the chosen game **/ internal void loadPlayState(int lvl) { musicFile.Stop(); PlayState ps = new PlayState(eng, _ms, lvl); LoadScreenState ls = new LoadScreenState(eng, ps, lvl); eng.ChangeState(ls); }
public void update(double time, PlayState playstate, Vector3 playerposn, Enemy me, bool enable3d, List<PhysicsObject> physList) { //update current animation and flip scale if necessary if(enable3d) { me.cycleNumber = (int)(me.moving ? GirlAnim.walk3d : GirlAnim.stand3d); if(me.scale.X < 0) { me.scale = new Vector3(-me.scale.X, me.scale.Y, me.scale.Z); } } else { //2D me.cycleNumber = (int)(me.moving ? GirlAnim.walk2d : GirlAnim.stand2d); if((me.velocity.X < 0 && me.scale.X < 0) || (me.velocity.X > 0 && me.scale.X > 0)) { me.scale = new Vector3(-me.scale.X, me.scale.Y, me.scale.Z); } } me.attackspeed = 1; //delay between each projectile (hack initialization) if (!me.frozen) { Vector3 dir = VectorUtil.getdir(playerposn, me.location); dir.Y = 0.0f; if (!enable3d) { dir.Z = 0.0f; } dir.NormalizeFast(); me.velocity.X = dir.X * me.speed; me.velocity.Z = dir.Z * me.speed; //Don't change y - out of our control //Look ahead to see if we are at an edge Vector3 origLoc = me.location; me.location += me.velocity * 0.1f; //move a little bit in this direction (will undo later) if (!(enable3d ? VectorUtil.overGround3dStrict(me, physList) : VectorUtil.overGround2d(me, physList))) { if (enable3d) { //If we're on edge, move along one axis to corner Vector3 origVel = new Vector3(me.velocity); //Check X first me.velocity.X = 0.0f; me.location = origLoc + me.velocity * 0.1f; if (!VectorUtil.overGround3dStrict(me, physList)) { me.velocity.X = origVel.X; me.velocity.Z = 0.0f; me.location = origLoc + me.velocity * 0.1f; if (!VectorUtil.overGround3dStrict(me, physList)) { //Now we're at corner me.velocity.X = 0.0f; me.velocity.Z = 0.0f; } } //Velocity now resulted in something over ground or is zero } else { //Only one option, so just stop me.velocity.X = 0.0f; me.velocity.Z = 0.0f; } } me.location = origLoc; //undo above } }