Pages

Se afișează postările cu eticheta 2020. Afișați toate postările
Se afișează postările cu eticheta 2020. Afișați toate postările

sâmbătă, 7 noiembrie 2020

PyGame : Install pygame 2.0 from GitHub on Linux.

Let's install all Fedora packages need for this python package:
[root@desk pygame]# dnf install SDL2-devel.x86_64 
...
Installed:
  SDL2-devel-2.0.12-4.fc33.x86_64                                               

Complete!
[root@desk pygame]# dnf install SDL2_ttf-devel.x86_64
...
Installed:
  SDL2_ttf-2.0.15-6.fc33.x86_64       SDL2_ttf-devel-2.0.15-6.fc33.x86_64      

Complete!
[root@desk pygame]# dnf install SDL2_image-devel.x86_64
...
Installed:
  SDL2_image-2.0.5-5.fc33.x86_64      SDL2_image-devel-2.0.5-5.fc33.x86_64     

Complete!
[root@desk pygame]# dnf install SDL2_mixer-devel.x86_64 
...
Installed:
  SDL2_mixer-2.0.4-7.fc33.x86_64      SDL2_mixer-devel-2.0.4-7.fc33.x86_64     

Complete!
[root@desk pygame]# dnf install SDL2_gfx-devel.x86_64 
...
Installed:
  SDL2_gfx-1.0.4-3.fc33.x86_64        SDL2_gfx-devel-1.0.4-3.fc33.x86_64       

Complete!
[root@desk pygame]# dnf install portmidi-devel.x86_64 
...
Installed:
  portmidi-devel-217-38.fc33.x86_64                                             

Complete!
Use this command to clone it from GitHub and install it:
[mythcat@desk ~]$ git clone https://github.com/pygame/pygame
Cloning into 'pygame'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 38509 (delta 0), reused 0 (delta 0), pack-reused 38505
Receiving objects: 100% (38509/38509), 17.78 MiB | 11.66 MiB/s, done.
Resolving deltas: 100% (29718/29718), done.
[mythcat@desk ~]$ cd pygame/
[mythcat@desk pygame]$ python3.9 setup.py install --user


WARNING, No "Setup" File Exists, Running "buildconfig/config.py"
Using UNIX configuration...


Hunting dependencies...
SDL     : found 2.0.12
FONT    : found
IMAGE   : found
MIXER   : found
PNG     : found
JPEG    : found
SCRAP   : found
PORTMIDI: found
PORTTIME: found
FREETYPE: found 23.4.17

If you get compiler errors during install, double-check
the compiler flags in the "Setup" file.
...
copying docs/pygame_tiny.gif -> build/bdist.linux-x86_64/egg/pygame/docs
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying pygame.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pygame.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pygame.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pygame.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pygame.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pygame.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
creating dist
creating 'dist/pygame-2.0.1.dev1-py3.9-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing pygame-2.0.1.dev1-py3.9-linux-x86_64.egg
creating /home/mythcat/.local/lib/python3.9/site-packages/pygame-2.0.1.dev1-py3.9-linux-x86_64.egg
Extracting pygame-2.0.1.dev1-py3.9-linux-x86_64.egg to /home/mythcat/.local/lib/python3.9/site-packages
Adding pygame 2.0.1.dev1 to easy-install.pth file

