The loop should update afer every 1/12th pf the secĬreate a new folder and open it in a code editor of your choice. Score_text = font.render('Score : ' + str(score), True, (255, 255, 255))Ĭlock.tick(FPS) # keep loop running at the right speed (manages the frame/second. Half_fruit_path = "images/" + "half_" + key + ".png" #if the user clicks bombs for three time, GAME OVER message should be displayed and the window should be reset If value value and current_position value and current_position < value+60: Value += 1 #increasing speed_y for next loop Value += (1 * value) #increasing y-corrdinate Value += value #moving the fruits in y-coordinate Value += value #moving the fruits in x-coordinates Game_running = True #used to manage the game loopĭraw_lives(gameDisplay, 690, 5, player_lives, 'images/red_lives.png') Game_over = True #terminates the game While loop if more than 3-Bombs are cut Img_rect.y = y #takes care of how many pixels the cross icon should be positioned from top of the screenĭraw_text(gameDisplay, "FRUIT NINJA!", 90, WIDTH / 2, HEIGHT / 4)ĭraw_text(gameDisplay,"Score : " + str(score), 50, WIDTH / 2, HEIGHT /2)ĭraw_text(gameDisplay, "Press a key to begin!", 64, WIDTH / 2, HEIGHT * 3 / 4) Img_rect.x = int(x + 35 * i) #sets the next cross icon 35pixels awt from the previous one Img_rect = img.get_rect() #gets the (x,y) coordinates of the cross icons (lives on the the top rightmost side) GameDisplay.blit(text_surface, text_rect)ĭef draw_lives(display, x, y, lives, image) : Text_surface = font.render(text, True, WHITE) # Generic method to draw fonts on the screenįont_name = _font('comic.ttf')ĭef draw_text(display, text, size, x, y): GameDisplay.blit(("images/red_lives.png"), (x, y)) # Dictionary to hold the data the random fruit generation If random.random() >= 0.75: #Return the next random floating point number in the range [0.0, 1.0) to keep the fruits inside the gameDisplay 'throw': False, #determines if the generated coordinate of the fruits is outside the gameDisplay or not. 'speed_y': random.randint(-80, -60), #control the speed of fruits in y-directionn ( UP ) 'speed_x': random.randint(-10,10), #how fast the fruit should move in x direction. 'x' : random.randint(100,500), #where the fruit should be positioned on x-coordinate # Generalized structure of the fruit Dictionary Lives_icon = ('images/white_lives.png') #images that shows remaining lives Score_text = font.render('Score : ' + str(score), True, (255, 255, 255)) #score display GameDisplay = _mode((WIDTH, HEIGHT)) #setting game display sizeīackground = ('back.jpg') #game backgroundįont = (os.path.join(os.getcwd(), 'comic.ttf'), 42) In our case, it will refresh every 1/12th second #2 Copy and paste the fruit ninja python codeįruits = #entities in the gameįPS = 12 #controls how often the gameDisplay should refresh. Wait for installation to complete after that you will have python installed, you can check it by typing python in your command prompt or terminal. The first step is to set up python on your computer so first you need to go to the python website and download the latest python version it will download the python installer.Īfter downloading you need to execute the python installer it will install and setup python on your computer, remember to check add python to path while installing. I will guide you till the end till you run the game so if you have python installed and setup then you can skip the first step now let’s start. The game is simple the fruits will start coming from the bottom the player has to slice it before they fall down on each slice they will get a point if the player slices a bomb by mistake then it is game over. Step By Step Tutorial To Create Fruit Ninja Game In Python Inorder to create this game in python we will use the pygame library, it is a library used to create games in python, It is one of the best python library for game development in python. Want to create fruit ninja game in python, then you are at the right place, the Fruit Ninja game is one of the most popular games, It is a game where fruits appear on the screen and you have to slice them by tapping them.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |