public void update(Character character) { int n; Projectile projectile; n = projectiles.Count; float x = character.getPos().X; float projX; Rectangle charBound = character.getColliBound(); for(int i = 0; i < n; i++) { projectile = projectiles.ElementAt(i); projectile.update(); projX = projectile.getPos().X; if(projX < -100) { projectiles.RemoveAt(i); i--; n--; } if((x - projX) < 100 && (x - projX) > -100) { if(projectile.getBound().Intersects(charBound)){ character.health--; projectiles.RemoveAt(i); i--; n--; } } } }
public GameHandler() { scoreUpdated = true; character = new Character(0); platforms = new Platforms(); obstacles = new Obstacles(); spikes = new Obstacles(); //pointers = new Pointers(); projectiles = new Projectiles(); coins = new Coins(); bg1 = new Background(0, 0, Background.NORMAL); bg2 = new Background(1512, 0, Background.NORMAL); sky = new Background(0, 0, Background.FAR); sky2 = new Background(1512, 0, Background.FAR); sky.setSpeed(-1, 0); sky2.setSpeed(-1, 0); platforms.addPlatform(0, Platform.DEFAULT_GROUND_Y, Platform.SIZE_TYPE_4); platforms.addPlatform(platforms.getLast().getBound().Right, Platform.DEFAULT_GROUND_Y, Platform.SIZE_TYPE_4); delayProjectiles = 0; delayCoins = 0; delayObstacles = 0; motionTime = 0; addMotionTime = false; state = GameHandler.STATE_ALIVE; hero = new Animation(Animation.DEPENDENT_SPEED); flipHero = new Animation(Animation.DEPENDENT_SPEED); freeze = false; random = new Random(); motionEffect = new Animation(Animation.INDEPENDENT_SPEED); DELAY_MIN_PRO=2000; DELAY_MAX_PRO = 5000; isf = IsolatedStorageFile.GetUserStoreForApplication(); try { srLevel = new StreamReader(new IsolatedStorageFileStream("Data\\level.sav", FileMode.Open, isf)); sLevel = srLevel.ReadLine(); elapsedX = Convert.ToInt32(sLevel); sLevel = srLevel.ReadLine(); obstaclesType = Convert.ToInt32(sLevel); } catch { elapsedX = -1; obstaclesType = -1; } }
public void update(Character character) { int n; Coin coin; Rectangle charBound = character.getBound(); n = coins.Count; for(int i = 0; i < n; i++) { coin = coins.ElementAt(i); coin.update(); if(coin.getBound().Intersects(charBound)) { character.points++; coins.RemoveAt(i); i--; n--; } } }
public void newLevel() { scoreUpdated = true; Game1.gameSpeed = 1; character = new Character(0); platforms = new Platforms(); obstacles = new Obstacles(); spikes = new Obstacles(); //pointers = new Pointers(); projectiles = new Projectiles(); bg1 = new Background(0, 0, Background.NORMAL); bg2 = new Background(1512, 0, Background.NORMAL); sky = new Background(0, 0, Background.FAR); sky2 = new Background(1512, 0, Background.FAR); sky.setSpeed(-1, 0); sky2.setSpeed(-1, 0); coins = new Coins(); platforms.addPlatform(0, Platform.DEFAULT_GROUND_Y, Platform.SIZE_TYPE_4); platforms.addPlatform(platforms.getLast().getBound().Right, Platform.DEFAULT_GROUND_Y, Platform.SIZE_TYPE_4); delayProjectiles = 0; delayCoins = 0; delayObstacles = 0; motionTime = 0; addMotionTime = false; state = GameHandler.STATE_ALIVE; freeze = false; DELAY_MIN_PRO=2000; DELAY_MAX_PRO = 5000; }