コード例 #1
0
ファイル: Manager.cs プロジェクト: remberluyckx/mygame
        public void RestartLvl2()
        {
            hero           = new Hero(mVideo, SdlDotNet.Input.Key.A, SdlDotNet.Input.Key.D, SdlDotNet.Input.Key.Space, SdlDotNet.Input.MouseButton.PrimaryButton);
            activelevel    = level2;
            hero.position  = hero.lvl2Position;
            heartContainer = new HeartContainer(mVideo, heartContainerPoint);

            spikes1_ColRectangle = new Rectangle(180, 420, 85, 71);

            platform1_ColRectangle = new Rectangle(0, 180, 350, 15);
            platform2_ColRectangle = new Rectangle(720, 240, 350, 15);
            platform3_ColRectangle = new Rectangle(330, 330, 350, 15);
            platform4_ColRectangle = new Rectangle(450, 330, 350, 15);

            enemy_1 = new Point(180, 125);
            enemy_2 = new Point(450, 275);
            enemy_3 = new Point(300, 425);
            enemy_4 = new Point(650, 425);
            vijand1 = new Vijand(mVideo, enemy_1, 180, 230);
            vijand2 = new Vijand(mVideo, enemy_2, 450, 600);
            vijand3 = new Vijand(mVideo, enemy_3, 300, 400);
            vijand4 = new Vijand(mVideo, enemy_4, 650, 700);
        }
コード例 #2
0
ファイル: Manager.cs プロジェクト: remberluyckx/mygame
        private void Events_Tick(object sender, TickEventArgs e)
        {
            //Clear
            mVideo.Blit(background);

            //Update
            if (startscreen.keypress == true && activelevel == startscreen)
            {
                activelevel = level1;
            }
            if (endscreen.keypress == true && activelevel == endscreen)
            {
                Environment.Exit(0);
            }

            if (hero.health == 3)
            {
                mVideo.Blit(heart, heartPoint);
                mVideo.Blit(heart, heartPoint2);
                mVideo.Blit(heart, heartPoint3);
            }
            if (hero.health == 2)
            {
                mVideo.Blit(heart, heartPoint);
                mVideo.Blit(heart, heartPoint2);
            }
            if (hero.health == 1)
            {
                mVideo.Blit(heart, heartPoint);
            }
            hero.Update();
            lasers.UpdateRight();
            lasers.UpdateLeft();
            slimes.UpdateLeft();
            slimes.UpdateRight();
            if (vijand1 != null)
            {
                vijand1.Update();
            }
            if (vijand2 != null)
            {
                vijand2.Update();
            }
            if (vijand3 != null)
            {
                vijand3.Update();
            }
            if (vijand4 != null)
            {
                vijand4.Update();
            }

            //Draw
            if (hero.immune == false)
            {
                hero.Draw();
            }
            else // HERO FLICKERS WHEN LOSING HEALTH
            {
                drawTimer++;
                if (drawTimer == 6)
                {
                    drawTimer = 0;
                }
                if (drawTimer >= 3)
                {
                    hero.Draw();
                }
            }
            lasers.Draw();
            slimes.Draw();
            if (vijand1 != null)
            {
                vijand1.Draw();
            }
            if (vijand2 != null)
            {
                vijand2.Draw();
            }
            if (vijand3 != null)
            {
                vijand3.Draw();
            }
            if (vijand4 != null)
            {
                vijand4.Draw();
            }
            if (activelevel == level2 && heartContainer != null)
            {
                heartContainer.Draw();
            }

            activelevel.DrawWorld();

            //COLLISION ETC

            //HERO ENTERS LEVEL 2
            if (activelevel == level1 && hero.colRectangle.Bottom < 130 && hero.colRectangle.Right >= 788)
            {
                RestartLvl2();
            }

            //HERO COMPLETES GAME
            if (activelevel == level2 && hero.colRectangle.Top > 380 && hero.colRectangle.Right >= 788)
            {
                activelevel = endscreen;
            }

            //HERO-HEARTCONTAINER COLLISION
            if (activelevel == level2)
            {
                if (heartContainer != null)
                {
                    if (heartContainer.colRectangle.IntersectsWith(hero.colRectangle))
                    {
                        heartContainer = null;
                        if (hero.health < 3)
                        {
                            hero.health++;
                        }
                    }
                }
            }

            //HERO-SPIKES COLLISION
            if (spikes1_ColRectangle.IntersectsWith(hero.colRectangle))
            {
                if (hero.immune == false)
                {
                    sndPain.Play();
                    hero.health--;
                    if (hero.health == 0)
                    {
                        hero.dead = true;
                    }
                    hero.immune = true;
                }
            }

            //HERO SHOOTS
            if (hero.shoot && activelevel != startscreen && activelevel != endscreen)
            {
                sndLaser.Play();
                if (hero.facingDirection == "right")
                {
                    laserPoint = new Point(hero.position.X + 35, hero.position.Y + 35);
                }
                if (hero.facingDirection == "left")
                {
                    laserPoint = new Point(hero.position.X, hero.position.Y + 35);
                }
                Laser laser = new Laser(mVideo, laserPoint, lasers, hero.facingDirection);
                hero.shoot = false;
            }

            //ENEMY DEAD CHECK
            if (vijand1 != null)
            {
                if (vijand1.dead)
                {
                    vijand1 = null;
                }
            }
            if (vijand2 != null)
            {
                if (vijand2.dead)
                {
                    vijand2 = null;
                }
            }
            if (vijand3 != null)
            {
                if (vijand3.dead)
                {
                    vijand3 = null;
                }
            }
            if (vijand4 != null)
            {
                if (vijand4.dead)
                {
                    vijand4 = null;
                }
            }



            //HERO DEAD CHECK
            if (hero.dead == true)
            {
                if (activelevel == level1)
                {
                    RestartLvl1();
                }
                if (activelevel == level2)
                {
                    RestartLvl2();
                }
            }

            //LASER COLLISION
            lasers.CheckHitPlatform(platform1_ColRectangle);
            lasers.CheckHitPlatform(platform2_ColRectangle);
            lasers.CheckHitPlatform(platform3_ColRectangle);
            lasers.CheckHitPlatform(platform4_ColRectangle);
            lasers.CheckHitSpikes(spikes1_ColRectangle);
            if (vijand1 != null)
            {
                lasers.CheckHitEnemy(vijand1);
            }
            if (vijand2 != null)
            {
                lasers.CheckHitEnemy(vijand2);
            }
            if (vijand3 != null)
            {
                lasers.CheckHitEnemy(vijand3);
            }
            if (vijand4 != null)
            {
                lasers.CheckHitEnemy(vijand4);
            }

            //SLIME COLLISION
            slimes.CheckHitHero(hero);
            slimes.CheckHitPlatform(platform1_ColRectangle);
            slimes.CheckHitPlatform(platform2_ColRectangle);
            slimes.CheckHitPlatform(platform3_ColRectangle);
            slimes.CheckHitPlatform(platform4_ColRectangle);
            slimes.CheckHitSpikes(spikes1_ColRectangle);

            //ENEMYSIGHT-HERO COLLISION (--> FOR WHEN TO SHOOT)
            checkSightCollision(vijand1);
            checkSightCollision(vijand2);
            checkSightCollision(vijand3);
            checkSightCollision(vijand4);

            //HERO-ENEMY COLLISION
            checkEnemyCollision(vijand1);
            checkEnemyCollision(vijand2);
            checkEnemyCollision(vijand3);
            checkEnemyCollision(vijand4);

            //IMMUNE TIMER (zodat hero even immune is als hij een leven verliest)
            if (hero.immune == true)
            {
                immuneTimer++;
                if (immuneTimer == 100)
                {
                    immuneTimer = 0;
                    hero.immune = false;
                }
            }

            //PLATFORM COLLSION
            if (platform1_ColRectangle.IntersectsWith(hero.colRectangle))
            {
                checkPlatformCollision(platform1_ColRectangle);
            }
            else if (platform2_ColRectangle.IntersectsWith(hero.colRectangle))
            {
                checkPlatformCollision(platform2_ColRectangle);
            }
            else if (platform3_ColRectangle.IntersectsWith(hero.colRectangle))
            {
                checkPlatformCollision(platform3_ColRectangle);
            }
            else if (platform4_ColRectangle.IntersectsWith(hero.colRectangle))
            {
                checkPlatformCollision(platform4_ColRectangle);
            }
            else
            {
                hero.down = true;
            }

            //GROUND COLLISION
            if (hero.colRectangle.IntersectsWith(groundColRectangle))
            {
                hero.down = false;
            }

            mVideo.Update();
        }
