Example #1
0
        public bool PerformFrame(DodgerX GameObject,GameTime gt)
        {
            //increment location.
            Location += new Vector2(Velocity.X*GameObject.SpeedMultiplier,Velocity.Y*GameObject.SpeedMultiplier);

            //return GameObject.Window.ClientBounds.Contains((new Rectangle((int)Location.X, (int)Location.Y, (int)Texture.Width, (int)Texture.Height)));
            Player pobj = null;
            var casted = (GameObject.CurrentState as  iGameRunner);
            if (casted != null)
            {
                pobj = casted.grd.PlayerObject;
            }
            bool playercollide = CheckPlayerCollision(GameObject,pobj);

            accumtime += gt.ElapsedGameTime;
            if (accumtime > Spawnparticledelay)
            {
                accumtime -= Spawnparticledelay;
                if (casted != null )
                {
                    Particle spawnparticle = new Particle(new Vector2(Location.X, Location.Y), RandomSpeed(2),GameObject.SpeckImage);
                    spawnparticle.Velocity += Velocity;
                    casted.grd.Particles.Add(spawnparticle);
                }
            }

            return !EntirelyWithinBounds(GameObject) || playercollide;

                ;
        }
Example #2
0
 public DodgerX()
 {
     ActiveInstance = this;
     //Components.Add(new GamerServicesComponent(this));
     graphics = new GraphicsDeviceManager(this);
     graphics.PreferredBackBufferHeight = 600;
     graphics.PreferredBackBufferWidth = 800;
     //graphics.ToggleFullScreen();
     Content.RootDirectory = "Content";
 }
Example #3
0
        public static void Main(string[] args)
        {
            GameObject = new DodgerX();

            try
            {
                GameObject.Run();
            }
            finally
            {
                GameObject.Dispose();
            }
        }
Example #4
0
        public void Draw(DodgerX gameobject, GameTime gameTime)
        {
            Vector2 CalculatedDimensions;
            CalculatedDimensions.X = gameobject.Window.ClientBounds.Width - 100;

            float ratio = (float)LogoImage.Width / (float)LogoImage.Height; //800/600, 8/6.
            CalculatedDimensions.Y = CalculatedDimensions.X / ratio;

            //gameobject.GraphicsDevice.Clear(Color.Black);
            //spritebatch.start already called.
            gameobject.spriteBatch.Draw(LogoImage,
                new Rectangle(50, 50, (int)CalculatedDimensions.X,(int)CalculatedDimensions.Y), new Color((int)AlphaValue, (int)AlphaValue, (int)AlphaValue, (int)AlphaValue));

            DodgerX.DrawVersion(gameobject);
        }
Example #5
0
        public Player(DodgerX gameobj,int NumCircles)
        {
            double currentangle = 0;
            double increment = (Math.PI * 2) / NumCircles;
            int curritem = 0;
            while (curritem < NumCircles)
            {
                float useradius = 32 * (curritem % 2 == 0 ? 1 : 2);
                float usespeed = ((float)increment / 8) * (curritem % 2 == 0 ? 1 : 1.25f);
                PlayerCircleItem rci = new PlayerCircleItem((float)(curritem*increment),usespeed,useradius,
                    new Texture2D[]{gameobj.greencircletexture,gameobj.yellowcircletexture,gameobj.redcircletexture},
                    new Texture2D[]{gameobj.GreenSpeck,gameobj.YellowSpeck,gameobj.RedSpeck});
                CircleItems.Add(rci);

                curritem++;
            }
        }
