コード例 #1
0
ファイル: Player.cs プロジェクト: mirhagk/TerrariaClone
 public int sumArmor()
 {
     return(TerrariaClone.getARMOR()[TerrariaClone.armor.ids[0]] +
            TerrariaClone.getARMOR()[TerrariaClone.armor.ids[1]] +
            TerrariaClone.getARMOR()[TerrariaClone.armor.ids[2]] +
            TerrariaClone.getARMOR()[TerrariaClone.armor.ids[3]]);
 }
コード例 #2
0
ファイル: Player.cs プロジェクト: mirhagk/TerrariaClone
        public Player(double x, double y)
        {
            oldx = this.x = x; oldy = this.y = y;

            vx  = 0;
            vy  = 0;
            pvy = 0;

            onGround = false;

            image = loadImage("sprites/player/right_still.png");

            width  = TerrariaClone.getPLAYERSIZEX();
            height = TerrariaClone.getPLAYERSIZEY();

            ix  = (int)x;
            iy  = (int)y;
            ivx = (int)ivx;
            ivy = (int)ivy;

            rect = new Rectangle(ix, iy, width, height);

            imgDelay = 0;
            imgState = "still right";

            thp = 50;

            hp = thp;
        }
コード例 #3
0
ファイル: Game1.cs プロジェクト: mirhagk/TerrariaClone
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            game = new TerrariaClone();
            game.init();
            base.Initialize();
            System.Console.WriteLine($"Screen size: {game.getWidth()}x{game.getHeight()}");
        }
コード例 #4
0
ファイル: Chunk.cs プロジェクト: mirhagk/TerrariaClone
        public Chunk(int cx, int cy)
        {
            this.cx = cx;
            this.cy = cy;

            Object[] rv = World.generateChunk(cx, cy, TerrariaClone.getRandom());
            blocks   = (int[][, ])rv[0];
            blockds  = (Byte[][, ])rv[1];
            blockdns = (Byte[, ])rv[2];
            blockbgs = (Byte[, ])rv[3];
            blockts  = (Byte[, ])rv[4];
            lights   = (float[, ])rv[5];
            power    = (float[, , ])rv[6];
            lsources = (Boolean[, ])rv[7];
            zqn      = (Byte[, ])rv[8];
            pzqn     = (Byte[, , ])rv[9];
            arbprd   = (Boolean[, , ])rv[10];
            wcnct    = (Boolean[, ])rv[11];
            drawn    = (Boolean[, ])rv[12];
            rdrawn   = (Boolean[, ])rv[13];
            ldrawn   = (Boolean[, ])rv[14];
        }
コード例 #5
0
        public Entity(double x, double y, double vx, double vy, short id, short num, short dur, int mdelay)
        {
            this.x      = x;
            this.y      = y;
            this.vx     = vx;
            this.vy     = vy;
            this.name   = name;
            this.id     = id;
            this.num    = num;
            this.dur    = dur;
            this.mdelay = mdelay;
            oldx        = x;
            oldy        = y;
            ix          = (int)x;
            iy          = (int)y;

            dframes = 0;

            image = TerrariaClone.getItemImgs()[id];

            width = image.Width * 2; height = image.Height * 2;
        }
