Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pygame setting borders?
#2
Line 68 is giving you trouble. If you want to go this route you'll need to make this a lot more complex.

if x >= 140 and x <= 340 and y <= 260 and y >= ?????..... etc, etc
basically, outer boundaries are easy to do this way because you only come at them from one side. The way you are doing it, you'll basically have to write big ifs for every side of every object.

The real solution to the problem is to use the pygame sprite class for your player and walls. Then it is easy to see if they hit and to stop your player from moving.

Here is a tutorial for pygame:
https://www.youtube.com/watch?v=3UxnelT9...5EMxUWPm2i

Here is a simpler one that used the Turtle module.
https://www.youtube.com/watch?v=inocKE13...q9RzORkQWP

Both these will show you how to draw your map with a .txt file, which you will find a lot better and easy to modify. Moreover, if you want enemies in your game or shooting, your will have a hell of at time without using some of these other tools.
Reply


Messages In This Thread
pygame setting borders? - by thepelican3 - Feb-15-2020, 02:08 PM
RE: pygame setting borders? - by michael1789 - Feb-15-2020, 06:48 PM
RE: pygame setting borders? - by Windspar - Feb-16-2020, 02:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Error setting up pygame wazee 10 13,411 Jun-14-2018, 11:19 PM
Last Post: wazee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020