Problem med min C# XNA kod!
Hallåj!
Jag har gjort ett litet "spel" där jag nu kan åka runt med en liten boll, sedan ska det vara en annan boll som åker automatiskt. Jag vill att när den bollen slår väggarna ska den studsa och åka tillbaka. Jag trodde att min kod stämde men när jag testade åkte den utanför.
Kolla igenom och hjälp mig är ni snälla!
bollOldposition = bollPosition;
// TODO: Add your update logic here
KeyboardState kstate = Keyboard.GetState();
if (kstate.IsKeyDown(Keys.Escape))
this.Exit();
if (kstate.IsKeyDown(Keys.Left))
{
bollPosition.X -= 3;
}
if (kstate.IsKeyDown(Keys.Right))
{
bollPosition.X += 3;
}
if (kstate.IsKeyDown(Keys.Down))
{
bollPosition.Y += 3;
}
if (kstate.IsKeyDown(Keys.Up))
{
bollPosition.Y -= 3;
}
boll2Position += redbollVelocity;
if (boll2Position.Y + boll2Texture.Height > this.Window.ClientBounds.Height && redbollVelocity.X < 0)
{
redbollVelocity = new Vector2(-1, -1);
}
if (boll2Position.X + boll2Texture.Width > this.Window.ClientBounds.Width && redbollVelocity.Y > 0)
{
redbollVelocity = new Vector2(-1, 1);
}
if (boll2Position.X + boll2Texture.Width > this.Window.ClientBounds.Width && redbollVelocity.Y > 0)
{
redbollVelocity = new Vector2(-1, -1);
}
if (boll2Position.Y == 0 && redbollVelocity.X < 0)
{
redbollVelocity = new Vector2(-1, 1);
}
if (boll2Position.Y == 0 && redbollVelocity.X > 0)
{
redbollVelocity = new Vector2(1, 1);
}
if (boll2Position.X == 0 && redbollVelocity.Y <0)
{
redbollVelocity = new Vector2(1, -1);
}
if (boll2Position.X == 0 && redbollVelocity.Y > 0)
{
redbollVelocity = new Vector2(1, 1);
}
if (boll2Position.Y + boll2Texture.Height >
this.Window.ClientBounds.Height && redbollVelocity.X > 0)
{
redbollVelocity = new Vector2(1, -1);
}
base.Update(gameTime);
}
om ni vill att jag ska skicka all kod notifiera mig gärna!