コード例 #6
0
ファイル: Player.cs プロジェクト: mirhagk/TerrariaClone
        public void update(int[,] blocks, bool[] queue, int u, int v)
        {
            grounded = (onGround || onGroundDelay);
            if (queue[0] == true)
            {
                if (vx > -4 || TerrariaClone.DEBUG_SPEED)
                {
                    vx = vx - 0.5;
                }
                if (imgState.Equals("still left") || imgState.Equals("still right") ||
                    imgState.Equals("walk right 1") || imgState.Equals("walk right 2"))
                {
                    imgDelay = 5;
                    imgState = "walk left 2";
                    image    = loadImage("sprites/player/left_walk.png");
                }
                if (imgDelay <= 0)
                {
                    if (imgState.Equals("walk left 1"))
                    {
                        imgDelay = 5;
                        imgState = "walk left 2";
                        image    = loadImage("sprites/player/left_walk.png");
                    }
                    else
                    {
                        if (imgState.Equals("walk left 2"))
                        {
                            imgDelay = 5;
                            imgState = "walk left 1";
                            image    = loadImage("sprites/player/left_still.png");
                        }
                    }
                }
                else
                {
                    imgDelay = imgDelay - 1;
                }
            }
            if (queue[1] == true)
            {
                if (vx < 4 || TerrariaClone.DEBUG_SPEED)
                {
                    vx = vx + 0.5;
                }
                if (imgState.Equals("still left") || imgState.Equals("still right") ||
                    imgState.Equals("walk left 1") || imgState.Equals("walk left 2"))
                {
                    imgDelay = 5;
                    imgState = "walk right 2";
                    image    = loadImage("sprites/player/right_walk.png");
                }
                if (imgDelay <= 0)
                {
                    if (imgState.Equals("walk right 1"))
                    {
                        imgDelay = 5;
                        imgState = "walk right 2";
                        image    = loadImage("sprites/player/right_walk.png");
                    }
                    else
                    {
                        if (imgState.Equals("walk right 2"))
                        {
                            imgDelay = 5;
                            imgState = "walk right 1";
                            image    = loadImage("sprites/player/right_still.png");
                        }
                    }
                }
                else
                {
                    imgDelay = imgDelay - 1;
                }
            }
            if (queue[2] == true)
            {
                if (TerrariaClone.DEBUG_FLIGHT)
                {
                    vy  -= 1;
                    pvy -= 1;
                }
                else
                {
                    if (onGround == true)
                    {
                        vy  = -7;
                        pvy = -7;
                    }
                }
            }
            if (queue[6] == true)
            {
                if (TerrariaClone.DEBUG_FLIGHT)
                {
                    vy  += 1;
                    pvy += 1;
                }
            }
            if (!onGround)
            {
                vy  = vy + 0.3;
                pvy = pvy + 0.3;
                if (vy > 7 && !TerrariaClone.DEBUG_FLIGHT)
                {
                    vy = 7;
                }
            }
            if (!queue[0] && !queue[1])
            {
                if (Math.Abs(vx) < 0.3)
                {
                    vx = 0;
                }
                if (vx >= 0.3)
                {
                    vx = vx - 0.3;
                }
                if (vx <= -0.3)
                {
                    vx = vx + 0.3;
                }
                if (grounded)
                {
                    if (imgState.Equals("still left") || imgState.Equals("walk left 1") ||
                        imgState.Equals("walk left 2"))
                    {
                        imgState = "still left";
                        image    = loadImage("sprites/player/left_still.png");
                    }
                    if (imgState.Equals("still right") || imgState.Equals("walk right 1") ||
                        imgState.Equals("walk right 2"))
                    {
                        imgState = "still right";
                        image    = loadImage("sprites/player/right_still.png");
                    }
                }
            }

            if (!grounded)
            {
                if (imgState.Equals("still left") || imgState.Equals("walk left 1") ||
                    imgState.Equals("walk left 2"))
                {
                    image = loadImage("sprites/player/left_jump.png");
                }
                if (imgState.Equals("still right") || imgState.Equals("walk right 1") ||
                    imgState.Equals("walk right 2"))
                {
                    image = loadImage("sprites/player/right_jump.png");
                }
            }

            onGroundDelay = onGround;

            oldx = x; oldy = y;

            x = x + vx;

            if (!TerrariaClone.DEBUG_NOCLIP)
            {
                for (i = 0; i < 2; i++)
                {
                    ix  = (int)x;
                    iy  = (int)y;
                    ivx = (int)vx;
                    ivy = (int)vy;

                    rect = new Rectangle(ix - 1, iy, width + 2, height);

                    bx1 = (int)x / BLOCKSIZE; by1 = (int)y / BLOCKSIZE;
                    bx2 = (int)(x + width) / BLOCKSIZE; by2 = (int)(y + height) / BLOCKSIZE;

                    for (i = bx1; i <= bx2; i++)
                    {
                        for (j = by1; j <= by2; j++)
                        {
                            if (blocks[j + v, i + u] != 0 && TerrariaClone.getBLOCKCD()[blocks[j + v, i + u]])
                            {
                                if (rect.Intersects(new Rectangle(i * BLOCKSIZE, j * BLOCKSIZE, BLOCKSIZE, BLOCKSIZE)))
                                {
                                    if (oldx <= i * 16 - width && vx > 0)
                                    {
                                        x  = i * 16 - width;
                                        vx = 0; // right
                                    }
                                    if (oldx >= i * 16 + BLOCKSIZE && vx < 0)
                                    {
                                        x  = i * 16 + BLOCKSIZE;
                                        vx = 0; // left
                                    }
                                }
                            }
                        }
                    }
                }
            }

            y        = y + vy;
            onGround = false;
            if (!TerrariaClone.DEBUG_NOCLIP)
            {
                for (i = 0; i < 2; i++)
                {
                    ix  = (int)x;
                    iy  = (int)y;
                    ivx = (int)vx;
                    ivy = (int)vy;

                    rect = new Rectangle(ix, iy - 1, width, height + 2);

                    bx1 = (int)x / BLOCKSIZE; by1 = (int)y / BLOCKSIZE;
                    bx2 = (int)(x + width) / BLOCKSIZE; by2 = (int)(y + height) / BLOCKSIZE;

                    by1 = Math.Max(0, by1);
                    by2 = Math.Min(blocks.Length - 1, by2);

                    for (i = bx1; i <= bx2; i++)
                    {
                        for (j = by1; j <= by2; j++)
                        {
                            if (blocks[j + v, i + u] != 0 && TerrariaClone.getBLOCKCD()[blocks[j + v, i + u]])
                            {
                                if (rect.Intersects(new Rectangle(i * BLOCKSIZE, j * BLOCKSIZE, BLOCKSIZE, BLOCKSIZE)))
                                {
                                    if (oldy <= j * 16 - height && vy > 0)
                                    {
                                        y = j * 16 - height;
                                        if (pvy >= 10 && !TerrariaClone.DEBUG_INVINCIBLE)
                                        {
                                            hp -= (int)((pvy - 12.5)) * 2;
                                        }
                                        onGround = true;
                                        vy       = 0; // down
                                        pvy      = 0;
                                    }
                                    if (oldy >= j * 16 + BLOCKSIZE && vy < 0)
                                    {
                                        y  = j * 16 + BLOCKSIZE;
                                        vy = 0; // up
                                    }
                                }
                            }
                        }
                    }
                }
            }

            ix  = (int)x;
            iy  = (int)y;
            ivx = (int)vx;
            ivy = (int)vy;

            rect = new Rectangle(ix - 1, iy - 1, width + 2, height + 2);
        }