Installed /home/mythcat/.local/lib/python3.9/site-packages/pygame-2.0.1.dev1-py3.9-linux-x86_64.egg
Processing dependencies for pygame==2.0.1.dev1
Finished processing dependencies for pygame==2.0.1.dev1
Let's test it:
[mythcat@desk pygame]$ ls
build	     dist  examples	    README.rst	setup.cfg  src_c   test
buildconfig  docs  pygame.egg-info  Setup	setup.py   src_py
[mythcat@desk pygame]$ python3.9
Python 3.9.0 (default, Oct  6 2020, 00:00:00) 
[GCC 10.2.1 20200826 (Red Hat 10.2.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 2.0.1.dev1 (SDL 2.0.12, python 3.9.0)
Hello from the pygame community. https://www.pygame.org/contribute.html
>>> 

PyGame : The new pygame 2.0 .

A few days ago PyGame celebrated the anniversary of this python module ...
The 28th of October 2020 is the pygame 2.0 release date because pygame turns 20 years of age.
Here's what we find for pygame on GitHub.
Here are some of the 3306 changes...
  • Support for Metal, Direct 3d, Vulkan, OpenGL 3.0+ in various profiles (core, compatibility, debug, robust, etc), OpenGL ES, and other modern hardware-accelerated video APIs across many platforms.
  • SSE2/Neon assembly image drawing. Much faster drawing routines, image loading, and alpha blending.
  • Type Hints, for code completion (and to help you make the squiggly lines disappear) in editors and IDEs.
  • Code cleanup, using lots of code robustness tools like static analyzers, and automated CI/CD. We've been able to help dozens of people new to community projects contribute. We have lots of work to go on code quality, but we're currently the highest rated Python and highest rate C large project on LGTM.
  • Many, many bug fixes including in our pygame.draw routines, pygame.math(for vectors), and pygame.mask for pixel-perfect collision detection.
  • better support for PyPy (the fast JIT based implementation of python). See our milestone
  • Are we pypy yet? No. for our progress on making PyPy the best python for games.
  • libsdl version 2 support. Technically pygame 2.0 still works with SDL 1, but we recommend SDL2 which is vastly improved over SDL1 for most use cases. Probably we will remove SDL 1 support starting pygame 2.1.
  • Touch support (multitouch, gestures, etc)
  • Audio input support (make games with your microphone!).
  • Message alert boxes (Press OK, or Cancel).
  • Better keyboard support. Proper Unicode input and IME support.
  • Much improved game controller support.
  • Better image and audio format support. Including webp, 32bit Wav files, and much more reliable mp3 support.
  • Multiple display support, and multiple window support (multi-window support is still experimental, more will come in pygame 2.1).
  • Android support through python for android (a fork of pygame subset for android). Better documentation and better support will come in future releases.
  • to make distributing your apps easier, a built-in "pyinstaller hook" and compatibility with cxfreeze.
  • binary "wheels" on many platforms and versions of python from the old python 2.7 - to the latest python 3.9 (and with pypy!).
  • lots of quality of life improvements like Surface.fill('black')instead of Surface.fill(pygame.Color(0, 0, 0)). Also, keywords are supported by many more function arguments. You can draw rounded corners on rects.
  • plenty of new examples, like, and python3 -m pygame.examples.music_drop_fade. Additionally, the example source code has been cleaned up a lot to follow a more current python style.
  • Hundreds of documentation improvements include a new Korean tutorial.
  • a special SCALED mode that takes low pixel games and automatically translates them to a larger window. Imagine your 320x200 resolution game of glorious pixel art... on modern screens that would be a very tiny window. Now with SCALED, it shows up big on a Full HD screen, or even a 4K/8K screen and the translation of mouse coordinates and up-scaling of pixels is done for you (hardware accelerated of course).

sâmbătă, 4 iulie 2020

PyGame : Positional axes - part 005.

The goal of this tutorial is to use python classes, inheritance, and draw positional axes for rectangles. I used two simple python scripts to solve these issues. This python script named testing_axes.py I create two classes named Point_XY and Columns_XY:
import random
#
class Point_XY:
    def __init__(self):
        self.x = random.randrange(400)
        self.y = random.randrange(400)
        self.dx = random.randrange(50)+10
        self.dy = random.randrange(50)+10

    def __repr__(self):
        return "" % (self.x, self.y)

    def __str__(self):
        return "From str method of Point_XY: a is %s, b is %s" % (self.x, self.y)
#   
class Columns_XY(Point_XY):
    def __init__(self):
        column = []
        p = Point_XY()
        self.column = (p.x, p.y, p.dx, p.dy)
        print(column)
        
    def __repr__(self,p):
        return "" % (self.column)
    
    def __str__(self):
        return "From str method of Columns_XY :%s>" % (self.column)
'''    
if __name__ == "__main__":
    Columns_XY()
    pass
'''
With this script named pygame_testing_axes.py I draw columns and axes:
import sys
import pygame
from pygame.locals import *
from testing_axes import *

# define a square for each column
squares = []
# create column position x,y and rect size dx, dy
def create_columns_rect(n):
    for i in range(n):
        col = Columns_XY()
        #print(col.column)
        squares.append(col.column)
    #print(squares)
    return squares
def main():
    # init PyGame
    pygame.init()
    # set size of screen
    size_screen = (640,480)
    # create display
    screen_display = pygame.display.set_mode(size_screen,0,32)
    # set color white
    color_white = (255,255,255)
    # set color blue
    color_blue = (0,0,255)
    # fill screen with a white color
    screen_display.fill(color_white)
    # set the numar of columns 
    nr_col = 5
    # create columns from classes
    cols = create_columns_rect(nr_col)
    # use each column
    for (px,py,dx,dy) in cols:
        # print positions and size of rectangle
        print (px,py,dx,dy)
        # draw column rectangle to display with color and position and size
        # screen_display , color_blue , px,py,dx,dy
        pygame.draw.rect(screen_display,color_blue,(px,py,dx,dy))
        # create a color for axes
        color_col = (random.randrange(255),random.randrange(255),random.randrange(255))
        # draw axes for x and y with the color
        pygame.draw.line(screen_display, color_col, ( px , 0) , ( px , py + dy) )
        pygame.draw.line(screen_display, color_col, ( 0 , py) , ( px +  dx , py) )
    # is workings get events 
    while True:
        for event in pygame.event.get():
            if event.type==QUIT:
                pygame.quit()
                sys.exit()
        pygame.display.update()
# run main 
if __name__ == "__main__":
    main()
    pass
This is result of the running python script pygame_testing_axes.py:

duminică, 24 mai 2020

PyGame : Effects - part 004.

This is an simple example about how can be use palette colors.
This effect was used in the old game development.
The base of this python script is the Surface.
If you read the documentation then you can see this:
pygame object for representing images
Surface((width, height), flags=0, depth=0, masks=None) -> Surface
Surface((width, height), flags=0, Surface) -> Surface
In this example I used a new_color to change one color.
Let's see the example:
#!/usr/bin/python
import sys 
import pygame
from pygame.locals import *

pygame.init()
pygame.display.set_caption('swap color pallete')
screen = pygame.display.set_mode((640,480),0,32)

clock = pygame.time.Clock()

test_image = pygame.image.load('test.png').convert()
image_back = test_image.copy()
def palette_swap(img_surface, old_color, new_color):
    
    img_copy = pygame.Surface(test_image.get_size())
    img_copy.fill(new_color)
    img_surface.set_colorkey(old_color)
    img_copy.blit(img_surface,(0,0))
    return img_copy

test_image = palette_swap(test_image, (210,0,1), (0,0,255)) 
test_image = palette_swap(test_image, (154, 209, 59), (205, 124, 97))   
test_image.set_colorkey((0,0,0))

while True:
    screen.fill((0,0,0))
    screen.blit(pygame.transform.scale(test_image,(test_image.get_width()*2, 
                                                   test_image.get_height() * 2)), (0,0))
    screen.blit(pygame.transform.scale(image_back,(image_back.get_width()*2, 
                                                   image_back.get_height() * 2)), (256,0))
    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit()
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                pygame.quit()
                sys.exit()
    pygame.display.update()
    clock.tick(60)
    # print the fps , time amd tick for this pygame test 
    #print(clock.get_fps(), clock.get_time(),clock.tick())
The test.png is a simple png file image with the size of 128 x 128 pixels.
This is the output of this simple example: