I'm making a game that has got an array, which represents an island, and this array should be randomly generated each time you start the game (I'll make the procedurally generated part when it will be finished). Also, if you click the arrows or wasd, it should make you see parts of the island that you couldn't. But I have a problem: when I click the key, nothing happens.
Here's the code for the movement (it's on three different classes):
//class Form
private Game game = new Game();
public int x = 0;
public int y = 0;
public GameWindow()
{
KeyPreview = true;
KeyDown += new KeyEventHandler(GameWindow_KeyDown);
InitializeComponent();
}
void GameWindow_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.W)
{
y = -1;
}
else if (e.KeyCode == Keys.A)
{
x = -1;
}
else if (e.KeyCode == Keys.S)
{
y = 1;
}
else if (e.KeyCode == Keys.D)
{
x = 1;
}
game.Move(x, y);
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics g = panel1.CreateGraphics();
game.startGraphics(g, 100);
}
private void GameWindow_FormClosing(object sender, FormClosingEventArgs e)
{
game.Stop();
}
private void timer1_Tick(object sender, EventArgs e)
{
x = 1;
y = 1;
game.Move(x, y); // I put this to see if it works, but it still does nothing
}
// class Game
public void Move(int x, int y)
{
if (x == -1 && gEngine.smallestXTileOnScreen == 0) { }
else if (x == 1 && gEngine.smallestXTileOnScreen == size - 25) { }
else if (y == -1 && gEngine.smallestYTileOnScreen == 0) { }
else if (y == 1 && gEngine.smallestYTileOnScreen == size - 15) { }
else
{
gEngine.smallestXTileOnScreen += x;
gEngine.smallestYTileOnScreen += y;
gEngine.render();
}
}
//class GraphEngine
public void render()
{
drawHandle.Clear(Color.Blue);
for (int i = 0; i < 25; i++)
{
for (int j = 0; j < 15; j++)
{
prop = world[i + smallestXTileOnScreen , j + smallestYTileOnScreen];
switch (prop)
{
case 0:
drawHandle.DrawImage(sea, i * 50, j * 50, 50, 50);
break;
case 1:
drawHandle.DrawImage(plain, i * 50, j * 50, 50, 50);
break;
case 2:
drawHandle.DrawImage(mountain, i * 50, j * 50, 50, 50);
break;
case 3:
drawHandle.DrawImage(valley, i * 50, j * 50, 50, 50);
break;
default:
drawHandle.DrawImage(sea, i * 50, j * 50, 50, 50);
break;
}
}
}
Form Debug = new Form(); //Notice that I put here a form, if it's shown,
Debug.Show();//then render() has been called. It doesn't show.
}
EDIT: I put the entire code of the first class, maybe it could help you... I don't know what should I do, I'm new to Visual Studio :/