Monday, 3 January 2022

Mario-Game-Program-In-Python

 Mario-Game-Program-In-Python 

Simple Mario Game: 

Code:


import pygame

import sys

pygame.init()


WINDOW_WIDTH = 1200

WINDOW_HEIGHT = 600

FPS = 20

BLACK = (0, 0, 0)

GREEN = (0, 255, 0)

ADD_NEW_FLAME_RATE = 25

cactus_img = pygame.image.load('cactus_bricks.png')

cactus_img_rect = cactus_img.get_rect()

cactus_img_rect.left = 0

fire_img = pygame.image.load('fire_bricks.png')

fire_img_rect = fire_img.get_rect()

fire_img_rect.left = 0

CLOCK = pygame.time.Clock()

font = pygame.font.SysFont('forte', 20)


canvas = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))

pygame.display.set_caption('Mario')



class Topscore:

    def __init__(self):

        self.high_score = 0

    def top_score(self, score):

        if score > self.high_score:

            self.high_score = score

        return self.high_score


topscore = Topscore()



class Dragon:

    dragon_velocity = 10


    def __init__(self):

        self.dragon_img = pygame.image.load('dragon.png')

        self.dragon_img_rect = self.dragon_img.get_rect()

        self.dragon_img_rect.width -= 10

        self.dragon_img_rect.height -= 10

        self.dragon_img_rect.top = WINDOW_HEIGHT/2

        self.dragon_img_rect.right = WINDOW_WIDTH

        self.up = True

        self.down = False


    def update(self):

        canvas.blit(self.dragon_img, self.dragon_img_rect)

        if self.dragon_img_rect.top <= cactus_img_rect.bottom:

            self.up = False

            self.down = True

        elif self.dragon_img_rect.bottom >= fire_img_rect.top:

            self.up = True

            self.down = False


        if self.up:

            self.dragon_img_rect.top -= self.dragon_velocity

        elif self.down:

            self.dragon_img_rect.top += self.dragon_velocity



class Flames:

    flames_velocity = 20


    def __init__(self):

        self.flames = pygame.image.load('fireball.png')

        self.flames_img = pygame.transform.scale(self.flames, (20, 20))

        self.flames_img_rect = self.flames_img.get_rect()

        self.flames_img_rect.right = dragon.dragon_img_rect.left

        self.flames_img_rect.top = dragon.dragon_img_rect.top + 30



    def update(self):

        canvas.blit(self.flames_img, self.flames_img_rect)


        if self.flames_img_rect.left > 0:

            self.flames_img_rect.left -= self.flames_velocity



class Mario:

    velocity = 10


    def __init__(self):

        self.mario_img = pygame.image.load('maryo.png')

        self.mario_img_rect = self.mario_img.get_rect()

        self.mario_img_rect.left = 20

        self.mario_img_rect.top = WINDOW_HEIGHT/2 - 100

        self.down = True

        self.up = False


    def update(self):

        canvas.blit(self.mario_img, self.mario_img_rect)

        if self.mario_img_rect.top <= cactus_img_rect.bottom:

            game_over()

            if SCORE > self.mario_score:

                self.mario_score = SCORE

        if self.mario_img_rect.bottom >= fire_img_rect.top:

            game_over()

            if SCORE > self.mario_score:

                self.mario_score = SCORE

        if self.up:

            self.mario_img_rect.top -= 10

        if self.down:

            self.mario_img_rect.bottom += 10



def game_over():

    pygame.mixer.music.stop()

    music = pygame.mixer.Sound('mario_dies.wav')

    music.play()

    topscore.top_score(SCORE)

    game_over_img = pygame.image.load('end.png')

    game_over_img_rect = game_over_img.get_rect()

    game_over_img_rect.center = (WINDOW_WIDTH/2, WINDOW_HEIGHT/2)

    canvas.blit(game_over_img, game_over_img_rect)

    while True:

        for event in pygame.event.get():

            if event.type == pygame.QUIT:

                pygame.quit()

                sys.exit()

            if event.type == pygame.KEYDOWN:

                if event.key == pygame.K_ESCAPE:

                    pygame.quit()

                    sys.exit()

                music.stop()

                game_loop()

        pygame.display.update()



def start_game():

    canvas.fill(BLACK)

    start_img = pygame.image.load('start.png')

    start_img_rect = start_img.get_rect()

    start_img_rect.center = (WINDOW_WIDTH/2, WINDOW_HEIGHT/2)

    canvas.blit(start_img, start_img_rect)

    while True:

        for event in pygame.event.get():

            if event.type == pygame.QUIT:

                pygame.quit()

                sys.exit()

            if event.type == pygame.KEYDOWN:

                if event.key == pygame.K_ESCAPE:

                    pygame.quit()

                    sys.exit()

                game_loop()

        pygame.display.update()