Example #6
0
        public void Update(DodgerX gameobject, GameTime gameTime)
        {
            if (FirstCall == null)
                FirstCall = gameTime.TotalGameTime;

            TimeSpan CurrentCall = gameTime.TotalGameTime;

            Debug.Print(mLogoMode.ToString() + " " + AlphaValue.ToString());
            //we want the Alpha value to ramp up to opaque, sit there for 5 seconds, and fade out when we detect a mouse click.
            switch (mLogoMode)
            {
                case LogoShowMode.Logo_Fadein:
                    TimeSpan es = CurrentCall-FirstCall.Value;
                    AlphaValue = ((float)es.Ticks / (float)FadeTime.Ticks)*255f;
                    AlphaValue = MathHelper.Clamp(AlphaValue, 0, 255);
                    if ((Mouse.GetState().LeftButton == ButtonState.Pressed))
                        es = FadeTime.Add(new TimeSpan(0,0,0,1));
                    if(es > FadeTime)
                    {
                        mLogoMode = LogoShowMode.Logo_Solid;
                        FadeinComplete = gameTime.TotalGameTime;
                    }
                    break;
                case LogoShowMode.Logo_Solid:
                    TimeSpan SolidElapsed = CurrentCall - FadeinComplete.Value;
                    AlphaValue = 255;
                    if ((Mouse.GetState().LeftButton == ButtonState.Pressed) || SolidElapsed > MaxLogoShowTime)
                        mLogoMode = LogoShowMode.Logo_Fadeout;

                    break;

                case LogoShowMode.Logo_Fadeout:
                    if (FadeOutStart == null) FadeOutStart = gameTime.TotalGameTime;
                     TimeSpan eso = CurrentCall-FadeOutStart.Value;
                     AlphaValue = ((float)eso.Ticks / (float)FadeTime.Ticks) * 255f;
                    AlphaValue = 255-MathHelper.Clamp(AlphaValue, 0, 255);
                    if(eso > FadeTime)
                    {
                        gameobject.CurrentState = _NextState;
                        FadeinComplete = gameTime.TotalGameTime;
                    }
                    break;
            }
        }
        public void Draw(DodgerX gameobject, GameTime gameTime)
        {
            Vector2 MousePos = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
            gameobject.GraphicsDevice.Clear(LevelColors[LevelNumber % LevelColors.Length]);
            if (grd.PlayerObject == null) return;

            grd.Draw(gameobject, gameTime);

              String ScoreString = "Score:" + CurrentScore.ToString();

              Vector2 ScoreSize = gameobject.StatusFont.MeasureString(ScoreString);

              gameobject.spriteBatch.DrawString(gameobject.StatusFont, ScoreString, new Vector2(gameobject.Window.ClientBounds.Width - ScoreSize.X, 0), Color.Black);
              gameobject.spriteBatch.Draw(MenuState.Cursor, MousePos, Color.White);

              String LevelString = "Level:" + LevelNumber.ToString();
              Vector2 LevelSize = gameobject.StatusFont.MeasureString(LevelString);
              gameobject.spriteBatch.DrawString(gameobject.StatusFont, LevelString, new Vector2(0, 0), Color.Black);
        }
Example #8
0
        public MenuState(DodgerX dodgerobj,String[] MenuOptions, Object[] MenuStates)
        {
            Vector2 CurrentLocation= new Vector2(dodgerobj.Window.ClientBounds.Width/2-intrologo.Width/2,intrologo.Height+50);

            for (int i = 0; i < Math.Min(MenuOptions.Length, MenuStates.Length); i++)
            {
                MenuStateItem msi = null;
                if (MenuStates[i] is MenuStateItem.StateAdvanceRoutine)
                {
                    msi = new MenuStateItem(MenuOptions[i], MenuStates[i] as MenuStateItem.StateAdvanceRoutine, CurrentLocation, MenuFont);
                }
                else if (MenuStates[i] is iGameState)
                    msi = new MenuStateItem(MenuOptions[i], MenuStates[i] as iGameState, CurrentLocation, MenuFont);

                msi.Location = new Vector2((dodgerobj.Window.ClientBounds.Width / 2) - msi.DrawSize.X / 2, msi.Location.Y);

                CurrentLocation = new Vector2(CurrentLocation.X, CurrentLocation.Y + msi.DrawSize.Y + 5);
                MenuItems.Add(msi);
            }
        }
Example #9
0
 /// <summary>
 /// hittests this Menu Item with the given position. returns true if within rectangle bounds.
 /// </summary>
 /// <param name="TestLocation"></param>
 /// <returns></returns>
 public bool HitTest(DodgerX gameobject,Vector2 TestLocation)
 {
     return TestLocation.X > Location.X &&
         TestLocation.X < Location.X + DrawSize.X &&
         TestLocation.Y > Location.Y &&
         TestLocation.Y < Location.Y + DrawSize.Y;
 }
Example #10
0
 protected void InvokeClick(MenuStateItem itemclicked,DodgerX gameobject)
 {
     var copied = ItemClicked;
     if (copied != null) copied(itemclicked,gameobject);
 }
Example #11
0
 public virtual void Draw(DodgerX gameobject, bool Selected)
 {
     gameobject.spriteBatch.DrawString(sf, Caption, Location, Selected ? Color.Blue : Color.White);
 }
Example #12
0
        public virtual void Draw(DodgerX gameobject, GameTime gameTime)
        {
            _grd.Draw(gameobject, gameTime);

            gameobject.spriteBatch.Draw(getintrologo(), new Vector2(gameobject.Window.ClientBounds.Width / 2 - getintrologo().Width / 2, 0), Color.White);

            //
            //draw our Menu items.
            Vector2 MousePos = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
            foreach (var msi in MenuItems)
            {

                msi.Draw(gameobject, msi == SelectedItem);

            }

            gameobject.spriteBatch.Draw(Cursor, MousePos,Color.White);
            DodgerX.DrawVersion(gameobject);
        }
Example #13
0
        public virtual void Update(DodgerX gameobject, GameTime gameTime)
        {
            if (prevmousestate == null) prevmousestate = Mouse.GetState();
            ElapseCounter += gameTime.ElapsedGameTime;
            if (ElapseCounter > SpawnObjectDelay)
            {

                ElapseCounter = ElapseCounter - SpawnObjectDelay;
                for (int i = 0; i < 2; i++)
                {
                    AttackingObject ao = new AttackingObject(new Vector2(0, 0), new Vector2(0, 0),
                                                             gameobject.attackerTexture);
                    ao.SetRandomStartPosition(gameobject, 8);

                    grd.Attackers.Add(ao);
                }

            }
            _grd.Update(gameobject, gameTime);
            MenuSelect = DodgerX.soundBank.GetCue("MenuSel");
            //Update the selected item based on the mouse position.
            MenuStateItem foundhit = null;
            foreach (var msi in MenuItems)
            {

                if (msi.HitTest(gameobject, new Vector2(Mouse.GetState().X, Mouse.GetState().Y)))
                {
                    foundhit = msi;
                    break;
                }

            }
            if (SelectedItem != foundhit)
            {
                if (MenuSelect.IsPlaying) MenuSelect.Stop(AudioStopOptions.AsAuthored);
                try
                {
                    MenuSelect.Play();
                } catch
                {
                }
            }
            SelectedItem = foundhit;
            Debug.Print("SelectedItem is now " + (SelectedItem==null?"Null":SelectedItem.Caption));

            if (SelectedItem != null)
            {

                if (Mouse.GetState().LeftButton == ButtonState.Pressed && prevmousestate.Value.LeftButton==ButtonState.Released)
                {

                    //gameobject.CurrentState = SelectedItem.AdvanceState;
                    InvokeClick(SelectedItem,gameobject);
                    SelectedItem.AdvanceRoutine(SelectedItem, gameobject);

                }

            }

            prevmousestate = Mouse.GetState();
        }
Example #14
0
        public void Update(DodgerX gameobject, GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {

                gameobject.CurrentState = MenuState.getMainMenu(gameobject);

            }

            //throw new NotImplementedException();
            if (drawlisting == "")
            {
                StringBuilder buildlisting = new StringBuilder();

                int numenumerated = 0;

                int maxlength = 0;
                buildlisting.Append("  -------TOP TEN-------\n");

               /* for(int currshow=1;currshow < 5;currshow++)
                {

                    var iterate = gameobject.HighScoreData.Scores.ElementAt(currshow - 1).Value;
                    String built=iterate.Name + iterate.Score.ToString();
                    if (built.Length > maxlength)
                        maxlength = built.Length;

                }*/
                maxlength = gameobject.HighScoreData.Scores.Max((t) => (t.Value.Name.Length+t.Value.Score.ToString().Length));
                for(int currshow=1;currshow < 10;currshow++)
                {
                    var scoreentry = gameobject.HighScoreData.Scores.ElementAt(gameobject.HighScoreData.Scores.Count - (currshow)).Value;
                    int useamount = 3+ (maxlength) - (scoreentry.Name.Length);
                    String dotstr = new string(Enumerable.Repeat('.', useamount).ToArray());

                    if (numenumerated == 11) break;
                    string buildline = (numenumerated+1).ToString() + ":" + scoreentry.Name + dotstr + scoreentry.Score.ToString();
                    //buildlisting.AppendLine(numenumerated.ToString() + ":\t" + scoreentry.Name + "\t\t" + scoreentry.Score.ToString());
                    buildlisting.AppendLine(buildline);

                    numenumerated++;
                }
                buildlisting.AppendLine("\nPress <space>");

                drawlisting = buildlisting.ToString();

            }
        }