コード例 #7
0
ファイル: Player.cs プロジェクト: mirhagk/TerrariaClone
 public static int mod(int a, int q)
 {
     return(TerrariaClone.mod(a, q));
 }
コード例 #8
0
        public List <short> drops()
        {
            List <short> dropList = new List <short>();
            Random       random   = TerrariaClone.getRandom();

            if (name == "blue_bubble")
            {
                for (i = 0; i < random.Next(3); i++)
                {
                    dropList.Add((short)97);
                }
            }
            if (name == "green_bubble")
            {
                for (i = 0; i < random.Next(3); i++)
                {
                    dropList.Add((short)98);
                }
            }
            if (name == "red_bubble")
            {
                for (i = 0; i < random.Next(3); i++)
                {
                    dropList.Add((short)99);
                }
            }
            if (name == "yellow_bubble")
            {
                for (i = 0; i < random.Next(3); i++)
                {
                    dropList.Add((short)100);
                }
            }
            if (name == "black_bubble")
            {
                for (i = 0; i < random.Next(3); i++)
                {
                    dropList.Add((short)101);
                }
            }
            if (name == "white_bubble")
            {
                for (i = 0; i < random.Next(3); i++)
                {
                    dropList.Add(((short)102));
                }
            }
            if (name == "shooting_star")
            {
                for (i = 0; i < random.Next(2); i++)
                {
                    dropList.Add(((short)103));
                }
            }
            if (name == "zombie")
            {
                for (i = 0; i < random.Next(3); i++)
                {
                    dropList.Add(((short)104));
                }
            }
            if (name == "armored_zombie")
            {
                for (i = 0; i < random.Next(3); i++)
                {
                    dropList.Add(((short)104));
                }
                if (random.Next(15) == 0)
                {
                    dropList.Add(((short)109));
                }
                if (random.Next(15) == 0)
                {
                    dropList.Add(((short)110));
                }
                if (random.Next(15) == 0)
                {
                    dropList.Add(((short)111));
                }
                if (random.Next(15) == 0)
                {
                    dropList.Add(((short)112));
                }
            }
            if (name == "sandbot")
            {
                for (i = 0; i < random.Next(3); i++)
                {
                    dropList.Add(((short)74));
                }
                if (random.Next(2) == 0)
                {
                    dropList.Add(((short)44));
                }
                if (random.Next(6) == 0)
                {
                    dropList.Add(((short)45));
                }
            }
            if (name == "snowman")
            {
                for (i = 0; i < random.Next(3); i++)
                {
                    dropList.Add(((short)75));
                }
            }
            return(dropList);
        }