def check_level(SCORE):

    global LEVEL

    if SCORE in range(0, 10):

        cactus_img_rect.bottom = 50

        fire_img_rect.top = WINDOW_HEIGHT - 50

        LEVEL = 1

    elif SCORE in range(10, 20):

        cactus_img_rect.bottom = 100

        fire_img_rect.top = WINDOW_HEIGHT - 100

        LEVEL = 2

    elif SCORE in range(20, 30):

        cactus_img_rect.bottom = 150

        fire_img_rect.top = WINDOW_HEIGHT - 150

        LEVEL = 3

    elif SCORE > 30:

        cactus_img_rect.bottom = 200

        fire_img_rect.top = WINDOW_HEIGHT - 200

        LEVEL = 4






def game_loop():

    while True:

        global dragon

        dragon = Dragon()

        flames = Flames()

        mario = Mario()

        add_new_flame_counter = 0

        global SCORE

        SCORE = 0

        global  HIGH_SCORE

        flames_list = []

        pygame.mixer.music.load('mario_theme.wav')

        pygame.mixer.music.play(-1, 0.0)

        while True:

            canvas.fill(BLACK)

            check_level(SCORE)

            dragon.update()

            add_new_flame_counter += 1


            if add_new_flame_counter == ADD_NEW_FLAME_RATE:

                add_new_flame_counter = 0

                new_flame = Flames()

                flames_list.append(new_flame)

            for f in flames_list:

                if f.flames_img_rect.left <= 0:

                    flames_list.remove(f)

                    SCORE += 1

                f.update()


            for event in pygame.event.get():

                if event.type == pygame.QUIT:

                    pygame.quit()

                    sys.exit()

                if event.type == pygame.KEYDOWN:

                    if event.key == pygame.K_UP:

                        mario.up = True

                        mario.down = False

                    elif event.key == pygame.K_DOWN:

                        mario.down = True

                        mario.up = False

                if event.type == pygame.KEYUP:

                    if event.key == pygame.K_UP:

                        mario.up = False

                        mario.down = True

                    elif event.key == pygame.K_DOWN:

                        mario.down = True

                        mario.up = False


            score_font = font.render('Score:'+str(SCORE), True, GREEN)

            score_font_rect = score_font.get_rect()

            score_font_rect.center = (200, cactus_img_rect.bottom + score_font_rect.height/2)

            canvas.blit(score_font, score_font_rect)


            level_font = font.render('Level:'+str(LEVEL), True, GREEN)

            level_font_rect = level_font.get_rect()

            level_font_rect.center = (500, cactus_img_rect.bottom + score_font_rect.height/2)

            canvas.blit(level_font, level_font_rect)


            top_score_font = font.render('Top Score:'+str(topscore.high_score),True,GREEN)

            top_score_font_rect = top_score_font.get_rect()

            top_score_font_rect.center = (800, cactus_img_rect.bottom + score_font_rect.height/2)

            canvas.blit(top_score_font, top_score_font_rect)


            canvas.blit(cactus_img, cactus_img_rect)

            canvas.blit(fire_img, fire_img_rect)

            mario.update()

            for f in flames_list:

                if f.flames_img_rect.colliderect(mario.mario_img_rect):

                    game_over()

                    if SCORE > mario.mario_score:

                        mario.mario_score = SCORE

            pygame.display.update()

            CLOCK.tick(FPS)



start_game()


Output:

Step 1:


Step 2:


Step 3:



Thursday, 9 December 2021

Python Programming

 Q1.The program takes two strings and displays which letters are in the first string but not in the second string.

Program:

my_str_1 = input("Enter the first string : ")
my_str_2 = input("Enter the second string : ")
my_result = list(set(my_str_1)-set(my_str_2))
print("The letters in first string but not in second string :")
for i in my_result:
   print(i)

Output:


                Download Code


Q2.Write a Python Program to find the union of two lists.

Sample Input:

lst1=[10,20,30,40,30,50,60]

lst2=[10,15,20,30,25,25]

Output:

lst3=[10,20,30,40,50,60,15,25]  # or in any other order


Program:

# Python program to illustrate union
# Maintained repetition
def Union(lst1, lst2):
    final_list = lst1 + lst2
    return final_list

