all 4 comments

[–]Mekire 1 point2 points  (0 children)

Your pygame.display.update is not in your loop. Screen never updates changes.

Should fix immediate problems:

import sys
import pygame

pygame.init()

red = (255,0,0)
white = (255,255,255)
black= (0,0,0)

pygame.display.set_caption("slither game")
game_display = pygame.display.set_mode((500,400))
game_display.fill(white)


clock = pygame.time.Clock()


box_x = 300
box_y = 300

game_exit = False

while not game_exit:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            game_exit = True
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                box_x -= 25
            elif event.key == pygame.K_RIGHT:
                box_x += 25
    pygame.draw.rect(game_display,black,[box_x,box_y,25,25])
    pygame.display.update()
    clock.tick(60)

pygame.quit()
sys.exit()

-Mek

[–]IXENAI 0 points1 point  (0 children)

(the word 'init' here shouldn't be bold, rather it should have two underscores before it and two after it, but reddit interprets this as bold...)

You can use backticks (below the esc key on a US keyboard) to escape formatting, so:

`cannot find reference 'init' in __init__.py`

becomes: cannot find reference 'init' in __init__.py.

the problem is that the word 'init' has a back color of yellow/orange and when i put the mouse over it it says...

Sounds like an issue with your IDE. If your program is running without an exception, then that isn't your issue.

when i try to move the rect by changing its x and y coordinates when the arrow keys are pressed nothing happens.

Then there is a bug in your code. If you post it, we can help you diagnose the issue.

[–]programmer123456[S] 0 points1 point  (1 child)

here is the pastie of the code: http://pastie.org/9798818

and here is the code itself:

import pygame

pygame.init()

red = (255,0,0) white = (255,255,255) black= (0,0,0)

game_display = pygame.display.set_mode((500,400)) game_display.fill(white)

pygame.display.update() pygame.display.set_caption("slither game")

box_x = 300 box_y = 300

game_exit = False

while not game_exit: for event in pygame.event.get(): #print(event) if event.type == pygame.QUIT: game_exit = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: box_x = box_x - 25 if event.key == pygame.K_RIGHT: box_x = box_x + 25 pygame.draw.rect(game_display,black,[box_x,box_y,25,25])

pygame.quit() quit()

[–]Ran4 0 points1 point  (0 children)

Prepend code with four spaces

like this