Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void CheckCollision()
- {
- bool gravitation = true;
- int l = -1;
- if (playerPosY > 26)
- {
- for (int i = 0; i < 360; i++) //Jeder Winkel wird gecheckt
- {
- float posX = (int)(Math.Round(playerPosX) + (Math.Cos(i) * 25)); //Cos(0) = 1
- float posY = (int)(Math.Round(playerPosY) + (Math.Sin(i) * 25)); //Sin(0) = 0
- if (terrain[(int)Math.Round(posY), (int)Math.Round(posX)] != '+') //Kollision tritt an der Stelle posX,posY auf
- {
- if (l == -1)
- Game1.ShowIntValue(i, spriteBatch);
- l = 1;
- gravitation = false; //Am Boden herrscht keine Schwerkraft (verhindert ruckeln auf der Y Achse)
- for (int j = 0; j < 100; j++)
- {
- if (terrain[(int)Math.Round(posY) - j, (int)Math.Round(posX)] != '+' && j != 0) //Wenn der Spieler den Boden durchschlägt, wird überprüft ob sich in den nächsten 10 pixel über ihn Luft befindet und er wird auf diese Position gesetzt
- {
- playerPosY -= 1;
- }
- }
- //playerPosY -= 1;
- playerPosYSpeed *= -1;
- playerPosYSpeed += 1f;
- //playerPosXSpeed *= (float)Math.Cos(Convert.ToDouble(i)); //Kollisionserkennung an der X-Achse
- break; //Schleife wird verlassen
- }
- }
- }
- if (gravitation)
- playerPosYSpeed += 0.04f; //Gravitation
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement