Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Better way to do bounding?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 PaladinJohn   Members   -  Reputation: 130

Like
0Likes
Like

Posted 27 March 2012 - 01:40 AM

Very simple problem I could use some input on. I'm working on a Dr. Mario-esque game, so a simple falling blocks game with control over a pair of blocks. Currently, I'm having a tough time with bounding in regards to rotating the blocks. Below are two snipets of code that control bounding:

keys = pygame.key.get_pressed()
	 if keys[pygame.K_LEFT]:
	 	 self.x -= 20
	 	 if self.rect.left <= 240:
	 	 	 self.x = 240
	 if keys[pygame.K_RIGHT]:
	 	 if self.rect.right <= 380:
	 	 	 self.x += 20
	 if keys[pygame.K_DOWN]:
	 	 self.y += 20
	 	 self.wait = 0
	 	 if self.rect.bottom >= 400:
	 	 	 self.y = 400

if event.key == pygame.K_RCTRL:
	 if self.mana.dir == 90 or 270:
	 	 if self.mana.x == 380:
	 	 	 self.mana.x -= 20
	 	 self.mana.dir += 90
	 	 if self.mana.dir > 360:
	 	 	 self.mana.dir = 90

For clarity sake, I thought I would also mention that I am rotating objects by the Bottom Left corner of the object to allow easy and accurate snapping to the grid and to better emulate the base material. The problem becomes that if the user presses the rotate button at exactly the right time, the game piece can get out of bounds overlapping the border for the grid the game takes place on. Is there a better way to make sure that there is absolutely no way that any part of my sprite can ever cross a particular point in the window the way I have things now? I tried adding a line of code in the sprite update method that checks to see if the right side of the sprite is past a certain point and if it is to move x back by 20, but it's still exhibiting the same behavior.

This only occurs on the right side, which leads me to believe this may all originate from how I'm rotating the piece and the challenges it produces in managing x in that manner. I'm going to try a few more methods in the morning, but I thought I would post this here to get some additional insight in better ways to manage boundaries.

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS