Fixing up how rotation works with combat and then making the lighting better.

master
Zed A. Shaw 1 week ago
parent 4eaf3c35d6
commit 90c37fe4c9
  1. 2
      assets/items.json
  2. 2
      camera.hpp
  3. 2
      constants.hpp
  4. 10
      gui/fsm.cpp
  5. 2
      gui/main_ui.hpp
  6. 28
      raycaster.cpp

@ -38,7 +38,7 @@
"foreground": [24, 205, 210],
"background": [24, 205, 210]
},
{"_type": "LightSource", "strength": 50, "radius": 2.8},
{"_type": "LightSource", "strength": 80, "radius": 2.8},
{"_type": "Sprite", "name": "torch_pillar", "width": 256, "height": 256, "scale": 1.0},
{"_type": "Sound", "attack": "pickup", "death": "blank"}
]

@ -17,7 +17,7 @@ struct CameraLOL {
rayview(rv) {}
Point plan_move(int dir, bool strafe);
void plan_rotate(int dir, float amount=0.5f);
void plan_rotate(int dir, float amount);
bool play_rotate();
bool play_move();

@ -63,6 +63,8 @@ constexpr int COMBAT_UI_HEIGHT = SCREEN_HEIGHT - RAY_VIEW_HEIGHT;
constexpr int INITIAL_MAP_W = 17;
constexpr int INITIAL_MAP_H = 15;
constexpr float DEFAULT_ROTATE=0.25f;
// for the panels/renderer
constexpr wchar_t BG_TILE = L'';
constexpr wchar_t UI_BASE_CHAR = L'';

@ -152,11 +152,11 @@ namespace gui {
try_move(1, true);
break;
case ROTATE_LEFT:
$main_ui.plan_rotate(-1, 0.5f);
$main_ui.plan_rotate(-1, 0.25f);
state(State::ROTATING);
break;
case ROTATE_RIGHT:
$main_ui.plan_rotate(1, 0.5f);
$main_ui.plan_rotate(1, 0.25f);
state(State::ROTATING);
break;
case MAP_OPEN:
@ -212,11 +212,11 @@ namespace gui {
state(State::ATTACKING);
break;
case ROTATE_LEFT:
$main_ui.plan_rotate(-1);
$main_ui.plan_rotate(-1, DEFAULT_ROTATE);
state(State::COMBAT_ROTATE);
break;
case ROTATE_RIGHT:
$main_ui.plan_rotate(1);
$main_ui.plan_rotate(1, DEFAULT_ROTATE);
state(State::COMBAT_ROTATE);
break;
case STOP_COMBAT:
@ -356,7 +356,7 @@ namespace gui {
if($map_open) {
$map_ui.render($window, $main_ui.$compass_dir);
} else {
$mini_map.render($window, $main_ui.$compass_dir);
// $mini_map.render($window, $main_ui.$compass_dir);
}
}
}

@ -29,7 +29,7 @@ namespace gui {
void debug();
void render_debug();
void plan_rotate(int dir, float amount=0.5f);
void plan_rotate(int dir, float amount);
bool play_rotate();
std::optional<Point> play_move();
Point plan_move(int dir, bool strafe);

@ -25,6 +25,27 @@ union ColorConv {
uint32_t as_int;
};
// from: https://permadi.com/1996/05/ray-casting-tutorial-19/
// Intensity = (kI/(d+do))*(N*L)
// rcr says: kI = intensity coefficient, d = distance, d0 = fudge term to prevent division by zero, N is surface, L is direction to light from surface
//
// That formula is just "Inverse-square law" (except they don't square, which is physically dubious), and "Lambertian reflectance" ("Diffuse reflection") which sounds fancy but is super standard. All the quoted terms have wikipedia articles
//
// Distance means distance to surface from light.
//
// Intensity = Object Intensity/Distance * Multiplier
//
inline uint32_t new_new_lighting(uint32_t pixel, float dist, int level) {
ColorConv conv{.as_int=pixel};
float intensity = (float(level) * PERCENT) / (dist+1) * 2.5;
conv.as_color.r *= intensity;
conv.as_color.g *= intensity;
conv.as_color.b *= intensity;
return conv.as_int;
}
inline uint32_t old_lighting(uint32_t pixel, float dist, int level) {
(void)level;
ColorConv conv{.as_int=pixel};
@ -41,6 +62,7 @@ inline uint32_t old_lighting(uint32_t pixel, float dist, int level) {
* bits around.
*/
inline uint32_t new_lighting(uint32_t pixel, float dist, int level) {
// Intensity = Object Intensity/Distance * Multiplier
(void)dist; // ignore for now until I can do more research
float factor = float(level) * PERCENT;
ColorConv conv{.as_int=pixel};
@ -310,7 +332,7 @@ void Raycaster::cast_rays() {
tex_pos += step;
RGBA pixel = texture[texture_height * tex_y + tex_x];
int light_level = lights[map_y][map_x];
$pixels[pixcoord(x, y)] = new_lighting(pixel, perp_wall_dist, light_level);
$pixels[pixcoord(x, y)] = new_new_lighting(pixel, perp_wall_dist, light_level);
}
// SET THE ZBUFFER FOR THE SPRITE CASTING
@ -378,11 +400,11 @@ void Raycaster::draw_ceiling_floor() {
// FLOOR
color = $floor_texture[texture_width * ty + tx];
$pixels[pixcoord(x, y)] = new_lighting(color, row_distance, light_level);
$pixels[pixcoord(x, y)] = new_new_lighting(color, row_distance, light_level);
// CEILING
color = $ceiling_texture[texture_width * ty + tx];
$pixels[pixcoord(x, $height - y - 1)] = new_lighting(color, row_distance, light_level);
$pixels[pixcoord(x, $height - y - 1)] = new_new_lighting(color, row_distance, light_level);
}
}
}

Loading…
Cancel
Save