C# Game Engine


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace Kf25

{

    public class Bridge

    {
        public UInt32 time = 0;

        public bool back = false;

        public int start = 0;

        public UInt32[] steps;

        public Bridge(int st, int sz)

        {

            start = st; steps = new UInt32[sz];            

        }

        public bool build(UInt32 a, UInt32 b)

        {

            if(0==time) return false;

            UInt32 step = (UInt32)((a-time)/750.0f);

            if(step<steps.Length)

            {

                if(back) step = (UInt32)steps.Length-1-step;

                steps[step] = 4000; //DUPLICATE

            }

            UInt32 d = a-b, z = 0;

            for(int i=steps.Length;i-->0;)

            {

                steps[i]-=Math.Min(steps[i],d);

                if(0==steps[i]) z++;

            }

            if(z==steps.Length) time = 0;

            return true;

        }

    }

    public partial class Map02 : Kf25.IMap

    {

        int[] steps = //(46)

        {

            //castle steps 1 (17)

            92,41,53,56,57,58,59,60,61,62,63,64,

            78,79,80,91,108,

            //castle steps 2 (22)

            65,66,67,72,73,75,93,94,95,96,97,264,

            262,263,218,105,103,102,101,100,99,98,

            //castle steps 3 (4)

            115,118,119,111,

            //corridor steps (3)

            42,43,124

        };

        Bridge[] bridges =
        {

            new Bridge(0,17),

            new Bridge(17,22),

            new Bridge(39,4),

            new Bridge(43,3)

        };

        

        public void init(Kf25.Engine e, Kf25.Frame a)

        {

            for(int i=steps.Length;i-->0;)

            {

                int o = steps[i];

                e.objflags[o] = 1;

                a.obj(o).spawn = 0;

            }

        }

        public void commit(Kf25.Frame a, Kf25.Frame b)

        {

            //show any active wind pillar bridges

            for(int i=4;i-->0;)

            if(bridges[i].build(a.clock,b.clock))

            {

                int s = bridges[i].start;

                int n = bridges[i].steps.Length;

                for(int j=0;j<n;j++)

                {

                    int o = steps[s+j];

                    if(bridges[i].steps[j]!=0)

                    {

                        double t = bridges[i].steps[j]/4000.0f; //DUPLICATE

                        t = Math.Cos(t*Math.PI*2)/2+0.5;

                        a.obj(o).spawn = 1-(float)(t*t*t);

                    }

                    else a.obj(o).spawn = 0;

                }

            }

            float x = a.x/2, y = a.z/2;

            if(Math.Abs(x-32)<=0.5&&Math.Abs(y-65)<=0.5)

            {

                if(bridges[0].time==0)

                bridges[0].time = a.clock;

                bridges[0].back = false;

            }

            if(Math.Abs(x-34)<=0.5&&Math.Abs(y-85)<=0.5)

            {

                if(bridges[1].time==0)

                bridges[1].time = a.clock;

                bridges[1].back = false;

            }

            if(Math.Abs(x-53)<=0.5&&Math.Abs(y-85)<=0.5)

            {

                if(bridges[1].time==0)

                bridges[1].time = a.clock;

                bridges[1].back = true;

            }

            if(Math.Abs(x-57)<=0.5&&Math.Abs(y-83)<=0.5)

            {

                if(bridges[2].time==0)

                bridges[2].time = a.clock;

                bridges[2].back = false;

            }

            if(Math.Abs(x-62)<=0.5&&Math.Abs(y-83)<=0.5)

            {

                if(bridges[2].time==0)

                bridges[2].time = a.clock;

                bridges[2].back = true;

            }

            if(Math.Abs(x-66)<=0.5&&Math.Abs(y-36)<=0.5)

            {

                if(bridges[3].time==0)

                bridges[3].time = a.clock;

                bridges[3].back = false;

            }

            if(Math.Abs(x-70)<=0.5&&Math.Abs(y-36)<=0.5)

            {

                if(bridges[3].time==0)

                bridges[3].time = a.clock;

                bridges[3].back = true;

            }

        }

    }

}

Get KING'S FIELD 25th PROJECT

Download NowName your own price

Comments

Log in with itch.io to leave a comment.

This is one code file for the Central Village map. I started working on this to see if I can recreate the wind pillar bridges, because I felt doing it with SOM_MAP by itself would be maddening. So I want this to be something others can  conceivably utilize. It's a C# module that SOM is able to support. For the first time you can get inside your game and program some stuff around it!