![]() ![]() game_loop () def game_loop ( self ): self. hud, text = text ) def start_game ( self ): self. ![]() create_text ( x, y, text = text, font = font ) def update_lives_text ( self ): text = '' Lives : % s '' % self. items = brick def draw_text ( self, x, y, text, size = '' 40 '' ): font = ( '' Forte '', size ) return self. ball ) def add_brick ( self, x, y, hits ): brick = Brick ( self. get_position () x = ( paddle_coords + paddle_coords ) * 0.5 self. start_game ()) def add_ball ( self ): if self. draw_text ( 300, 200, '' Press Space to start '' ) self. move ( 10 )) def setup_game ( self ): self. direction = 1 elif x = 0 and coords + offset '', lambda _ : self. direction *= - 1 elif len ( game_objects ) = 1 : game_object = game_objects coords = game_object. ![]() _init_ ( canvas, item ) def update ( self ): coords = self. radius, fill = '' white '' ) super ( Ball, self ). item ) class Ball ( GameObject ): def _init_ ( self, canvas, x, y ): self. item, x, y ) def delete ( self ): self. item = item def get_position ( self ): return self. Import tkinter as tk class GameObject ( object ): def _init_ ( self, canvas, item ): self. Now, you can create your own breakout game using Odinub! Read more Num_bricks =len(_withtag('brick'))Įlif _position() >=self.height: X = (paddle_coords +paddle_coords) * 0.5ĭef draw_text(self, x, y, text, size='40'): Item =canvas.create_oval(x-self.radius, y-self.radius, The 'collide' function : As the name suggests this function will compute the collsions between the ball and the bricks, the paddle as well as the edge of the screen.The 'update' function : It will keep the track of the co-ordinates of the ball and constantly update them.The '_init_' function : It will contain the attributes of the ball like speed, radius and direction.This class will be the child class of the GameObject class. This class will contain the following functions. When this method is called an object is created from the class and it allows the class to initialize the attributes of the class. The ‘_init_’ is a reserved method in python. The 'def' is the keyword used as a function header of all the function i.e It is used to define a function. By using the ‘self ‘ keyword we can access all the attributes and methods of class python. The 'self' keyword is the instance of the class. Step 3: Creating the main class: classGameObject(object): sudo apt-get install python-tk python3-tk python-imaging-tk If you have not installed the package install it using the following command. Step 2: Importing the tkinter package import tkinter as tk Step 1: Creating a new file in gedit: gedit filename.py Python with tkinter gives the output is the fastest and easiest way to create GUI. It is a standard python interface to the Tk GUI toolkit which is shipped with python. Out of all the GUI methods, it is the most commonly used method. Pyth-on offers multiple options for developing GUI(Graphical User Interface). In the following article we will learn how to create a simple brick breaker game using python ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |