gamengine2d is a python pypi package designed to make games in 2d with python simple.
You can view the youtube tutorial here:
To get started, first install gamengine3d with:
The vector2d class
The vector2d class is a class that holds a 2-dimensional vector with x and y components. To create a vector2d instance, you can use vector2d(x value, y value), and you can access the instance’s .x and .y attributes. If only 1 argument is provided, such as vector2d(60), then both components will be set to that value. If 2 arguments are provided, they are used for x and y respectively.
By taking v as vector2d(1, 4), the vector2d class supports:
magnitude as a property that gets the magnitude of the vector — v.magnitude
sqr_magnitude as a property that gets the squared magnitude of the vector — v.sqr_magnitude
normalize as a method that normalizes the vector in place — v.normalize()
normalized as a property that returns a new normalized vector — v.normalized
dot product as a method that takes another vector2d and returns the dot product of the vectors — v.dot(other vector2d object)
addition of 2 vectors that adds each component of one vector to the corresponding component of the other — v + other vector2d object
addition of a vector and a scalar that adds the scalar to each component of the vector — v + scalar
subtraction of 2 vectors that subtracts each component of one vector from the corresponding component of the other — v - other vector2d object
subtraction of a vector and a scalar that subtracts the scalar from each component of the vector — v - scalar
multiplication of 2 vectors that multiplies each component of one vector with the corresponding component of the other — v * other vector2d object
multiplication of a vector with a scalar that multiplies each component of the vector with the scalar — v * scalar
division of 2 vectors that divides each component of one vector by the corresponding component of the other — v / other vector2d object
division of a vector by a scalar that divides each component of the vector by the scalar — v / scalar
converting the vector into a tuple as a method — v.totuple()
creating a vector2d object from a tuple as a method — vector2d.fromtuple(tuple containing x and y values)
copying a vector2d object and returning it into another variable as a method — v.copy()
negating the vector that multiplies both components by –1 — -v
The vector2d class has a built-in __repr__ method that returns a string like vector2d(x value, y value). You can also use vector2d.up as a property to get a vector2d object pointing upwards, same for down, right, and left. You can also use vector2d.one to get a vector2d object with both components equal to 1, and vector2d.zero to get a vector2d object with both components equal to 0.
The Color class
The Color class is a class that has built in colors and functionality. It has an r, g, and b value for each instance. After creating a Color instance, you can access its .r, .g, and .b values. You can create a color class with rgb values using :
Color(r value, g value, b value).
The Color class supports:
getting color from hex values as a method -- Color.hex(hex code starting with #)
comparing Color instances to see if they are the same color -- color_instance1 == color_instance2
converting to hex as a method -- color_instance.to_hex()
converting to rgb as a method -- color_instance.to_rgb()
The Color class also has built in colors like using Color.color_name, like:
Color.black
Color.white
Color.red
Color.green
Color.blue
Color.yellow
Color.cyan
Color.magenta
Color.grey
Color.light_grey
Color.light_red
Color.light_green
Color.light_yellow
Color.light_blue
Color.orange
The Engine class
The Engine class is used to create the actual game engine object in order to create the game. It creates a new window with the scene when the instance's run() method is called. While creating an instance, the first argument is the width of the window (px) that will be created, the second argument is the height of the window (px), the resizable argument allows the user to select whether the window should be resizable or always have the same dimensions. The name argument becomes the name of the window created. the background_color argument is set as the background color for the window.