super()._init_() is a whole different concept related to Classes in Python. Passing super().init() then calls the init() function of the Sprite class. Passing into the parameters,makes the Player Class it’s child class. Now, this doesn’t really apply to the Player Class, since most games will only have one player but it does apply to the Enemy Class as most games will have multiple enemies. The benefit of using classes here is that we can spawn multiple entities from the same block of code.
Pygame key codes code#
Self.image = ("Player.png")Ībove you can see the Code for the Player Class. More about information about Pygame Rects can be found here.ĭISPLAYSURF = _mode((400,600))
When the snake hits any boundary of the window, the user loses the game. These keys represent the arrow keys to move the snake left, right, up and down. The events that we have used here are K_LEFT, K_RIGHT, K_UP, and K_DOWN.
The pygame KEYDOWN class gets the event when the keyword buttons are pressed. To move the snake, we need key input from the user.