Example #15
0
 public static void LoadContent(DodgerX gameobject)
 {
     MenuFont = gameobject.Content.Load<SpriteFont>(@"Fonts\menufont");
     Cursor = gameobject.Content.Load<Texture2D>(@"Images\arrow");
     intrologo = gameobject.Content.Load<Texture2D>(@"Images\bcdodgertitle");
     pauselogo = gameobject.Content.Load<Texture2D>(@"Images\bcdodgerpause");
 }
Example #16
0
 public MenuState(DodgerX dodgerobj, String[] MenuOptions, iGameState[] MenuStates)
     : this(dodgerobj,MenuOptions,(from p in MenuStates select MenuStateItem.DefaultAdvanceRoutine(p)).ToArray())
 {
 }
Example #17
0
 public MenuState(DodgerX dodgerobj, String[] MenuOptions, MenuStateItem.StateAdvanceRoutine[] stateroutines)
     : this(dodgerobj,MenuOptions,(Object[])stateroutines)
 {
 }
Example #18
0
 void PlayerObject_PlayerDeath(DodgerX arg1, Player arg2)
 {
     int pos = 0;
     if (-1 < (pos = arg1.HighScoreData.Eligible((int)CurrentScore)))
     {
         ValueEntryState ves = new ValueEntryState("High Score (#" + (pos+1).ToString() + ")", GetUsername(), "YOu got a High Score! Please Enter your name.", HighScoreEntered);
         arg1.CurrentState = ves;
     }
 }
Example #19
0
        public static void DrawVersion(DodgerX gameobj)
        {
            //draw version using statusfont.
            //upper-right...
            SpriteFont sf = gameobj.DefaultFont;

            Assembly us = Assembly.GetExecutingAssembly();
            String verinfo = us.GetName().Name + " V." + us.GetName().Version;
            Vector2 sizedvalue = sf.MeasureString(verinfo);
            gameobj.spriteBatch.DrawString(sf, verinfo, new Vector2(gameobj.Window.ClientBounds.Width - sizedvalue.X, 0), Color.Black);
        }
Example #20
0
        private void RearrangeItems(DodgerX gameobject, Texture2D imagelogo, MenuStateItem[] loopitem)
        {
            Vector2 currentlocation = new Vector2(0, imagelogo.Height + 8);

            for (int i = 0; i < loopitem.Length; i++)
            {
                Vector2 measuredsize = loopitem[i].sf.MeasureString(loopitem[i].Caption);
                loopitem[i].Location = new Vector2(gameobject.Window.ClientBounds.Width / 2 - measuredsize.X / 2, currentlocation.Y);
                currentlocation.Y += measuredsize.Y + 5;

            }
        }
Example #21
0
        public void Update(DodgerX gameobject, GameTime gameTime)
        {
            TotalRunningTime += gameTime.ElapsedGameTime;

            if(NextTimeGen ==null) NextTimeGen = TotalRunningTime + new TimeSpan(0,0,0,3);

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                gameobject.Exit();

            if (grd.PlayerObject == null)
            {
                grd.Attackers.Clear();
                grd.PlayerObject = new Player(gameobject, 8);
                grd.PlayerObject.Position = new Vector2(gameobject.Window.ClientBounds.Width / 2, gameobject.Window.ClientBounds.Height / 2);
                grd.PlayerObject.PlayerDeath += new Action<DodgerX, Player>(PlayerObject_PlayerDeath);
            }

            grd.Update(gameobject, gameTime);

            if (TotalRunningTime > NextTimeGen.Value && !grd.Attackers.Any((w)=>w is HealyBall ))
            {
                CurrentScore += ((numgens + 1) * ReleaseCount) * grd.PlayerObject.NumItemsLeft();
                numgens++;
                //release 5+numgens healyOrbs.

                TimeSpan addthis = new TimeSpan(new TimeSpan(0, 0, 0, 2,500).Ticks - (numgens * 1000000));
                if (addthis < Minimumspan)
                {
                    numgens = 0;
                    ReleaseCount++;
                    LevelNumber++;
                    for (int addorb = 0; addorb < 8 + numgens; addorb++)
                    {
                        Vector2 chosenLocation = new Vector2((float)(gameobject.Window.ClientBounds.Width * DodgerX.rgen.NextDouble()),
                                                         (float)(gameobject.Window.ClientBounds.Y * DodgerX.rgen.NextDouble()));
                        Vector2 chosenspeed = new Vector2(((float)DodgerX.rgen.NextDouble() * MaximumSpeed) - HalfMaxSpeed,
                                                          ((float)DodgerX.rgen.NextDouble() * MaximumSpeed) - HalfMaxSpeed);

                        //ao.SetRandomStartPosition(gameobject, MaximumSpeed);
                        HealyBall hb = new HealyBall(chosenLocation, chosenspeed*(3/4), gameobject.healyTexture);
                        hb.SetRandomStartPosition(gameobject, MaximumSpeed);
                        grd.Attackers.Add(hb);
                    }
                }
                Debug.Print("adding " + addthis.ToString() + " to nexttimegen...");
                NextTimeGen += addthis;

                for (int i = 0; i < ReleaseCount; i++)
                {

                    Vector2 chosenLocation = new Vector2((float) (gameobject.Window.ClientBounds.Width*DodgerX.rgen.NextDouble()),
                                                         (float) (gameobject.Window.ClientBounds.Y*DodgerX.rgen.NextDouble()));
                    Vector2 chosenspeed = new Vector2(((float) DodgerX.rgen.NextDouble()*MaximumSpeed) - HalfMaxSpeed,
                                                      ((float) DodgerX.rgen.NextDouble()*MaximumSpeed) - HalfMaxSpeed);
                    AttackingObject ao = new AttackingObject(chosenLocation, chosenspeed, gameobject.attackerTexture);
                    ao.SetRandomStartPosition(gameobject, 4);
                    grd.Attackers.Add(ao);
                    //SetRandomStartPosition
                    Debug.Print("attacker added at " + chosenLocation + " with speed " + chosenspeed);
                }
            }
        }
