programsolve.com Open in urlscan Pro
54.151.156.30  Public Scan

URL: https://programsolve.com/python-to-space-bullet-shooter-game-with-full-source-code-for-beginners/
Submission: On April 21 via manual from AU — Scanned from AU

Form analysis 3 forms found in the DOM

https://programsolve.com/

<form class="search-form navigation-search" action="https://programsolve.com/"><input type="search" class="search-field" name="s" title="Search"></form>

POST https://programsolve.com/wp-comments-post.php

<form action="https://programsolve.com/wp-comments-post.php" method="post" id="commentform" class="comment-form" novalidate="">
  <p class="comment-form-comment"><label for="comment" class="screen-reader-text">Comment</label><textarea id="comment" name="comment" cols="45" rows="8" required=""></textarea></p><label for="author" class="screen-reader-text">Name</label><input
    placeholder="Name *" id="author" name="author" size="30" required="">
  <label for="email" class="screen-reader-text">Email</label><input placeholder="Email *" id="email" name="email" type="email" size="30" required="">
  <label for="url" class="screen-reader-text">Website</label><input placeholder="Website" id="url" name="url" type="url" size="30">
  <p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"> <label for="wp-comment-cookies-consent">Save my name, email, and website in this browser for the next time
      I comment.</label></p>
  <p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Post Comment"> <input type="hidden" name="comment_post_ID" value="1993" id="comment_post_ID">
    <input type="hidden" name="comment_parent" id="comment_parent" value="0">
  </p>
  <p style="display:none"><input type="hidden" id="akismet_comment_nonce" name="akismet_comment_nonce" value="3ca2f0eb58"></p>
  <p style="display:none!important"><label>Δ<textarea name="ak_hp_textarea" cols="45" rows="8" maxlength="100"></textarea></label><input type="hidden" id="ak_js_1" name="ak_js" value="1682118412574">
    <script ez-screx="true">
      document.getElementById("ak_js_1").setAttribute("value", (new Date()).getTime());
    </script>
  </p>
</form>

https://programsolve.com/

<form class="search-form" action="https://programsolve.com/"><label><span class="screen-reader-text">Search for:</span>
    <input type="search" class="search-field" placeholder="Search …" name="s" title="Search for:"></label>
  <button class="search-submit" aria-label="Search"><span class="gp-icon icon-search"><svg viewBox="0 0 512 512" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em">
        <path fill-rule="evenodd" clip-rule="evenodd"
          d="M208 48c-88.366 0-160 71.634-160 160s71.634 160 160 160 160-71.634 160-160S296.366 48 208 48zM0 208C0 93.125 93.125 0 208 0s208 93.125 208 208c0 48.741-16.765 93.566-44.843 129.024l133.826 134.018c9.366 9.379 9.355 24.575-.025 33.941-9.379 9.366-24.575 9.355-33.941-.025L337.238 370.987C301.747 399.167 256.839 416 208 416 93.125 416 0 322.875 0 208z">
        </path>
      </svg></span></button>
</form>

Text Content

Skip to content


Menu
 * C
   * Computer Architecture and Organization
   * Data Structures and Algorithms
   * Operating Systems
   * HackerRank C
   * More C Programs
 * C++
   * Object Oriented Programming
   * More C++ Programs
 * Java
   * More Java Programs
 * Python
   * More Python Programs
 * Kotlin
 * JavaScript
   * More JavaScript Programs
   * React JS
 * Competitive Coding
   * Coding Ninjas
   * HackerRank
     * HackerRank C
 * Sap
   * Sap ABAP
 * Course




PYTHON TO SPACE BULLET SHOOTER GAME WITH FULL SOURCE CODE FOR BEGINNERS

December 8, 2021 by Admin

A Simple Space Bullet Shooter Game.


TO BE PLAYED WITH A COMPUTER:

 * Arrows to move up and down and left and right.
 * Enter to shoot a bullet.


REQUIRED LIBRARY:

Python 3 PyGame Tetris Game GUI Scr...


Please enable JavaScript



Video Player is loading.
Play Video
Pause
Unmute

