Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pygame setting borders?
#1
# I am having trouble with the borders around the castle walls?
import pygame

pygame.init() #Initialize

#==============================INITIALIZING==============================

screen = pygame.display.set_mode((600,500)) # (x, y)

#=============================== (R,G,B) ================================

red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
black = (0,0,0)
white = (255,255,255)
yellow = (255,255,0)
grey = (128,128,128)

x = 290
y = 400
width = 20
height = 20
vel = 10




 
# ========================================Game Loop=============================
while True:
    pygame.time.delay(100)
    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()
        
        

    keys = pygame.key.get_pressed()

    if keys[pygame.K_LEFT]:
        x -= vel

    if keys[pygame.K_RIGHT]:
        x += vel

    if keys[pygame.K_UP]:
        y -= vel

    if keys[pygame.K_DOWN]:
        y += vel

# player stops at the sidewalls and top and bottom walls
    if x <= 30:
        x = 30
    if x >= 550:
        x = 550
    if y <= 31:
        y = 31
    if x <= 250 and y >= 450:
        y = 450
    if x >= 350 and y >= 450:
        y = 450

# player stops at castle walls

    if x >= 140 and y <= 260:
        x = 140
    
    
    
            




    screen.fill(grey)
    pygame.draw.rect(screen,yellow,[0,0,30,500])
    pygame.draw.rect(screen,yellow,[570,0,30,500])
    pygame.draw.rect(screen,yellow,[0,470,250,30])
    pygame.draw.rect(screen,yellow,[350,470,250,30])
    pygame.draw.rect(screen,yellow,[0,0,200,30])
    pygame.draw.rect(screen,yellow,[400,0,200,30])
    pygame.draw.rect(screen,yellow,[210,0,10,30])
    pygame.draw.rect(screen,yellow,[230,0,10,30])
    pygame.draw.rect(screen,yellow,[250,0,10,30])
    pygame.draw.rect(screen,yellow,[380,0,10,30])
    pygame.draw.rect(screen,yellow,[360,0,10,30])
    pygame.draw.rect(screen,yellow,[340,0,10,30])
    pygame.draw.rect(screen,yellow,[160,30,100,200])
    pygame.draw.rect(screen,yellow,[340,30,100,240])
    pygame.draw.rect(screen,yellow,[160,130,200,140])
    pygame.draw.rect(screen,yellow,[180,130,100,240])
    pygame.draw.rect(screen,yellow,[320,130,100,240])
    pygame.draw.rect(screen,yellow,[x,y,20,20])

    pygame.display.update()
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,337 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