Started to import assets from old project
This commit is contained in:
142
Collector/src/Character/InputController.cs
Normal file
142
Collector/src/Character/InputController.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using System.Collections.Generic;
|
||||
using Collector;
|
||||
using Collector.Dimension;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
public class InputController : IRestrictions {
|
||||
|
||||
private Player player;
|
||||
private Mouse mouse;
|
||||
//private Dictionary<string, Animation<TextureAtlas.AtlasRegion>> animations;
|
||||
int i = 0;
|
||||
|
||||
public InputController(Player player, Mouse mouse)
|
||||
{
|
||||
this.player = player;
|
||||
this.mouse = mouse;
|
||||
}
|
||||
|
||||
public InputController() {
|
||||
|
||||
/*
|
||||
animations = new HashMap<>();
|
||||
animations.put("Up", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "Up")));
|
||||
animations.put("UpRight", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "UpRight")));
|
||||
animations.put("UpLeft", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "UpLeft")));
|
||||
animations.put("Down", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "Down")));
|
||||
animations.put("DownRight", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "DownRight")));
|
||||
animations.put("DownLeft", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "DownLeft")));
|
||||
animations.put("Left", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "Left")));
|
||||
animations.put("Right", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "Right")));
|
||||
*/
|
||||
}
|
||||
|
||||
private void PlayerInput()
|
||||
{
|
||||
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
|
||||
{
|
||||
Exit();
|
||||
}
|
||||
else if(Keyboard.GetState().IsKeyDown(Keys.W))
|
||||
{
|
||||
|
||||
}
|
||||
else if(Keyboard.GetState().IsKeyDown(Keys.A))
|
||||
{
|
||||
|
||||
}
|
||||
else if(Keyboard.GetState().IsKeyDown(Keys.S))
|
||||
{
|
||||
|
||||
}
|
||||
else if(Keyboard.GetState().IsKeyDown(Keys.D))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
public void handleInput() {
|
||||
i++;
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.Q)) {
|
||||
Main.cam.zoom += 5;
|
||||
}
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.E)) {
|
||||
Main.cam.zoom -= 5;
|
||||
}
|
||||
if ((Gdx.input.isButtonJustPressed(Input.Buttons.LEFT) || Gdx.input.isButtonJustPressed(Input.Buttons.RIGHT) )&& i > KEY_DELAY) {
|
||||
Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
|
||||
Main.cam.unproject(mousePos);
|
||||
int x = mouse.getSelectedX(mousePos) >> TILE_SHIFT;
|
||||
int y = mouse.getSelectedY(mousePos) >> TILE_SHIFT;
|
||||
if(Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)) {
|
||||
i = 0;
|
||||
Chunks.placeBlock(x, y, "wood");
|
||||
}
|
||||
if (Gdx.input.isButtonJustPressed(Input.Buttons.RIGHT)) {
|
||||
i = 0;
|
||||
Chunks.removeBlock(x,y);
|
||||
}
|
||||
}
|
||||
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.W) && Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("UpLeft"));
|
||||
Player.addX(-MOVEMENT_SPEED);
|
||||
Player.addY(MOVEMENT_SPEED);
|
||||
Main.cam.translate(-MOVEMENT_SPEED, MOVEMENT_SPEED);
|
||||
}
|
||||
else if (Gdx.input.isKeyPressed(Input.Keys.W) && Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("UpRight"));
|
||||
Player.addX(MOVEMENT_SPEED);
|
||||
Player.addY(MOVEMENT_SPEED);
|
||||
Main.cam.translate(MOVEMENT_SPEED, MOVEMENT_SPEED);
|
||||
}
|
||||
else if (Gdx.input.isKeyPressed(Input.Keys.S) && Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("DownLeft"));
|
||||
Player.addX(-MOVEMENT_SPEED);
|
||||
Player.addY(-MOVEMENT_SPEED);
|
||||
Main.cam.translate(-MOVEMENT_SPEED, -MOVEMENT_SPEED);
|
||||
}
|
||||
else if (Gdx.input.isKeyPressed(Input.Keys.S) && Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("DownRight"));
|
||||
Player.addX(MOVEMENT_SPEED);
|
||||
Player.addY(-MOVEMENT_SPEED);
|
||||
|
||||
Main.cam.translate(MOVEMENT_SPEED, -MOVEMENT_SPEED);
|
||||
}
|
||||
else if (Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("Left"));
|
||||
Player.addX(-MOVEMENT_SPEED);
|
||||
Main.cam.translate(-MOVEMENT_SPEED, 0);
|
||||
}
|
||||
else if (Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("Right"));
|
||||
Player.addX(MOVEMENT_SPEED);
|
||||
Main.cam.translate(MOVEMENT_SPEED, 0);
|
||||
}
|
||||
else if (Gdx.input.isKeyPressed(Input.Keys.S) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("Down"));
|
||||
Player.addY(-MOVEMENT_SPEED);
|
||||
Main.cam.translate(0, -MOVEMENT_SPEED);
|
||||
}
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.W) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("Up"));
|
||||
Player.addY(MOVEMENT_SPEED);
|
||||
Main.cam.translate(0, MOVEMENT_SPEED);
|
||||
}
|
||||
Main.cam.update();
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
package Collector.Character;
|
||||
|
||||
import Collector.Main;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.graphics.g2d.Animation;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import Collector.Dimension.Chunks;
|
||||
import Collector.Restrictions;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class InputController implements Restrictions {
|
||||
|
||||
private Player player;
|
||||
private HashMap<String, Animation<TextureAtlas.AtlasRegion>> animations;
|
||||
private Mouse mouse;
|
||||
int i = 0;
|
||||
|
||||
public InputController(Player player, Mouse mouse) {
|
||||
this.player = player;
|
||||
this.mouse = mouse;
|
||||
animations = new HashMap<>();
|
||||
animations.put("Up", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "Up")));
|
||||
animations.put("UpRight", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "UpRight")));
|
||||
animations.put("UpLeft", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "UpLeft")));
|
||||
animations.put("Down", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "Down")));
|
||||
animations.put("DownRight", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "DownRight")));
|
||||
animations.put("DownLeft", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "DownLeft")));
|
||||
animations.put("Left", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "Left")));
|
||||
animations.put("Right", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "Right")));
|
||||
}
|
||||
|
||||
public void handleInput() {
|
||||
i++;
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.Q)) {
|
||||
Main.cam.zoom += 5;
|
||||
}
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.E)) {
|
||||
Main.cam.zoom -= 5;
|
||||
}
|
||||
if ((Gdx.input.isButtonJustPressed(Input.Buttons.LEFT) || Gdx.input.isButtonJustPressed(Input.Buttons.RIGHT) )&& i > KEY_DELAY) {
|
||||
Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
|
||||
Main.cam.unproject(mousePos);
|
||||
int x = mouse.getSelectedX(mousePos) >> TILE_SHIFT;
|
||||
int y = mouse.getSelectedY(mousePos) >> TILE_SHIFT;
|
||||
if(Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)) {
|
||||
i = 0;
|
||||
Chunks.placeBlock(x, y, "wood");
|
||||
}
|
||||
if (Gdx.input.isButtonJustPressed(Input.Buttons.RIGHT)) {
|
||||
i = 0;
|
||||
Chunks.removeBlock(x,y);
|
||||
}
|
||||
}
|
||||
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.W) && Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("UpLeft"));
|
||||
Player.addX(-MOVEMENT_SPEED);
|
||||
Player.addY(MOVEMENT_SPEED);
|
||||
Main.cam.translate(-MOVEMENT_SPEED, MOVEMENT_SPEED);
|
||||
}
|
||||
else if (Gdx.input.isKeyPressed(Input.Keys.W) && Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("UpRight"));
|
||||
Player.addX(MOVEMENT_SPEED);
|
||||
Player.addY(MOVEMENT_SPEED);
|
||||
Main.cam.translate(MOVEMENT_SPEED, MOVEMENT_SPEED);
|
||||
}
|
||||
else if (Gdx.input.isKeyPressed(Input.Keys.S) && Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("DownLeft"));
|
||||
Player.addX(-MOVEMENT_SPEED);
|
||||
Player.addY(-MOVEMENT_SPEED);
|
||||
Main.cam.translate(-MOVEMENT_SPEED, -MOVEMENT_SPEED);
|
||||
}
|
||||
else if (Gdx.input.isKeyPressed(Input.Keys.S) && Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("DownRight"));
|
||||
Player.addX(MOVEMENT_SPEED);
|
||||
Player.addY(-MOVEMENT_SPEED);
|
||||
|
||||
Main.cam.translate(MOVEMENT_SPEED, -MOVEMENT_SPEED);
|
||||
}
|
||||
else if (Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("Left"));
|
||||
Player.addX(-MOVEMENT_SPEED);
|
||||
Main.cam.translate(-MOVEMENT_SPEED, 0);
|
||||
}
|
||||
else if (Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("Right"));
|
||||
Player.addX(MOVEMENT_SPEED);
|
||||
Main.cam.translate(MOVEMENT_SPEED, 0);
|
||||
}
|
||||
else if (Gdx.input.isKeyPressed(Input.Keys.S) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("Down"));
|
||||
Player.addY(-MOVEMENT_SPEED);
|
||||
Main.cam.translate(0, -MOVEMENT_SPEED);
|
||||
}
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.W) && i > KEY_DELAY) {
|
||||
i = 0;
|
||||
player.setAnimation(animations.get("Up"));
|
||||
Player.addY(MOVEMENT_SPEED);
|
||||
Main.cam.translate(0, MOVEMENT_SPEED);
|
||||
}
|
||||
Main.cam.update();
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,13 @@ using Collector;
|
||||
public class Player : IRestrictions {
|
||||
private static int X;
|
||||
private static int Y;
|
||||
//private string SpriteName;
|
||||
//private TextureAtlas textureAtlas;
|
||||
//private Animation<TextureAtlas.AtlasRegion> animation;
|
||||
private string SpriteName;
|
||||
private Inventory playerInventory;
|
||||
|
||||
public Player(int x, int y) {
|
||||
//Player location
|
||||
Player.X = x<<IRestrictions.TileShift;
|
||||
Player.Y = y<<IRestrictions.TileShift;
|
||||
X = x<<IRestrictions.TileShift;
|
||||
Y = y<<IRestrictions.TileShift;
|
||||
|
||||
//Player Inventory
|
||||
playerInventory = new Inventory();
|
||||
@@ -33,11 +31,11 @@ public class Player : IRestrictions {
|
||||
}
|
||||
|
||||
public static void addX(int x){
|
||||
Player.X += x;
|
||||
X += x;
|
||||
}
|
||||
|
||||
public static void addY(int y){
|
||||
Player.Y += y;
|
||||
Y += y;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user