Windows Mobile

I updated the code on the weekend packaged it and sent it to the Windows Store, just waiting for it to be certified and published. The new package will include 64-bit and Windows Mobile.

Next week I will start working on porting it to Android, it is working in Android I just have a few tweaks to do here and there.

Lessons Learned

I have dug back into my MemoryLapse code, it has been a long, long time. I noticed I was doing something very embarrassing. I was performing IO calls to the database in one of my Update functions. Sometimes you just code without really thinking about what you are doing. While this is a small game and it was not a huge performance hit, I still noticed a bit of lag. Lessons Learned I guess.

Anyway, this morning I wanted to do away with SQLite in my code and just serialize and deserialize JSON instead. So I have updated my Database class shown below:

namespace MemoryLapse
{
    public class Animal
    {
        public int Theme { getset; }
        public int LevelNumber { getset; }
        public int Unlocked { getset; }
    }
}
using System;
using System.IO;
using System.Runtime.Serialization.Json;
 
namespace MemoryLapse
{
    public class Database
    {
        public String Path { getset; }
        public String Name { getset; }
        public Animal[] Levels { getset; }
 
        public Database(String name)
        {
            Name = name;
            Path = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
 
            if (!File.Exists(System.IO.Path.Combine(Path, Name)))
            {
                Levels = new Animal[Enum.GetValues(typeof(Theme)).Length * Enum.GetValues(typeof(Level)).Length];
 
                int i = 0;
                for (int t = 0; t < Enum.GetValues(typeof(Theme)).Length; t++)
                {
                    for (int l = 0; l < Enum.GetValues(typeof(Level)).Length; l++)
                    {
                        Levels[i] = new Animal();
 
                        Levels[i].Theme = t;
                        Levels[i].LevelNumber = l;
                        Levels[i].Unlocked = 0;
 
                        if (Levels[i].Theme == 0 && Levels[i].LevelNumber == 0)
                            Levels[i].Unlocked = 1;
 
                        i++;
                    }
                }
 
                WriteLevels();
            }
            else
            {
                ReadLevels();
            }
        }
 
        public void ReadLevels()
        {
            byte[] json = File.ReadAllBytes(System.IO.Path.Combine(Path, Name));
            using (MemoryStream ms = new MemoryStream(json))
            {
                DataContractJsonSerializer data = new DataContractJsonSerializer(typeof(Animal[]));
                Levels = data.ReadObject(ms) as Animal[];
            }
        }
 
        public void WriteLevels()
        {
            byte[] json = null;
            using (MemoryStream ms = new MemoryStream())
            {
                DataContractJsonSerializer data = new DataContractJsonSerializer(typeof(Animal[]));
                data.WriteObject(ms, Levels);
                json = ms.ToArray();
            }
            File.WriteAllBytes(System.IO.Path.Combine(Path, Name), json);
        }
 
        public void LockTheme(Theme theme)
        {
            for (int i = 0; i < Levels.Length; i++)
            {
                if (Levels[i].Theme == (int)theme)
                {
                    Levels[i].Unlocked = 0;
                    return;
                }
            }
        }
 
        public void UnlockTheme(Theme theme)
        {
            for (int i = 0; i < Levels.Length; i++)
            {
                if (Levels[i].Theme == (int)theme)
                {
                    Levels[i].Unlocked = 1;
                    return;
                }
            }
        }
 
        public void LockLevel(Theme theme, int levelNumber)
        {
            for (int i = 0; i < Levels.Length; i++)
            {
                if (Levels[i].Theme == (int)theme && Levels[i].LevelNumber == levelNumber)
                {
                    Levels[i].Unlocked = 0;
                    return;
                }
            }
        }
 
        public void UnlockLevel(Theme theme, int levelNumber)
        {
            for (int i = 0; i < Levels.Length; i++)
            {
                if (Levels[i].Theme == (int)theme && Levels[i].LevelNumber == levelNumber)
                {
                    Levels[i].Unlocked = 1;
                    return;
                }
            }
        }
 
        public bool IsThemeUnlocked(Theme theme)
        {
            for (int i = 0; i < Levels.Length; i++)
                if (Levels[i].Theme == (int)theme)
                    if (Levels[i].Unlocked == 1)
                        return true;
            return false;
        }
 
        public bool IsLevelUnlocked(Theme theme, int levelNumber)
        {
            for (int i = 0; i < Levels.Length; i++)
                if (Levels[i].Theme == (int)theme && Levels[i].LevelNumber == levelNumber)
                    if (Levels[i].Unlocked == 1)
                        return true;
            return false;
        }
    }
}

SQLite Database

Not much going on this weekend, did not have much free time. I did start setting up a database so I build an unlocking system for levels and themes.

Added the ‘SQLite-net-pcl’ and ‘SQLite.Core.UAP’ NuGet packages to my Universal Windows game. So far just figuring out how and where to save the database.

Just started so this is far from finished code.

using System;
using System.IO;
using System.Collections.Generic;
using SQLite;
 
namespace MemoryLapse
{
    public class Database
    {
        public String Name { getset; }
        public String Path { getset; }
        public String ConnectionString { getset; }
 
        public List<Tables.Level> Levels { getset; }
 
        public Database(String name)
        {
            Name = name;
            Path = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
            ConnectionString = System.IO.Path.Combine(Path, Name);
 
            bool exist = File.Exists(ConnectionString);
 
            using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
            {
                #region Create Database
                if (!exist)
                {
                    connection.CreateTable(typeof(Tables.Level));
 
                    for (int t = 0; t < Enum.GetValues(typeof(Theme)).Length; t++)
                    {
                        for (int l = 0; l < Enum.GetValues(typeof(Level)).Length; l++)
                        {
                            Tables.Level level = new Tables.Level();
 
                            level.Theme = t;
                            level.LevelNumber = l;
                            level.Unlocked = 0;
 
                            if (level.Theme == 0 && level.LevelNumber == 0)
                                level.Unlocked = 1;
 
                            connection.Insert(level);
                        }
                    }
                }
                #endregion
 
                Levels = connection.Query<Tables.Level>("select * from Level"new Object[] { });
            }
        }
    }
}
namespace MemoryLapse.Tables
{
    public class Level
    {
        public int Theme { getset; }
        public int LevelNumber { getset; }
        public int Unlocked { getset; }
    }
}

3D Particle System

This morning I put together a 3D particle system to fling out gold coins when you make a match. Let me know if it is too cheesy.

I have been working on the menu.

I put the virtual keyboard on hold, this morning I started working on on a Menu. Check it out. Leave a comment, good or bad. What should be improved.

Some updates

– added keyboard and gamepad support
– updated the fonts
– updated the background art for each theme
– starting to work on a virtual keyboard

Welcome to Memory Lapse.

Hi I’m Steve, I have been playing with monogame as a hobby for the last few months and have started building Memory Lapse. Memory Lapse is my first real attempt at building a game. It is still very much in the works. The heart of the game is complete, I have begun designing the menus and have yet to create a leaderboard. I hope people enjoy it when it is finished.

Top