Skip to content

Commit

Permalink
Added crates, blast attack and light that follows the player
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubbad committed Apr 30, 2017
1 parent ceb3c09 commit a3ecfea
Show file tree
Hide file tree
Showing 14 changed files with 223 additions and 126 deletions.
Binary file added assets/meshes/SmallCrate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions assets/meshes/obstacle.mtl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Blender MTL File: 'None'
# Material Count: 1

newmtl Material
Ns 96.078431
newmtl Material.001
Ns 94.117647
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
map_Kd floor.png
map_Kd SmallCrate.png
28 changes: 14 additions & 14 deletions assets/meshes/obstacle.obj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Blender v2.76 (sub 0) OBJ File: ''
# www.blender.org
mtllib obstacle.mtl
o Cube
o Cube.001
v 1.000000 0.000000 -1.000000
v 1.000000 0.000000 1.000000
v -1.000000 0.000000 1.000000
v 1.000000 -0.000000 1.000000
v -1.000000 -0.000000 1.000000
v -1.000000 0.000000 -1.000000
v 1.000000 2.000000 -0.999999
v 0.999999 2.000000 1.000001
v -1.000000 2.000000 1.000000
v -1.000000 2.000000 -1.000000
v -1.000000 2.000000 1.000000
v 0.999999 2.000000 1.000001
vt -0.988327 0.996109
vt 0.003891 0.996109
vt 0.003891 1.988327
Expand All @@ -23,17 +23,17 @@ vt -0.988327 0.003891
vt -0.988327 -0.988326
vt 1.988327 0.003891
vt 1.988327 -0.988327
vn 0.000000 -1.000000 0.000000
vn 0.000000 -1.000000 -0.000000
vn 0.000000 1.000000 0.000000
vn 1.000000 0.000000 0.000000
vn -0.000000 -0.000000 1.000000
vn -1.000000 -0.000000 -0.000000
vn -1.000000 -0.000000 0.000000
vn 0.000000 0.000000 -1.000000
usemtl Material
s off
usemtl Material.001
s 1
f 1/1/1 2/2/1 3/3/1 4/4/1
f 5/5/2 8/6/2 7/2/2 6/7/2
f 1/5/3 5/7/3 6/8/3 2/9/3
f 2/10/4 6/11/4 7/8/4 3/7/4
f 3/12/5 7/5/5 8/9/5 4/13/5
f 5/10/6 1/7/6 4/2/6 8/1/6
f 5/5/2 6/6/2 7/2/2 8/7/2
f 1/5/3 5/7/3 8/8/3 2/9/3
f 2/10/4 8/11/4 7/8/4 3/7/4
f 3/12/5 7/5/5 6/9/5 4/13/5
f 5/10/6 1/7/6 4/2/6 6/1/6
2 changes: 1 addition & 1 deletion bubba-3d
8 changes: 5 additions & 3 deletions src/components/PlayerController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
#include <linmath/SmallVector2.h>
#include <Globals.h>
#include <ResourceManager.h>
#include <Lights.h>
#include "PlayerController.h"
#include "Camera.h"


PlayerController::PlayerController(std::function<void(GameObject*, std::shared_ptr<Texture>)> spawnBulletFunc, Camera *camera) :
spawnBulletFunc(spawnBulletFunc), camera(camera){
PlayerController::PlayerController(std::function<void(GameObject*, std::shared_ptr<Texture>)> spawnBulletFunc, std::function<void(GameObject*, std::shared_ptr<Texture>)> spawnBlastBulletFunc, Camera *camera, std::shared_ptr<PointLight> light) :
spawnBulletFunc(spawnBulletFunc), spawnBlastBulletFunc(spawnBlastBulletFunc), camera(camera), light(light){

}

Expand Down Expand Up @@ -90,7 +91,7 @@ void PlayerController::update(float dt) {
if (shootButton.isActive()) {
for (int i = 0; i < 8; ++i) {
owner->setRotation(owner->getAbsoluteRotation() * chag::make_quaternion_axis_angle(chag::make_vector(0.0f, 1.0f, 0.0f), degreeToRad(45.0f * i)));
spawnBulletFunc(owner, ResourceManager::loadAndFetchTexture("../assets/meshes/blast.png"));
spawnBlastBulletFunc(owner, ResourceManager::loadAndFetchTexture("../assets/meshes/blast.png"));
}
timeSinceLastShotAttackRMB = 0.0f;
}
Expand All @@ -107,6 +108,7 @@ void PlayerController::update(float dt) {
}

owner->setRotation(chag::make_quaternion_axis_angle(chag::make_vector(0.0f, 1.0f, 0.0f), angle));
light->position = owner->getAbsoluteLocation() + chag::make_vector(0.0f, 2.0f, 0.0f);
}

void PlayerController::beforeCollision(std::shared_ptr<GameObject> collider) {
Expand Down
4 changes: 3 additions & 1 deletion src/components/PlayerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class PlayerController : public IComponent {

public:
PlayerController(std::function<void(GameObject*, std::shared_ptr<Texture>)> spawnBulletFunc, Camera *camera);
PlayerController(std::function<void(GameObject*, std::shared_ptr<Texture>)> spawnBulletFunc, std::function<void(GameObject*, std::shared_ptr<Texture>)> spawnBlastBulletFunc, Camera *camera, std::shared_ptr<PointLight> light);
chag::float3 getPlaneIntersectionPoint();

virtual void update(float dt) override;
Expand All @@ -23,10 +23,12 @@ class PlayerController : public IComponent {

private:
std::function<void(GameObject*, std::shared_ptr<Texture>)> spawnBulletFunc;
std::function<void(GameObject*, std::shared_ptr<Texture>)> spawnBlastBulletFunc;
Camera *camera;
float timeSinceLastShotAttackLMB = 1.0f;
float timeSinceLastShotAttackRMB = 1.0f;
chag::float3 locationAtLastUpdate;
std::shared_ptr<PointLight> light;

chag::float3 getMouseRayInWorldSpace(float mouseX, float mouseY, int width, int height) const;
};
Expand Down
Loading

0 comments on commit a3ecfea

Please sign in to comment.