Games based on python

11 easy Games made in Python Programming

Python is not the most performant language for game development and other high-performance applications. However, it can still be used to create games, especially 2D games, and simple 3D games, thanks to its ease of use and wide range of libraries and frameworks such as Pygame, PyOpenGL, Panda3D, and Ren’Py. Choosing the right library or framework will depend on the type of game you want to make and your level of experience.

Below are some easy games you can build as a beginner to practice python language.

Easy games made in python

The games below, snake game, Tetris, and Pacman, are others in the list that are easy to code in python. You can make these games only using python code.

1. Snake

Snake is a fun game, super easy to code it using python, in which you get a snake on a board grid box. You let him feed, your food, and each time your snake eats, it grows a segment. Avoid poisonous pills or any obstacles that can kill it. Limit your boundary walls or use them as dimensions, like in Nokia mobiles. A fun game that you can make using Python codes.

Developing your own snake game in python is very straightforward. And things become even easier with the Pygame library.

Source code of Snake game in python

2. Tetris

Tetris is a puzzling game that can be made in Python code. An easy and fun project for beginners. It begins with an empty box and vertically falling randomized shapes. Put the shapes in order to avoid reaching the utmost border. If it does, you lose! Focus on each shape, and place them in such a way that they fit and make a perfect horizontal row. Perfect rows will get vanished, and you get points. Score high as you can!

3. Space Invaders

Space Invader is an arcade game that you can make in python. By Writing only python codes, this game can be made from scratch. In this game (as half of the gameplay is already covered by its name), you are on a space mission. On your way, some invaders-jets attack your aircraft, dodge them! Encounter their attacks, and make your move ahead. Complete all the stages, and mind it! Every next stage will step up the difficulty level.

4. Pac Man

Pac-man is another interesting game on the list that python can make. You get a squared box filled with tiny particles all around. On the box, there will be random lines like open tunnels to walk through your character. Eat as much as you can, and at the same time avoid touching foes that will be there after you. You touch, you lose! Build different stages for boosting up fun!

5. Skudo

Skudo is a kind of puzzle game that is also wholly written in Python. Basically, it’s a multiplayer number-based game where each player tries to score higher than the opponent by listing numbers on a grid or something similar to this. Actually, I don’t really understand this game until now. Somehow, I saw this game so many times in different places so, if you get it! Pick this game for your next python project.

Читайте также:  Videos in html format

6. Minigolf

Minigolf is a strategic game. The entire source code of this game is written in Python, and a YouTuber made this game in python. It’s a golf-sport game where you have to put a ball into a hole. You get limited moves to finish a stage and draw lines for the ball to move in that direction. Within the limits of moves, insert the ball into the hole. Despite this simple gameplay, the stages are a big challenge there!

7. Hangman (word-based game)

Hangman is a word-puzzled game that can be written in Python. The game’s concept is funny rather than puzzling such that a cartoonish man is hanging on a rod. You’ve to save him from dying, and for this, you have to make a word under the given slots. Use the English alphabet to compose an English word under given turns. You mistake, the man will be hanged! Save it, and do your best to make this possible.

8. Flappy Bird

Flappy bird is a popular classic game that is basically a usual project for python programmers. On Youtube, you can see that almost every python developer once makes this game for his subscribers. You fly a bird by tapping a certain key to perform little jumps. The Bird moves forward direction where it has to avoid obstacles coming in the way. You crash, you lose. Restart the game and score higher as you could! Each flying interval will speed up the gameplay, which means more challenge!

9. Chess

Chess is a top-level strategic game that you can also write in python. A YouTuber (Tim) made this and has a complete video on how to make the chess game in python. He made this game to be played online (Multiplayer). If you’ve ever played this chess game, try to write this game in python. Nonetheless, this project lists in the expert category. Best of luck!

10. Tic-tac-toe

Tic-tac-toe is a popular multiplayer turn-based strategy battle game, easily made with Python. In this video game, two players play together on a single board. Each carries a different mark (often, they’re a circle and a cross-mark).

One who marks first in a consecutive row wins the battle.

11. Rock-paper-scissor

Rock paper scissor is not a video game indeed. It’s rather a way to decide one will go first. Often players used this in physical action to toss before playing a physical game.

So, if you’re familiar with this game, and know how things work there. Luckily, you can build this using python, and it’s one of the easier projects that you can go after.

Читайте также:  Массив внутри массива javascript

Источник

Easy Games in Python

game

