C
C
Canta2019-08-18 21:27:43
Python
Canta, 2019-08-18 21:27:43

Shape not drawing in PYGAME?

I don't understand why the rectangle is not being drawn in pygame. It is marked with question marks.

import pygame

pygame.init()

dis_width = 800
dis_height = 600
clock = pygame.time.Clock()
FPS = 60

name_game = 'Run Dino! Run'
icon_game = pygame.image.load('img/dino.png')

display = pygame.display.set_mode((dis_width, dis_height)) # размеры окна игры
pygame.display.set_caption(name_game) # название игры
pygame.display.set_icon(icon_game) # иконка игры



user_width = 60
user_height = 100
user_x = dis_width // 3
user_y = dis_height - user_height - 100

make_jump = False
jump_counter = 30



cactus_width = 20
cactus_height = 70
cactus_x = dis_width - 50
cactus_y = dis_width - cactus_height - 100



def run_game():
  game = True
  global make_jump

  while game:
    for event in pygame.event.get():
      if event.type == pygame.QUIT:
        pygame.quit()
        quit()

    keys = pygame.key.get_pressed()
    if keys[pygame.K_SPACE]:
      make_jump = True

    if make_jump:
      jump()

    if keys[pygame.K_d]:
      right()

    elif keys[pygame.K_a]:
      left()


    display.fill((128, 0, 128)) # цвет фона
    
    pygame.draw.rect(display, (218, 165, 32), (cactus_x, cactus_y, cactus_width, cactus_height)) # !!!!!!!!!!!!!!!!!!!!!!!!!

    pygame.draw.rect(display, (218, 165, 32), (user_x, user_y, user_width, user_height)) # прямоугольник (персонаж)
    

    pygame.display.update() # обновление экрана
    clock.tick(FPS) # частота обновления 


def jump(): # прыжок
  global user_y, make_jump, jump_counter

  if jump_counter >= -30:
    user_y -= jump_counter / 2.5
    jump_counter -= 1
  else:
    jump_counter = 30
    make_jump = False


def cactus():
  global cactus_x

  if cactus_x >= -cactus_width:
    pygame.draw.rect(display, (218, 165, 32), (cactus_x, cactus_y, cactus_width, cactus_height))
    cactus_x -= 4
  else:
    cactus_x = dis_width - 50



def right():
  global user_x

  if user_x == dis_width - user_width:
    user_x += 0
  else:
    user_x += 3

def left():
  global user_x

  if user_x < 0:
    user_x -= 0
  else:
    user_x -= 3



run_game() # запуск игры

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
P47r1ck, 2019-08-19
@P47r1ck

>> cactus_y = dis_width - cactus_height - 100
cactus_y = dis_height - cactus_height - 100

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question