Doodle Jump on pygame

    Kind ...
    I want to tell and show you my experience with the pygame library, which is supposedly an excellent library for implementing graphical applications (mostly arcade games) in python. For example, the (partially) Doodle Jump game was implemented.

    Disclaimer


    • Yes, I used other people's pictures - I am ashamed and I will fix it soon.
    • The character can only jump now, but I plan to finish the game to the end.
    • Yes, the idea is not new, but it turned out cool.
    • Yes, most likely nonsense - to use an interpreted language for writing games.
    • I am not a professional programmer and this is not my main activity.


    Instead of introducing


    Python Python is great in terms of documentation. She is, she is understandable, she is not without excellent examples. Pygame is no exception, so I suggest not dwell on the details of the implementation of this library, but it should be noted that its tools allow you to load an image, and simply move it around x and y. Nothing extra.

    Architecture


    We will try to develop the application architecture in the best traditions of OOP . We have the following class diagram:

    Supporters of the MVC model are already crying, because and logic and representation are thrust into the body of the class.
    We have 3 locations:
    • StartLocation - the menu and the invitation to the game are spinning here.
    • GameLocation - the subject itself.
    • ExitLocation - output, results, fanfare-ovations.

    The basic Sprite object from which all game objects are inherited - platforms, buttons, the main character, etc. According to the scheme, everything is clear.

    Key points


    Events

    defevent(self, event):if event.type == QUIT:
                sys.exit()
            elif event.type == KEYUP:
                if event.key == K_ESCAPE:
                    # do somethingif event.type == MOUSEMOTION:
                for btn in self.buttons:
                    if btn.rect.collidepoint(pygame.mouse.get_pos()):
                    #pass
                        btn.changeState(1)

    Using the event mechanism, keystrokes and mouse manipulations are transparently intercepted.

    Images

    
            self.img_l = pygame.image.load('img/doodle_l.png').convert()
            self.image = self.img_l
            self.image.set_colorkey(self.image.get_at((0,0)), RLEACCEL)
            self.rect = self.image.get_rect()
            self.rect.center = (self.x,self.y)

    We load pictures for sprites.

    Clashes

    self.doodle.getLegsRect().colliderect(spr.getSurfaceRect())

    The coliderect method returns true if the rectangles bordering the sprites intersect.

    A couple of screenshots





    Todo


    • Work out the gameplay
    • Draw new sprites
    • Add sounds
    • Add statistics
    • Correct platform location algorithms
    • Add arrow control
    • What else?


    Instead of an afterword


    Acquaintance with pygame can be considered finished, the doder jumps and enjoys life, but the processor load at the same time tends to 50-70%, which is not a buzz. What is it, govnokod poor application architecture or language features - you decide. Thanks for attention.
    Sources on github.

    Also popular now: