/// <summary>
        /// This function will merge global config with local SMBX NPC.txt config and will return merged config set
        /// </summary>
        /// <param name="global">Global config, read from INI file</param>
        /// <param name="local">SMBX Locak NPC config, read from NPC.txt or edited by UI</param>
        /// <param name="captured">Size of whole image sprite</param>
        /// <returns></returns>
        public obj_npc mergeConfigs(obj_npc global, SMBXNpc local, Size captured )
        {
            obj_npc merged = global;
            merged.name = (local.en_name)?local.name:global.name;

            merged.gfx_offset_x = (local.en_gfxoffsetx)?local.gfxoffsetx:global.gfx_offset_x;
            merged.gfx_offset_y = (local.en_gfxoffsety)?local.gfxoffsety:global.gfx_offset_y;

            merged.width = (local.en_width)?local.width:global.width;
            merged.height = (local.en_height)?local.height:global.height;

            merged.foreground = (local.en_foreground)?local.foreground:global.foreground;

            merged.framespeed = (local.en_framespeed)?
                (int)Math.Round( (double)(global.framespeed) / ((double)8 / (double)(local.framespeed)) )
                                : global.framespeed;
            merged.framestyle = (local.en_framestyle)?local.framestyle:global.framestyle;

            //Copy physical size to GFX size
            if( (local.en_width) && (merged.custom_physics_to_gfx) )
                merged.gfx_w = (int)merged.width;
            else
            {
                if ((!local.en_gfxwidth) && (captured.Width != 0) && (global.gfx_w != captured.Width))
                    merged.width = (uint)captured.Width;

                merged.gfx_w = ((captured.Width != 0) ? captured.Width : global.gfx_w);
            }

            //Copy physical size to GFX size
            if( (local.en_height) && (merged.custom_physics_to_gfx) )
                merged.gfx_h = (int)merged.height;
            else
                merged.gfx_h = global.gfx_h;

            if ((!local.en_gfxwidth) && (captured.Width != 0) && (global.gfx_w != captured.Width))
                merged.gfx_w = captured.Width;
            else
                merged.gfx_w = (local.en_gfxwidth) ? (local.gfxwidth>0 ? local.gfxwidth : 1 ) : merged.gfx_w;

            merged.gfx_h = (local.en_gfxheight) ? (local.gfxheight>0 ? local.gfxheight : 1 ) : merged.gfx_h;

            if(((int)merged.width>=(int)merged.grid))
                merged.grid_offset_x = -1 * (int)Math.Round( (double)((int)merged.width % merged.grid)/2 );
            else
                merged.grid_offset_x = (int)Math.Round((double)(merged.grid - (int)merged.width) / 2);

            if(merged.grid_attach_style==1) merged.grid_offset_x += 16;

            merged.grid_offset_y = (int)(-merged.height % merged.grid);

            if((merged.framestyle==0)&&((local.en_gfxheight)||(local.en_height))&&(!local.en_frames))
            {
                merged.frames = (int)Math.Round((double)(captured.Height) / (double)(merged.gfx_h));
                //merged.custom_animate = false;
            }
            else
                merged.frames = (local.en_frames)?local.frames:global.frames;

            if((local.en_frames)||(local.en_framestyle))
            {
                merged.ani_bidir = false; //Disable bidirectional animation
                if((local.en_frames)) merged.custom_animate = false; //Disable custom animation
            }

            // Convert out of range frames by framestyle into animation with controlable diraction
            if((merged.framestyle>0)&&(merged.gfx_h*merged.frames >= (uint)captured.Height))
            {
                merged.framestyle = 0;
                merged.ani_direct = false;
                merged.ani_directed_direct = true;
            }

            merged.score = (local.en_score)?local.score:global.score;
            merged.block_player = (local.en_playerblock)?local.playerblock:global.block_player;
            merged.block_player_top = (local.en_playerblocktop)?local.playerblocktop:global.block_player_top;
            merged.block_npc = (local.en_npcblock)?local.npcblock:global.block_npc;
            merged.block_npc_top = (local.en_npcblocktop)?local.npcblocktop:global.block_npc_top;
            merged.grab_side = (local.en_grabside)?local.grabside:global.grab_side;
            merged.grab_top = (local.en_grabtop)?local.grabtop:global.grab_top;
            merged.kill_on_jump = (local.en_jumphurt)? (!local.jumphurt) : global.kill_on_jump ;
            merged.hurt_player = (local.en_nohurt)?!local.nohurt:global.hurt_player;
            merged.collision_with_blocks = (local.en_noblockcollision)?(!local.noblockcollision):global.collision_with_blocks;
            merged.turn_on_cliff_detect = (local.en_cliffturn)?local.cliffturn:global.turn_on_cliff_detect;
            merged.can_be_eaten = (local.en_noyoshi)?(!local.noyoshi):global.can_be_eaten;
            merged.speed = (local.en_speed) ? (int)Math.Round(global.speed * local.speed) : global.speed;
            merged.kill_by_fireball = (local.en_nofireball)?(!local.nofireball):global.kill_by_fireball;
            merged.gravity = (local.en_nogravity)?(!local.nogravity):global.gravity;
            merged.freeze_by_iceball = (local.en_noiceball)?(!local.noiceball):global.freeze_by_iceball;
            merged.kill_hammer = (local.en_nohammer)?(!local.nohammer):global.kill_hammer;
            merged.kill_by_npc = (local.en_noshell)?(!local.noshell):global.kill_by_npc;

            return merged;
        }
        /// <summary>
        /// Defining configuration of NPC animator
        /// </summary>
        /// <param name="config">Merged configuration set</param>
        /// <param name="direction">Current direction of NPC</param>
        public void configureAnimator(obj_npc config, int direct)
        {
            mainImage = originalImage;
            setup = config;
            ////Wohlstand's//////////////////////
            npcID = setup.id.ToString();

            animated = true;
            framesQ = setup.frames;
            frameSpeed = setup.framespeed;
            frameStyle = setup.framestyle;
            direction = direct;
            frameStep = 1;

            frameSequance = false;

            frameSequance = false;

            aniBiDirect = setup.ani_bidir;
            customAniAlg = setup.custom_ani_alg;

            customAnimate = setup.custom_animate;

            custom_frameFL = setup.custom_ani_fl;//first left
            custom_frameEL = setup.custom_ani_el;//end left
            custom_frameFR = setup.custom_ani_fr;//first right
            custom_frameER = setup.custom_ani_er;//enf right

            frameSize = setup.gfx_h; // height of one frame
            frameWidth = setup.gfx_w; //width of target image

            frameHeight = mainImage.Height; // Height of target image

            //Protectors
            if (frameSize <= 0) frameSize = 1;
            if (frameSize > mainImage.Height) frameSize = mainImage.Height;

            if (frameWidth <= 0) frameWidth = 1;
            if (frameWidth > mainImage.Width) frameWidth = mainImage.Width;

            int dir = direction;
            if (direction == 0) //if direction=random
            {
                Random rnd = new Random();
                dir = ((0 == rnd.Next(0,1)) ? -1 : 1); //set randomly 1 or -1
            }

            if (setup.ani_directed_direct)
                aniDirect = (dir == -1) ^ (setup.ani_direct);
            else
                aniDirect = setup.ani_direct;

            if (customAnimate) // User defined spriteSet (example: boss)
            {
                switch (dir)
                {
                    case -1: //left
                        frameFirst = custom_frameFL;
                        switch (customAniAlg)
                        {
                            case 2:
                                frameSequance = true;
                                frames_list = setup.frames_left;
                                frameFirst = 0;
                                frameLast = frames_list.Count - 1;
                                break;
                            case 1:
                                frameStep = custom_frameEL;
                                frameLast = -1; break;
                            case 0:
                            default:
                                frameLast = custom_frameEL; break;
                        }
                        break;
                    case 1: //Right
                        frameFirst = custom_frameFR;
                        switch (customAniAlg)
                        {
                            case 2:
                                frameSequance = true;
                                frames_list = setup.frames_right;
                                frameFirst = 0;
                                frameLast = frames_list.Count - 1; break;
                            case 1:
                                frameStep = custom_frameER;
                                frameLast = -1; break;
                            case 0:
                            default:
                                frameLast = custom_frameER; break;
                        }
                        break;
                    default: break;
                }
            }
            else
            {
                switch (frameStyle)
                {
                    case 2: //Left-Right-upper sprite
                        framesQ = setup.frames * 4;
                        switch (dir)
                        {
                            case -1: //left
                                frameFirst = 0;
                                frameLast = (int)(framesQ - (framesQ / 4) * 3) - 1;
                                break;
                            case 1: //Right
                                frameFirst = (int)(framesQ - (framesQ / 4) * 3);
                                frameLast = (int)(framesQ / 2) - 1;
                                break;
                            default: break;
                        }
                        break;

                    case 1: //Left-Right sprite
                        framesQ = setup.frames * 2;
                        switch (dir)
                        {
                            case -1: //left
                                frameFirst = 0;
                                frameLast = (int)(framesQ / 2) - 1;
                                break;
                            case 1: //Right
                                frameFirst = (int)(framesQ / 2);
                                frameLast = framesQ - 1;
                                break;
                            default: break;
                        }

                        break;

                    case 0: //Single sprite
                    default:
                        frameFirst = 0;
                        frameLast = framesQ - 1;
                        break;
                }
            }

            curDirect = dir;
            createAnimationFrames();
            isInitialized = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This function will merge global config with local SMBX NPC.txt config and will return merged config set
        /// </summary>
        /// <param name="global">Global config, read from INI file</param>
        /// <param name="local">SMBX Locak NPC config, read from NPC.txt or edited by UI</param>
        /// <param name="captured">Size of whole image sprite</param>
        /// <returns></returns>
        public obj_npc mergeConfigs(obj_npc global, SMBXNpc local, Size captured)
        {
            obj_npc merged = global;

            merged.name = (local.en_name)?local.name:global.name;

            merged.gfx_offset_x = (local.en_gfxoffsetx)?local.gfxoffsetx:global.gfx_offset_x;
            merged.gfx_offset_y = (local.en_gfxoffsety)?local.gfxoffsety:global.gfx_offset_y;

            merged.width  = (local.en_width)?local.width:global.width;
            merged.height = (local.en_height)?local.height:global.height;

            merged.foreground = (local.en_foreground)?local.foreground:global.foreground;

            merged.framespeed = (local.en_framespeed)?
                                (int)Math.Round((double)(global.framespeed) / ((double)8 / (double)(local.framespeed)))
                                : global.framespeed;
            merged.framestyle = (local.en_framestyle)?local.framestyle:global.framestyle;

            //Copy physical size to GFX size
            if ((local.en_width) && (merged.custom_physics_to_gfx))
            {
                merged.gfx_w = (int)merged.width;
            }
            else
            {
                if ((!local.en_gfxwidth) && (captured.Width != 0) && (global.gfx_w != captured.Width))
                {
                    merged.width = (uint)captured.Width;
                }

                merged.gfx_w = ((captured.Width != 0) ? captured.Width : global.gfx_w);
            }

            //Copy physical size to GFX size
            if ((local.en_height) && (merged.custom_physics_to_gfx))
            {
                merged.gfx_h = (int)merged.height;
            }
            else
            {
                merged.gfx_h = global.gfx_h;
            }


            if ((!local.en_gfxwidth) && (captured.Width != 0) && (global.gfx_w != captured.Width))
            {
                merged.gfx_w = captured.Width;
            }
            else
            {
                merged.gfx_w = (local.en_gfxwidth) ? (local.gfxwidth > 0 ? local.gfxwidth : 1) : merged.gfx_w;
            }

            merged.gfx_h = (local.en_gfxheight) ? (local.gfxheight > 0 ? local.gfxheight : 1) : merged.gfx_h;


            if (((int)merged.width >= (int)merged.grid))
            {
                merged.grid_offset_x = -1 * (int)Math.Round((double)((int)merged.width % merged.grid) / 2);
            }
            else
            {
                merged.grid_offset_x = (int)Math.Round((double)(merged.grid - (int)merged.width) / 2);
            }

            if (merged.grid_attach_style == 1)
            {
                merged.grid_offset_x += 16;
            }

            merged.grid_offset_y = (int)(-merged.height % merged.grid);


            if ((merged.framestyle == 0) && ((local.en_gfxheight) || (local.en_height)) && (!local.en_frames))
            {
                merged.frames = (int)Math.Round((double)(captured.Height) / (double)(merged.gfx_h));
                //merged.custom_animate = false;
            }
            else
            {
                merged.frames = (local.en_frames)?local.frames:global.frames;
            }

            if ((local.en_frames) || (local.en_framestyle))
            {
                merged.ani_bidir = false; //Disable bidirectional animation
                if ((local.en_frames))
                {
                    merged.custom_animate = false;                   //Disable custom animation
                }
            }

            // Convert out of range frames by framestyle into animation with controlable diraction
            if ((merged.framestyle > 0) && (merged.gfx_h * merged.frames >= (uint)captured.Height))
            {
                merged.framestyle          = 0;
                merged.ani_direct          = false;
                merged.ani_directed_direct = true;
            }

            merged.score                 = (local.en_score)?local.score:global.score;
            merged.block_player          = (local.en_playerblock)?local.playerblock:global.block_player;
            merged.block_player_top      = (local.en_playerblocktop)?local.playerblocktop:global.block_player_top;
            merged.block_npc             = (local.en_npcblock)?local.npcblock:global.block_npc;
            merged.block_npc_top         = (local.en_npcblocktop)?local.npcblocktop:global.block_npc_top;
            merged.grab_side             = (local.en_grabside)?local.grabside:global.grab_side;
            merged.grab_top              = (local.en_grabtop)?local.grabtop:global.grab_top;
            merged.kill_on_jump          = (local.en_jumphurt)? (!local.jumphurt) : global.kill_on_jump;
            merged.hurt_player           = (local.en_nohurt)?!local.nohurt:global.hurt_player;
            merged.collision_with_blocks = (local.en_noblockcollision)?(!local.noblockcollision):global.collision_with_blocks;
            merged.turn_on_cliff_detect  = (local.en_cliffturn)?local.cliffturn:global.turn_on_cliff_detect;
            merged.can_be_eaten          = (local.en_noyoshi)?(!local.noyoshi):global.can_be_eaten;
            merged.speed                 = (local.en_speed) ? (int)Math.Round(global.speed * local.speed) : global.speed;
            merged.kill_by_fireball      = (local.en_nofireball)?(!local.nofireball):global.kill_by_fireball;
            merged.gravity               = (local.en_nogravity)?(!local.nogravity):global.gravity;
            merged.freeze_by_iceball     = (local.en_noiceball)?(!local.noiceball):global.freeze_by_iceball;
            merged.kill_hammer           = (local.en_nohammer)?(!local.nohammer):global.kill_hammer;
            merged.kill_by_npc           = (local.en_noshell)?(!local.noshell):global.kill_by_npc;

            return(merged);
        }
        public SMBXNpc getDefaultValues(obj_npc global)
        {
            SMBXNpc local = new SMBXNpc();

            local.gfxoffsetx = global.gfx_offset_x;
            local.gfxoffsety = global.gfx_offset_y;
            local.width = global.width;
            local.height = global.height;
            local.gfxwidth = global.gfx_w;
            local.gfxheight = global.gfx_h;
            local.score = global.score;
            local.playerblock = global.block_player;
            local.playerblocktop = global.block_player_top;
            local.npcblock = global.block_npc;
            local.npcblocktop = global.block_player_top;
            local.grabside = global.grab_side;
            local.grabtop = global.grab_top;
            local.jumphurt = (
                        (global.hurt_player)
                                          &&
                                          (!global.kill_on_jump));
            local.nohurt = (!global.hurt_player);
            local.noblockcollision = (!global.collision_with_blocks);
            local.cliffturn = global.turn_on_cliff_detect;
            local.noyoshi = (!global.can_be_eaten);
            local.foreground = global.foreground;
            local.speed = 1;
            local.nofireball = (!global.kill_by_fireball);
            local.nogravity = (!global.gravity);
            local.frames = global.frames;
            local.framespeed = 8;
            local.framestyle = global.framestyle;
            local.noiceball = (!global.freeze_by_iceball);
            //Extended
            local.nohammer = (!global.kill_hammer);
            local.noshell = (!global.kill_by_npc);
            local.name = global.name;

            return local;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Defining configuration of NPC animator
        /// </summary>
        /// <param name="config">Merged configuration set</param>
        /// <param name="direction">Current direction of NPC</param>
        public void configureAnimator(obj_npc config, int direct)
        {
            mainImage = originalImage;
            setup     = config;
            ////Wohlstand's//////////////////////
            npcID = setup.id.ToString();

            animated   = true;
            framesQ    = setup.frames;
            frameSpeed = setup.framespeed;
            frameStyle = setup.framestyle;
            direction  = direct;
            frameStep  = 1;

            frameSequance = false;

            frameSequance = false;

            aniBiDirect  = setup.ani_bidir;
            customAniAlg = setup.custom_ani_alg;

            customAnimate = setup.custom_animate;

            custom_frameFL = setup.custom_ani_fl; //first left
            custom_frameEL = setup.custom_ani_el; //end left
            custom_frameFR = setup.custom_ani_fr; //first right
            custom_frameER = setup.custom_ani_er; //enf right

            frameSize  = setup.gfx_h;             // height of one frame
            frameWidth = setup.gfx_w;             //width of target image

            frameHeight = mainImage.Height;       // Height of target image

            //Protectors
            if (frameSize <= 0)
            {
                frameSize = 1;
            }
            if (frameSize > mainImage.Height)
            {
                frameSize = mainImage.Height;
            }

            if (frameWidth <= 0)
            {
                frameWidth = 1;
            }
            if (frameWidth > mainImage.Width)
            {
                frameWidth = mainImage.Width;
            }

            int dir = direction;

            if (direction == 0) //if direction=random
            {
                Random rnd = new Random();
                dir = ((0 == rnd.Next(0, 1)) ? -1 : 1); //set randomly 1 or -1
            }

            if (setup.ani_directed_direct)
            {
                aniDirect = (dir == -1) ^ (setup.ani_direct);
            }
            else
            {
                aniDirect = setup.ani_direct;
            }

            if (customAnimate) // User defined spriteSet (example: boss)
            {
                switch (dir)
                {
                case -1:     //left
                    frameFirst = custom_frameFL;
                    switch (customAniAlg)
                    {
                    case 2:
                        frameSequance = true;
                        frames_list   = setup.frames_left;
                        frameFirst    = 0;
                        frameLast     = frames_list.Count - 1;
                        break;

                    case 1:
                        frameStep = custom_frameEL;
                        frameLast = -1; break;

                    case 0:
                    default:
                        frameLast = custom_frameEL; break;
                    }
                    break;

                case 1:     //Right
                    frameFirst = custom_frameFR;
                    switch (customAniAlg)
                    {
                    case 2:
                        frameSequance = true;
                        frames_list   = setup.frames_right;
                        frameFirst    = 0;
                        frameLast     = frames_list.Count - 1; break;

                    case 1:
                        frameStep = custom_frameER;
                        frameLast = -1; break;

                    case 0:
                    default:
                        frameLast = custom_frameER; break;
                    }
                    break;

                default: break;
                }
            }
            else
            {
                switch (frameStyle)
                {
                case 2:     //Left-Right-upper sprite
                    framesQ = setup.frames * 4;
                    switch (dir)
                    {
                    case -1:         //left
                        frameFirst = 0;
                        frameLast  = (int)(framesQ - (framesQ / 4) * 3) - 1;
                        break;

                    case 1:         //Right
                        frameFirst = (int)(framesQ - (framesQ / 4) * 3);
                        frameLast  = (int)(framesQ / 2) - 1;
                        break;

                    default: break;
                    }
                    break;

                case 1:     //Left-Right sprite
                    framesQ = setup.frames * 2;
                    switch (dir)
                    {
                    case -1:         //left
                        frameFirst = 0;
                        frameLast  = (int)(framesQ / 2) - 1;
                        break;

                    case 1:         //Right
                        frameFirst = (int)(framesQ / 2);
                        frameLast  = framesQ - 1;
                        break;

                    default: break;
                    }

                    break;

                case 0:     //Single sprite
                default:
                    frameFirst = 0;
                    frameLast  = framesQ - 1;
                    break;
                }
            }

            curDirect = dir;
            createAnimationFrames();
            isInitialized = true;
        }