From 1a37787012e03d4be75ebff3131ff7ee618e3789 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 2 Jun 2022 12:21:03 -0400 Subject: [PATCH] Refactor if statements --- src/GenericSprite.java | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/GenericSprite.java b/src/GenericSprite.java index abffe35..3900833 100644 --- a/src/GenericSprite.java +++ b/src/GenericSprite.java @@ -29,22 +29,10 @@ public class GenericSprite extends Rectangle{ //updates the direction of the ball based on user input //if the keyboard input isn't any of the options (d, a, w, s), then nothing happens public void keyPressed(KeyEvent e){ - if(e.getKeyChar() == 'd'){ - rightPressed = true; - - } - if(e.getKeyChar() == 'a'){ - leftPressed = true; - - } - if(e.getKeyChar() == 'w'){ - upPressed = true; - - } - if(e.getKeyChar() == 's'){ - downPressed = true; - - } + rightPressed = e.getKeyChar() == 'd'; + leftPressed = e.getKeyChar() == 'a'; + upPressed = e.getKeyChar() == 'w'; + downPressed = e.getKeyChar() == 's'; move(); }