player.cs
General player code that is shared between both game modes
Show Code
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public enum GameModeEnum
{
Survival,
Racing
};
public class Player : Inputable {
//Picks which gamemode we are in and tells the player which state
public GameModeEnum gameModeID;
//Player Id for controller input
public int playerID;
//Calling the PlayerStates
[HideInInspector]
public PlayerState currentState;
[HideInInspector]
public PlayerState survivalState;
[HideInInspector]
public PlayerState raceState;
//Calling camera and script
public GameObject cameraFollowObj;
public cameraFollow myCamera;
public ParticleController pc;
//Position & rotation of camera
Vector3 camFollowPos;
Vector3 defaultPos;
Quaternion defaultRotation;
//FOV for camera
public float camMaxDist;
//Speed for player
public float speed = 20f;
//Minimum speed for player
public float minSpeed = 5.0f;
//accel speed
public float accelSpeed;
//Accel speed default
[HideInInspector]
public float accelSpeedDefault;
//Maximum speed the player can reach with acceleration
public float maxAccelSpeed;
//Maximum speed the player can reach with boost
public float maxBoostSpeed = 20.0f;
//Counter to see how long the boost has been on cooldown
[HideInInspector]
public float boostCooldownCounter = 0.0f;
//Boost Duration
public float boostDuration = 4.0f;
//Boost Duration Counter
[HideInInspector]
public float boostDurationCounter = 0.0f;
//Cooldown (in seconds) until next boost.
public float boostCooldown = 10.0f;
//boolean for whether or not we're currently boosting
//[HideInInspector]
public bool boosting = false;
//Float that affects the change in the Speed variable
public float deltaSpeed = 1f;
//Player boost speed
[HideInInspector]
public float boostSpeed;
//Float that affects the change in the Boost variable
public float deltaBoost = 3f;
//Float that affects the change in the Brake variable
public float deltaBrake = 1f;
//boolean for whether or not we're accelerating
[HideInInspector]
public bool accelerating = false;
//Starting speed for player
private float defaultSpeed;
//Counter to see how long the right trigger has been released
[HideInInspector]
public float rightTriggerCounter;
//Counter to see how long the left trigger has been released
//public float leftTriggerCounter;
//Bool that returns true once the right trigger has been released for a certain amount of time
//private bool rightTriggerUp;
//Bool that returns true once the boost is off of cooldown
//private bool boostReset;
//Bool that returns true once the left trigger has been released for a certain amount of time
//private bool leftTriggerUp;
//use for future math
//public float turnAccelHorizontal = 0.2f;
//public float turnAccelVertical = 0.2f;
//Acceleration and Deceleration variables
public float acceleration;
public float maxAccel = 10.0f;
public float accelDefault = 2.0f;
public float accelDelta = 1.1f;
public float deceleration;
public float maxDecel = 10.0f;
public float decelDefault = 2.0f;
public float decelDelta = 1.1f;
//Handling variables for the player
public float rotSpeedVert = 90f;
public float rotSpeedHorz = 150f;
public float rotSpeedTurn = 20f;
public bool dead;
public Rigidbody body;
//Counter to see how long the player has been dead for
public float undead = 0.0f;
public Vector3 lastPos;
public Vector3 pos;
public MeshRenderer meshRend;
public CapsuleCollider capColl;
void Awake()
{
survivalState = new SurvivalState(this);
raceState = new RaceState(this);
body = GetComponent<rigidbody>();
defaultPos = body.transform.position;
defaultRotation = body.transform.rotation;
lastPos = defaultPos;
dead = false;
FindObjectOfType<inputmanager>().ClearAllArrays(playerID);
}
// Use this for initialization
void Start()
{
if (gameModeID == GameModeEnum.Survival)
{
currentState = survivalState;
currentState.Initialize();
}
else if (gameModeID == GameModeEnum.Racing)
{
currentState = raceState;
currentState.Initialize();
}
accelSpeed = accelSpeedDefault;
float acceleration = accelDefault;
float deceleration = decelDefault;
defaultSpeed = speed;
boostCooldownCounter = boostCooldown;
camFollowPos = cameraFollowObj.transform.position;
FindObjectOfType<inputmanager>().AddToArray(playerID, this);
capColl = GetComponent<capsulecollider>();
meshRend = GetComponent<meshrenderer>();
}
public void Reset()
{
FindObjectOfType<inputmanager>().ClearAllArrays(playerID);
acceleration = accelDefault;
deceleration = decelDefault;
FindObjectOfType<inputmanager>().AddToArray(playerID, this);
Debug.Log(playerID);
GetComponentInChildren<trailrenderer>().Clear();
body.transform.rotation = defaultRotation;
body.transform.position = defaultPos;
body.constraints = RigidbodyConstraints.FreezeRotation;
speed = defaultSpeed;
accelSpeed = accelSpeedDefault;
body.velocity = Vector3.zero;
dead = false;
meshRend.enabled = true;
StartCoroutine(SafeRespawn());
//capColl.enabled = true;
pc.thrusterSystem.Play();
GetComponent<animator>().enabled = true;
}
void OnTriggerEnter(Collider other)
{
currentState.OnTriggerEnter(other);
}
void OnCollisionEnter(Collision other)
{
currentState.OnCollisionEnter(other);
}
void OnCollisionStay(Collision other)
{
currentState.OnCollisionStay(other);
}
public void PlayerDeath()
{
FindObjectOfType<inputmanager>().RemoveFromArray(playerID, this);
body.constraints = RigidbodyConstraints.FreezeAll;
FindObjectOfType<survival_gamemanager>().PlayerDead(playerID);
}
// Update is called once per frame
void Update()
{
camFollowPos = body.transform.position;
currentState.UpdateState();
}
IEnumerator SafeRespawn()
{
capColl.enabled = false;
yield return 0;
yield return new WaitForSeconds(1);
capColl.enabled = true;
}
void FixedUpdate()
{
currentState.FixedUpdateState();
}
public override void LeftStickRight()
{
currentState.LeftStickRight();
}
public override void LeftStickLeft()
{
currentState.LeftStickLeft();
}
public override void LeftStickUp()
{
currentState.LeftStickUp();
}
public override void LeftStickDown()
{
currentState.LeftStickDown();
}
public override void TriggerRight()
{
currentState.TriggerRight();
}
public override void TriggerLeft()
{
currentState.TriggerLeft();
}
public override void TriggerRightUp()
{
currentState.TriggerRightUp();
}
public override void TriggerLeftUp()
{
currentState.TriggerLeftUp();
}
public override void ButtonRight()
{
currentState.ButtonRight();
}
public override void ButtonRightRelease()
{
currentState.ButtonRightRelease();
}
public override void ButtonDown()
{
currentState.ButtonDown();
}
public override void ButtonDownRelease()
{
currentState.ButtonDownRelease();
}
}
PlayerState.cs
Interface for our player state machine
Show Code
using UnityEngine;
using System.Collections;
public interface PlayerState
{
void Initialize();
void UpdateState();
void FixedUpdateState();
void OnTriggerEnter(Collider other);
void OnCollisionEnter(Collision other);
void OnCollisionStay(Collision other);
void NextState(PlayerState next);
void LeftStickRight();
void LeftStickLeft();
void LeftStickUp();
void LeftStickDown();
void TriggerRight();
void TriggerLeft();
void TriggerRightUp();
void TriggerLeftUp();
void ButtonRight();
void ButtonRightRelease();
void ButtonDown();
void ButtonDownRelease();
}
RaceState.cs
State for the race mode, giving the player behavior that is specific to it
Show Code
using UnityEngine;
using System.Collections;
public class RaceState : PlayerState
{
private readonly Player player;
public Checkpoint nextCheckpoint;
public CheckpointManager CM;
public int Lap;
public int id;
public RaceState(Player thisPlayer)
{
player = thisPlayer;
id = player.playerID;
}
public void Initialize()
{
CM = ScriptableObject.FindObjectOfType<CheckpointManager>();
Lap = 0;
nextCheckpoint = CM.GetCheckPoint(0,this);
}
public float GetPos()
{
float p;
p = Lap * 20000;
p += nextCheckpoint.CheckpointNumber * 4000;
p += 1500 - (player.transform.position - nextCheckpoint.transform.position).magnitude;
return p;
}
public int GetRacePos(RaceState[] allRacers)
{
float distance = GetPos();
int position = 1;
foreach(RaceState racer in allRacers)
{
if(racer.GetPos() > distance)
{
position += 1;
}
}
return position;
}
public void UpdateState()
{
if (player.dead)
{
player.speed = player.minSpeed;
player.undead += 1.0f * Time.deltaTime;
if (player.undead > 4.0f)
{
player.undead = 0.0f;
//Debug.Log("Alive");
player.dead = false;
player.boostCooldownCounter = 0.0f;
player.boosting = false;
player.boostSpeed = 0.0f;
}
}
if (!player.accelerating)
{
player.accelSpeed = Mathf.Clamp(player.accelSpeed - player.decelDefault * Time.deltaTime, player.minSpeed, player.maxAccelSpeed);
}
if (player.boosting)
{
player.boostSpeed = Mathf.Clamp(player.boostSpeed + player.deltaBoost * Time.deltaTime, 0, player.maxBoostSpeed);
player.speed = player.accelSpeed + player.boostSpeed;
player.boostDurationCounter += Time.deltaTime * 1;
if (player.boostDurationCounter > player.boostDuration)
{
player.boosting = false;
player.boostSpeed = 0;
}
}
else
{
player.speed = player.accelSpeed;
}
player.boostCooldownCounter += Time.deltaTime * 1;
player.lastPos = player.body.transform.position;
}
public void FixedUpdateState()
{
player.body.velocity = Vector3.Lerp(player.body.velocity,player.body.transform.forward * player.speed,Time.deltaTime);
}
public void OnTriggerEnter(Collider other)
{
if(other.gameObject == nextCheckpoint.gameObject)
{
//Debug.Log("Player " + player.playerID + " Reached Checkpoint " + (nextCheckpoint.CheckpointNumber + 1) + ". Lap: " + (Lap + 1));
nextCheckpoint = CM.GetCheckPoint(nextCheckpoint.CheckpointNumber + 1,this);
}
if (other.gameObject.CompareTag("Line"))
{
if (player.dead == false)
{
player.undead = 0.0f;
//Debug.Log("Dead");
player.dead = true;
}
}
}
public void OnCollisionEnter(Collision other)
{
ContactPoint p = other.contacts[0];
if(other.gameObject.tag == "Wall")
{
player.body.transform.Rotate(Vector3.Cross(player.transform.forward,p.normal),-10,Space.World);
}
}
public void OnCollisionStay(Collision other)
{
}
public void NextState(PlayerState next)
{
player.currentState = next;
player.currentState.Initialize();
}
public void LeftStickRight()
{
player.body.transform.Rotate(Vector3.back * player.rotSpeedHorz * Time.deltaTime + Vector3.up * player.rotSpeedTurn * Time.deltaTime);
player.myCamera.GetComponent<cameraFollow>().SwingCamera(player.body.transform.right);
}
public void LeftStickLeft()
{
player.body.transform.Rotate(Vector3.forward * player.rotSpeedHorz * Time.deltaTime - Vector3.up * player.rotSpeedTurn * Time.deltaTime);
player.myCamera.GetComponent<cameraFollow>().SwingCamera(-player.body.transform.right);
}
public void LeftStickUp()
{
player.body.transform.Rotate(Vector3.left * player.rotSpeedVert * Time.deltaTime);
player.myCamera.GetComponent<cameraFollow>().SwingCamera(player.body.transform.up);
}
public void LeftStickDown()
{
player.body.transform.Rotate(Vector3.right * player.rotSpeedVert * Time.deltaTime);
player.myCamera.GetComponent<cameraFollow>().SwingCamera(-player.body.transform.up);
}
public void TriggerRight()
{
Debug.Log("RIGHT TRIGGER");
player.accelSpeed = Mathf.Clamp(player.accelSpeed + player.acceleration * Time.deltaTime, player.minSpeed, player.maxAccelSpeed);
player.acceleration += player.accelDelta*Time.deltaTime;
if(player.acceleration > player.maxAccel)
{
player.acceleration = player.maxAccel;
}
player.accelerating = true;
}
public void TriggerLeft()
{
//Debug.Log("LEFT TRIGGER");
player.accelSpeed += -player.deceleration * Time.deltaTime;
player.deceleration += player.decelDelta * Time.deltaTime;
if (player.deceleration > player.maxDecel)
{
player.deceleration = player.maxDecel;
}
}
public void TriggerRightUp()
{
player.acceleration = player.accelDefault;
player.accelerating = false;
}
public void TriggerLeftUp()
{
player.deceleration = player.decelDefault;
}
public void ButtonRight()
{
if (player.boostCooldownCounter > player.boostCooldown)
{
player.boosting = true;
player.boostDurationCounter = 0.0f;
player.boostCooldownCounter = 0.0f;
}
}
public void ButtonRightRelease()
{
}
public void ButtonDown()
{
}
public void ButtonDownRelease()
{
}
}
DDRMat.cs
Script used to collect inputs for a ddr mat and send them to the Input Manager
Show Code
using UnityEngine;
using System.Collections;
public class DDRMat : MonoBehaviour {
public InputManager inputManager;
public string VerticalAxis;
public string HorizontalAxis;
public KeyCode topLeft;
public KeyCode topRight;
public KeyCode bottomLeft;
public KeyCode bottomRight;
public KeyCode start;
public KeyCode select;
// Use this for initialization
void Start () {
GameScore.JoinScoreList(this);
}
// Update is called once per frame
void Update () {
if(Input.GetAxisRaw(VerticalAxis) > 0)
{
//Up Press
inputManager.KeyPress(DDRKey.DDRUp,this);
}
else if (Input.GetAxisRaw(VerticalAxis) < 0)
{
//Down Press
inputManager.KeyPress(DDRKey.DDRDown, this);
}
if (Input.GetAxisRaw(HorizontalAxis) > 0)
{
//Right Press
inputManager.KeyPress(DDRKey.DDRRight, this);
}
else if (Input.GetAxisRaw(HorizontalAxis) < 0)
{
//Left Press
inputManager.KeyPress(DDRKey.DDRLeft, this);
}
if(Input.GetKey(topLeft))
{
//Top Left Press
inputManager.KeyPress(DDRKey.DDRTopLeft, this);
}
if(Input.GetKeyDown(topLeft))
{
inputManager.KeyPress(DDRKey.DDRTopLeft_Down,this);
}
if (Input.GetKey(topRight))
{
//Top Right Press
inputManager.KeyPress(DDRKey.DDRTopRight, this);
}
if(Input.GetKeyDown(topRight))
{
inputManager.KeyPress(DDRKey.DDRTopRight_Down, this);
}
if (Input.GetKey(bottomLeft))
{
//Bottom Left Press
inputManager.KeyPress(DDRKey.DDRBottomLeft, this);
}
if (Input.GetKeyDown(bottomLeft))
{
inputManager.KeyPress(DDRKey.DDRBottomLeft_Down, this);
}
if (Input.GetKey(bottomRight))
{
//Bottom Right Press
inputManager.KeyPress(DDRKey.DDRBottomRight, this);
}
if(Input.GetKeyDown(bottomRight))
{
inputManager.KeyPress(DDRKey.DDRBottomRight_Down, this);
}
if (Input.GetKey(start))
{
//Start Press
inputManager.KeyPress(DDRKey.DDRStart, this);
}
if (Input.GetKey(select))
{
//Select Press
inputManager.KeyPress(DDRKey.DDRSelect, this);
}
}
}
Inputable.cs
Script for each gameobject requiring input to inherit from, adding functions for each keypress
Show Code
using UnityEngine;
using System.Collections;
public class Inputable : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public virtual void DDRRight()
{
}
public virtual void DDRLeft()
{
}
public virtual void DDRDown()
{
}
public virtual void DDRUp()
{
}
public virtual void DDRTopLeft()
{
}
public virtual void DDRTopLeft_Down()
{
}
public virtual void DDRTopRight()
{
}
public virtual void DDRTopRight_Down()
{
}
public virtual void DDRBottomLeft()
{
}
public virtual void DDRBottomLeft_Down()
{
}
public virtual void DDRBottomRight()
{
}
public virtual void DDRBottomRight_Down()
{
}
public virtual void DDRStart()
{
}
public virtual void DDRSelect()
{
}
}
InputManager.cs
Manager to tell each inputable linked to a player when there is relevant input
Show Code
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public enum DDRKey
{
DDRUp,
DDRDown,
DDRLeft,
DDRRight,
DDRTopRight,
DDRTopRight_Down,
DDRTopLeft,
DDRTopLeft_Down,
DDRBottomRight,
DDRBottomRight_Down,
DDRBottomLeft,
DDRBottomLeft_Down,
DDRSelect,
DDRStart,
}
public class InputManager : MonoBehaviour {
public DDRMat Player1;
public DDRMat Player2;
public DDRMat Player3;
public DDRMat Player4;
public List<Inputable> Player1Objects;
public List<Inputable> Player2Objects;
public List<Inputable> Player3Objects;
public List<Inputable> Player4Objects;
// Use this for initialization
void Start () {
}
void Awake()
{
DontDestroyOnLoad(this.gameObject);
}
// Update is called once per frame
void Update () {
}
public void KeyPress(DDRKey pressedKey, DDRMat sender)
{
if (sender == Player1)
{
for(int i = 0;i<Player1Objects.Count;i++)
{
Player1Objects[i].Invoke(pressedKey.ToString(), 0);
}
}
else if (sender == Player2)
{
for (int i = 0; i < Player2Objects.Count; i++)
{
Player2Objects[i].Invoke(pressedKey.ToString(), 0);
}
}
else if (sender == Player3)
{
for (int i = 0; i < Player3Objects.Count; i++)
{
Player3Objects[i].Invoke(pressedKey.ToString(), 0);
}
}
else if (sender == Player4)
{
for (int i = 0; i < Player4Objects.Count; i++)
{
Player4Objects[i].Invoke(pressedKey.ToString(), 0);
}
}
}
public void AddToArray(int playerID,Inputable objectScript)
{
if(playerID == 1)
{
Player1Objects.Add(objectScript);
Debug.Log("player 1 added");
}
else if(playerID == 2)
{
Player2Objects.Add(objectScript);
Debug.Log("player 2 added");
}
else if (playerID == 3)
{
Player3Objects.Add(objectScript);
Debug.Log("player 3 added");
}
else if (playerID == 4)
{
Player4Objects.Add(objectScript);
Debug.Log("player 4 added");
}
}
public void RemoveFromArray(int playerID, Inputable objectScript)
{
if (playerID == 1)
{
Player1Objects.Remove(objectScript);
}
else if (playerID == 2)
{
Player2Objects.Remove(objectScript);
}
else if (playerID == 3)
{
Player3Objects.Remove(objectScript);
}
else if (playerID == 4)
{
Player4Objects.Remove(objectScript);
}
}
public void ClearAllArrays(int playerID)
{
if(playerID == 1)
{
Player1Objects.Clear();
}
else if(playerID == 2)
{
Player2Objects.Clear();
}
else if(playerID == 3)
{
Player3Objects.Clear();
}
else if(playerID == 4)
{
Player4Objects.Clear();
}
}
}
DefaultScene.h
Sample user code for a scene's header
Show Code
#ifndef _DefaultScene
#define _DefaultScene
#include "Scene.h"
//Game Objects
class Box;
class Sphere;
class WireframeFrigate;
class Frigate;
class Cottage;
class SpriteTest;
class GodCam;
class TerrainTest;
class DefaultScene : public Scene
{
private:
//override our scene's functions
virtual void Initialize() override;
virtual void SceneEnd() override;
SpriteTest* TestingSprite;
Frigate* gObjFrig;
Cottage* gObjCottage;
Box* gObjBox;
Sphere* gObjSphere;
WireframeFrigate* gObjWireframeFrigate;
GodCam* myGodCam;
TerrainTest* myTerrain;
public:
DefaultScene(){};
virtual ~DefaultScene(){};
DefaultScene(const DefaultScene&) = delete;
DefaultScene& operator=(const DefaultScene&) = delete;
};
#endif _DefaultScene
DefaultScene.cpp
Sample user code for a scene's cpp
Show Code
#include "DefaultScene.h"
#include "CameraManager.h"
//objects
#include "Cottage.h"
#include "Box.h"
#include "Sphere.h"
#include "WireframeFrigate.h"
#include "Frigate.h"
#include "SpriteTest.h"
#include "GodCam.h"
#include "TextureManager.h"
void DefaultScene::Initialize()
{
gObjFrig = new Frigate(AB);
gObjBox = new Box();
gObjSphere = new Sphere();
gObjWireframeFrigate = new WireframeFrigate();
TestingSprite = new SpriteTest();
SetCollisionSelf<Cottage>();
SetCollisionPair<Cottage, Frigate>();
SetTerrain("Terrain");
//DEBUG
myGodCam = new GodCam();
}
void DefaultScene::SceneEnd()
{
delete gObjFrig;
delete gObjBox;
delete gObjSphere;
delete gObjWireframeFrigate;
delete this;
}
Frigate.h
Sample user code for a simple Game Object's header
Show Code
#ifndef _Frigate
#define _Frigate
#include "Drawable.h"
#include "Updatable.h"
#include "Alarmable.h"
#include "Inputable.h"
#include "HouseFactory.h"
#include "Collidable.h"
#include "fmod.hpp"
class Cottage;
class TerrainTest;
class Frigate : public Drawable, public Updatable, public Alarmable, public Inputable, public Collidable
{
private:
GraphicsObject_TextureFlat* pGObj;
Matrix world;
Matrix Rot;
Matrix Scale;
Matrix Trans;
//TerrainTest *myTerrain;
Vect pos;
Vect Max;
Vect Min;
float angle = 0.0f;
float speed = .35f;
HouseFactory *hf;
bool bDebugCol;
bool spherescolliding;
float velocityx = 0.0f;
float velocityy = 0.0f;
Vect collColor = Vect(1.0f, 0.0f, 0.0f);
Vect noCollColor = Vect(0.0f, 0.0f, 1.0f);
Vect bSphereColor = Vect(.8f, .5f, .7f);
public:
Frigate(CollisionType type);
virtual ~Frigate();
virtual void Draw();
virtual void Update();
virtual void Deregistration();
virtual void Collision(Cottage*);
virtual void BSphereCollision(Cottage*);
virtual void KeyPressed(AZUL_KEY k, bool ctrl, bool shift, bool alt);
virtual void KeyReleased(AZUL_KEY k, bool ctrl, bool shift, bool alt);
};
#endif _Frigate
Frigate.cpp
Sample user code for a simple Game Object's cpp
Show Code
#include "Frigate.h"
#define _USE_MATH_DEFINES
#include "TextureManager.h"
#include "ModelManager.h"
#include "ShaderManager.h"
#include "CameraManager.h"
#include "SceneManager.h"
#include "DefaultScene2.h"
#include <math.h>
Frigate::Frigate(CollisionType type)
{
pGObj = new GraphicsObject_TextureFlat(ModelManager::publicGetModel("space_frigate.azul"), ShaderManager::publicGetShaderObject("textureFlatRender"), TextureManager::publicGetTexture("space_frigate.tga"));
world = Scale * Rot * Trans;
pGObj->SetWorld(world);
DrawRegistration();
UpdateRegistration();
KeyRegister(KEY_Z);
KeyRegister(KEY_H);
KeyRegister(KEY_L);
KeyRegister(KEY_P);
CollisionRegistration<Frigate>(this);
//TERRAIN
//myTerrain = new TerrainTest("Textures/HeightMap.tga", 160, 160, 0, "TerrainTexture.tga", 1000, 1000);
//myTerrain;
Scale.set(SCALE, .5f,.5f,.5f);
//Scale.set(SCALE, 1.0f,1.0f,1.0f);
Trans.set(TRANS, 0,0,0);
angle = 0;
velocityx = 0;
velocityy = 0;
SetColliderModel(pGObj->getModel());
SetCollisionVolume(type);
UpdateCollisionData(pGObj->getWorld());
bDebugCol = false;
spherescolliding = false;
}
void Frigate::Update()
{
if (Keyboard::GetKeyState(KEY_A) == true)
{
angle += -.07f;
if (angle <= 0)
{
angle = 360;
}
}
else if (Keyboard::GetKeyState(KEY_D) == true)
{
angle += .07f;
if (angle >= 360)
{
angle = 0;
}
}
if (Keyboard::GetKeyState(KEY_W) == true)
{
velocityx += cos(angle) * speed;
velocityy += sin(angle) * speed;
}
else if (Keyboard::GetKeyState(KEY_S) == true)
{
velocityx += cos(angle) * -speed;
velocityy += sin(angle) * -speed;
}
Trans.set(TRANS, velocityy, 0, velocityx);
Rot = Matrix(ROT_Y, angle) * Matrix(ROT_X, 0) * Trans;
world = Scale * Rot * Trans;
//Draw TerrainCell Under Position
Max = this->GetBoundingSphere()->GetCenter();
Min = this->GetBoundingSphere()->GetCenter();
float radius = this->GetBoundingSphere()->GetRadius();
Max.X() += radius;
Max.Y() += radius;
Max.Z() += radius;
Min.X() += -radius;
Min.Y() += -radius;
Min.Z() += -radius;
pos = this->GetBoundingSphere()->GetCenter();
pGObj->SetWorld(world);
this->UpdateCollisionData(world);
}
void Frigate::KeyPressed(AZUL_KEY k, bool ctrl, bool shift, bool alt)
{
k; ctrl; shift; alt;
/* KEY TESTING*/
if (k == KEY_Z)
{
DebugMsg::out("Z Pressed\n");
KeyRegister(KEY_Z);
}
else if (k == KEY_L)
{
DebugMsg::out("Z & L Deregistered\n");
KeyDeregister(KEY_Z);
KeyDeregister(KEY_L);
}
else if (k == KEY_H)
{
HouseFactory::CallCreate();
}
else if (k == KEY_P)
{
SceneManager::publicSetScene(new DefaultScene2());
}
}
void Frigate::KeyReleased(AZUL_KEY k, bool ctrl, bool shift, bool alt)
{
ctrl; shift; alt;
if (k == KEY_L)
{
DebugMsg::out("L Released\n");
}
}
void Frigate::Draw()
{
pGObj->Render(SceneManager::publicGetScene()->GetCamera());
if (bDebugCol)
{
Visualizer::ShowCollisionVolume(this->GetCollisionVolume(), collColor);
}
else if (spherescolliding)
{
Visualizer::ShowCollisionVolume(this->GetCollisionVolume(), noCollColor);
}
else
{
Visualizer::ShowCollisionVolume(this->GetBoundingSphere(), bSphereColor);
}
spherescolliding = false;
bDebugCol = false;
DrawMyCells(pos, Max, Min);
}
void Frigate::Collision(Cottage*)
{
DebugMsg::out("Frigate vs Cottage\n");
bDebugCol = true;
}
void Frigate::BSphereCollision(Cottage*)
{
spherescolliding = true;
}
void Frigate::Deregistration()
{
DrawDeregister();
UpdateDeregister();
KeyDeregister(KEY_Z);
KeyDeregister(KEY_L);
KeyDeregister(KEY_H);
KeyDeregister(KEY_P);
CollisionDeregistration<Frigate>(this);
}
Frigate::~Frigate()
{
Deregistration();
}
Form to request code or Unity projects
please include specific projects you'd like me to send and a little bit about who you are.