• Content count

  • Joined

  • Last visited

Community Reputation

108 Neutral

About Juvelbagarn

  • Rank
  1. [quote name='ShadowValence' timestamp='1346354708' post='4974887'] It looks to me like WarAmp was correct in his response. Your logic is only checking a single point of the 20 pixel ball (X, Y). To correct for this you'll have to extend your logic to include the size. Try something like this: [source lang="csharp"]if (ballvec.X + ballrec.Width > maxX || ballvec.X < 0) ballspeed.X *= -1; if (ballvec.Y + ballrec.Height > maxY || ballvec.Y < 0) ballspeed.Y *= -1;[/source] This makes sure that the furthest part of the ball (not just its current position) is taken into consideration (by adding the width and height). [/quote] Thank you, it worked. If I study the code you write it all make sense. i hope i get the collision with ball -> paddle correct aswell now Thanks once more.
  2. [quote name='ShadowValence' timestamp='1346353189' post='4974878'] I read the question wrong.. My bad. [/quote] Alright, I'm using [CODE]spritebatch.Draw(ball, ballvec, Color.White);[/CODE] right now, and the problem is still there. here's some more code. [CODE] int maxX = GraphicsDevice.Viewport.Width; int maxY = GraphicsDevice.Viewport.Height; ballrec = new Rectangle((int)ballvec.X, (int)ballvec.Y, ball.Width, ball.Height); //check for bounce if (ballvec.X > maxX || ballvec.X < 0) ballspeed.X *= -1; if (ballvec.Y > maxY || ballvec.Y < 0) ballspeed.Y *= -1; [/CODE] As I said before, the ball is 20x20px and i want the recangle to be 20x20 aswell. EDIT: changed "ballvec" to "ballrec" in "check for bounce" and the ball did not even bounce, just keept going off screen.
  3. Hello everyone! I've just started programming XNA again and did not remember much about it, I didnt really complete any games.. Anyway, I ran in to some problem today, I'm trying to create a pong game and the bounces are kind of wierd. It seems like the rectangle is not a rectangle, more like a 1px dot on the top left corner, The ball is 20x20px size and the rectangle code looks like this: [CODE]ballrec = new Rectangle((int)ballvec.X, (int)ballvec.Y, ball.Width, ball.Height);[/CODE] And this is the Draw section: [CODE]spritebatch.Draw(ball,ballvec,ballrec,Color.White,0,new Vector2(0,0),1,SpriteEffects.None,0);[/CODE] when it bounces the ball only reacts to the top left corner, what am I doing wrong here? /Freemountain
  4. Jansic was on to something there.. i tried it but not with the result i wanted.. I simply want a rectangle for every sprite i draw, so that i make something happen when my mouse sprite touches (intersects) with the sprites. Simply, a maze, you tuch the walls you die and have to restart from "start position".. I don't know how to explain any better. As i said before, im verry new to OOP and C#/XNA. But i'm still lerning.
  5. [quote name='boogyman19946' timestamp='1311940051' post='4842097'] Ok, so what exactly do mazeBounds do and why do you keep resetting their position to the last tile's position? [/quote] mazeBounds tells me where the blocks are, i don't WANT em to reset, i want to create new ones, but i dont know how to.
  6. [quote name='boogyman19946' timestamp='1311908886' post='4841973'] Oh wait, I figured out what you're trying to find. You're trying to find the positioning of the tiles right? [/quote] Yea, i want the rectangles to loop, just like the sprites..
  7. Hello, I'm new to this forum and pretty new to C# and XNA (Still lerning a lot of C# and i'm NOT giving that shit up cus i KNOW i can lern it if i reallt try). ive made a 2d sprite -map, more or less.. it looks like this when the loop is finishd: ############ #-----------------# #-----------------# #-----------------# ############ Its all 32x32px squares and the sprites are drawn verry nice.. The only problem is.. I dont know how to loop the rectangles so i can find out the bounds. the only rectangle that work is the far bottom right, I think i know the problem but not how to solv it. I think i need several new names for the rectangles or loop them.. If you would be kind to explain it to me it would be verry helpfull. here are some of my code(Its all in the DRAW method): [code] for (int i = 0; i < levels.level_0.GetLength(0); ++i) for (int j = 0; j < levels.level_0.GetLength(1); ++j) { Vector2 tilePos = new Vector2(j * 32, i * 32); if (levels.level_0[i, j] == 1) { mazeBounds = new Rectangle((int)tilePos.X, (int)tilePos.Y, 32, 32); spriteBatch.Draw(mapBrick, tilePos, Color.White); } } [/code] UPPDATE, this is the code im working with, the other one was the old one, from some wierd tutorial. Om sorry to confuse you.