This is my first python game using Pycharm IDE. This game has two characters: player or spaceship and enemies or zombies.
We have to shoot bullets before zombies reach near spaceship.
At top left, Score will be calculated, 1 point for each successful shot & 0 point for miss. After any of the zombie reached near spaceship, then game finishes displayed by GAME OVER text.
This game has different sound, image & display combinations which enthrills player with gaming endeavours.
So, what are you waiting for??
Just run it in your IDE or PyCharm, Enjoy & Share your score on LinkedIn or Mail.
- pygame
- random
- math
- pygame.init()
- pygame.display.update()
I used List python data structure and appended element in empty lists using .append method. I also used Distance Formula to find distance between bullets and zombie or enemy.
- Ready:
- Fire:
When we can't see the bullet on screen. It is in state of going to be ejected from spaceship.
The state in which bullet is in moving condition.
- pygame.image.load("image name")
- from pygame import mixer
- mixeer.music.load ("music file")
- mixeer.music.play ()
- variable = mixer.Sound("filename") & then variable.play()
mixer class help us to handle all type of activities to perform with music in game whether it can be repeating, loading or anything to do with music.
Use -1 only when you want to persists this music during whole game.
- pygame.font.Font("Font family file", font-size)
- font.render(self, text, antialias, color, background)
- pygame.display.set_mode((height, width))
- pygame.display.set_caption("Text")
- pygame.display.set_icon("Icon variable in which icon image is loaded")
- screen.blit(variable name, (x,y))
- screen.fill((R,G,B))
Don't Forget to use inner bracket for making it tuple.😛😂
blit means to just draw !!
Math library was used to implement two functions i.e. sqrt() & pow(a,b) .
Random library was used for respawning of zombie in gaming terms by giving random coordinates over a certain range of coordinates.
- To get all events we used pygame.event.get().
- for identifying event type, we used event.type.
- to know about event of key like it is released or pressed or whether it is space, left & right arrow key or any other key, we used event.key.
- For space, right arrow & left arrow key it has to match with pygame.K_SPACE, pygame.K_RIGHT and pygame.K_LEFTrespectively.
- If we close window...then while loop has to be closed & game over....we used pygame.QUIT.
- Install Python and Pycharm
- Creating Our First Game Window
- Changing the Title, Logo and Background Color
- Adding Images into Our Space Invader Game
- Movement Mechanics in Game Development
- Keyboard Input Controls & Key Pressed Event
- Adding Boundaries to Our Game
- Creating the Enemy
- Movement Mechanics of the Enemy Space Invader
- Adding a Background Image
- Creating Bullets for Shooting
- Shooting Multiple Bullets at Space Invaders
- Collision Detection
- Creating Multiple Enemies
- Adding Text and Displaying Score
- Adding Sounds and Background Music
- Game Over