Current Time 0:12
/
Duration 2:07
Loaded: 42.44%


0:12

Stream Type LIVE
Seek to live, currently behind liveLIVE
Remaining Time -1:55
 
1x
Playback Rate

Chapters
 * Chapters

Descriptions
 * descriptions off, selected

Captions
 * captions settings, opens captions settings dialog
 * captions off, selected

Audio Track
 * und, selected

Auto(360pLQ)
 * 1080pFHD
 * 720pHD
 * Auto(360pLQ)

ShareFullscreen

This is a modal window.



Beginning of dialog window. Escape will cancel and close the window.

TextColorWhiteBlackRedGreenBlueYellowMagentaCyanTransparencyOpaqueSemi-TransparentBackgroundColorBlackWhiteRedGreenBlueYellowMagentaCyanTransparencyOpaqueSemi-TransparentTransparentWindowColorBlackWhiteRedGreenBlueYellowMagentaCyanTransparencyTransparentSemi-TransparentOpaque
Font Size50%75%100%125%150%175%200%300%400%Text Edge
StyleNoneRaisedDepressedUniformDropshadowFont FamilyProportional
Sans-SerifMonospace Sans-SerifProportional SerifMonospace SerifCasualScriptSmall
Caps
Reset restore all settings to the default valuesDone
Close Modal Dialog

End of dialog window.




Python 3 PyGame Tetris Game GUI Script Desktop App Full Project For Beginners

python3 -m pip install -U pygame --user
pip install random2
pip install python-math
pip install python-time
pip install mixer


SOURCE CODE:

space_bullet_shooter.py

import pygame
import random
import math
import time

from pygame import mixer


pygame.init()

clock = pygame.time.Clock()
# bg sound
mixer.music.load("bg.wav")
mixer.music.play(-1)


score_value = 0


# setting the display
screen = pygame.display.set_mode((800, 600))

# background
bg = pygame.image.load("img2.png")

icon = pygame.image.load("icond.png")
pygame.display.set_caption("Space Bullet Shooter")
# display the icon
pygame.display.set_icon(icon)


# showing the bird imageo
playeimg = pygame.image.load("pl4.png")
playerx = 370
playery = 460

playerx_change = 0


def player(x, y):
    screen.blit(playeimg, (x, y))

 # moving the playerimag
 # for this we will use cordinate movement
 # we will pass arugument to the function


# for enemy
enemyimg = []
enemyX = []
enemyY = []
enemyX_change = []
enemyY_change = []

number_of_enemy = 6
for i in range(number_of_enemy):

    enemyimg.append(pygame.image.load("ens.png"))

    enemyX.append(random.randint(0, 736))
    enemyY.append(random.randint(50, 150))
    enemyX_change.append(4)
    enemyY_change.append(30)


# bullet
bulletimg = pygame.image.load("bullet.png")
bulletX = 0
bulletY = 480
bulletX_change = 0
bulletY_change = 20
bullet_state = "ready"
# function for enemy


def enemy(x, y, i):
    screen.blit(enemyimg[i], (x, y))


# function for fire bullet

def fire_bullet(x, y):
    global bullet_state
    bullet_state = "fire"
    screen.blit(bulletimg, (x+53, y+10))


# checking if collision
def is_collision(enemyX, enemyY, playerx, playery):

    distance = math.sqrt((math.pow(enemyX-bulletX, 2)) +
                         (math.pow(enemyY-bulletY, 2)))
    if distance < 27:
        return True

    else:
        return False


# showing score

font = pygame.font.Font("freesansbold.ttf", 35)
score_cordinate_X = 10
Score_cordinate_Y = 10


def showscore(x, y):
    score = font.render("Score : " + str(score_value), True, (255, 255, 255))
    screen.blit(score, (x, y))


OVER = pygame.font.Font("freesansbold.ttf", 60)
# game over


def game_over():
    over = OVER.render("GAME OVER   ", True, (0, 0, 255))
    screen.blit(over, (250, 250))


final = pygame.font.Font("freesansbold.ttf", 50)