# Driver Code
lst1 = [10,20,30,40,30,50,60]
lst2 = [10,15,20,30,25,25]
print(Union(lst1, lst2))

Output:


                Download Code

Wednesday, 28 July 2021

C

 C Programming

C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, with a static type system. By design, C provides constructs that map efficiently to typical machine instructions 

Saturday, 16 January 2021

Unix Command / Shall programming

 Unix Command    :

$logname - (Display the login name of user).
$exit - (Exit from the unique terminal).
$id - (Id no. of user).
$uname - (The name of the unique system).
$tty - (Display the terminal name).
$pwd - (Display the present working directory).
$date - (Display system date).
$date + %m - (System month).
$date + %h -(Display name of the month).
$date + %d - (Day of the system month).
$date + %y - (Display the system year).
$date + %h - (Hour of the system time).
$date + %m - (Display the minuet of system time).
$date + %s - (Display the second of system time).
$date + %m%s%h(Display the minuet , second & hours).
$clear - (Clear the screen).
$cal - (Calendar of current next , previous month).
$cal <year> - (Display the calendar of year).
$cal <June 2008> - (Display Only June calendar).
$echo - (Display text in normal format).
$banner <ABC> - (Bold and bigger format).
$echo path - (Display the current path).
$who -(List of the users at work).
$who i am -(Display particular terminal user).
$mkdir Narendra - (Create a directory name Narendra).
$cd - (Change directory).
$cd .. - (Change to current directory to previous directory).
$ls - (Long listing of directory).
$cal - (Display record of the file).
$chmod - (To change directory permissions).
$chmod go - x <file name> -(Not execute from group other).
$chmod +x <file name> - (To allow executable permissions).
$chmod +rwx <file name> - (To add permissions).
$chmod -rwx <file name> - (Directory name to remove permissions).
$chmod -wx <file name> - (File name to take out write and executable permissions).
$ls -m* - (All the files starting with m).
$ls -x - (Read wise file listing).
$ls -r -(Sort in reverse order).
$ls -(All file list in sorted order).
$ls -fx -(Display start after all directory and executive file).
$s-tu -(Sorts file by access time).
$ls -t  -(Sort file by modification time).
$wc <F1> -(Count the line , word , character of F1 file).
$cp <file1 file2> -(Copy the content of file1 to file2).
$x=5 -(Assign a value of a variable).
$bc 10/2*3=15
$man - (Can get all features and functionality).
$spell <f1> - (List of wrong spelling of f1 file).
$lp <f1> - (Printing a file).
$comm <f1 f2> - (Compare file line wish and display the common text).
$set - (Display all system variable).
$finger - (Display detail of user).
$greap -(Such in the part in the file and return the line number in which they were found).
$gzip - (Produces a compress zip file).
$gunzip - (Uncompressed file).
$du - (Generate of the report of the user).
$df - (Generate the report of disk free).
$ulimit - (User limit indicate).
$ping - (The command will begin printing the result).
$sort <f1> - (Sort the file contains f1).
$head -10 <f1> - (Display of 10 line of the file).
$tail -10 <f1> - (Last 10 line of the file).
$ps - (Indicate which process are running current instant).

Example 1:

create a directory name.
D: Name1.1
F: f1(output of ls)
F: f2(blank file)
D: Name1.1.1
F:f3
F:f4
Remove f3 as f3.1
copy the content of f1 to f2
create another directory Name1.1.2 inside Name1.1
Delete the directory.
Give read ,write ,executed permission for f2 to others.
with down executed permission from group.
move f3.1 to Name1.1
(Name will your Name, F denotes file and D denotes directory).


Example 2 :
Create a directory cst create another directory cst 1.1 inside cst directory. Inside cst1.1 there are two files f1 and f2. F1 contains output of ls. And f2 is a blank file. Rename f2 as f2.1





Wednesday, 13 January 2021

History of java

 history of java:

In java was developed by James Gosling, who is known as the father of Java, in 1995. James Gosling and his team members started the project in the early '90s.Currently, Java is used in internet programming, mobile devices, games, e-business solutions, etc. There are given significant points that describe the history of Java programming.

 java was started as a project called "Oak" by James Gosling in June 1991.James Gosling, Mike Sheridan, and Patrick Naughton  initiated the Java language project in June 1991. The small team of sun engineers called "Green Team".


Mario-Game-Program-In-Python

  Mario-Game-Program-In-Python  Simple Mario Game:   Code: import pygame import sys pygame.init() WINDOW_WIDTH = 1200 WINDOW_HEIGHT = 600 FP...