lizard: add new map; implement platformer mechanics

This commit is contained in:
Zack Buhman 2025-07-31 15:53:12 -05:00
parent a9bde33a07
commit efb03b9370
9 changed files with 1568 additions and 106 deletions

File diff suppressed because it is too large Load Diff

View File

@ -47,14 +47,15 @@ namespace demo {
mat4x4 lizard::init()
{
vx = 0;
vy = 0;
vx = -pi / 4;
vy = -pi / 4;
current_level = &demo::level1_level;
current_level = &demo::igh25_map1_level;
world::table_build(*current_level);
lizard_position = {7.5, 1, 7.5};
lizard_position = {2.5, 1, 2.5};
//lizard_position = {218.5, 0, 65.5};
lizard_velocity = {0, 0, 0};
return view_trans;
@ -70,40 +71,41 @@ namespace demo {
void lizard::update()
{
/*
if (!collided)
lizard_velocity.y -= 0.01;
*/
lizard_rotation *= 0.8;
lizard_turning_frame += lizard_rotation * 10;
lizard_heading += lizard_rotation;
if (abs(lizard_velocity.x) > 0.05)
lizard_velocity.x = 0.05 * sign(lizard_velocity.x);
if (abs(lizard_velocity.y) > 0.05)
lizard_velocity.y = 0.05 * sign(lizard_velocity.y);
if (abs(lizard_velocity.z) > 0.05)
lizard_velocity.z = 0.05 * sign(lizard_velocity.z);
if (abs(lizard_velocity.x) > 0.10)
lizard_velocity.x = 0.10 * sign(lizard_velocity.x);
if (abs(lizard_velocity.y) > 0.20)
lizard_velocity.y = 0.20 * sign(lizard_velocity.y);
if (abs(lizard_velocity.z) > 0.10)
lizard_velocity.z = 0.10 * sign(lizard_velocity.z);
lizard_velocity.x *= 0.8;
lizard_velocity.y *= 0.8;
lizard_velocity.y *= 0.99;
lizard_velocity.z *= 0.8;
lizard_walking_frame += magnitude(lizard_velocity) * 15;
world::platform * p = lizard_collide();
collided = (p != nullptr);
if (!collided) {
lizard_velocity.y -= 0.01;
} else {
last_platform = p;
//lizard_position.y -= -lizard_velocity.y;
float pp = p->position.y + p->scale.y * 0.5;
//lizard_velocity.y *= 0.1;
lizard_position.y = pp + 0.5;
}
lizard_position.x += lizard_velocity.x;
lizard_position.y += lizard_velocity.y;
lizard_position.z += lizard_velocity.z;
world::platform * p = lizard_collide();
collided = p != nullptr;
if (collided) {
lizard_position.y -= -lizard_velocity.y;
}
view_trans
= translate(vec3(0, 0, 3))
* rotate_x(vy)
@ -113,35 +115,72 @@ namespace demo {
void lizard::y()
{
lizard_velocity.y += 0.01;
//lizard_velocity.y += 0.01;
}
void lizard::a()
{
lizard_velocity.y -= 0.01;
//lizard_velocity.y -= 0.01;
if (collided) {
lizard_velocity.y = 30;
}
}
void lizard::start()
{
if (last_platform == nullptr)
init();
else {
lizard_velocity = {0, 0, 0};
lizard_position = last_platform->position;
lizard_position.y += 0.5;
}
}
void lizard::ra()
{
vx += 0.01f;
}
void lizard::la()
{
vx -= 0.01f;
}
void lizard::ua()
{
vy += 0.01f;
}
void lizard::da()
{
vy -= 0.01f;
}
void lizard::x()
{
lizard_rotation += pi * (1.0f / 160);
//lizard_rotation += pi * (1.0f / 160);
}
void lizard::b()
{
lizard_rotation -= pi * (1.0f / 160);
//lizard_rotation -= pi * (1.0f / 160);
}
void lizard::analog(float dl, float dr, float dx, float dy)
{
//float forward = (dr - dl) * -0.001f;
//alpha_mul += forward;
float forward = (dr - dl) * -0.04f;
float forward = (dr - dl) * -0.1f;
//vx += forward * 0.5f;
lizard_velocity.x += -cos(lizard_heading) * forward;
lizard_velocity.z += sin(lizard_heading) * forward;
vy += dy * 0.03f;
vx += dx * 0.03f;
lizard_rotation += -dx * 0.03f;
//vy += dy * 0.03f;
//vx += dx * 0.03f;
}
world::platform * lizard::lizard_collide()
@ -181,7 +220,12 @@ namespace demo {
font::ter_u12n.draw_string(writer, status_p, "air", 0xffffffff);
*/
font::ter_u12n.draw_float(writer, status_p, (float)last_drawn_frame, 0xffffffff, 10);
font::ter_u12n.draw_float(writer, status_p, (float)lizard_position.x, 0xffffffff, 10);
status_p.y += 12;
font::ter_u12n.draw_float(writer, status_p, (float)lizard_position.y, 0xffffffff, 10);
status_p.y += 12;
font::ter_u12n.draw_float(writer, status_p, (float)lizard_position.z, 0xffffffff, 10);
//font::ter_u12n.draw_float(writer, status_p, (float)last_drawn_frame, 0xffffffff, 10);
}
void lizard::draw_platform(ta_parameter_writer& writer, const mat4x4& trans, const world::platform& p)
@ -209,7 +253,7 @@ namespace demo {
t,
vec3(1, 0.5, 0));
*/
if (abs(lizard_rotation) > 0) {
if (abs(lizard_rotation) > 0.1) {
int frame = ((int)lizard_turning_frame) % lizard_turning_frames_count;
if (frame < 0)
frame = lizard_turning_frames_count + frame;
@ -236,7 +280,6 @@ namespace demo {
const mat4x4& trans = view_trans;
draw_hud(writer);
draw_lizard(writer, trans);
writer.append<ta_global_parameter::end_of_list>() =

View File

@ -7,6 +7,7 @@ namespace demo {
struct lizard : scene {
world::level * current_level;
world::platform * last_platform;
vec3 lizard_position;
vec3 lizard_velocity;
float lizard_heading;
@ -30,6 +31,13 @@ namespace demo {
void b() override;
void a() override;
void ra() override;
void la() override;
void ua() override;
void da() override;
void start() override;
void analog(float dl, float dr, float dx, float dy) override;
world::platform * lizard_collide();

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -16,7 +16,7 @@ namespace demo::world {
int platforms_length;
};
constexpr int lookup_table_dim = 128;
constexpr int lookup_table_dim = 256;
struct platform_lookup {
vec2i xz_offset;

View File

@ -16,6 +16,7 @@ namespace demo {
virtual void la() {}
virtual void da() {}
virtual void ua() {}
virtual void start() {}
virtual void update() = 0;
virtual void draw(ta_parameter_writer& writer, const mat4x4& trans) = 0;
};

View File

@ -193,7 +193,9 @@ namespace graphics {
bool da = ft0::data_transfer::digital_button::da(data.digital_button) == 0;
bool ua = ft0::data_transfer::digital_button::ua(data.digital_button) == 0;
if (a) current_scene->a();
bool start = ft0::data_transfer::digital_button::start(data.digital_button) == 0;
if (last[port_ix].a != a && a) current_scene->a();
if (b) current_scene->b();
if (x) current_scene->x();
if (y) current_scene->y();
@ -203,6 +205,8 @@ namespace graphics {
if (da) current_scene->da();
if (ua) current_scene->ua();
if (start) current_scene->start();
last[port_ix].a = a;
last[port_ix].b = b;
last[port_ix].x = x;

View File

@ -9,6 +9,10 @@
void vbr100()
{
if (sh7091.CCN.EXPEVT == 0xe0) {
serial::string("vbr100 expevt == 0xe0\n");
return;
}
serial::string("vbr100\n");
interrupt_exception();
}

View File

@ -51,6 +51,8 @@ def visit_pixels(x, y, width, height):
xx = x + xi
yy = y + yi
location = (xx, yy)
if location in visited:
print(location)
assert location not in visited
visited.add(location)