Skip to content

Commit

Permalink
Agrego colision con los decorados; no colisiona con los faraones :(
Browse files Browse the repository at this point in the history
Signed-off-by: pepeciavirella <[email protected]>
  • Loading branch information
pepeciavirella committed May 9, 2018
1 parent 0cc5a27 commit 50b2c4c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 22 deletions.
Binary file added TGC.Group/Media/damero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 39 additions & 20 deletions TGC.Group/Model/GameModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.DirectX.DirectInput;
using System;
using System.Drawing;
using TGC.Core.BoundingVolumes;
using TGC.Core.Collision;
using TGC.Core.Example;
using TGC.Core.Mathematica;
Expand Down Expand Up @@ -48,27 +49,14 @@ public override void Update() {
// calculo nueva velocidad
personaje.update(ElapsedTime, Input);

// checkeo si empujo alguna caja
checkearEmpujeCajas();

// gravito las cajas
aplicarGravedadCajas();

// checkeo sobre que estoy parado
// TODO: hacer funcion aparte
foreach (var box in nivel.getPisos()) {
if (TgcCollisionUtils.testSphereAABB(personaje.getPies(), box)) {
if (nivel.esPisoDesplazante(box)) {
personaje.addVelocity(nivel.getPlataformaDesplazante(box).getVelocity());
} else if (nivel.esPisoRotante(box)) {
var plataformaRotante = nivel.getPlataformaRotante(box);
personaje.addVelocity(plataformaRotante.getVelAsVector(personaje.getPosition()) * ElapsedTime);
personaje.setRotation(plataformaRotante.getAngle());
} else if (nivel.esPisoAscensor(box)) {
personaje.addVelocity(nivel.getPlataformaAscensor(box).getVel());
}

personaje.aterrizar();
personaje.setPatinando(nivel.esPisoResbaladizo(box));
}
}
checkearDesplazamientoPorPlataformas();

// muevo plataformas
nivel.update(ElapsedTime);
Expand Down Expand Up @@ -117,11 +105,12 @@ public override void Dispose() {
nivel.dispose();
}

private void checkearEmpujeCajas() {
private void checkearEmpujeCajas() { // ARREGLAR :(

foreach (var caja in nivel.getCajas()) {

if (TgcCollisionUtils.testSphereAABB(personaje.getBoundingSphere(), caja.getCuerpo())) {

// obtengo dirección para mover la caja
var distanciaPersonajeCaja = caja.getCuerpo().calculateBoxCenter() - personaje.getBoundingSphere().Center;
var cajaMovementDeseado = TGCVector3.Empty;

Expand All @@ -139,7 +128,37 @@ private void checkearEmpujeCajas() {
}
}

caja.move(cajaMovementDeseado); //TEMP
caja.move(cajaMovementDeseado);
}
}

}

private void checkearDesplazamientoPorPlataformas()
{
foreach (var box in nivel.getPisos()) {

if (TgcCollisionUtils.testSphereAABB(personaje.getPies(), box))
{

if (nivel.esPisoDesplazante(box))
{
personaje.addVelocity(nivel.getPlataformaDesplazante(box).getVelocity());
}
else if (nivel.esPisoRotante(box))
{
var plataformaRotante = nivel.getPlataformaRotante(box);
personaje.addVelocity(plataformaRotante.getVelAsVector(personaje.getPosition()) * ElapsedTime);
personaje.setRotation(plataformaRotante.getAngle());
}
else if (nivel.esPisoAscensor(box))
{
personaje.addVelocity(nivel.getPlataformaAscensor(box).getVel());
}

personaje.aterrizar();
personaje.setPatinando(nivel.esPisoResbaladizo(box));

}
}
}
Expand Down
20 changes: 19 additions & 1 deletion TGC.Group/Model/Nivel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public Nivel(string mediaDir) {
var piedraTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, mediaDir + "piedra.png");
var precipicioTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, mediaDir + "precipicio.jpg");
var maderaTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, mediaDir + "tronco.jpg");
var endingTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, mediaDir + "damero.png");

