This site requires JavaScript, please enable it in your browser!
Greenfoot back
Bench
Bench wrote ...

2016/3/12

Right Click Movement (Top-Down Shooter)

Bench Bench

2016/3/12

#
Hello there, I'm trying to think of ways to do right-click movement with the mouse. The game is a top-down shooter so you don't have to select/deselect units like an RTS, but you do have to move from A to B using the right mouse button. The player also rotates based on where the mouse is, and shooting is done via left click to keep controls unified to the mouse. So far, I've been googling and searching ways to do this but I haven't found any good examples to learn off of yet, or I get examples for things that aren't quite the same as the movement system I have in my head. I'm extremely new to Greenfoot with only past experience at high school with Python & TrueBasic, but neither of those courses involved programming anything too interactive, or game-like. Any tips, examples, suggestions, tutorials are greatly appreciated! The more streamlined/easier to follow the better. The following is a suggestion given to me by my lecturer (It was on paper and wasn't written in the software), if it would provide any context and help with this; PART ONE: Distance = SquareRoot of XSqaured + YSquared = FramesRequired FramesRequired = Distance/PlayerSpeed PART TWO: IF (FramesRequired > 0) { IF (PlayerSpeed > Distance) { Move (Distance) Distance = 0; } ELSE { Move (PlayerSpeed); Distance = Distance - PlayerSpeed; } FramesRequired - -; }
Super_Hippo Super_Hippo

2016/3/12

#
It looks like you lecturer does not know it either. I don't see any reason to calculate 'framesRequired'. If I understand you correctly, it will more look like this: ----------------- get the position of the mouse turn to that position check if the mouse was clicked if the click was with the right button, set the position as a destination point if it was the left button, shoot if it has a destination point, move in the direction of this point if the point was reached, "remove it" -----------------
Bench Bench

2016/3/12

#
Thanks for the reply, my lecturer gave me these notes as a rough guideline/idea and not as a copy-paste sort of example or solution. Your summary sounds accurate to what I was trying to describe, so yes that's more what I am looking to do. I've done a similar movement system using Game Maker but unfortunately that was with the "Drag & Drop" style and so I basically didn't learn much about how that actually worked.
Super_Hippo Super_Hippo

2016/3/12

#
Try to do it step-by-step. To start, you can use this:
1
2
3
4
5
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse != null)
{
    //...
}
You need to login to post a reply.