Can't get player sprite to move in maze game?

  • Thread starter Thread starter togepixels
  • Start date Start date
T

togepixels

Guest
Hi there! Probably a bit of a simple question but I could really use some help!

I'm trying to make a maze game, but no matter what I do, I can't get the player sprite to move - I've tried with arrow keys, separate If statements.. can't seem to find anything to work, as there's no errors, it just doesn't move!

I've pasted what I have so far below, please let me know if you spot anything that might be causing the issue, I'm very much a beginner!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Maze_game
{
public partial class Mazegame : Form
{
readonly bool goleft;
readonly bool goright;
//int score = 0;
//int points = 13;
int playerSpeed = 500;
//int health = 100;
public Mazegame()

{
InitializeComponent();
}

private void MazeGame_Load(object sender, EventArgs e)
{

}


private void timer1_Tick(object sender, EventArgs e)
{


if (goleft)
{
ball.Left -= playerSpeed;
}

if (goright)
{
ball.Left += playerSpeed;
}

}
private void Keyisdown(object sender, KeyEventArgs e)
{

int x = ball.Location.X;
int y = ball.Location.Y;

if (e.KeyCode == Keys.W)

ball.Top = ball.Top - 5;

else if (e.KeyCode == Keys.D)

ball.Left = ball.Left + 5;

else if (e.KeyCode == Keys.A)

ball.Left = ball.Left - 5;

else if (e.KeyCode == Keys.S)

ball.Top = ball.Top + 5;

foreach (Control a in this.Controls) ;
}


private void Mazegame_Load(object sender, EventArgs e)
{

}

private void KeyIsUp(object sender, KeyEventArgs e)
{

int x = ball.Location.X;
int y = ball.Location.Y;

if (e.KeyCode == Keys.W)

ball.Top = ball.Top - 5;


else if (e.KeyCode == Keys.D)

ball.Left = ball.Left + 5;

else if (e.KeyCode == Keys.A)

ball.Left = ball.Left - 5;

else if (e.KeyCode == Keys.S)

ball.Top = ball.Top + 5;

foreach (Control a in this.Controls) ;
}

}

}

Continue reading...
 
Back
Top