コード例 #9
0
        public bool collide(int[,] blocks, Player player, int u, int v)
        {
            bool rv = false;

            grounded = (onGround || onGroundDelay);

            onGroundDelay = onGround;

            oldx = x; oldy = y;

            x = x + vx;

            for (i = 0; i < 2; i++)
            {
                ix  = (int)x;
                iy  = (int)y;
                ivx = (int)vx;
                ivy = (int)vy;

                rect = new Rectangle(ix - 1, iy, width + 2, height);

                bx1 = (int)x / BLOCKSIZE; by1 = (int)y / BLOCKSIZE;
                bx2 = (int)(x + width) / BLOCKSIZE; by2 = (int)(y + height) / BLOCKSIZE;

                bx1 = Math.Max(0, bx1); by1 = Math.Max(0, by1);
                bx2 = Math.Min(blocks.GetUpperBound(1) - 1, bx2); by2 = Math.Min(blocks.Length - 1, by2);

                for (i = bx1; i <= bx2; i++)
                {
                    for (j = by1; j <= by2; j++)
                    {
                        if (blocks[j, i] != 0 && TerrariaClone.getBLOCKCD()[blocks[j + v, i + u]])
                        {
                            if (rect.Intersects(new Rectangle(i * BLOCKSIZE, j * BLOCKSIZE, BLOCKSIZE, BLOCKSIZE)))
                            {
                                if (oldx <= i * 16 - width && (vx > 0 || AI == "shooting_star"))
                                {
                                    x = i * 16 - width;
                                    if (AI == "bubble")
                                    {
                                        vx = -vx;
                                    }
                                    else if (AI == "zombie")
                                    {
                                        vx = 0;
                                        if (onGround && player.x > x)
                                        {
                                            vy = -7;
                                        }
                                    }
                                    else if (AI == "bat")
                                    {
                                        vx = -vx;
                                    }
                                    else
                                    {
                                        vx = 0; // right
                                    }
                                    rv = true;
                                }
                                if (oldx >= i * 16 + BLOCKSIZE && (vx < 0 || AI == "shooting_star"))
                                {
                                    x = i * 16 + BLOCKSIZE;
                                    if (AI == "bubble")
                                    {
                                        vx = -vx;
                                    }
                                    else if (AI == "zombie")
                                    {
                                        vx = 0;
                                        if (onGround && player.x < x)
                                        {
                                            vy = -7;
                                        }
                                    }
                                    else if (AI == "bat")
                                    {
                                        vx = -vx;
                                    }
                                    else
                                    {
                                        vx = 0; // left
                                    }
                                    rv = true;
                                }
                            }
                        }
                    }
                }
            }

            y        = y + vy;
            onGround = false;

            for (i = 0; i < 2; i++)
            {
                ix  = (int)x;
                iy  = (int)y;
                ivx = (int)vx;
                ivy = (int)vy;

                rect = new Rectangle(ix, iy - 1, width, height + 2);

                bx1 = (int)x / BLOCKSIZE; by1 = (int)y / BLOCKSIZE;
                bx2 = (int)(x + width) / BLOCKSIZE; by2 = (int)(y + height) / BLOCKSIZE;

                bx1 = Math.Max(0, bx1); by1 = Math.Max(0, by1);
                bx2 = Math.Min(blocks.GetUpperBound(1) - 1, bx2); by2 = Math.Min(blocks.Length - 1, by2);

                for (i = bx1; i <= bx2; i++)
                {
                    for (j = by1; j <= by2; j++)
                    {
                        if (blocks[j, i] != 0 && TerrariaClone.getBLOCKCD()[blocks[j + v, i + u]])
                        {
                            if (rect.Intersects(new Rectangle(i * BLOCKSIZE, j * BLOCKSIZE, BLOCKSIZE, BLOCKSIZE)))
                            {
                                if (oldy <= j * 16 - height && (vy > 0 || AI == "shooting_star"))
                                {
                                    y        = j * 16 - height;
                                    onGround = true;
                                    if (AI == "bubble")
                                    {
                                        vy = -vy;
                                    }
                                    else
                                    {
                                        vy = 0; // down
                                    }
                                    rv = true;
                                }
                                if (oldy >= j * 16 + BLOCKSIZE && (vy < 0 || AI == "shooting_star"))
                                {
                                    y = j * 16 + BLOCKSIZE;
                                    if (AI == "bubble")
                                    {
                                        vy = -vy;
                                    }
                                    else
                                    {
                                        vy = 0; // up
                                    }
                                    rv = true;
                                }
                            }
                        }
                    }
                }
            }

            ix  = (int)x;
            iy  = (int)y;
            ivx = (int)vx;
            ivy = (int)vy;

            rect = new Rectangle(ix - 1, iy - 1, width + 2, height + 2);

            return(rv);
        }