Fix gravity

it works now
This commit is contained in:
Edgaru089 2024-03-05 14:26:39 +08:00
parent 4f9ea0a09a
commit c5a230647e
4 changed files with 16 additions and 18 deletions

View File

@ -17,11 +17,17 @@ void app_DebugText(App *app, vector_Vector *vec_string) {
} else {
snprintf(
buf, sizeof(buf) - 1,
"Player:\n Pos: [%.4lf, %.4lf], Vec:[%.4lf, %.4lf]\n",
"Player:\n"
" Pos: [%.4lf, %.4lf]\n"
" Vec:[%.4lf, %.4lf]\n"
" OnGround: %s\n"
" JumpCount: %d\n",
player->super->position->position.x,
player->super->position->position.y,
player->super->position->velocity.x,
player->super->position->velocity.y);
player->super->position->velocity.y,
(player->onGround ? "true" : "false"),
player->jumpCount);
PUSH_STRING(buf);
}

View File

@ -86,7 +86,7 @@ static inline void _physics_AdvanceEntity(System_Physics *sys, Entity *e, Durati
}
static double gravity = 30;
static double gravity = 1000;
void physics_Advance(System_Physics *sys, Duration deltaTime) {
for (tree_Node *i = tree_FirstNode(sys->pos);

View File

@ -46,7 +46,7 @@ void player_DeleteEntity(System_Player *sys, uintptr_t id) {
}
static double walkSpeed = 200.0, jumpSpeed = 500.0;
static double walkSpeed = 300.0, jumpSpeed = 500.0;
static int airjumpCount = 1;
void player_Advance(System_Player *sys, Duration deltaTime) {
@ -61,26 +61,20 @@ void player_Advance(System_Player *sys, Duration deltaTime) {
targetVecX += -walkSpeed;
if (input_IsPressed(input->keys[input_Key_Right]))
targetVecX += walkSpeed;
double targetVecY = 0.0;
if (input_IsPressed(input->keys[input_Key_Up]))
targetVecY += -walkSpeed;
if (input_IsPressed(input->keys[input_Key_Down]))
targetVecY += walkSpeed;
sys->player->super->position->velocity.x = targetVecX;
sys->player->super->position->velocity.y = targetVecY;
if (sys->player->onGround)
sys->player->jumpCount = 0;
// Jump
if (sys->super->input->keys[input_Key_Jump] == JustPressed) {
if (sys->player->onGround || sys->player->jumpCount < airjumpCount)
if (sys->player->onGround || sys->player->jumpCount < airjumpCount) {
sys->player->super->position->velocity.y = -jumpSpeed;
if (!sys->player->onGround) // Took the second clause, airjumped
sys->player->jumpCount++;
}
}
// Check OnGround again
if (dabs(sys->player->super->position->velocity.y) > EPS)

View File

@ -20,12 +20,10 @@ void render_DrawText(int x, int y, const char *str) {
vector_Clear(tbuf);
int len = strlen(str);
printf("%s, len=%d\n", str, len);
int i = 0;
while (i < len) {
if (str[i] == '\n') {
vector_Push(tbuf, &zero);
printf("outtext: \"%s\"\n", vector_Data(tbuf));
outtextxy(cx, cy, (LPCTSTR)vector_Data(tbuf));
cy += TEXTHEIGHT;