Пример #1
0
 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;
     }
 }
Пример #2
0
        public void update(Platforms platforms, Obstacles obstacles, Obstacles spikes)
        {
            if(goBottom) {
                if(speed.Y < 40)
                    speed.Y += 2*Game1.gameSpeed;
                goTop = false;
                if(speed.Y > 5)
                    state = Character.STATE_SKY_DOWN;
            }
            if(goTop) {
                if(speed.Y > -40)
                    speed.Y -= 2*Game1.gameSpeed;
                goBottom = false;
                if(speed.Y < -5)
                    state = Character.STATE_SKY_UP;
            }
            if(curPlatforms != -1) {
                Platform platform = platforms.getPlatform(curPlatforms);
                if(platform.getType() == Platform.TYPE_GROUND) {
                    if(goTop)
                        speed.Y = 0;
                    goBottom = true;
                    goTop = false;
                    if(bound.Intersects(platform.getBound())){
                        if(getCollisionType(platform.getBound()) == Character.COLLISION_Y) {
                            speed.Y = 0;
                            goBottom = false;
                            position.Y = platform.getBound().Top - Character.HEIGHT+1;
                            state = Character.STATE_BOTTOM;
                            if(position.X < Character.DEFAULT_POS_X) {
                                speed.X = 3;
                            }
                        }
                        else if(getCollisionType(platform.getBound()) == Character.COLLISION_X){
                            position.X = platform.getBound().Left - Character.WIDTH + 1;
                        }
                    }
                }
                else {
                    if(goBottom)
                        speed.Y = 0;
                    goTop = true;
                    goBottom = false;
                    if(bound.Intersects(platform.getBound())) {
                        speed.Y = 0;
                        goTop = false;
                        position.Y = platform.getBound().Bottom -1;
                        state = Character.STATE_TOP;
                        if(position.X < Character.DEFAULT_POS_X) {
                            speed.X = 3;
                        }
                    }
                }
            }
            else {
                goBottom = true;
                if(goTop) {
                    goTop = false;
                    speed.Y = 0;
                }

            }
            if(position.X > Character.DEFAULT_POS_X) {
                position.X = Character.DEFAULT_POS_X;
                speed.X = 0;
            }
            int n = obstacles.getSize();
            int i = 0;
            Rectangle rect;
            while(i < n) {
                rect = obstacles.getObstacle(i).getBound();
                if(bound.Intersects(rect)){
                    if(getCollisionType(rect) == Character.COLLISION_Y) {
                        if(drawBound.Center.Y < rect.Center.Y  && (state == Character.STATE_SKY_DOWN || state == Character.STATE_BOTTOM)) {
                            speed.Y = 0;
                            goBottom = false;
                            position.Y = rect.Top - Character.HEIGHT + 1;
                        }
                        else if(drawBound.Center.Y > rect.Center.Y && (state == Character.STATE_SKY_UP || state == Character.STATE_TOP)) {
                            speed.Y = 0;
                            position.Y = rect.Bottom - 1;
                        }
                        if(position.X < Character.DEFAULT_POS_X) {
                            speed.X = 3;
                        }
                        if(position.X > Character.DEFAULT_POS_X) {
                            position.X = Character.DEFAULT_POS_X;
                            speed.X = 0;
                        }
                    }
                    else if(getCollisionType(rect) == Character.COLLISION_X && drawBound.Center.X < rect.Center.X){
                        position.X = rect.Left - Character.WIDTH + 1;
                    }
                }
                i++;
            }

            for(i = 0; i < n;i++ ) {
                rect = obstacles.getObstacle(i).getDeathBound();
                if(bound.Intersects(rect)) {
                    if (!songstart)
                    {
                        MediaPlayer.Play(Assets.ScreamBGM);
                        songstart = true;
                    }
                    songstart = false;
                    MediaPlayer.Stop();
                    health--;
                    position.X = Character.DEFAULT_POS_X;
                    position.Y = Platform.DEFAULT_SKY_Y + Platform.SIZE_TYPE_1.Y;
                    songstart = false;
                    MediaPlayer.Stop();
                }
                i++;
            }
            if(position.Y > Game1.screenSize.Y + 70 || position.X < -100) {
                position.Y = Game1.screenSize.Y - 200;
                if(health > 0)
                    position.X = Character.DEFAULT_POS_X;
                platforms.addPlatform(position.X + 30, Platform.DEFAULT_GROUND_Y, Platform.SIZE_TYPE_1);
                speed.Y = 0;
                health--;
            }
            distance += (-1 * Background.simultanSpeed.X);
            position += (speed * Game1.gameSpeed);
            bound.Offset((int)(position.X - bound.Left), (int)(position.Y - bound.Top));
            drawBound.Offset((int)(position.X - drawBound.Left), (int)(position.Y - drawBound.Top));
            colliBound.Offset((int)(10 + position.X - colliBound.Left), (int)(10 + position.Y - colliBound.Top));
        }
Пример #3
0
 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;
 }