Today we’re going to learn how to code some easy games in Python using a few common Python modules.

Why are we using Python?

Python is a well-known programming language. Python is very easy to understand and code. It is believed to be developer-friendly. Any beginner can learn to code in python within a short span of time.

Some of most interesting features of this language are as follows :

  • Python is open source and free
  • Portable and dynamic
  • Super easy to understand etc.

Creating Easy Games in Python

Let’s now implement some easy games in Python that you can build as a beginner to get a headstart in your learning curve!

1. A Quiz Game in Python

This is a very simple text-based game in python. It a small quiz which you can make for yourself as well or your friends. We do not need to import any modules for this game which makes it easier! Try it yourself 😉

print('Welcome to AskPython Quiz') answer=input('Are you ready to play the Quiz ? (yes/no) :') score=0 total_questions=3 if answer.lower()=='yes': answer=input('Question 1: What is your Favourite programming language?') if answer.lower()=='python': score += 1 print('correct') else: print('Wrong Answer :(') answer=input('Question 2: Do you follow any author on AskPython? ') if answer.lower()=='yes': score += 1 print('correct') else: print('Wrong Answer :(') answer=input('Question 3: What is the name of your favourite website for learning Python?') if answer.lower()=='askpython': score += 1 print('correct') else: print('Wrong Answer :(') print('Thankyou for Playing this small quiz game, you attempted',score,"questions correctly!") mark=(score/total_questions)*100 print('Marks obtained:',mark) print('BYE!')
Welcome to AskPython Quiz Are you ready to play the Quiz ? (yes/no) :yes Question 1: What is your Favourite programming language?python correct Question 2: Do you follow any author on AskPython? yes correct Question 3: What is the name of your favourite website for learning Python?askpython correct Thankyou for Playing this small quiz game, you attempted 3 questions correctly! Marks obtained: 100.0 BYE!

2. Pong Game in Python

Most of us have heard about the famous pong game. Many of us love playing it. Today lets learn how to code this classic game using the python programming language!

Before starting with the coding part we first need to install the turtle module. The turtle module is a Python library that enables users to create pictures and shapes by providing them with a virtual canvas.

If you don’t already have it, you can install the library using pip.

C:\Users\Admin>pip install turtle

Read more about the turtle library in their official documentation.

import turtle as t playerAscore=0 playerBscore=0 #create a window and declare a variable called window and call the screen() window=t.Screen() window.title("The Pong Game") window.bgcolor("green") window.setup(width=800,height=600) window.tracer(0) #Creating the left paddle leftpaddle=t.Turtle() leftpaddle.speed(0) leftpaddle.shape("square") leftpaddle.color("white") leftpaddle.shapesize(stretch_wid=5,stretch_len=1) leftpaddle.penup() leftpaddle.goto(-350,0) #Creating the right paddle rightpaddle=t.Turtle() rightpaddle.speed(0) rightpaddle.shape("square") rightpaddle.color("white") rightpaddle.shapesize(stretch_wid=5,stretch_len=1) rightpaddle.penup() rightpaddle.goto(-350,0) #Code for creating the ball ball=t.Turtle() ball.speed(0) ball.shape("circle") ball.color("red") ball.penup() ball.goto(5,5) ballxdirection=0.2 ballydirection=0.2 #Code for creating pen for scorecard update pen=t.Turtle() pen.speed(0) pen.color("Blue") pen.penup() pen.hideturtle() pen.goto(0,260) pen.write("score",align="center",font=('Arial',24,'normal')) #code for moving the leftpaddle def leftpaddleup(): y=leftpaddle.ycor() y=y+90 leftpaddle.sety(y) def leftpaddledown(): y=leftpaddle.ycor() y=y+90 leftpaddle.sety(y) #code for moving the rightpaddle def rightpaddleup(): y=rightpaddle.ycor() y=y+90 rightpaddle.sety(y) def rightpaddledown(): y=rightpaddle.ycor() y=y+90 rightpaddle.sety(y) #Assign keys to play window.listen() window.onkeypress(leftpaddleup,'w') window.onkeypress(leftpaddledown,'s') window.onkeypress(rightpaddleup,'Up') window.onkeypress(rightpaddledown,'Down') while True: window.update() #moving the ball ball.setx(ball.xcor()+ballxdirection) ball.sety(ball.ycor()+ballxdirection) #border set up if ball.ycor()>290: ball.sety(290) ballydirection=ballydirection*-1 if ball.ycor() 390: ball.goto(0,0) ball_dx = ball_dx * -1 player_a_score = player_a_score + 1 pen.clear() pen.write("Player A: <> Player B: <> ".format(player_a_score,player_b_score),align="center",font=('Monaco',24,"normal")) os.system("afplay wallhit.wav&") if(ball.xcor()) < -390: # Left width paddle Border ball.goto(0,0) ball_dx = ball_dx * -1 player_b_score = player_b_score + 1 pen.clear() pen.write("Player A: <>Player B: <> ".format(player_a_score,player_b_score),align="center",font=('Monaco',24,"normal")) os.system("afplay wallhit.wav&") # Handling the collisions with paddles. if(ball.xcor() > 340) and (ball.xcor() < 350) and (ball.ycor() < rightpaddle.ycor() + 40 and ball.ycor() >rightpaddle.ycor() - 40): ball.setx(340) ball_dx = ball_dx * -1 os.system("afplay paddle.wav&") if(ball.xcor() < -340) and (ball.xcor() >-350) and (ball.ycor() < leftpaddle.ycor() + 40 and ball.ycor() >leftpaddle.ycor() - 40): ball.setx(-340) ball_dx = ball_dx * -1 os.system("afplay paddle.wav&")

