# Maze Game Simple Question

**URL:** <https://discourse.processing.org/t/maze-game-simple-question/10816>\
**Category:** Coding Questions\
**Created:** [May 1, 2019, 8:41pm UTC](https://discourse.processing.org/t/maze-game-simple-question/10816 "2019-05-01T20:41:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GuerillaGirl](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@GuerillaGirl](https://discourse.processing.org/u/GuerillaGirl)\
**Post date:** [May 1, 2019, 8:41pm UTC](https://discourse.processing.org/t/maze-game-simple-question/10816/1 "2019-05-01T20:41:33Z")

</div>

Here is the code that we have. We need to know how to make the dot go faster because when we start it moves slow. We just need to know how to increase the speed of the ellipse. We are beginners!

```auto
PImage GreenMaze;
int x = 162;
int y = 162;

void setup(){
GreenMaze = loadImage("GreenMaze.gif"); 
size(290, 290);
}

void draw()
{
background(255);
image(GreenMaze,0,0);
if((x > 155) && (x < 180) && (y < 10)){
textSize(48);
textAlign(CENTER);
fill(255,0,0);
text("YOU WIN!",width/2,height/2);
println(mouseX + "," + mouseY);
}

fill(255, 0, 0);
noStroke();
float touch = red(get(x,y));
ellipse(x,y, 10, 10);
if(touch <= 200){
x = 162;
y = 162;
println(mouseX + "," + mouseY);
}
}

void keyPressed(){
if ((key == CODED) && (keyCode == UP)){
y--;
} 
if ((key == CODED) && (keyCode == DOWN)){
y++;
} 
if ((key == CODED) && (keyCode == RIGHT)){
x++;
} 

if ((key == CODED) && (keyCode == LEFT)){
x--;
}
}

```

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [May 1, 2019, 10:29pm UTC](https://discourse.processing.org/t/maze-game-simple-question/10816/2 "2019-05-01T22:29:52Z")

</div>

Right now, when you press a key, your code may increase or decrease `x` or `y` (by 1). This is a good start.

What you could do instead is keep track yourself of which of the four movement keys are being pressed, and depeniding on which keys are pressed, move the player every frame, instead of every key press. This means you will need to use the `keyReleased()` function too!

For example:

```auto
boolean move_right, move_down;
float x, y;
float speed = 1.3;

void setup(){
  size(200,200);
}

void draw(){
  if( move_down ){
    y+=speed;
  }
  if( move_right ){
    x+=speed;
  }
  background(0);
  fill(0,200,0);
  rect(x,y,20,20);
}

void keyPressed(){
  if( keyCode == RIGHT ){
    move_right = true;
  }
  if( keyCode == DOWN ){
    move_down = true;
  }
}

void keyReleased(){
  if( keyCode == RIGHT ){
    move_right = false;
  }
  if( keyCode == DOWN ){
    move_down = false;
  }
}

```

You can add code for UP and LEFT yourself, and adjust the `speed` variable as you like! Notice that this provides a much smoother movement!
