Posts

Showing posts from August, 2020

How to create a box pusher game with Python and Pygame Source Code (2020)

Image
This game needs two files, first is the box_pusher.py file, second is the box_pusher_game_level.py file. I have added just 31 levels, there are another 200 levels. I wll add those levels later. Those two files need to be placed inside the same folder as the pictures below. Three pictures are all 20x20 pixels and need to be placed in the same folder as the source code. # box_pusher.py import pygame , sys from pygame.locals import * from box_pusher_game_level import game_level SCREEN_WIDTH = 640 SCREEN_HEIGHT = 480 BOARD_WIDTH = 20 BOARD_HEIGHT = 16 CELL_SIZE = 20 FPS = 30 START_POS = ( 119 , 79 ) # color preset WHITE = ( 255 , 255 , 255 ) BLACK = ( 0 , 0 , 0 ) RED = ( 255 , 0 , 0 ) GREEN = ( 0 , 255 , 0 ) BLUE = ( 0 , 0 , 155 ) # game level dictionary # 'B' represent bricks # 'M' represent marks # 'O' represent boxes # 'P' represent player ##game_level = { ## 1: ( ## '...................

How to create a Tetris clone with python and pygame (2020 tutorial)

Image
 This is a simple python game, use left and right arrows to move left and right. # tetris import pygame , sys , random , time from pygame.locals import * SCREEN_WIDTH = 640 SCREEN_HEIGHT = 480 BOARD_WIDTH = 10 BOARD_HEIGHT = 20 SQUARE_SIZE = 20 # coordinates of the board's top-left corner START_POS = ( 218 , 78 ) # fps FPS = 30 # color set up WHITE = ( 255 , 255 , 255 ) BLACK = ( 0 , 0 , 0 ) RED = ( 255 , 0 , 0 ) GREEN = ( 0 , 255 , 0 ) BLUE = ( 0 , 0 , 255 ) LIGHT_GREEN = ( 144 , 238 , 144 ) # define shapes # T shape data structure t_shape = [[ ' ' , ' * ' , ' *** ' , ' ' , ' ' , ], [ ' ' , ' *** ' , ' * ' , ' ' , ' ' , ], [ ' ' , ' * ' , ' ** ' , ' * ' , ' '