Pong - easy games in Python

3. Hungry Snake Game in Python

This was most of our favorite game when we were kids. We can actually code this game in python by importing just two modules! How cool is that!

Читайте также:  Public class line java

Firstly, we need to install turtle. If you don’t have it already installed, open your cmd and type in the following command.

C:\Users\Admin>pip install turtle

Now we will install the random module. The random module is used to generate random numbers. In your cmd type in the following command.

C:\Users\Admin>pip install random2

Code and Try it yourself and enjoy the game!

import turtle import random w = 500 h = 500 food_size = 10 delay = 100 offsets = < "up": (0, 20), "down": (0, -20), "left": (-20, 0), "right": (20, 0) >def reset(): global snake, snake_dir, food_position, pen snake = [[0, 0], [0, 20], [0, 40], [0, 60], [0, 80]] snake_dir = "up" food_position = get_random_food_position() food.goto(food_position) move_snake() def move_snake(): global snake_dir new_head = snake[-1].copy() new_head[0] = snake[-1][0] + offsets[snake_dir][0] new_head[1] = snake[-1][1] + offsets[snake_dir][1] if new_head in snake[:-1]: reset() else: snake.append(new_head) if not food_collision(): snake.pop(0) if snake[-1][0] > w / 2: snake[-1][0] -= w elif snake[-1][0] < - w / 2: snake[-1][0] += w elif snake[-1][1] >h / 2: snake[-1][1] -= h elif snake[-1][1] < -h / 2: snake[-1][1] += h pen.clearstamps() for segment in snake: pen.goto(segment[0], segment[1]) pen.stamp() screen.update() turtle.ontimer(move_snake, delay) def food_collision(): global food_position if get_distance(snake[-1], food_position) < 20: food_position = get_random_food_position() food.goto(food_position) return True return False def get_random_food_position(): x = random.randint(- w / 2 + food_size, w / 2 - food_size) y = random.randint(- h / 2 + food_size, h / 2 - food_size) return (x, y) def get_distance(pos1, pos2): x1, y1 = pos1 x2, y2 = pos2 distance = ((y2 - y1) ** 2 + (x2 - x1) ** 2) ** 0.5 return distance def go_up(): global snake_dir if snake_dir != "down": snake_dir = "up" def go_right(): global snake_dir if snake_dir != "left": snake_dir = "right" def go_down(): global snake_dir if snake_dir!= "up": snake_dir = "down" def go_left(): global snake_dir if snake_dir != "right": snake_dir = "left" screen = turtle.Screen() screen.setup(w, h) screen.title("Snake") screen.bgcolor("blue") screen.setup(500, 500) screen.tracer(0) pen = turtle.Turtle("square") pen.penup() food = turtle.Turtle() food.shape("square") food.color("yellow") food.shapesize(food_size / 20) food.penup() screen.listen() screen.onkey(go_up, "Up") screen.onkey(go_right, "Right") screen.onkey(go_down, "Down") screen.onkey(go_left, "Left") reset() turtle.done()

Snake - easy games in Python

Conclusion

And that’s it! These are some of the easy games in Python that you can create as a beginner and have some fun! We loved building these projects and we hope you do too!

Источник

Оцените статью