So i'm new to C#, but i have experience in C++, python and JavaScript.
i'm trying to recreate space invaders in a console application. I've managed to render the border that the characters will be in and have rendered a character with basic controls.
** - The Question **
public static void Update()
{
ConsoleKeyInfo keypressed = Console.ReadKey();
//Console.
up = keypressed.Key == ConsoleKey.W;
down = keypressed.Key == ConsoleKey.S;
left = keypressed.Key == ConsoleKey.A;
right = keypressed.Key == ConsoleKey.D;
checkUp = (playerPosY > height - 7);
checkDown = (playerPosY < height - 2);
checkLeft = (playerPosX > 1);
checkRight = (playerPosX < width - 2);
shoot = keypressed.Key == ConsoleKey.Spacebar;
if (up && checkUp) playerPosY--;
if (down && checkDown) playerPosY++;
if (left && checkLeft) playerPosX--;
if (right && checkRight) playerPosX++;
if (shoot) { }
}
This is how the controls work at the moment. But I know this has a few faults already. e.g.
Does anyone have any suggestions as to how I can improve these controls?
p.s. The method is called in the main() within a while loop, I have 2 other functions... Initialize() (outside of the main loop) and Render() which runs just after the Update method.
p.p.s. I'm using a nested for loop to render the screen using Console.Write(" ");