def final_score():
    finalscore = final.render(
        "Total Score : " + str(score_value), True, (0, 255, 0))
    screen.blit(finalscore, (280, 350))


author = pygame.font.Font("freesansbold.ttf", 16)
# showing author name


def author_name():
    subject = author.render(
        "Copyright ©2020 TheKnight All Right Reseved By TheKnight ", True, (0, 255, 0))
    screen.blit(subject, (170, 580))


# game loop
running = True

while running:
    screen.fill((0, 0, 0))
    screen.blit(bg, (0, 0))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

        # controlling the bird by arrow keys

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                playerx_change = -5

            if event.key == pygame.K_RIGHT:
                playerx_change = 5

            if event.key == pygame.K_SPACE:
                if bullet_state == "ready":
                    bulletX = playerx
                    bulletsound = mixer.Sound("bulletout.wav")
                    bulletsound.play()

                    fire_bullet(bulletX, bulletY)

        if event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT or event.key == pygame.K_LEFT:
                playerx_change = 0

    for i in range(number_of_enemy):

        # game over
        if enemyY[i] > 440:

            for j in range(number_of_enemy):
                enemyY[j] = 2000
            game_over()
            time.sleep(2)

            final_score()

            break

        enemyX[i] += enemyX_change[i]
        if enemyX[i] <= 0:
            enemyX_change[i] = 4
            enemyY[i] += enemyY_change[i]

        elif enemyX[i] >= 736:
            enemyX_change[i] = -4
            enemyY[i] += enemyY_change[i]

        # collision

        collision = is_collision(enemyX[i], enemyY[i], bulletX, bulletY)
        if collision:
            bulletsound = mixer.Sound("bulletshoot.wav")
            bulletsound.play()
            bulletY = 480
            bullet_state = "ready"

            score_value += 1

            enemyX[i] = random.randint(0, 736)
            enemyY[i] = random.randint(50, 150)

        enemy(enemyX[i], enemyY[i], i)

    # checking boundries of spacechip
    playerx += playerx_change

    if playerx <= 0:
        playerx = 0
    elif playerx >= 730:
        playerx = 730

    # playerx -=0.2
    # playery -=.2

    # bullet movement
    if bulletY <= 0:
        bulletY = 480
        bullet_state = "ready"
    if bullet_state == "fire":
        fire_bullet(bulletX, bulletY)
        bulletY -= bulletY_change

    player(playerx, playery)
    showscore(score_cordinate_X, Score_cordinate_Y)

    author_name()

    pygame.display.update()
Code language: PHP (php)




OUTPUT:




DOWNLOAD ADDITIONAL FILES AND FOLDER.

Categories Python Tags Python
Python to Solve Linear Equation and return 3D Graph with Full Source Code For
Beginners
Python Speaking Dictionary with Full Source Code For Beginners
Sponsored Content
Recommended by
Skip Ad
▶


Skip
Ads by





LEAVE A COMMENT CANCEL REPLY

Comment

Name Email Website

Save my name, email, and website in this browser for the next time I comment.





Δ

report this ad

report this ad
Search for:


RECENT POSTS

 * React JS Interview Questions [Part – 1]
 * Sap ABAP 7.4 Question and Answers
 * Write a program to randomly generate a list with 5 numbers, which are
   divisible by 5 and 7, between 1 and 1000 inclusive
 * Write a program to randomly generate a list with 5 even numbers between 100
   and 200 inclusive
 * Write a program to generate a list with 5 random numbers between 100 and 200
   inclusive


report this ad
 * April 2023
 * March 2023
 * December 2022
 * November 2022
 * October 2022
 * September 2022
 * August 2022
 * July 2022
 * June 2022
 * April 2022
 * March 2022
 * February 2022
 * January 2022
 * December 2021
 * November 2021
 * October 2021
 * September 2021
 * August 2021
 * July 2021
 * June 2021
 * May 2021


PAGES

 * About Us
 * Contact Us
 * Privacy Policy

report this adreport this ad
© 2023 Program Solve


PLEASE ENABLE JAVASCRIPT IN YOUR BROWSER TO VISIT THIS SITE.





x

x

x