Skip to content

Commit

Permalink
more plants, more betta movements
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarroqe committed May 12, 2020
1 parent 273e9ef commit 32b2acf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
Binary file not shown.
16 changes: 14 additions & 2 deletions 06-Students-Choice/SDLProject/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ void Entity::Update(float deltaTime, Entity *snail, Entity *player, Entity *obje
modelMatrix = glm::rotate(modelMatrix, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));

if (entityType == ENEMY) {
// something subtle here..
rotation.z -= 0.5 * deltaTime;
rotation.y -= 0.5 * deltaTime;

if (CheckCollision(snail)) {
std::cout << "snail collision w betta\n";
previouslyCollided = true;
}

// BETTA MOVEMENT BASED ON IF SNAIL IS NEAR A PLANT
for (int i = 0; i < objectCount - 1; i++) {
// if snail is not near plant, follow
Expand All @@ -80,8 +86,8 @@ void Entity::Update(float deltaTime, Entity *snail, Entity *player, Entity *obje
position.z -= 0.1 * deltaTime;
}
}
// if snail is near a plant, go the opposite way TODO: check this makes sense
else {
// if snail is near a plant, go the opposite way
else if (previouslyCollided) {
if (position.x < snail->position.x) {
position.x -= 1 * deltaTime;
}
Expand All @@ -96,6 +102,12 @@ void Entity::Update(float deltaTime, Entity *snail, Entity *player, Entity *obje
position.z += 1 * deltaTime;
}
}
// if you haven't collided before, live ur life, betta
else {
position.x += rand() % 20 - 10;
position.y -= 0.01;
position.z += rand() % 20 - 10;
}
}


Expand Down
2 changes: 2 additions & 0 deletions 06-Students-Choice/SDLProject/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Entity {
float height;
float depth;

bool previouslyCollided = false;

GLuint textureID;
Mesh *mesh;

Expand Down
8 changes: 4 additions & 4 deletions 06-Students-Choice/SDLProject/Level.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Level.h"

#define OBJECT_COUNT 11
#define OBJECT_COUNT 20
#define ENEMY_COUNT 1

Level::Level(int _lives) {
Expand Down Expand Up @@ -37,7 +37,7 @@ void Level::Initialize() {
Mesh *fernMesh = new Mesh();
fernMesh->LoadOBJ("fern.obj", 1);

int num_ferns = 3;
int num_ferns = (OBJECT_COUNT - 2) / 3;
for (int i = 0; i < num_ferns; i++) {
int num = 1 + i;
state.objects[num].textureID = fernTextureID;
Expand All @@ -53,7 +53,7 @@ void Level::Initialize() {
Mesh *grassMesh = new Mesh();
grassMesh->LoadOBJ("Low Grass.obj", 1);

int num_grass = 3;
int num_grass = (OBJECT_COUNT - 2) / 3;
for (int i = 0; i < num_grass; i++) {
int num = 1 + num_ferns + i;
state.objects[num].textureID = grassTextureID;
Expand All @@ -68,7 +68,7 @@ void Level::Initialize() {
Mesh *palmMesh = new Mesh();
palmMesh->LoadOBJ("Palm_01.obj", 1);

int num_palms = 3;
int num_palms = (OBJECT_COUNT - 2) / 3;
for (int i = 0; i < num_palms; i++) {
int num = 1 + num_ferns + num_grass + i;
state.objects[num].textureID = palmTextureID;
Expand Down
2 changes: 1 addition & 1 deletion 06-Students-Choice/SDLProject/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "Win.h"
#include "Lose.h"

#define OBJECT_COUNT 11
#define OBJECT_COUNT 20
#define ENEMY_COUNT 1

SDL_Window* displayWindow;
Expand Down

0 comments on commit 32b2acf

Please sign in to comment.