Last modified: March 28, 2023
In this lab, you will add another player to your Lode Runner game. This second player will be controlled by mouse.
You can see how this will look like in the demo of this lab here.
Start with the level you had from HW 1, 2, or 3 (the most recent assignment that is working).
Create a MousePlayer class. The MousePlayer class should represent players that behave exactly like other players, following the same movement rules, except that they get their input from the mouse instead of the keyboard.
Your MousePlayer:
Your MousePlayer should only move in one direction at a time, so if multiple conditions are true, the MousePlayer should prioritize horizontal movement. If none of the conditions are true, then don't move.
According to the Greenfoot API,
by calling Greenfoot.getMouseInfo()
,
you can get an MouseInfo
object, which contains information regarding the mouse.
Therefore, in your act() method, you can add something like:
MouseInfo mouseInfo = Greenfoot.getMouseInfo();
According to the MouseInfo API,
the most helpful methods in MouseInfo
are:
Method Name | Return Type | Method Description |
---|---|---|
getX() | int | Return the current x position of the mouse cursor |
getY() | int | Return the current y position of the mouse cursor |
IMPORTANT: If the user's mouse is not currently on the Greenfoot game screen,
Greenfoot.getMouseInfo()
will returnnull
. Therefore, before callingmouseInfo.getX()
ormouseInfo.getY(),
you need to check if mouseInfo is null using something likeif (mouseInfo != null)
Zip your entire project folder and submit it below.
PX_LastName_FirstName_LodeRunner
.PX_LastName_FirstName_LodeRunner.zip
. For example if you were in 3rd period and named Michael Wang, then you would name the file P3_Wang_Michael_LodeRunner.zip
You must Sign In to submit to this assignment