Python Forum
[PyGame] Creating Map Obstacles
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Creating Map Obstacles
#6
after screen.blit(farm_image, (0, 0))
pygame.draw.rect(screen, pygame.Color('red'), char)

this need to go in main loop. After screen.blit(farm_image, (0,0))
# Puts the fences on the screen
for fence in fences:
    pygame.draw.rect(screen, pygame.Color('red'), fence)

Romove this. No longer used.
# Coordinates of the rectangle (player) object
x = 507
y = 60

If you want to make sure object stay on screen.
# Initializes the window's title, width, and height
screen = pygame.display.set_mode((720, 320))
rect = screen.get_rect()
if moved:
    if moved.collidelist(fences) == -1 and rect.contains(moved):
        char = moved
Pygame Rect

If you don't do method above.
if pressed[pygame.K_UP] and not pressed[pygame.K_DOWN]:
    if y != 3:
        moved = char.move(0, -3)
Change to.
if pressed[pygame.K_UP] and not pressed[pygame.K_DOWN]:
    if char.y != 3:
        moved = char.move(0, -3)
If you did rect for stay on screen.
if pressed[pygame.K_UP] and not pressed[pygame.K_DOWN]:
    moved = char.move(0, -3)
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
Creating Map Obstacles - by cameron121901 - Jun-05-2019, 08:00 PM
RE: Creating Map Obstacles - by metulburr - Jun-05-2019, 08:40 PM
RE: Creating Map Obstacles - by cameron121901 - Jun-06-2019, 06:09 AM
RE: Creating Map Obstacles - by Windspar - Jun-06-2019, 11:06 AM
RE: Creating Map Obstacles - by cameron121901 - Jun-06-2019, 07:42 PM
RE: Creating Map Obstacles - by Windspar - Jun-06-2019, 08:45 PM
RE: Creating Map Obstacles - by cameron121901 - Jun-07-2019, 06:08 PM
RE: Creating Map Obstacles - by Windspar - Jun-07-2019, 07:53 PM
RE: Creating Map Obstacles - by cameron121901 - Jun-10-2019, 03:56 PM
RE: Creating Map Obstacles - by Windspar - Jun-10-2019, 05:43 PM

Forum Jump:

User Panel Messages

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