Beispiel #1
0
        public void Update(Action a)
        {
            if (a == Action.move_down || a == Action.move_up || a == Action.move_left || a == Action.move_right)
            {
                moveClock = (byte)((moveClock + 1) % 64);
                if (a == Action.move_down)
                {
                    facing = EdgedAdventure.Directions.down;
                    float[] raw = new float[2];
                    raw[0] = (chunkX * 8) + X;
                    raw[1] = (chunkY * 8) + Y + movementSpeed;
                    if (!LCM.IsBlocking(raw))
                    {
                        if (Y + movementSpeed >= 8)
                        {
                            { }

                            chunkY++;
                            Y = ((Y - (8 - movementSpeed)) % 8);
                        }
                        else
                        {
                            Y += movementSpeed;
                        }
                    }
                }
                else if (a == Action.move_up)
                {
                    facing = EdgedAdventure.Directions.up;
                    float[] raw = new float[2];
                    raw[0] = (chunkX * 8) + X;
                    raw[1] = (chunkY * 8) + Y - movementSpeed;


                    if (!LCM.IsBlocking(raw))
                    {
                        if (Y - movementSpeed < 0)
                        {
                            { }

                            chunkY--;
                            Y = ((Y + (8 - movementSpeed)) % 8);
                        }
                        else
                        {
                            Y -= movementSpeed;
                        }
                    }
                }
                else if (a == Action.move_left)
                {
                    facing = EdgedAdventure.Directions.left;
                    float[] raw = new float[2];
                    raw[0] = (chunkX * 8) + X - movementSpeed;
                    raw[1] = (chunkY * 8) + Y;
                    if (!LCM.IsBlocking(raw))
                    {
                        if (X - movementSpeed < 0)
                        {
                            { }

                            chunkX--;
                            X = ((X + (8 - movementSpeed)) % 8);
                        }
                        else
                        {
                            X -= movementSpeed;
                        }
                    }
                }
                else if (a == Action.move_right)
                {
                    facing = EdgedAdventure.Directions.right;
                    float[] raw = new float[2];
                    raw[0] = (chunkX * 8) + X + movementSpeed;
                    raw[1] = (chunkY * 8) + Y;
                    if (!LCM.IsBlocking(raw))
                    {
                        if (X + movementSpeed >= 8)
                        {
                            { }

                            chunkX++;
                            X = ((X - (8 - movementSpeed)) % 8);
                        }
                        else
                        {
                            X += movementSpeed;
                        }
                    }
                }
            }
            else if (a == Action.attack)
            {
                if (energy > 0 && sel == -1)
                {
                    energy -= 40;
                    if ((0 <= moveClock && moveClock < 16) || (32 <= moveClock && moveClock < 48))
                    {
                        moveClock += 16;
                        moveClock %= 64;
                    }
                    else
                    {
                        moveClock += 32;
                        moveClock %= 64;
                    }

                    Game.DebugBreakPoint();

                    Effect slash = (Effect)Entity.GetEntity(1);
                    slash.chunkX = this.chunkX;
                    slash.chunkY = this.chunkY;
                    slash.layer  = this.layer;
                    int[] dir = DirVector(facing);
                    slash.X      = this.X + (dir[0] * 0.8F);
                    slash.Y      = this.Y + (dir[1] * 0.8F);
                    slash.health = 1;
                    slash.tile   = @"particles\slash_" + DirString(facing);
                    int[] index = LCM.GetIndices(new float[] { ((slash.chunkX * 8) + slash.X), ((slash.chunkY * 8) + slash.Y) });
                    LCM.world[index[0], index[1]].ents.Add(slash);

                    float[] raw      = { ((chunkX * 8) + slash.X), ((chunkY * 8) + slash.Y) };
                    Entity  attacked = LCM.GetAttackableEntityInRadius(raw, 0.8F);
                    if (attacked != null)
                    {
                        uint attackDamage = 1;
                        if (selItem != -1)
                        {
                            attackDamage += inv[selItem].attackBonus;
                        }
                        if (attacked.Attack(attackDamage))
                        {
                            LCM.RemoveEntity(attacked);
                        }
                    }
                    else
                    {
                        Item use = null;
                        if (selItem != -1)
                        {
                            use = inv[selItem];
                        }
                        LCM.MineAt(raw, use);
                    }
                }
            }
            else if (a == Action.test)
            {
                //Game.DebugBreakPoint();

                energy = 500;
            }

            X %= 8;
            Y %= 8;
        }