Fix gravity
it works now
This commit is contained in:
parent
4f9ea0a09a
commit
c5a230647e
10
app_debug.c
10
app_debug.c
@ -17,11 +17,17 @@ void app_DebugText(App *app, vector_Vector *vec_string) {
|
|||||||
} else {
|
} else {
|
||||||
snprintf(
|
snprintf(
|
||||||
buf, sizeof(buf) - 1,
|
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.x,
|
||||||
player->super->position->position.y,
|
player->super->position->position.y,
|
||||||
player->super->position->velocity.x,
|
player->super->position->velocity.x,
|
||||||
player->super->position->velocity.y);
|
player->super->position->velocity.y,
|
||||||
|
(player->onGround ? "true" : "false"),
|
||||||
|
player->jumpCount);
|
||||||
PUSH_STRING(buf);
|
PUSH_STRING(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
void physics_Advance(System_Physics *sys, Duration deltaTime) {
|
||||||
for (tree_Node *i = tree_FirstNode(sys->pos);
|
for (tree_Node *i = tree_FirstNode(sys->pos);
|
||||||
|
14
player.c
14
player.c
@ -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;
|
static int airjumpCount = 1;
|
||||||
|
|
||||||
void player_Advance(System_Player *sys, Duration deltaTime) {
|
void player_Advance(System_Player *sys, Duration deltaTime) {
|
||||||
@ -61,26 +61,20 @@ void player_Advance(System_Player *sys, Duration deltaTime) {
|
|||||||
targetVecX += -walkSpeed;
|
targetVecX += -walkSpeed;
|
||||||
if (input_IsPressed(input->keys[input_Key_Right]))
|
if (input_IsPressed(input->keys[input_Key_Right]))
|
||||||
targetVecX += walkSpeed;
|
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.x = targetVecX;
|
||||||
sys->player->super->position->velocity.y = targetVecY;
|
|
||||||
|
|
||||||
if (sys->player->onGround)
|
if (sys->player->onGround)
|
||||||
sys->player->jumpCount = 0;
|
sys->player->jumpCount = 0;
|
||||||
|
|
||||||
// Jump
|
// Jump
|
||||||
if (sys->super->input->keys[input_Key_Jump] == JustPressed) {
|
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;
|
sys->player->super->position->velocity.y = -jumpSpeed;
|
||||||
if (!sys->player->onGround) // Took the second clause, airjumped
|
if (!sys->player->onGround) // Took the second clause, airjumped
|
||||||
sys->player->jumpCount++;
|
sys->player->jumpCount++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check OnGround again
|
// Check OnGround again
|
||||||
if (dabs(sys->player->super->position->velocity.y) > EPS)
|
if (dabs(sys->player->super->position->velocity.y) > EPS)
|
||||||
|
@ -20,12 +20,10 @@ void render_DrawText(int x, int y, const char *str) {
|
|||||||
|
|
||||||
vector_Clear(tbuf);
|
vector_Clear(tbuf);
|
||||||
int len = strlen(str);
|
int len = strlen(str);
|
||||||
printf("%s, len=%d\n", str, len);
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < len) {
|
while (i < len) {
|
||||||
if (str[i] == '\n') {
|
if (str[i] == '\n') {
|
||||||
vector_Push(tbuf, &zero);
|
vector_Push(tbuf, &zero);
|
||||||
printf("outtext: \"%s\"\n", vector_Data(tbuf));
|
|
||||||
outtextxy(cx, cy, (LPCTSTR)vector_Data(tbuf));
|
outtextxy(cx, cy, (LPCTSTR)vector_Data(tbuf));
|
||||||
|
|
||||||
cy += TEXTHEIGHT;
|
cy += TEXTHEIGHT;
|
||||||
|
Loading…
Reference in New Issue
Block a user