Making some magic with XNA with Mage Defender Deluxe

Today's project is cool little C# XNA 4 game. Not only is there the game, but also a couple "editors" too. This game shows off a number of things, from creating games with custom content to particle engine usage and more...

XNA 4.0 Game with Source: Mage Defender Deluxe

Mage Defender Deluxe was created as a remake during a workshop/presentation I had. It was made pretty fast but I decided to share the source anyways.

In the game, you will need to defend your castle at all cost. Shoot the enemies that move towards you with multiple spells and strategies to take them out one by one. After each wave, you will be able to visit the shop to upgrade abilities, buy new spells, mana/health potions and upgrade your castle (Gameplay video can be found below).

The original game was a DOS game made by Dark Codex in 1999 and looked like this:

image

The new version contains more enemies, spells, upgradable castle, skill points, attributes, homing spells, controllable spells, many enemies with basic AI and much more.

The game works with the XBox360 controller, just connect it to your PC and play.

You can find the source for the game at GitHub:
https://github.com/petriw/MageDefenderDeluxe/downloads

Click the “Download as zip” button to download the latest source.

Some snaps from the game;

image

image

image

image

image

Here's what the Solution looks like

image

image

Here's some snaps of the two editors;

SNAGHTML9569eee

SNAGHTML95705f9

Here's a quick code snip;

/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
     engine.Update();

     gameManager.Update(gameTime);

     if (gameManager.IsGameStateChange())
     {
         switch (gameManager.GetNextState())
         {
             case (int)MageDefenderStates.PressStart:
             {
                 gameManager.ChangeToState(pressStartState);
                 break;
             }
             case (int)MageDefenderStates.MainMenu:
             {
                 menuCue.Stop(AudioStopOptions.Immediate);
                 ingameCue.Stop(AudioStopOptions.Immediate);

                 menuCue = soundBank.GetCue("menuMusic");
                 if (!menuCue.IsPlaying)
                 {
                     menuCue.Play();
                 }
                 gameManager.ChangeToState(mainMenuState);
                 break;
             }
             case (int)MageDefenderStates.Story:
             {
                 gameManager.ChangeToState(storyState);
                 break;
             }
             case (int)MageDefenderStates.Level:
             {
                 menuCue.Stop(AudioStopOptions.Immediate);
                 ingameCue.Stop(AudioStopOptions.Immediate);

                 ingameCue = soundBank.GetCue("ingameMusic");
                 if (!ingameCue.IsPlaying)
                 {
                     ingameCue.Play();
                 }

                 gameManager.ChangeToState(levelState);
                 break;
             }
             case (int)MageDefenderStates.Shop:
             {
                 gameManager.ChangeToState(shopState);
                 break;
             }
             case (int)MageDefenderStates.GameOver:
             {
                 gameManager.ChangeToState(gameOverState);
                 break;
             }
             case (int)MageDefenderStates.Credits:
             {
                 gameManager.ChangeToState(creditsState);
                 break;
             }
         }
     }

     base.Update(gameTime);
}

And a snap from the LevelState screen

public void PrepareNextLevel()
{
    pressTimerPrimary = 500;
    pressTimerSecondary = 500;
    pressTimerSpellBrowse = 500;
    drinkPotionTimer = 500;

    Level nextLevel;
    try
    {
        nextLevel = Game.Content.Load<Level>("Levels/level" + (castleHandler.Castle.Level + 1));
    }
    catch(Exception ex)
    {
        nextLevel = new Level();
    }

    isCurrentLevelABoss = nextLevel.IsBoss;

    if (isCurrentLevelABoss)
    {
        if (!nextLevel.BossCodeName.Equals("None"))
        {
            enemyHandler.BossBehaviour = Game.Content.Load<BossBehaviour>("Bosses/" + nextLevel.BossCodeName);
        }
        else
        {
            enemyHandler.BossBehaviour = null;
        }
    }
    else
    {
        enemyHandler.BossBehaviour = null;
    }

    string[] spawnEnemiesofTypes = nextLevel.SpawnEnemies.Split(',');


    spellHandler.NextLevel();
    enemyHandler.NextLevel();
    castleHandler.NextLevel(nextLevel);

    player.Mana = player.MaxMana;
    player.Health = player.MaxHealth;

    foreach(String s in spawnEnemiesofTypes)
    {
        if (s.Equals("Slime1"))
        {
            enemyHandler.SpawnEnemyTypes.Add(GameObjects.EnemyHandler.Enemies.Slime);
        }
        if (s.Equals("Slime2"))
        {
            enemyHandler.SpawnEnemyTypes.Add(GameObjects.EnemyHandler.Enemies.Slime2);
        }
        if (s.Equals("Slime3"))
        {
            enemyHandler.SpawnEnemyTypes.Add(GameObjects.EnemyHandler.Enemies.Slime3);
        }
        if (s.Equals("Slime4"))
        {
            enemyHandler.SpawnEnemyTypes.Add(GameObjects.EnemyHandler.Enemies.Slime4);
        }
        if (s.Equals("Ghost"))
        {
            enemyHandler.SpawnEnemyTypes.Add(GameObjects.EnemyHandler.Enemies.Ghost);
        }
        if (s.Equals("Zombie"))
        {
            enemyHandler.SpawnEnemyTypes.Add(GameObjects.EnemyHandler.Enemies.Zombie);
        }
        if (s.Equals("Skeleton"))
        {
            enemyHandler.SpawnEnemyTypes.Add(GameObjects.EnemyHandler.Enemies.Skeleton);
        }
        if (s.Equals("Boss"))
        {
            enemyHandler.SpawnEnemyTypes.Add(GameObjects.EnemyHandler.Enemies.Boss);
        }
    }
}

If you're interested in XNA based game writing, this is a project you might like to dig through...

Tags:

Follow the Discussion

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.