Package: e2D
e2DA Python Game Development Librarye2D is an open-source Python game development library that aims to simplify the process of creating 2D games and apps using the popular Pygame framework. It provides a collection of utilities and environments to speed up game development and make it more enjoyable for developers of all skill levels.FeaturesEasy-to-Use: e2D is designed with simplicity in mind, making it accessible to both beginners and experienced developers.Efficient handling of keyboard and mouseinput for interactive gameplay.Powerfulvector calculationsfor easy position manipulation,distance calculation, andangle manipulation.Flexiblecolor manipulationfunctions for smooth transitions and visual effects.Convenient positioning andcollision detectionfunctions to handle game object interactions.Versatile: The library offers various utilities and environments that cater to different game genres and styles.Customizable: Developers can extend and modify e2D's functionality to suit their specific project requirements.Fast and Efficient: e2D can be used on top of Pygame, which is known for its performance and efficiency.Open-Source: e2D is distributed under the MIT License, allowing for free and unrestricted usage and modification.InstallationTo install e2D, you can use pip:pipinstalle2Dpip3installe2DUsage1.__init__.py__The__init__.pymodule is the entry point of the e2D library. It provides the following classes:Key Features:Easy Initialization: The V2 class can be easily initialized by providing the x and y components of the vector.Clean Representation: The V2 class provides a clean and readable representation of 2D vectors, making it easy to work with and understand.Lightweight: The V2 class is a lightweight implementation, making it suitable for performance-critical applications.Example 1: Basic Vector Operationsfrome2DimportV2# Create some 2D vectorsvector1=V2(3.0,4.0)vector2=V2(-1.0,2.5)# Perform vector additionresult_add=vector1+vector2print("Vector Addition:",result_add)# Output: Vector Addition: V2(2.0, 6.5)# Perform vector subtractionresult_sub=vector1-vector2print("Vector Subtraction:",result_sub)# Output: Vector Subtraction: V2(4.0, 1.5)# Perform vector scalingscalar=2.5scaled_vector=vector1*scalarprint("Vector Scaling:",scaled_vector)# Output: Vector Scaling: V2(7.5, 10.0)# Calculate the dot product of two vectorsdot_product=vector1.dot(vector2)print("Dot Product:",dot_product)# Output: Dot Product: 0.5# Calculate the magnitude (length) of a vectormagnitude=vector1.magnitude()print("Magnitude:",magnitude)# Output: Magnitude: 5.0# Normalize a vector (convert to unit vector)normalized_vector=vector1.normalize()print("Normalized Vector:",normalized_vector)# Output: Normalized Vector: V2(0.6, 0.8)# Calculate the distance between two points represented by vectorsdistance=vector1.distance_to(vector2)print("Distance between vectors:",distance)# Output: Distance between vectors: 6.324555320336759Example 2: Using Vectors in a Simple Physics Simulationfrome2DimportV2# Define the position and velocity of an objectposition=V2(0.0,0.0)velocity=V2(5.0,2.0)# Update the position based on velocity and timetime_step=0.1position+=velocity*time_stepprint("New Position:",position)# Output: New Position: V2(0.5, 0.2)Example 3: Calculating Forces in a 2D Physics Enginefrome2DimportV2# Define a force acting on an objectforce=V2(10.0,-5.0)# Define the mass of the objectmass=2.0# Calculate the acceleration of the object using Newton's second law (F = ma)acceleration=force/massprint("Acceleration:",acceleration)# Output: Acceleration: V2(5.0, -2.5)Example 4: Interpolating Between Two Pointsfrome2DimportV2# Define two points A and Bpoint_a=V2(0.0,0.0)point_b=V2(10.0,5.0)# Interpolate between the two points at t = 0.3t=0.3interpolated_point=V2.lerp(point_a,point_b,t)print("Interpolated Point:",interpolated_point)# Output: Interpolated Point: V2(3.0, 1.5)Example 5: Using Vectors in a Game Characterfrome2DimportV2classCharacter:def__init__(self,position):self.position=positionself.velocity=V2(0.0,0.0)defupdate(self,time_step):# Update the position based on velocity and timeself.position+=self.velocity*time_stepdefapply_force(self,force):# Calculate the acceleration and update velocity based on the applied forcemass=1.0# Assume mass is 1 for simplicityacceleration=force/massself.velocity+=acceleration# Create a character at position (0, 0)character=Character(V2(0.0,0.0))# Apply a force to the characterforce=V2(5.0,2.0)character.apply_force(force)# Update the character's position after 0.1 secondstime_step=0.1character.update(time_step)print("Character Position:",character.position)# Output: Character Position: V2(0.5, 0.2)These examples demonstrate various use cases of theV2orVector2Dclass, including basic vector operations, physics simulations, interpolation, and game character movement. TheV2class is versatile and can be used in a wide range of 2D applications and simulations.2.envs.pyTheenvs.pymodule provides theRootEnvclass, which acts as the root environment for a Pygame-based application.frome2D.envsimport*classGame:def__init__(self):self.position=V2(100,100)self.velocity=V2(5,2)defupdate(self):self.position=(self.position[0]+self.velocity[0],self.position[1]+self.velocity[1])defdraw(self):rootEnv.print("Game Position:{}".format(self.position),rootEnv.screen_size*.5,center_y=True,center_x=True)# Create a RootEnv with a screen size of 800x600 and target FPS of 60rootEnv=RootEnv(screen_size=V2(800,600),target_fps=60)# Initialize the game with the Game classgame=Game()rootEnv.init(game)# Game loopwhilenotrootEnv.quit:rootEnv.frame()2.utils.pyTheutils.pymodule provides various utility classes and functions for input handling and more.frome2D.envsimport*# e2D.utils is already importedclassGame:def__init__(self):self.position=V2(100,100)defupdate(self):# Move the position based on arrow key presseskeyboard=rootEnv.keyboardifkeyboard.get_key(pg.K_UP,mode=KEY_MODE_PRESSED):self.position=(self.position[0],self.position[1]-5)ifkeyboard.get_key(pg.K_DOWN,mode=KEY_MODE_PRESSED):self.position=(self.position[0],self.position[1]+5)ifkeyboard.get_key(pg.K_LEFT,mode=KEY_MODE_PRESSED):self.position=(self.position[0]-5,self.position[1])ifkeyboard.get_key(pg.K_RIGHT,mode=KEY_MODE_PRESSED):self.position=(self.position[0]+5,self.position[1])defdraw(self):# Draw a circle at the mouse position when the left mouse button is pressedmouse=rootEnv.mouseifmouse.just_pressed[0]:pg.draw.circle(rootEnv.screen,(255,127,0),rootEnv.mouse.position(),10)rootEnv.print("Game Position:{}".format(self.position),V2(10,10))# Create a RootEnv with a screen size of 800x600 and target FPS of 60rootEnv=RootEnv(screen_size=V2(800,600),target_fps=60)# Initialize the game with the Game classgame=Game()rootEnv.init(game)# Game loopwhilenotrootEnv.quit:rootEnv.frame()ContributingContributions to e2D are welcome! If you find any bugs or have suggestions for improvements, feel free to open an issue or submit a pull request.Licensee2D is open-source software licensed under theMIT License.ContactFor inquiries, you can reach me atricomari2006@gmail.com.AcknowledgementsThe e2D is developed and maintained bymarick-pybut is inspired by the Pygame library and various other game development resources. We would like to express our gratitude to the Pygame community and all the developers who have contributed to the open-source projects that made e2D possible.Thank you for using e2D! Happy game development! 🚀