Author - StudySection Post Views - 130 views
Develop Graphical

Develop Graphical Projects In Python

In this topic, we will discuss how someone can develop Graphical projects (say a simple 2D game) in Python. Here we will show how to use the Ursina Game Engine. Basically, the Ursina Game Engine is powered by Python. By using Ursina Game Engine we can develop anything like 2D games, 3D games, applications, Visualizations, etc.
Using Game Engine is an open-source project free to use, it was launched in 2019. It is entirely built in Python. It has compatibility with Photoshop and Blender (accepts files from both). It is very easy to install and use, one can directly install it using the following command:
pip install ursina
or
pip install git+https://github.com/pokepetter/ursina.git

In other game engines developers found certain problems:

  • Wait for the code to compile
  • Overlay verbose code
  • Subscription fee/revenue cut
  • Waiting for imports
  • Much longer built times
  • Adding new features is not easy
  • Bug fixing is not easy
  • The possibility of losing code if IDE crashed.

The Ursina Game Engine solves almost all the above problems. It has some very useful features as below:

  • Developers can directly code, textures, functions, and models while in the game.
  • It can easily import .psd and .blend files because of compatibility with photoshop and blender.
  • Developers can play in full screen while developing.
  • Make it very easy to use mesh class for making geometry.
  • Included procedural 3D primitives.

Advantages of using Ursina Game Engine:

  • Make any type of game.
  • Iterate faster between modules/assets.
  • Provide a very modern UI for development.
  • It has many things included like the following:
    • Includes very easy use of mesh class for making geometry.
    • Includes built-in animation
    • Pre-made first-person controller, 2D platform control, and camera control.
    • Many shaders are available to select and developers can write their own.
  • Free to use under MIT license.

Dependencies and Platforms:

  • Python3.6 and above
  • pillow for texture
  • Blender or photoshop for .blend or .psd files
  • Payerclip for copy and paste
  • Windows
  • Ubuntu
  • Mac
  • psutil for managing space

Example:

2D car game using Ursina Game Engine
A 2d car game is basically a two-dimensional graphical racing game in which a car is racing through other cars on a road. One can control the movement of a car using ‘w’, ‘a’, ‘s’, ‘d’(to move forward, left, backward, and right respectively). This is a very simple project in which we use Python and Ursina. Python and Ursina make it quite easy to make it under 50 lines of code.

Code:

# Importing Libraries
from ursina import *
import random
app = Ursina()
# Setting Camera View
camera.orthographic = True
# Importing Car
car = Entity(model = 'quad', texture = 'Resource/car', collider = 'box', scale = (5,2), rotation_z = 90, y = -3)
# Importing road
road_1 = Entity(model = 'quad', texture = 'Resource/road', scale = 40, z = 1)
road_2 = duplicate(road_1, y = 15)
pair = [road_1, road_2] # Importing Enemies
enemies = [] def newEnemy():
val = random.uniform(-4,3)
new = duplicate(car, texture = 'enemy', x = 2*val, y = 25, color = color.random_color(), rotation_z = -90 if val < 0 else 90)
enemies.append(new)
invoke(newEnemy, delay = 1)
newEnemy()
# For Changing the Position of the Car by 'a', 'd'
def update():
car.x -= held_keys['a']*10*time.dt
car.x += held_keys['d']*10*time.dt
car.y -= held_keys['s']*5*time.dt
car.y += held_keys['w']*5*time.dt
for road in pair:
road.y -= 6*time.dt
if road.y < -15:
road.y += 30
for enemy in enemies:
if enemy.x < 0:
enemy.y -= 10*time.dt
else:
enemy.y -= 5*time.dt
if enemy.y < -15:
enemies.remove(enemy)
destroy(enemy)
if car.intersects().hit:
car.shake()
app.run()

Get certification for your knowledge in the fundamentals of Computer functioning by clearing the Computer Certification Exam conducted by StudySection. After going through this Computer Certification exam, you will be able to evaluate your basic knowledge of computers.

Leave a Reply

Your email address will not be published. Required fields are marked *

fiteesports.com rivierarw.com cratosroyalbet betwoon grandpashabet grandpashabet giriş deneme bonusu veren siteler casino siteleri