Fixing up how rotation works with combat and then making the lighting better.
This commit is contained in:
parent
4eaf3c35d6
commit
90c37fe4c9
6 changed files with 35 additions and 11 deletions
|
@ -38,7 +38,7 @@
|
||||||
"foreground": [24, 205, 210],
|
"foreground": [24, 205, 210],
|
||||||
"background": [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": "Sprite", "name": "torch_pillar", "width": 256, "height": 256, "scale": 1.0},
|
||||||
{"_type": "Sound", "attack": "pickup", "death": "blank"}
|
{"_type": "Sound", "attack": "pickup", "death": "blank"}
|
||||||
]
|
]
|
||||||
|
|
|
@ -17,7 +17,7 @@ struct CameraLOL {
|
||||||
rayview(rv) {}
|
rayview(rv) {}
|
||||||
|
|
||||||
Point plan_move(int dir, bool strafe);
|
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_rotate();
|
||||||
bool play_move();
|
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_W = 17;
|
||||||
constexpr int INITIAL_MAP_H = 15;
|
constexpr int INITIAL_MAP_H = 15;
|
||||||
|
|
||||||
|
constexpr float DEFAULT_ROTATE=0.25f;
|
||||||
|
|
||||||
// for the panels/renderer
|
// for the panels/renderer
|
||||||
constexpr wchar_t BG_TILE = L'█';
|
constexpr wchar_t BG_TILE = L'█';
|
||||||
constexpr wchar_t UI_BASE_CHAR = L'█';
|
constexpr wchar_t UI_BASE_CHAR = L'█';
|
||||||
|
|
10
gui/fsm.cpp
10
gui/fsm.cpp
|
@ -152,11 +152,11 @@ namespace gui {
|
||||||
try_move(1, true);
|
try_move(1, true);
|
||||||
break;
|
break;
|
||||||
case ROTATE_LEFT:
|
case ROTATE_LEFT:
|
||||||
$main_ui.plan_rotate(-1, 0.5f);
|
$main_ui.plan_rotate(-1, 0.25f);
|
||||||
state(State::ROTATING);
|
state(State::ROTATING);
|
||||||
break;
|
break;
|
||||||
case ROTATE_RIGHT:
|
case ROTATE_RIGHT:
|
||||||
$main_ui.plan_rotate(1, 0.5f);
|
$main_ui.plan_rotate(1, 0.25f);
|
||||||
state(State::ROTATING);
|
state(State::ROTATING);
|
||||||
break;
|
break;
|
||||||
case MAP_OPEN:
|
case MAP_OPEN:
|
||||||
|
@ -212,11 +212,11 @@ namespace gui {
|
||||||
state(State::ATTACKING);
|
state(State::ATTACKING);
|
||||||
break;
|
break;
|
||||||
case ROTATE_LEFT:
|
case ROTATE_LEFT:
|
||||||
$main_ui.plan_rotate(-1);
|
$main_ui.plan_rotate(-1, DEFAULT_ROTATE);
|
||||||
state(State::COMBAT_ROTATE);
|
state(State::COMBAT_ROTATE);
|
||||||
break;
|
break;
|
||||||
case ROTATE_RIGHT:
|
case ROTATE_RIGHT:
|
||||||
$main_ui.plan_rotate(1);
|
$main_ui.plan_rotate(1, DEFAULT_ROTATE);
|
||||||
state(State::COMBAT_ROTATE);
|
state(State::COMBAT_ROTATE);
|
||||||
break;
|
break;
|
||||||
case STOP_COMBAT:
|
case STOP_COMBAT:
|
||||||
|
@ -356,7 +356,7 @@ namespace gui {
|
||||||
if($map_open) {
|
if($map_open) {
|
||||||
$map_ui.render($window, $main_ui.$compass_dir);
|
$map_ui.render($window, $main_ui.$compass_dir);
|
||||||
} else {
|
} 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 debug();
|
||||||
void render_debug();
|
void render_debug();
|
||||||
|
|
||||||
void plan_rotate(int dir, float amount=0.5f);
|
void plan_rotate(int dir, float amount);
|
||||||
bool play_rotate();
|
bool play_rotate();
|
||||||
std::optional<Point> play_move();
|
std::optional<Point> play_move();
|
||||||
Point plan_move(int dir, bool strafe);
|
Point plan_move(int dir, bool strafe);
|
||||||
|
|
|
@ -25,6 +25,27 @@ union ColorConv {
|
||||||
uint32_t as_int;
|
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) {
|
inline uint32_t old_lighting(uint32_t pixel, float dist, int level) {
|
||||||
(void)level;
|
(void)level;
|
||||||
ColorConv conv{.as_int=pixel};
|
ColorConv conv{.as_int=pixel};
|
||||||
|
@ -41,6 +62,7 @@ inline uint32_t old_lighting(uint32_t pixel, float dist, int level) {
|
||||||
* bits around.
|
* bits around.
|
||||||
*/
|
*/
|
||||||
inline uint32_t new_lighting(uint32_t pixel, float dist, int level) {
|
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
|
(void)dist; // ignore for now until I can do more research
|
||||||
float factor = float(level) * PERCENT;
|
float factor = float(level) * PERCENT;
|
||||||
ColorConv conv{.as_int=pixel};
|
ColorConv conv{.as_int=pixel};
|
||||||
|
@ -310,7 +332,7 @@ void Raycaster::cast_rays() {
|
||||||
tex_pos += step;
|
tex_pos += step;
|
||||||
RGBA pixel = texture[texture_height * tex_y + tex_x];
|
RGBA pixel = texture[texture_height * tex_y + tex_x];
|
||||||
int light_level = lights[map_y][map_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
|
// SET THE ZBUFFER FOR THE SPRITE CASTING
|
||||||
|
@ -378,11 +400,11 @@ void Raycaster::draw_ceiling_floor() {
|
||||||
|
|
||||||
// FLOOR
|
// FLOOR
|
||||||
color = $floor_texture[texture_width * ty + tx];
|
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
|
// CEILING
|
||||||
color = $ceiling_texture[texture_width * ty + tx];
|
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…
Add table
Add a link
Reference in a new issue