0

I am developing a game and have encountered a few unsolvable (by me at least) issues.

Problems that I have with my code are:

  1. When asking if you want to save a screenshot, only inputting anything which can be translated, by the lower() method, into either "yes" or "no" will be accepted despite the or statement - one of the conditions in that code block is if save_option.lower() == ("yes" or "y"): and it will only accept "yes", or else the condition is evaluated as False. I don't know why this is.

  2. When rendering the introduction to the game in def introduction():, for some reason, each surface object is getting drawn twice. Here is what it looks like: However, when I increase the pixels moved every frame to 60, this happens:

  3. When 'deliver all his presents' reaches the top of the screen, introduction() ends and the main game loop starts. I can see any logic error relating to this in this bit of code:

    while not pygame.sprite.Group.has(intro_story_surface_objects): for event in pygame.event.get(): if event.type == QUIT or event.type == KEYDOWN and event.key
    == K_ESCAPE: destroy()

    DS.blit(BACKGROUND, (0, 0))
    pygame.draw.rect(DS, (0, 0, 0, 50), (0, DISPLAY_HEIGHT - 200, DISPLAY_WIDTH, 200), 0) # (screen, color, (x,y,width,height), thickness)
    
    count = 0
    for line in intro_story_surface_objects:
    
        line_x_y = (intro_story_surface_objects[line].rect.x, intro_story_surface_objects[line].rect.y)
        intro_story_sprite_group.draw(DS)
        intro_story_surface_objects[line].rect.y -= 60 # intro_story_surface_objects[line].speed
    
        if intro_story_surface_objects[line].rect.y + intro_story_surface_objects[line].rect.height < 0:
            intro_story_surface_objects[line].kill()
            # print("Kill")
            line_kills += 1
    
            if line_kills == len(intro_story_surface_objects):
                return
    
    
    pygame.display.update()
    clock.tick(30)
    

Thanks again, in advance for trying to help.

From Kiran

2
  • Please ask only one question at a time. Also, make sure that your code is complete and verifiable, so that we can run and test it: stackoverflow.com/help/mcve Commented Mar 29, 2018 at 2:39
  • Is there anyone else that can help with pygame issues or even control flow as this might be the problem Commented Mar 29, 2018 at 13:29

2 Answers 2

3
  1. For problem one. Try: if save_option.lower() in ['yes', 'y']:

What your or statement within the parens is saying is: If the first value evaluates to false, compare against the second. Since the string 'yes' is always True save_option.lower() is never compared against 'y'.

I can't help with the rest of it unfortunately. I haven't used Pygame. Good luck though! And happy gaming.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your help @Harry MW.
At least you helped me solve one problem. I really appreciate it. :-)
1

Answering my own question 2.

I still need 2 other questions answered apart from this.

When the code is executed, the text looks like it is being drawn twice. The problem is that every time that the x and y coordinates for each line of text are changed, the WHOLE list of lines what being drawn twice.

Just a little accident. My code was meant to be structured like this:

  • while there are lines of text:
  • draw all the lines in this command - intro_story_sprite_group.draw(DS)
  • loop through each line:
  • Change its (x, y)

Not do this:

  • while there are lines of text:
  • loop through each line:
  • draw all the lines in this command - intro_story_sprite_group.draw(DS)
  • Change its (x, y)

Please don't forget that I still need 2 more questions answered! Thanks for your help,

Kiran

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.