Added back the map, movement and zooming. Also changed all Textures to 32bit

This commit is contained in:
2020-04-21 13:39:42 -06:00
parent 2892570539
commit 85af72cfa1
56 changed files with 659 additions and 241 deletions

View File

@@ -1,59 +1,91 @@
using System.Collections.Generic;
using Collector;
using Collector.Character;
using Collector.Dimension;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGame.Extended;
using Mouse = Collector.Character.Mouse;
public class InputController : IRestrictions {
private Player player;
private Mouse mouse;
//private Dictionary<string, Animation<TextureAtlas.AtlasRegion>> animations;
int i = 0;
private Player _player;
private Mouse _mouse;
private OrthographicCamera _cam;
private Dictionary<string, Rectangle> animations;
public string Input { get; set; }
private SpriteBatch _spriteBatch;
private ContentManager _content;
public InputController(Player player, Mouse mouse)
public InputController(Player player, Mouse mouse, OrthographicCamera cam, SpriteBatch spriteBatch, ContentManager contentManager)
{
this.player = player;
this.mouse = mouse;
_player = player;
_mouse = mouse;
_cam = cam;
_spriteBatch = spriteBatch;
_content = contentManager;
Input = "Down";
animations = new Dictionary<string, Rectangle>
{
["Up"] = new Rectangle(0, 0, 32, 32),
["Right"] = new Rectangle(0, 0, 32, 32),
["Left"] = new Rectangle(0, 0, 32, 32),
["Right"] = new Rectangle(0, 0, 32, 32)
};
}
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()
public void PlayerInput(Main main, SpriteBatch spriteBatch)
{
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
var keyboardState = Keyboard.GetState();
const int movementSpeed = IRestrictions.MovementSpeed;
if (keyboardState.IsKeyDown(Keys.Escape))
{
Exit();
Quit(main);
}
else if(Keyboard.GetState().IsKeyDown(Keys.W))
if (keyboardState.IsKeyDown(Keys.W))
{
Input = "Up";
Player.Y += -movementSpeed;
_cam.Move(new Vector2(0,-movementSpeed));
}
else if(Keyboard.GetState().IsKeyDown(Keys.A))
if (keyboardState.IsKeyDown(Keys.A))
{
Player.X += -movementSpeed;
_cam.Move(new Vector2(-movementSpeed,0));
Input = "Left";
}
else if(Keyboard.GetState().IsKeyDown(Keys.S))
if (keyboardState.IsKeyDown(Keys.S))
{
Player.Y += movementSpeed;
_cam.Move(new Vector2(0,movementSpeed));
Input = "Down";
}
else if(Keyboard.GetState().IsKeyDown(Keys.D))
if (keyboardState.IsKeyDown(Keys.D))
{
Player.X += movementSpeed;
_cam.Move(new Vector2(movementSpeed, 0));
Input = "Right";
}
if (keyboardState.IsKeyDown(Keys.Q))
{
_cam.ZoomIn(0.05f);
}
if (keyboardState.IsKeyDown(Keys.E))
{
_cam.ZoomOut(0.05f);
}
}
private static void Quit(Game main)
{
main.Exit();
}
/*
@@ -138,5 +170,10 @@ public void handleInput() {
}
*/
public void Draw()
{
var texture = _content.Load<Texture2D>("man/man-0");
_spriteBatch.Draw(texture,new Vector2(Player.X,Player.Y),Color.White);
}
}

View File

@@ -1,25 +1,33 @@
package Collector.Character;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
import Collector.Restrictions;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Vector3;
namespace Collector.Character
{
public class Mouse : IRestrictions {
private SpriteBatch _spriteBatch;
private ContentManager _contentManager;
private Texture2D Crosshair { get; set; }
public class Mouse implements Restrictions {
Texture crosshair;
public Mouse(ContentManager contentManager, SpriteBatch spriteBatch)
{
_spriteBatch = spriteBatch;
_contentManager = contentManager;
Crosshair = _contentManager.Load<Texture2D>("crosshair");
}
public Mouse() {
this.crosshair = new Texture("assets/crosshair.png");
}
public void Draw()
{
_spriteBatch.Draw(Crosshair, new Vector2(Player.X, Player.Y),Color.Aqua);
}
public Texture getCrosshair() {
return crosshair;
}
public int GetSelectedX(Vector3 mousePos) {
return ((int)(mousePos.X)>>4)<<4;
}
public int getSelectedX(Vector3 mousePos) {
return ((int)(mousePos.x)>>4)<<4;
}
public int getSelectedY(Vector3 mousePos) {
return ((int)(mousePos.y)>>4)<<4;
public int GetSelectedY(Vector3 mousePos) {
return ((int)(mousePos.Y)>>4)<<4;
}
}
}

View File

@@ -1,62 +1,19 @@
using Collector;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
public class Player : IRestrictions {
private static int X;
private static int Y;
private string SpriteName;
private Inventory playerInventory;
namespace Collector.Character
{
public class Player : IRestrictions
{
public static int X { get; set; }
public static int Y { get; set; }
public Dictionary<string,Rectangle> Animation { get; set; }
//private Inventory PlayerInventory { get; }
public Player(int x, int y) {
//Player location
X = x<<IRestrictions.TileShift;
Y = y<<IRestrictions.TileShift;
//Player Inventory
playerInventory = new Inventory();
//Player animation
//spriteName = "man";
//textureAtlas = new TextureAtlas("man.atlas");
//Array<TextureAtlas.AtlasRegion> keyFrames = textureAtlas.findRegions(spriteName + "_Down");
//float frameDuration = 1 / 4f;
//animation = new Animation<>(frameDuration, keyFrames);
public Player(int x, int y) {
X = x<<IRestrictions.TileShift;
Y = y<<IRestrictions.TileShift;
//PlayerInventory = new Inventory();
}
}
public static int getX() {
return X;
}
public static int getY() {
return Y;
}
public static void addX(int x){
X += x;
}
public static void addY(int y){
Y += y;
}
/*
public String getSpriteName() {
return spriteName;
}
public Animation<TextureAtlas.AtlasRegion> getAnimation() {
return animation;
}
public void setAnimation(Animation<TextureAtlas.AtlasRegion> animationTemp) {
animation = animationTemp;
}
public void dispose(){
//textureAtlas.dispose();
}
public TextureAtlas getTextureAtlas() {
return textureAtlas;
}
*/
}