Skip to content

Commit

Permalink
recoger items
Browse files Browse the repository at this point in the history
  • Loading branch information
brunotonelli committed May 7, 2019
1 parent b3a35c3 commit 20c06a6
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 70 deletions.
57 changes: 29 additions & 28 deletions CShark/Items/Recolectable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using System.Threading.Tasks;
using CShark.Jugador;
using Microsoft.DirectX.DirectInput;
using TGC.Core.BoundingVolumes;
using TGC.Core.Collision;
using TGC.Core.Mathematica;
Expand All @@ -15,32 +16,14 @@ namespace CShark.Items
public abstract class Recolectable : IRecolectable
{
protected TgcMesh Mesh;

public TgcBoundingSphere EsferaCercania;

protected TGCVector3 Posicion {
get {
return Mesh.Position;
}
set {
Mesh.Position = value;
}
}

protected TGCVector3 Rotacion {
get {
return Mesh.Rotation;
}
set {
Mesh.Rotation = value;
}
}
private bool Recogido = false;

public Recolectable(string mesh, TGCVector3 posicion) {
var ruta = Game.Default.MediaDirectory + "Recolectables\\" + mesh + "-TgcScene.xml";
var ruta = Game.Default.MediaDirectory + @"Recolectables\" + mesh + "-TgcScene.xml";
Mesh = new TgcSceneLoader().loadSceneFromFile(ruta).Meshes[0];
Mesh.Position = posicion;
EsferaCercania = new TgcBoundingSphere(Posicion, 100f);
EsferaCercania = new TgcBoundingSphere(Posicion, 400f);
EsferaCercania.setRenderColor(Color.Red);
}

Expand All @@ -49,16 +32,24 @@ public void Desaparecer() {
}

public virtual void Update(Player player) {
MoverEsferaCercania();
if (EstaCerca(player))
EsferaCercania.setRenderColor(Color.Yellow);
else
EsferaCercania.setRenderColor(Color.Red);
if (!Recogido) {
MoverEsferaCercania();
if (EstaCerca(player)) {
EsferaCercania.setRenderColor(Color.Yellow);
if (player.Input.keyDown(Key.E)) {
Recogido = true;
player.Recoger(this);
}
}
else EsferaCercania.setRenderColor(Color.Red);
}
}

public virtual void Render() {
Mesh.Render();
EsferaCercania.Render();
if (!Recogido) {
Mesh.Render();
EsferaCercania.Render();
}
}

public bool EstaCerca(Player player) {
Expand All @@ -71,5 +62,15 @@ private void MoverEsferaCercania() {
var z = EsferaCercania.Position.Z - Posicion.Z;
EsferaCercania.moveCenter(new TGCVector3(x, y, z));
}

public TGCVector3 Posicion {
get { return Mesh.Position; }
set { Mesh.Position = value; }
}

public TGCVector3 Rotacion {
get { return Mesh.Rotation; }
set { Mesh.Rotation = value; }
}
}
}
4 changes: 1 addition & 3 deletions CShark/Items/Recolectables/Bateria.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace CShark.Items.Recolectables
{
public class Bateria : Recolectable
{
public Bateria(float x, float y, float z)
: base("Bateria", new TGCVector3(x, y, z)) { }

public Bateria(TGCVector3 posicion) : base("Bateria", posicion) { }
}
}
4 changes: 1 addition & 3 deletions CShark/Items/Recolectables/Chip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace CShark.Items.Recolectables
{
public class Chip : Recolectable
{
public Chip(float x, float y, float z)
: base("Chip", new TGCVector3(x, y, z)) { }

public Chip(TGCVector3 posicion) : base("Chip", posicion) { }
}
}
4 changes: 1 addition & 3 deletions CShark/Items/Recolectables/Medkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace CShark.Items.Recolectables
{
public class Medkit : Recolectable
{
public Medkit(float x, float y, float z)
: base("Medkit", new TGCVector3(x, y, z)) { }

public Medkit(TGCVector3 posicion) : base("Medkit", posicion) { }
}
}
4 changes: 1 addition & 3 deletions CShark/Items/Recolectables/Oxigeno.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace CShark.Items.Recolectables
{
public class Oxigeno : Recolectable
{
public Oxigeno(float x, float y, float z)
: base("Oxigeno", new TGCVector3(x, y, z)) { }

public Oxigeno(TGCVector3 posicion) : base("Oxigeno", posicion) { }
}
}
2 changes: 1 addition & 1 deletion CShark/Items/Recolectables/Wumpa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Wumpa : Recolectable
{
RigidBody Body;

public Wumpa(float x, float y, float z) : base("Wumpa", new TGCVector3(x, y, z)) {
public Wumpa(TGCVector3 posicion) : base("Wumpa", posicion) {
Body = RigidBodyUtils.CrearEsfera(Mesh, 10f);
Body.Friction = 1f;
Body.RollingFriction = 100f;
Expand Down
29 changes: 26 additions & 3 deletions CShark/Jugador/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
using TGC.Core.Geometry;
using System.Drawing;
using TGC.Core.BoundingVolumes;
using CShark.Utils;
using Microsoft.DirectX.DirectInput;
using CShark.Variables;
using CShark.Managers;
using CShark.Items;

namespace CShark.Jugador
{
Expand All @@ -30,8 +33,11 @@ public class Player
public bool EstaVivo => Vida > 0 && Oxigeno > 0;
public bool onPause;

private Variable<float> VelocidadMovimiento;

public TgcFpsCamera CamaraInterna { get; private set; }
private TgcD3dInput Input;
public TgcD3dInput Input;
public TGCVector3 MoveVector;

public Player(TGCVector3 posicion, int vidaInicial, int oxigenoInicial, TgcD3dInput input) {
Inventario = new Inventario();
Expand All @@ -40,15 +46,28 @@ public Player(TGCVector3 posicion, int vidaInicial, int oxigenoInicial, TgcD3dIn
Oxigeno = oxigenoInicial;
HUD = new HUD(Vida, Oxigeno);
Input = input;
CamaraInterna = new TgcFpsCamera(posicion, input);
CamaraInterna = new TgcFpsCamera(input, this);
Arma = new Crossbow();
onPause = false;
VelocidadMovimiento = Configuracion.Instancia.VelocidadMovimiento;
}

public void Update(GameModel game) {
if (!onPause)
{
Posicion = CamaraInterna.Position;

MoveVector = TGCVector3.Empty;

if (Input.keyDown(Key.W))
MoveVector += new TGCVector3(0, 0, -1) * VelocidadMovimiento.Valor;
if (Input.keyDown(Key.S))
MoveVector += new TGCVector3(0, 0, 1) * VelocidadMovimiento.Valor;
if (Input.keyDown(Key.D))
MoveVector += new TGCVector3(-1, 0, 0) * VelocidadMovimiento.Valor;
if (Input.keyDown(Key.A))
MoveVector += new TGCVector3(1, 0, 0) * VelocidadMovimiento.Valor;

ActualizarOxigeno(game);
if (EstaVivo)
{
Expand All @@ -63,6 +82,10 @@ public void Update(GameModel game) {
}
}

public void Recoger(Recolectable item) {
Inventario.Agregar(item);
}

private void ActualizarOxigeno(GameModel game)
{
Oxigeno = Posicion.Y >= 2800f && Oxigeno < HUD.BarraOxigeno.ValorMaximo ?
Expand Down
15 changes: 8 additions & 7 deletions CShark/Managers/RecolectablesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TGC.Core.Mathematica;

namespace CShark.Managers
{
Expand All @@ -18,13 +19,13 @@ public RecolectablesManager() {
}

public void Initialize() {
/*Recolectables.Add(new Wumpa(100, 500, 100));
Recolectables.Add(new Wumpa(0, 1000, 0));
Recolectables.Add(new Oxigeno(250, 100, 0));
Recolectables.Add(new Oxigeno(350, 100, 100));
Recolectables.Add(new Oxigeno(-100, 100, -50));
Recolectables.Add(new Medkit(500, 50, -300));
Recolectables.Add(new Medkit(-400, 50, -100));*/
Recolectables.Add(new Wumpa(new TGCVector3(100, 500, 100)));
Recolectables.Add(new Wumpa(new TGCVector3(0, 1000, 0)));
Recolectables.Add(new Oxigeno(new TGCVector3(250, 400, 0)));
Recolectables.Add(new Oxigeno(new TGCVector3(350, 400, 100)));
Recolectables.Add(new Oxigeno(new TGCVector3(-100, 400, -50)));
Recolectables.Add(new Medkit(new TGCVector3(500, 400, -300)));
Recolectables.Add(new Medkit(new TGCVector3(-400, 400, -100)));
}

public void Render(GameModel game) {
Expand Down
28 changes: 9 additions & 19 deletions CShark/Model/FpsCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using TGC.Core.SceneLoader;
using CShark.Variables;
using CShark.Managers;
using CShark.Jugador;

namespace CShark.Model
{
Expand All @@ -23,41 +24,30 @@ public class TgcFpsCamera : TgcCamera
public float leftrightRot;
public float updownRot;
private TGCVector3 PositionEye;

private TgcD3dInput Input;
private Variable<float> VelocidadMovimiento;
private Variable<float> VelocidadRotacion;
private TgcD3dInput Input;
private bool bloquear = false;
private Player Player;

public TgcFpsCamera(TGCVector3 positionEye, TgcD3dInput input) {
public TgcFpsCamera(TgcD3dInput input, Player player) {
Input = input;
PositionEye = positionEye;
VelocidadMovimiento = Configuracion.Instancia.VelocidadMovimiento;
VelocidadRotacion = Configuracion.Instancia.VelocidadRotacion;
Player = player;
PositionEye = player.Posicion;
directionView = new TGCVector3(0, 0, -1);
leftrightRot = FastMath.PI_HALF;
updownRot = -FastMath.PI / 10.0f;
cameraRotation = TGCMatrix.RotationX(updownRot) * TGCMatrix.RotationY(leftrightRot);
VelocidadRotacion = Configuracion.Instancia.VelocidadRotacion;
}

public override void UpdateCamera(float elapsedTime) {
var moveVector = TGCVector3.Empty;

if (Input.keyDown(Key.W))
moveVector += new TGCVector3(0, 0, -1) * VelocidadMovimiento.Valor;
if (Input.keyDown(Key.S))
moveVector += new TGCVector3(0, 0, 1) * VelocidadMovimiento.Valor;
if (Input.keyDown(Key.D))
moveVector += new TGCVector3(-1, 0, 0) * VelocidadMovimiento.Valor;
if (Input.keyDown(Key.A))
moveVector += new TGCVector3(1, 0, 0) * VelocidadMovimiento.Valor;

if (!bloquear)
{
leftrightRot -= -Input.XposRelative * VelocidadRotacion.Valor;
updownRot -= Input.YposRelative * VelocidadRotacion.Valor;
cameraRotation = TGCMatrix.RotationX(updownRot) * TGCMatrix.RotationY(leftrightRot);
PositionEye += TGCVector3.TransformNormal(moveVector * elapsedTime, cameraRotation);
PositionEye += TGCVector3.TransformNormal(Player.MoveVector * elapsedTime, cameraRotation);
}

var cameraRotatedTarget = TGCVector3.TransformNormal(directionView, cameraRotation);
Expand Down

0 comments on commit 20c06a6

Please sign in to comment.