Skip to main content

Posts

Showing posts from April, 2017

Events Handling

Events in a game are the different things that happen during a game. Games are controlled by the user inputs either through mouse or keyboard. Whenever the user gives an input in some way to the game, the game has to react correspondingly according to what the user expects. Handling these events to produce some output is known as Event Handling. Suppose the user opens a game. The user has option to quit the game any time they want.There are keyboard button controls for playing the game as well as mouse clicks and motions. Every event is tracked by the pygame and it is our duty to just instruct what to do if that event occurs. There are many types of events in pygame. Some of them are : QUIT ACTIVEEVENT KEYDOWN KEYUP MOUSEMOTION MOUSEBUTTONUP MOUSEBUTTONDOWN VIDEORESIZE Let me write a code to show how the events are identified in  pygame. import pygame pygame.init() display=pygame.display.set_mode((500,500)) game_loop=False while not game_loop: ...

Introducing Pygame

Hello Everyone! Let's get into the most interesting topic. We are going to see how we design games using python programming language, Let me introduce you to ' pygame' . Pygame is an open-source and free python library which is used for creating multimedia applications like games built on the top of an excellent SDL library. Pygame is highly portable and can be run on nearly any platform and operating system. First of all,We need to download the pygame library which can be downloaded from the official Pygame  website. Several versions of pygame compatible for the various versions of python are available. We need to select the appropriate version of pygame for our version of python and download and install it. Here i use Python-2.7. So i downloaded pygame-1.9.1 For using pygame library in a python program, like importing any other module, we must import pygame using the command.               import pygame You can also check if you ...

Python functions and modules

Functions are a block of code that performs the task specified. They either just perform some computation and display the result or returns the result to the main function. In python, functions are defined with the keyword 'def'. The syntax for defining a function in python is : def function_name :       #Block of statements The keyword def is followed by the name of the function. It is a good practise to name the functions meaningfully representing the task done by it. The function name is followed by a colon (:). In python, Comments are represented by the symbol #. So here #Block of statements is commented and hence it will not be executed by the compiler. # is used to comment one line of code. ''' .......''' is used to comment a block of code. For example, #this is a commented line of code. ''' this is a block of commented code Everything in this code will not be looked into by the compiler This is helpful in comment...