Android Open Source - SpaceGame Player Input Processor






From Project

Back to project page SpaceGame.

License

The source code is released under:

Copyright (c) 2012 ??ukasz Patalas Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the So...

If you think the Android project SpaceGame listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lpatalas.spacegame;
//w w  w  .j a va2 s.co  m
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.math.Vector2;

/**
 * User: Lukasz
 * Date: 11.08.12
 */
class PlayerInputProcessor extends InputAdapter {
  private final GameplayScreen game;
  private final Player player;

  public PlayerInputProcessor(GameplayScreen game, Player player) {
    this.game = game;
    this.player = player;
  }

  @Override
  public boolean touchDown(int x, int y, int pointer, int button) {
    if (game.isRunning()) {
      movePlayerToPosition(x, y);
    }
    else {
      game.resetGame();
    }

    return true;
  }

  @Override
  public boolean touchDragged(int x, int y, int pointer) {
    if (game.isRunning()) {
      movePlayerToPosition(x, y);
      return true;
    }

    return super.touchDragged(x, y, pointer);
  }

  private void movePlayerToPosition(int x, int y) {
    Vector2 position = transformPosition(x, y);
    player.moveTo(position);
  }

  private static Vector2 transformPosition(float x, float y) {
    return new Vector2(x, Gdx.graphics.getHeight() - y);
  }
}




Java Source Code List

com.lpatalas.spacegame.Assets.java
com.lpatalas.spacegame.Asteroid.java
com.lpatalas.spacegame.Asteroids.java
com.lpatalas.spacegame.CloudLayer.java
com.lpatalas.spacegame.Clouds.java
com.lpatalas.spacegame.DesktopStarter.java
com.lpatalas.spacegame.GameplayScreen.java
com.lpatalas.spacegame.MainMenuScreen.java
com.lpatalas.spacegame.Particles.java
com.lpatalas.spacegame.PlayerInputProcessor.java
com.lpatalas.spacegame.Player.java
com.lpatalas.spacegame.SpaceGameActivity.java
com.lpatalas.spacegame.SpaceGame.java
com.lpatalas.spacegame.Stars.java