1

I'm making code for a Python game and I have the following

WIDTH = 600
HEIGHT = 800
player_x = 600
player_y = 350
def draw():
    screen.blit(images.backdrop, (0, 0))
    screen.blit(images.mars, (50, 50))
    screen.blit(images.astronaut, (player_x, player_y))
    screen.blit(images.ship, (550, 300))
def game_loop():
    global player_x, player_y
    if keyboard.right:
        player_x += 5
    elif keyboard.left:
        player_x -= 5
    elif keyboard.up:
        player_y -= 5
    elif keyboard.down:
        player_y += 5
    clock.schedule_interval(game_loop, 0.03)

However, when I run it, it won't show the astronaut. I have the astronaut image for it but whatever I try doing, it will not work. Can someone please tell me where the problem is?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • You're drawing the astronaut at x=600, and your width is apparently 600. Maybe try moving the astronaut a bit to the left to make sure they are onscreen. – khelwood Jul 02 '20 at 19:57
  • What happens when you initialize the astronaut to be at e.g. `width//2` and `height//2` rather than at the edge of the screen (which your code is currently doing)? – John Coleman Jul 02 '20 at 19:57

1 Answers1

2

The coordinate which is passed to blit, is the position of the top left corner of the surface. Since the width of the surface is 600 and the x coordinate is 600, the surface outside of the window on the right.
You can switch the x coordinate of the astronaut, but most likely the WIDTH and HEIGHT of your window are switched:

WIDTH = 600
HEIGHT = 800

WIDTH = 800
HEIGHT = 600
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • Thanks for your input guys! I actually looked at my code and found out I switched my original width and height –  Jul 02 '20 at 22:29