Package: tools-for-pygame
Pygame ToolsThis module offers many useful tools that make using pygame easier.The goal of this package is to be as reliable as possible offering
many customization options.Any release before 1.0.0 or of which the first version number changes
can have non backwards compatible changesElementsThe element is the base building block of the package, almost every
class inherits from the base Element class and adds some functionality
on top.An element, in its most basic form, has a position, a size and an
image. Elements can be anchored to other elements to change their
position dynamically, can be rotated around a pivot and scaled without
loosing any quality of the original image.# Declaration of an elementelement=pgt.Element(pos=(100,100),size=(100,70),image=pgt.load_image('sample_image.png'))AnimationsA subclass of Element is AniElement, an element with animations.Animations are very flexible allowing you to change any attribute of
an element, at a constant rate.Animations support both a predefined list of frames and a function
that returns the appropriate value.
You can also create your custom animation by creating a class that
inherits from AniBase and defining a couple of methods!# Creating an animation that changes the alpha of an elementclassMyAnimation(pgt.AniBase):defstart(self,*args,**kwargs):self.element_val=self.e.alphasuper().start(*args,**kwargs)defset_element(self):self.e.alpha=pgt.clamp(0,255,self.get_frame())defreset_element(self):self.e.alpha=self.element_valGUIPygame Tools also adds a basic GUI system that implements buttons,
text labels, text boxes, draggable elements, sliders, and a layout
system that allows you automatically position elements.# Creating a simple button that prints "Hello, world"button=pgt.gui.Button(pos=(100,100),size=(200,60),image=pgt.draw.aa_rect(surface=None,rect=pygame.Rect(0,0,200,60),color=pgt.GRAY(220),corner_radius=10),func=print,func_args=["Hello, world!"])DrawPygame Tools adds some new draw functions that should probably be
in pygame itself. It adds anti-aliased versions of rects, circles
(in pygame anti-aliased circles are only empty) and lines.
The last one is present in pygame but doesn't allow you to change
its thickness.# Getting a rectangle with rounded corners imagesimg=pgt.draw.aa_rect(# With no surface the function just returns the created imagesurface=None,rect=pygame.Rect(0,0,100,100),color=pgt.WHITE,corner_radius=20,border_width=10,border_color=pgt.BLACK)LangPygame Tools introduces a useful .lang file loader that allows you
to easily implement many languages inside your game, and it's designed
to allow an easy resource-pack implementation.:: This is an example of a .lang file
%=utf-8
:: a set is a container for related strings
$this_is_a_set
  :: attributes contain strings
  @this_is_an_attribute:And this is it's value
  :: references get the value of the specified attribute or set
  .~@this_is_a_reference;this_is_an_attributeMathPygame Tools adds many useful functions such as easings.In the math module there is also a very useful Pos (and Size) class
that can be used to access both the x and y components of the point
simultaneously.# The point class has 'x' and 'y' as attributesp1=Point(2,3)p2=pgt.Pos(2,3)speed=[10,5]# Move the point by the speedp1.x+=speed[0]p1.y+=speed[1]p2+=speed# With Pos it's more concise and readable