コード例 #3
0
ファイル: Manager.cs プロジェクト: remberluyckx/mygame
        private void Events_Tick(object sender, TickEventArgs e)
        {            
                
            //Clear
            mVideo.Blit(background);
               
            //Update
            if (startscreen.keypress == true && activelevel == startscreen)
                activelevel = level1;
            if (endscreen.keypress == true && activelevel == endscreen)
                Environment.Exit(0);

            if (hero.health == 3)
            {
                mVideo.Blit(heart, heartPoint);
                mVideo.Blit(heart, heartPoint2);
                mVideo.Blit(heart, heartPoint3);
            }
            if (hero.health == 2)
            {
                mVideo.Blit(heart, heartPoint);
                mVideo.Blit(heart, heartPoint2);
            }
            if (hero.health == 1)
            {
                mVideo.Blit(heart, heartPoint);
            }
            hero.Update();
            lasers.UpdateRight();            
            lasers.UpdateLeft();
            slimes.UpdateLeft();
            slimes.UpdateRight();
            if (vijand1 != null)
            vijand1.Update();
            if (vijand2 != null)
            vijand2.Update();
            if (vijand3 != null)
                vijand3.Update();
            if (vijand4 != null)
                vijand4.Update();

            //Draw
            if (hero.immune == false)
            hero.Draw();
            else // HERO FLICKERS WHEN LOSING HEALTH
            {
                drawTimer++;
                if (drawTimer == 6)
                    drawTimer = 0;
                if (drawTimer >= 3)                
                    hero.Draw();              
            }
            lasers.Draw();
            slimes.Draw();
            if (vijand1 != null)
            vijand1.Draw();
            if (vijand2 != null)
            vijand2.Draw();
            if (vijand3 != null)
                vijand3.Draw();
            if (vijand4 != null)
                vijand4.Draw();
            if (activelevel == level2 && heartContainer != null)
                heartContainer.Draw();

            activelevel.DrawWorld();

            //COLLISION ETC

            //HERO ENTERS LEVEL 2
            if (activelevel == level1 && hero.colRectangle.Bottom < 130 && hero.colRectangle.Right >= 788)
                RestartLvl2();

            //HERO COMPLETES GAME
            if (activelevel == level2 && hero.colRectangle.Top > 380 && hero.colRectangle.Right >= 788)
                activelevel = endscreen;

            //HERO-HEARTCONTAINER COLLISION
            if (activelevel == level2)
            {
                if (heartContainer != null)
                {
                    if (heartContainer.colRectangle.IntersectsWith(hero.colRectangle))
                    {
                        heartContainer = null;
                        if (hero.health < 3)
                        hero.health++;
                    }
                }               
            }

            //HERO-SPIKES COLLISION
            if (spikes1_ColRectangle.IntersectsWith(hero.colRectangle))
            {
                if (hero.immune == false)
                {
                    sndPain.Play();
                    hero.health--;
                    if (hero.health == 0)
                        hero.dead = true;
                    hero.immune = true;
                }                
            }
  
            //HERO SHOOTS
            if (hero.shoot && activelevel != startscreen && activelevel != endscreen)
            {
                sndLaser.Play();
                if (hero.facingDirection == "right")
                    laserPoint = new Point(hero.position.X + 35, hero.position.Y + 35);
                if (hero.facingDirection == "left")
                    laserPoint = new Point(hero.position.X, hero.position.Y + 35);
                Laser laser = new Laser(mVideo, laserPoint, lasers, hero.facingDirection);
                hero.shoot = false;
            }
           
            //ENEMY DEAD CHECK
            if (vijand1 != null)
            {
                if (vijand1.dead)
                    vijand1 = null;
            }            
            if (vijand2 != null)
            {          
                if (vijand2.dead)
                    vijand2 = null;
            }
            if (vijand3 != null)
            {
                if (vijand3.dead)
                    vijand3 = null;
            }
            if (vijand4 != null)
            {
                if (vijand4.dead)
                    vijand4 = null;
            }

            

            //HERO DEAD CHECK
            if (hero.dead == true)
            {
                if (activelevel == level1)
                    RestartLvl1();
                if (activelevel == level2)
                    RestartLvl2();               
            }

            //LASER COLLISION
            lasers.CheckHitPlatform(platform1_ColRectangle);
            lasers.CheckHitPlatform(platform2_ColRectangle);
            lasers.CheckHitPlatform(platform3_ColRectangle);
            lasers.CheckHitPlatform(platform4_ColRectangle);
            lasers.CheckHitSpikes(spikes1_ColRectangle);
            if (vijand1 != null)
            lasers.CheckHitEnemy(vijand1);
            if (vijand2 != null)
            lasers.CheckHitEnemy(vijand2);
            if (vijand3 != null)
            lasers.CheckHitEnemy(vijand3);
            if (vijand4 != null)
            lasers.CheckHitEnemy(vijand4);

            //SLIME COLLISION
            slimes.CheckHitHero(hero);
            slimes.CheckHitPlatform(platform1_ColRectangle);
            slimes.CheckHitPlatform(platform2_ColRectangle);
            slimes.CheckHitPlatform(platform3_ColRectangle);
            slimes.CheckHitPlatform(platform4_ColRectangle);
            slimes.CheckHitSpikes(spikes1_ColRectangle);

            //ENEMYSIGHT-HERO COLLISION (--> FOR WHEN TO SHOOT)
            checkSightCollision(vijand1);
            checkSightCollision(vijand2);
            checkSightCollision(vijand3);
            checkSightCollision(vijand4); 

            //HERO-ENEMY COLLISION               
            checkEnemyCollision(vijand1);                                        
            checkEnemyCollision(vijand2);            
            checkEnemyCollision(vijand3);        
            checkEnemyCollision(vijand4);     
            
            //IMMUNE TIMER (zodat hero even immune is als hij een leven verliest)
            if (hero.immune == true)
            {
                immuneTimer++;
                if (immuneTimer == 100) {
                    immuneTimer = 0;
                    hero.immune = false;
                }
            }

            //PLATFORM COLLSION
            if (platform1_ColRectangle.IntersectsWith(hero.colRectangle))
                checkPlatformCollision(platform1_ColRectangle);
            else if (platform2_ColRectangle.IntersectsWith(hero.colRectangle)) {
                checkPlatformCollision(platform2_ColRectangle);
            }
            else if (platform3_ColRectangle.IntersectsWith(hero.colRectangle))
            {
                checkPlatformCollision(platform3_ColRectangle);
            }
            else if (platform4_ColRectangle.IntersectsWith(hero.colRectangle))
            {
                checkPlatformCollision(platform4_ColRectangle);
            }   
            else 
            {
                hero.down = true;                 
            }            

            //GROUND COLLISION
           if (hero.colRectangle.IntersectsWith(groundColRectangle))
                    hero.down = false;   
 
            mVideo.Update();
        }
