C#C
C#•2y ago•
10 replies
marine2oorah4u

how do i make a loop or array to choose between different color[]? (csharp)

im new to c# so i dont know a whole lot, but im trying to do something with my version of snake.

So what i want to try to do is, essentially i want to add in a way to choose between different color combinations for the tail, i.e: like the different colors of different irl snakes as a cool little feature

this is my code that i added to the post for the game.

this is the code for the color of the snake tail currently
            tailColorList = new Color[] {Color.Red, Color.Black };

nothing special lol

this is the draw code for the snake
            int colorOn = 0;
            for (int i = 0; i < snake.TailLength; ++i)
            {
                spriteBatch.Draw(texture, new Rectangle(snake.Tail[i].X * cellSize, snake.Tail[i].Y * cellSize + worldScreenTopY, cellSize, cellSize), tailColorList[colorOn]);

                if (++colorOn >= tailColorList.Length)
                {
                    colorOn = 0;
                }
            }

i have a gamestate that i was starting to work on that i would have the skin selector active, in which you could swap through and choose different color combinations to use.
basically, how would i go about adding support for this, or what code would i do to do so?



I imagine that it would involve either a Color[] array of each combination of colors, maybe an array for the picker? otherwise i dont really know what i would do. Again im still learning, so my code probably isn't the best, or my thinking/logic is post likely wrong, via how i would have to do this. But if youre able to help, then that would be super helpful. let me know 🙂
Was this page helpful?