From 59860415a2782694f630f7803ae4bcf445b3f5f1 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 21 Feb 2015 15:22:21 -0500 Subject: Player can short jump --- maps/embarass.txt | 28 ++++++++++++++-------------- res/tiles2.bmp | Bin 4664 -> 4664 bytes shaders/final.fragment | 16 +--------------- shaders/final.vertex | 8 ++------ src/map.h | 1 + src/mapview.cpp | 26 +++++++++++++++++++++----- src/mapview.h | 1 + 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/maps/embarass.txt b/maps/embarass.txt index 6cf029e..8ef69d3 100644 --- a/maps/embarass.txt +++ b/maps/embarass.txt @@ -1,25 +1,25 @@ --1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,9,8,10,8,11,8,10,10,8,11,8,9,10,12,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,8,8,8,0,0,0,0,0,0,0,0,0,0,0,0,0,8,12, --1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,8,8,8,8,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12, -0,0,-1,-1,-1,0,0,0,0,0,0,0,0,14,8,8,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12, -0,0,-1,-1,-1,0,0,0,0,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,13, -0,0,-1,-1,0,0,0,0,0,0,0,14,8,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0, -0,0,0,0,-1,0,14,8,8,8,8,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0, -0,0,14,8,8,8,8,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0, -8,8,8,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,1,4,2,1,3,3,1,4,2,2,1,1,1,3,1,2,4,1,3,2,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,4,3,1,2,1,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19,0,2,1,3,2,1,0,0,0,0,0,0, +1,2,3,1,4,0,0,0,0,0,20,0,0,0,0,0,0,19,0,0,0,0,0,0,20,0,0,0,0,0,0,0,0,1,1,2,2,4,3,1, +0,0,0,0,0,0,19,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20,0,0,0,0,0,0,0,0,0,0, Everything Is Embarrassing \ No newline at end of file diff --git a/res/tiles2.bmp b/res/tiles2.bmp index 851f892..1166976 100644 Binary files a/res/tiles2.bmp and b/res/tiles2.bmp differ diff --git a/shaders/final.fragment b/shaders/final.fragment index 4a51ad3..f9d8995 100644 --- a/shaders/final.fragment +++ b/shaders/final.fragment @@ -4,7 +4,6 @@ in vec2 UV; in vec3 normIn; in vec3 camDirIn; in vec3 lightDirIn; -//in vec3 vertPos; out vec3 color; @@ -53,7 +52,6 @@ void main() vec3 norm = normalize(normIn); vec3 camDir = normalize(camDirIn); vec3 lightDir = normalize(lightDirIn); - //vec3 refl = reflect(camDir, normIn); float diffuse = clamp(dot(norm, lightDir), 0.0f, 1.0f); vec4 colordiff = vec4(0.175, 0.15, 0.2, 1) * diffuse * Tuning_Diff_Brightness; @@ -65,19 +63,7 @@ void main() float fres = 1.0f - dot(camDir, norm); fres = (fres*fres) * Tuning_Fres_Brightness; - vec4 colorfres = vec4(0.45, 0.4, 0.5, 1) * fres;/* - - float lambertian = max(dot(camDirNorm,norm),0.0); - vec4 colorspec = vec4(0.0); - vec4 colorfres = vec4(0.0); - vec4 colordiff = vec4(0.175,0.15,0.2,1) * lambertian * Tuning_Diff_Brightness; - if (lambertian > 0.0) - { - vec3 viewDir = normalize(-vertPos); - vec3 halfDir = normalize(camDirNorm + viewDir); - float specAngle = max(dot(halfDir, normnorm), 0.0); - colorspec = vec4(0.25,0.25,0.25,1) * pow(specAngle, Tuning_Spec_Power) * Tuning_Spec_Brightness; - }*/ + vec4 colorfres = vec4(0.45, 0.4, 0.5, 1) * fres; vec4 emissive = sampleCRT(UV); diff --git a/shaders/final.vertex b/shaders/final.vertex index 4c5b1d5..ed6079f 100644 --- a/shaders/final.vertex +++ b/shaders/final.vertex @@ -8,12 +8,11 @@ out vec2 UV; out vec3 normIn; out vec3 camDirIn; out vec3 lightDirIn; -//out vec3 vertPos; uniform mat4 MVP; uniform mat4 worldMat; -const vec3 Tuning_LightPos = vec3(1, 1, -1.0); +const vec3 Tuning_LightPos = vec3(2, 1, -1); void main() { @@ -22,11 +21,8 @@ void main() normIn = vertexNormal; mat3 invWorldRot = transpose(mat3(worldMat[0].xyz, worldMat[1].xyz, worldMat[2].xyz)); - //mat3 invWorldRot = mat3(1.0f); vec3 worldPos = (worldMat * vec4(vertexPosition_modelspace,1)).xyz; + camDirIn = invWorldRot * (vec3(2,0,0) - worldPos); - //camDir = worldPos; lightDirIn = invWorldRot * (Tuning_LightPos - worldPos); - //vec4 vertPos4 = vec4(vertexPosition_modelspace,1); - //vertPos = vec3(vertPos4) / vertPos4.w; } diff --git a/src/map.h b/src/map.h index 2acce59..d7b4ecf 100644 --- a/src/map.h +++ b/src/map.h @@ -3,6 +3,7 @@ class Map { public: + Map(); Map(char* filename); ~Map(); const int* mapdata(); diff --git a/src/mapview.cpp b/src/mapview.cpp index 78dd770..76d7f02 100644 --- a/src/mapview.cpp +++ b/src/mapview.cpp @@ -1,10 +1,16 @@ #include "mapview.h" +#define JUMP_VELOCITY(h, l) (-2 * (h) / (l)) +#define JUMP_GRAVITY(h, l) (2 * ((h) / (l)) / (l)) + // Initialize jump physics -double jump_height = TILE_HEIGHT*3; +double jump_height = TILE_HEIGHT*4; double jump_length = 0.25 * FRAMES_PER_SECOND; -double jump_velocity = -2 * jump_height / jump_length; -double jump_gravity = -1 * jump_velocity / jump_length; +//double jump_velocity = -2 * jump_height / jump_length; +//double jump_gravity = -1 * jump_velocity / jump_length; +double jump_velocity = JUMP_VELOCITY(TILE_HEIGHT*4, 0.30*FRAMES_PER_SECOND); +double jump_gravity = JUMP_GRAVITY(TILE_HEIGHT*4, 0.30*FRAMES_PER_SECOND); +double jump_gravity_short = JUMP_GRAVITY(TILE_HEIGHT*3, 0.20*FRAMES_PER_SECOND); MapView::MapView(Map* first, int x, int y) { @@ -14,8 +20,8 @@ MapView::MapView(Map* first, int x, int y) player->y = y; player->x_vel = 0; player->y_vel = 0; + player->y_accel = jump_gravity_short; player->x_accel = 0; - player->y_accel = jump_gravity; player->w = 10; player->h = 12; player->onGround = false; @@ -123,6 +129,7 @@ void MapView::input(int key, int action) { player->y_vel = jump_velocity; player->onGround = false; + holding_up = true; } break; case GLFW_KEY_DOWN: @@ -144,6 +151,9 @@ void MapView::input(int key, int action) case GLFW_KEY_DOWN: holding_down = false; break; + case GLFW_KEY_UP: + holding_up = false; + break; } } } @@ -165,7 +175,13 @@ void MapView::tick() if (player->x_vel > 16) player->x_vel = 16; int playerx_next = player->x + player->x_vel; - player->y_vel += player->y_accel; + if (holding_up) + { + player->y_vel += jump_gravity; + } else { + player->y_vel += jump_gravity_short; + } + if (player->y_vel > 16) player->y_vel = 16; // Terminal velocity if (player->y_vel < -16) player->y_vel = -16; int playery_next = player->y + player->y_vel; diff --git a/src/mapview.h b/src/mapview.h index 06309e3..505ab25 100644 --- a/src/mapview.h +++ b/src/mapview.h @@ -54,6 +54,7 @@ class MapView : public State { bool holding_left = false; bool holding_right = false; bool holding_down = false; + bool holding_up = false; mob_t* player; Map* curMap; -- cgit 1.4.1