public override void Update(float dt, Gui_Manager guimanager) { base.Update(dt, guimanager); // makes spider walk if (left) { new_x_add -= speed * dt; } else { new_x_add += speed * dt; } x_addition = (int)(new_x_add); this.steps_out += x_addition; new_x_add = new_x_add - x_addition; Fallable_Object main = guimanager.GetMain_Character(); if (main != null) { if (left == false && !guimanager.Check_Collision(this, this.position.x + x_addition + 2, this.position.y, this.size.x, this.size.y)) { this.left = true; } else if (left == true && (!guimanager.Check_Collision(this, this.position.x - x_addition - 2, this.position.y, this.size.x, this.size.y))) { this.left = false; } else { if (!((this.position.x + x_addition + 2 < main.position.x + main.size.x && this.position.x + x_addition - 2 + this.size.x > main.position.x && this.position.y + this.size.y > main.position.y && this.position.y < main.position.y + main.size.y))) { this.position.x += x_addition; } else { guimanager.Main_Dead(); } } } if (this.position.y > 600) { Console.WriteLine("respawning"); this.position.y = startposition.y; this.position.x = this.startposition.x - guimanager.movementchange; } }
public void Jump(Gui_Manager guimanager) { if (IsMainCharacter) { if (this.velocity == 0 && (guimanager.Check_Collision(this, position.x, position.y - 1, size.x, size.y)) == true) { this.velocity = jumpvelocity; } } }
public void Update_Gravity(float dt, Gui_Manager guimanager) // updates gravity: falls faster when falling a longer distance by velocity { float startvelocity = velocity; velocity = velocity - (15 * dt); if (startvelocity > 0.6 && velocity < 0.6) { velocity = -1.0f; // boost for when in midair } if (guimanager.Check_Collision(this, position.x, position.y - (int)velocity, size.x, size.y) || Collides == false) // check if able to fall { this.position.y = this.position.y - (int)velocity; } else { bool minimalfound = true; for (int i = (int)velocity; i < 0 && minimalfound; i++) { if (guimanager.Check_Collision(this, position.x, position.y - i, size.x, size.y)) { minimalfound = false; this.position.y = this.position.y - i; } } velocity = 0; if (guimanager.Check_Collision(this, position.x, position.y + 1, size.x, size.y) == true) // for when bounching on platform { velocity = -1; } } }