Example #22
0
 public void UnloadContent(DodgerX gameobject)
 {
     // throw new NotImplementedException();
 }
Example #23
0
 public override void Draw(DodgerX gameobject, bool Selected)
 {
     Caption = ItemChoices[SelectedIndex].Caption;
     base.Draw(gameobject, Selected);
 }
Example #24
0
        public void Draw(DodgerX gameobject, GameTime gameTime)
        {
            SpriteFont usehsfont = HighScoreFont;
            Vector2 stringsize = usehsfont.MeasureString(drawlisting);

            Vector2 DrawPosition = new Vector2(gameobject.Window.ClientBounds.Width/2-(stringsize.X/2),
                                            gameobject.Window.ClientBounds.Height/2-stringsize.Y/2);

            Vector2 ShadowPos = DrawPosition + new Vector2(2);
            gameobject.spriteBatch.DrawString(usehsfont, drawlisting, ShadowPos, Color.Gray);
            gameobject.spriteBatch.DrawString(usehsfont, drawlisting, DrawPosition, Color.Black);
        }
Example #25
0
 private void AdvanceState(MenuStateItem msi,DodgerX gameobject)
 {
     SelectedIndex = (SelectedIndex + 1) % ItemChoices.Length;
 }
Example #26
0
 public static void LoadContent(DodgerX gameobject)
 {
     // throw new NotImplementedException();
     TrackCue = DodgerX.soundBank.GetCue("basestompx");
 }
Example #27
0
 public MenuState(DodgerX dodgerobj, MenuStateItem[] menuitems)
 {
     MenuItems = menuitems.ToList();
 }
Example #28
0
 public static MenuState getMainMenu(DodgerX gameobject)
 {
     return new MenuState(gameobject, new string[] { "Play","High Scores", "Exit" }, new Object[] { new GameRunningState(),new HighScoreListState(), DynaState.QuitState });
 }
Example #29
0
        public static MenuState GetPauseState(DodgerX dx, iGameState currentstate)
        {
            String[] pauseItems = new string[] { "Resume Game", "Quit" };
            var copied = currentstate;
            var pausemenu = new MenuState(dx, pauseItems, new Object[] { new MenuStateItem.StateAdvanceRoutine((msi,dxa)=>
                {
                    dxa.CurrentState = copied;
                    if(copied is GameRunningState)
                    {
                        GameRunningState grs = copied as GameRunningState;
                        GameRunningState.TrackCue.Resume();

                    }

                })

                , MenuState.getMainMenu(dx) });

            pausemenu.MenuLogo = pauselogo;
            return pausemenu;
        }
Example #30
0
 public static void LoadContent(DodgerX gameobject)
 {
     HighScoreFont = gameobject.Content.Load<SpriteFont>(@"Fonts\monospace");
 }