int onfloor(struct character *chara, struct platform *ground, int ground_length);
int gravity(struct character *character, struct platform *ground, int ground_length);
int move_character(struct character *character, struct platform *ground, int ground_length, float delta);
+int infloor(struct character *character, struct platform *ground, int ground_length);
int main(void)
{
return 1;
}
-struct Vector2 infloor(struct character *chara, struct platform *ground, int length) {
+int infloor(struct character *chara, struct platform *ground, int length) {
struct Vector2 depth = {0,0};
struct Rectangle charrect = {chara->position.x, chara->position.y, chara->size.x, chara->size.y};
struct Rectangle groundrect, collrect;
groundrect.height=ground[i].size.y;
if (CheckCollisionRecs(charrect, groundrect)) {
collrect = GetCollisionRec(charrect, groundrect);
- if (collrect.height > 1) {
- if (ground[i].position.x > charrect.x) { depth.x = (int)(collrect.width) * -1; } else { depth.x = (int)(collrect.width);};
- if (ground[i].position.y > charrect.y) { depth.y = (int)(collrect.height) * -1; } else { depth.y = (int)(collrect.height);};
- return depth;
- }
+ return 1;
}
}
- return depth;
+ return 0;
}
int move_character(struct character *chara, struct platform *ground, int length, float delta)
{
- chara->position.x += ceil(chara->velocity.x * delta);
- chara->position.y += ceil(chara->velocity.y * delta);
- struct Vector2 depth;
- depth = infloor(chara, ground, length);
- while ((depth.y != 0) && (depth.x != 0)) {
- chara->position.x += depth.x;
- chara->position.y += depth.y;
- depth = infloor(chara, ground, length);
+ int stepx, stepy, steps;
+ if (abs(chara->velocity.x) > abs(chara->velocity.y)) { //x is a larger movement
+ steps = chara->velocity.y; stepy = 1; stepx = round(chara->velocity.x/steps);
+ } else {
+ steps = chara->velocity.x + 1; stepx = 1; stepy = round(chara->velocity.y/steps);
+ }
+ printf("stepx: %d stepy: %d steps: %d yvel: %d xvel:%d\n", stepx, stepy, steps, chara->velocity.y, chara->velocity.x);
+ while ((infloor(chara, ground, length) == 0) && (steps != 0)) {
+ chara->position.x += stepx;
+ chara->position.y += stepy;
+ steps--;
}
+ chara->position.x -= stepx;
+ chara->position.y -= stepy;
+ chara->position.y += 1;
return 1;
}