Python Forum
[PyGame] Creating Map Obstacles
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Creating Map Obstacles
#8
I over looked that.
speed = 3
movement = pygame.Vector2(0, 0)
# If the UP key is pressed, move the player upwards
    if pressed[pygame.K_UP] and not pressed[pygame.K_DOWN]:
        if char.y != 3:
            movement.y -= speed
 
    # If the DOWN key is pressed, move the player downwards
    if pressed[pygame.K_DOWN] and not pressed[pygame.K_UP]:
        if char.y != 279:
            movement.y += speed
 
    # If the LEFT key is pressed, move the player to the left
    if pressed[pygame.K_LEFT] and not pressed[pygame.K_RIGHT]:
        if char.x != minimum_x and not unlocked:
            movement.x -= speed

    # If the RIGHT key is pressed, move the player to the right
    if pressed[pygame.K_RIGHT] and not pressed[pygame.K_LEFT]:
        if char.x != 693:
            movement.x += speed

    if movement.x != 0 or movement.y != 0:
        moved = char.move(movement.x, movement.y)
        if moved.collidelist(fences) == -1:
            char = moved
or
speed = 3
movement = pygame.Vector2(0, 0)
# If the UP key is pressed, move the player upwards
    if pressed[pygame.K_UP] and not pressed[pygame.K_DOWN]:
        movement.y -= speed
 
    # If the DOWN key is pressed, move the player downwards
    if pressed[pygame.K_DOWN] and not pressed[pygame.K_UP]:        
        movement.y += speed
 
    # If the LEFT key is pressed, move the player to the left
    if pressed[pygame.K_LEFT] and not pressed[pygame.K_RIGHT]:
        movement.x -= speed

    # If the RIGHT key is pressed, move the player to the right
    if pressed[pygame.K_RIGHT] and not pressed[pygame.K_LEFT]:
        movement.x += speed

    if movement.x != 0 or movement.y != 0:
        # Deflate. Where 3 pixels away from edge
        rect = screen.get_rect().inflate(-6, -6) 
        moved = char.move(movement.x, movement.y)
        if moved.collidelist(fences) == -1 and rect.contains(moved):
            char = moved
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