Java tutorial
/* * Copyright 2014 Jesse Corbett * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package us.notsoserio.ninja.session.server; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.math.Vector2; import us.notsoserio.ninja.NinjaGame; import us.notsoserio.ninja.network.Command; import us.notsoserio.ninja.entity.behavior.PlayerBehavior; import us.notsoserio.ninja.weapons.projectiles.Projectiles; public class ServerInputManager { static boolean recoil = false; public static void ProcessInput(PlayerBehavior player, Command command) { if (Gdx.input.isButtonPressed(Input.Buttons.RIGHT) && !recoil) { Vector2 velocity = new Vector2((Gdx.input.getX() - 1280 / 2) / NinjaGame.ZoomFactor, ((720 - Gdx.input.getY()) - 720 / 2) / NinjaGame.ZoomFactor); velocity.scl(0.4f); player.FireProjectile(velocity, Projectiles.Kunai); recoil = true; } else if (!Gdx.input.isButtonPressed(Input.Buttons.RIGHT)) { recoil = false; } if (player.isInControl) { if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) { player.isWalkingLeft = false; player.isWalkingRight = false; player.isWalkingUp = false; player.isWalkingDown = false; player.isJumping = true; player.JumpX = (Gdx.input.getX() - 1280 / 2) / NinjaGame.ZoomFactor; player.JumpX *= 3f; player.JumpY = ((720 - Gdx.input.getY()) - 720 / 2) / NinjaGame.ZoomFactor; player.JumpY *= 3f; } else if (Gdx.input.isKeyPressed(Input.Keys.A)) { player.isWalkingLeft = true; } else if (Gdx.input.isKeyPressed(Input.Keys.D)) { player.isWalkingRight = true; } else if (Gdx.input.isKeyPressed(Input.Keys.W)) { player.isWalkingUp = true; } else if (Gdx.input.isKeyPressed(Input.Keys.S)) { player.isWalkingDown = true; } else { player.isWalkingLeft = false; player.isWalkingRight = false; player.isWalkingUp = false; player.isWalkingDown = false; } } else { player.isWalkingLeft = false; player.isWalkingRight = false; player.isWalkingUp = false; player.isWalkingDown = false; } } }