// Cargo objetos decorativos
var escenaCalavera1 = loader.loadSceneFromFile(mediaDir + "\\Decorativos\\Calabera\\Calabera-TgcScene.xml");
Expand Down Expand Up @@ -143,6 +144,13 @@ public Nivel(string mediaDir) {
pEstaticas.Add(new Plataforma(new TGCVector3(3000, -250, 1400), new TGCVector3(2, 500, 1200), precipicioTexture)); // izquierda
pEstaticas.Add(new Plataforma(new TGCVector3(2500, -250, 2000), new TGCVector3(1000, 500, 2), precipicioTexture)); // frontal

// Sector post-precipicio del tronco
piso = new TgcPlane(new TGCVector3(3000, 0, 800), new TGCVector3(1200, 0, 1200), TgcPlane.Orientations.XZplane, endingTexture);
pisosNormales.Add(piso);
pEstaticas.Add(new Plataforma(new TGCVector3(4190, 20, 1400), new TGCVector3(20, 40, 1200), paredJunglaTexture));
pEstaticas.Add(new Plataforma(new TGCVector3(3600, 20, 1990), new TGCVector3(1200, 40, 20), paredJunglaTexture));
pEstaticas.Add(new Plataforma(new TGCVector3(3600, 20, 790), new TGCVector3(1200, 40, 20), paredJunglaTexture));

// Cajas movibles del escenario
cajas.Add(new Caja(mediaDir, new TGCVector3(-250, 40, -1000)));
cajas.Add(new Caja(mediaDir, new TGCVector3(250, 40, 250)));
Expand All @@ -154,13 +162,14 @@ public Nivel(string mediaDir) {
pDesplazan.Add(new PlataformaDesplazante(new TGCVector3(2075, -60, 1400), new TGCVector3(150, 50, 80), maderaTexture, new TGCVector3(2925, -60, 1400), new TGCVector3(0.2f, 0, 0)));

// Plataforma rotante
pRotantes.Add(new PlataformaRotante(new TGCVector3(0, 70, 300), new TGCVector3(100, 50, 100), cajaTexture, FastMath.PI * 100));
pRotantes.Add(new PlataformaRotante(new TGCVector3(0, 70, 300), new TGCVector3(100, 50, 100), cajaTexture, FastMath.PI * 200));

// Plataforma ascensor en Y
pAscensor.Add(new PlataformaAscensor(new TGCVector3(0, -140, 2800), new TGCVector3(200, 50, 200), cajaTexture, 200, 0.1f));
}

public void update(float deltaTime) {

foreach (var p in pDesplazan) {
p.update(deltaTime);
}
Expand All @@ -172,9 +181,11 @@ public void update(float deltaTime) {
foreach (var p in pAscensor) {
p.update(deltaTime);
}

}

public void render() {

foreach (var piso in pisosNormales) {
piso.Render();
}
Expand Down Expand Up @@ -215,6 +226,7 @@ public void render() {
}

public void dispose() {

foreach (var piso in pisosNormales) {
piso.Dispose();
}
Expand Down Expand Up @@ -247,6 +259,11 @@ public void dispose() {
foreach (var p in pAscensor) {
p.dispose();
}

foreach (var decorativo in decorativos) {
decorativo.Dispose();
}

}

public void cargarDecorativo (TgcMesh unDecorativo, TgcScene unaEscena, TGCVector3 posicion, TGCVector3 escala, float rotacion)
Expand All @@ -268,6 +285,7 @@ public List<TgcBoundingAxisAlignBox> getBoundingBoxes() {
list.AddRange(pDesplazan.Select(desplazante => desplazante.getAABB()).ToArray());
list.AddRange(pRotantes.Select(rotante => rotante.getAABB()).ToArray());
list.AddRange(pAscensor.Select(ascensor => ascensor.getAABB()).ToArray());
list.AddRange(aabbDeDecorativos);
return list;
}

Expand Down
3 changes: 2 additions & 1 deletion TGC.Group/Model/PlataformaRotante.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
using TGC.Core.Textures;

namespace TGC.Group.Model {
// TODO: podría ser un cilindro en vez de un rectángulo

class PlataformaRotante : Plataforma {

private float vel;

public PlataformaRotante(TGCVector3 pos, TGCVector3 size, TgcTexture textura, float velAng)
Expand Down
2 changes: 2 additions & 0 deletions TGC.Group/TGC.Group.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
<Content Include="Media\Ciudad\Textures\Traffic Light.jpg" />
<Content Include="Media\Ciudad\Textures\White Wall.JPG" />
<Content Include="Media\Ciudad\Textures\Yellow Painted.jpg" />
<Content Include="Media\damero.png" />
<Content Include="Media\Decorativos\ArbolBananas\ArbolBananas-TgcScene.xml" />
<Content Include="Media\Decorativos\ArbolBananas\preview.jpg" />
<Content Include="Media\Decorativos\ArbolBananas\Textures\banana.jpg" />
Expand Down Expand Up @@ -307,6 +308,7 @@
<Content Include="Media\Jungla\Textures\SassiWall1.jpg" />
<Content Include="Media\Jungla\Textures\WoodTexture.jpg" />
<Content Include="Media\LogoTGC-TgcScene.xml" />
<Content Include="Media\NsanityBeach.mp3" />
<Content Include="Media\paredJungla.jpg" />
<Content Include="Media\piedra.png" />
<Content Include="Media\piso.jpg" />
Expand Down

0 comments on commit 50b2c4c

Please sign in to comment.