コード例 #4
0
ファイル: Manager.cs プロジェクト: remberluyckx/mygame
         public void RestartLvl2()
         {
             hero = new Hero(mVideo, SdlDotNet.Input.Key.A, SdlDotNet.Input.Key.D, SdlDotNet.Input.Key.Space, SdlDotNet.Input.MouseButton.PrimaryButton);
             activelevel = level2;
             hero.position = hero.lvl2Position;
             heartContainer = new HeartContainer(mVideo, heartContainerPoint);

             spikes1_ColRectangle = new Rectangle(180, 420, 85, 71);

             platform1_ColRectangle = new Rectangle(0, 180, 350, 15);
             platform2_ColRectangle = new Rectangle(720, 240, 350, 15);
             platform3_ColRectangle = new Rectangle(330, 330, 350, 15);
             platform4_ColRectangle = new Rectangle(450, 330, 350, 15);

             enemy_1 = new Point(180, 125);
             enemy_2 = new Point(450, 275);
             enemy_3 = new Point(300, 425);
             enemy_4 = new Point(650, 425);
             vijand1 = new Vijand(mVideo, enemy_1, 180, 230);
             vijand2 = new Vijand(mVideo, enemy_2, 450, 600);
             vijand3 = new Vijand(mVideo, enemy_3, 300, 400);
             vijand4 = new Vijand(mVideo, enemy_4, 650, 700);
         }