#Need help moving diagonally in game/ also a timer

4 messages · Page 1 of 1 (latest)

pliant dew
#

So what I have right now my player can move up down left right using wasd but I cant figure out how to allow the player to move diagonally. I am using KeyEvent and a switch statement.
Also for the timer I have tried many different things but I cant figure out what timer to use-- I want it to count from when the program starts, and be displayed using the timeLabel JLabel

what Im trying to get to right now is just the red dot following the player who has to avoid the red dot--also I am unable to figure out a way to make the red dot move without making the player unable to move. Right now i just have it to where it updates when the graphics component is repainted, which happens when the player presses a button

supple rainBOT
#

This post has been reserved for your question.

Hey @pliant dew! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

severe fulcrum
#

I found this StackOverflow which may solve the diagonal movement problem. https://stackoverflow.com/questions/22580933/diagonal-movement-of-a-sprite

As for the red dot problem. What you could try to look into is creating a custom class that extends Component. Within this class, you would override the paint function with whatever you want so when you call repaint on that specific object, it executes differently compared to the player.

I know my explanation is very sub-par but hopefully it is good enough to get you in the right direction.