Changing the Player Movement to Enemy Movement

122 views
Skip to first unread message

Sean Kelly

unread,
Mar 27, 2013, 4:15:49 PM3/27/13
to replica-island-...@googlegroups.com
Hey everyone, I'm hoping someone might be able to help me out with this since I've been stuck for a while now.

I'm trying to change the movement system that the player currently uses to a system like the one that flying enemies use in the game (ie. Sting and Karaguin). I know the enemies get their input from the HotSpotSystem Class which is registered through the PatrolComponent Class so I went in there and it looks like once you get your input as "right, left, up, or down" then it uses the following if, else statement:

if (goUp) {
                        parentObject.getTargetVelocity().x = 0.0f;
                        parentObject.getTargetVelocity().y = mMaxSpeed;
                        parentObject.getAcceleration().y = mAcceleration;
                        parentObject.getAcceleration().x = mAcceleration;

                    } else if (goDown) {
                        parentObject.getTargetVelocity().x = 0.0f;
                        parentObject.getTargetVelocity().y = -mMaxSpeed;
                        parentObject.getAcceleration().y = mAcceleration;
                        parentObject.getAcceleration().x = mAcceleration;

                    } else if (goRight) {
                        parentObject.getTargetVelocity().x = mMaxSpeed;
                        parentObject.getAcceleration().x = mAcceleration;
                        parentObject.getAcceleration().y = mAcceleration;
                        parentObject.getTargetVelocity().y = 0.0f;
                    } else if (goLeft) {
                        parentObject.getTargetVelocity().x = -mMaxSpeed;
                        parentObject.getAcceleration().x = mAcceleration;
                        parentObject.getAcceleration().y = mAcceleration;
                        parentObject.getTargetVelocity().y = 0.0f;
                    }

So the problem is I can't find where the Game registers input from the user (button presses) and where it translates into the player movements. I pretty much just need to know where the result of pressing say the jump button can be found so that I can change it to be registered as "up", etc. for the player, and then where the playercomponent reads button input so that if up was registered i can implement the above movement system.

Hopefully that makes sense. Any help appreciated!

Sean Kelly

unread,
Mar 27, 2013, 11:10:53 PM3/27/13
to replica-island-...@googlegroups.com
Edit:

Nevermind, I found out how and got everything working!

Bart Hirst

unread,
Mar 28, 2013, 9:21:10 AM3/28/13
to ReplicaIsland Coding Community
Cool thanks Sean


--
You received this message because you are subscribed to the Google Groups "ReplicaIsland Coding Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to replica-island-coding...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Praneeth Paruchuri

unread,
Jun 30, 2014, 2:54:21 PM6/30/14
to replica-island-...@googlegroups.com
Hello Sean, 

I'm stuck at the same point and the exact same problem. Can you please help me out here?

Thanks.

JF

unread,
Jul 1, 2014, 12:28:13 AM7/1/14
to replica-island-...@googlegroups.com
Which component are you interested in?

For example, you'll find the code looking for screen input for the jump button in the class "InputGameInterface."  The good stuff starts here:       

final InputXY jumpTouch = touch.findPointerInRegion(
                flyButtonRegionX,
                ButtonConstants.FLY_BUTTON_REGION_Y,
                ButtonConstants.FLY_BUTTON_REGION_WIDTH,
                ButtonConstants.FLY_BUTTON_REGION_HEIGHT);


Then in PlayerComponent class, you'll see the code looking at whether that input has been triggered, and based on a set of rules, then influencing the player.  I'd focus on the code starting here:

           final InputButton jumpButton = input.getJumpButton();
            if (dpad.getPressed() || jumpButton.getPressed()) {
                Vector2 impulse = pool.allocate();
                if (dpad.getPressed()) {
                    impulse.set(dpad.getX(), 0.0f);
                }                               

Hope that helps!!

Joe

Praneeth Paruchuri

unread,
Jul 1, 2014, 8:54:20 PM7/1/14
to replica-island-...@googlegroups.com
Thanks Joe, That's all I need. 

Praneeth Paruchuri

unread,
Jul 11, 2014, 12:15:41 PM7/11/14
to replica-island-...@googlegroups.com
Hello, 

I am trying to control the movement of the player in the game by hand movements. When a person moves his hand to the right the robot goes on moving to the right until we pass another movement to stop. And the same for the rest.
So, I wrote a method and it gets called when the gesture is done.

public void moveRight(){
final float gameTime = sSystemRegistry.timeSystem.getGameTime();
final float halfWidth = ButtonConstants.MOVEMENT_SLIDER_BAR_WIDTH / 2.0f;
final float center = ButtonConstants.MOVEMENT_SLIDER_X + halfWidth;
final float offset = ButtonConstants.MOVEMENT_SLIDER_REGION_WIDTH - center;
float magnitudeRamp = Math.abs(offset) > halfWidth ? 1.0f : (Math.abs(offset) / halfWidth);
final float magnitude = magnitudeRamp * Utils.sign(offset) * SLIDER_FILTER * mMovementSensitivity;
mDirectionalPad.press(gameTime, magnitude, 0.0f);
             //mDirectionalPad.press(gameTime,1.0f,0.0f);
}

To test if its working I created a dummy button and when we press it this method get called.
 testButton.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {

input = BaseObject.sSystemRegistry.inputGameInterface;
if (event.getAction() == MotionEvent.ACTION_DOWN){
    input.moveRight();
    }else if(event.getAction() == MotionEvent.ACTION_UP){
    input.release();
    }
}
       return true;
 }
});

But it isn't working. 
Any help is appreciated! 
Thank you. 

Bart Hirst

unread,
Jul 14, 2014, 9:02:33 AM7/14/14
to ReplicaIsland Coding Community
I don't think you're going to be able to handle it at that level (using input.moveRight() or mDirectionalPad.press etc.) .. doesn't feel right on many levels.

Off the cuff, I think you should implement some new methods in the player class that will add constant impulse to the player after a gesture, then remove that with the opposite gesture.  good luck.

--
You received this message because you are subscribed to the Google Groups "ReplicaIsland Coding Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to replica-island-coding...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Praneeth Paruchuri

unread,
Jul 14, 2014, 10:35:16 AM7/14/14
to replica-island-...@googlegroups.com
Thank you. Can you maybe give me a flow of how and where to change or write the new code?
To unsubscribe from this group and stop receiving emails from it, send an email to replica-island-coding-community+unsubscribe@googlegroups.com.

Bart Hirst

unread,
Jul 14, 2014, 1:48:11 PM7/14/14
to ReplicaIsland Coding Community
I could but you really wouldn't learn much.  Just google "2d Java game tutorial" or similar and you'll find some good materials.  Is this for a school project perhaps :)
To unsubscribe from this group and stop receiving emails from it, send an email to replica-island-coding...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages