www.main.lv
Don't think just code it

Search results for 'tutorial'

2009-11-12 Python PyGame Tutorial Fullscreen

added new variable tha tcheck in with mode now screen is
fullscreen = False
Used new event type
if event.type == pygame.KEYDOWN:
When pressing key m we making new screen surface in fullscreen mode. If screen is in fuulscreen mode make window.
if event.key == pygame.K_m:		
  if not fullscreen:
    screen = pygame.display.set_mode( (SCREEN_X,SCREEN_Y) , pygame.FULLSCREEN )
    fullscreen = True
  else:
    screen = pygame.display.set_mode( (SCREEN_X,SCREEN_Y) )
    fullscreen = False
Tutorial Source

2009-09-23 Python Pygame Tutorial Randomnes

All boxes moving with same speed in same directions and all boxes have same size and colorMake changes step by step to see result

self.dx = randint(1,BOX_SPEED)
self.dy = randint(1,BOX_SPEED)
and boxes now moving all seperatly at diferent directions.
self.boxes.append( Box( i*2 , i*2 , randint(BOX_MIN_SIZE,BOX_MAX_SIZE) ,
(i,0,0) ) 
now boxes have diferent sizes
Tutorial source

2009-09-23 Python Pygame Tutorial Boxes Move

New class boxes handles many boxes. Number of boxes depends on cpnstant MAX_BOXES.

MAX_BOXES = 100
and all class Boxes methods is the same only diference is that it handles many boxes.Tutorial Source

2009-09-15 Python Pygame Tutorial Box Move

added constants that helps controlling screen size

SCREEN_X = 500
SCREEN_Y = 500
BOX_SIZE = 20
BOX_SPEED = 1
box have speed by axis
self.dx = BOX_SPEED
self.dy = BOX_SPEE
detecting if given rect is inside screen borders or not if not then change it direction
def move( self ):
        if self.rect.left+BOX_SIZE > SCREEN_X:
            self.dx = -BOX_SPEED
        if self.rect.left < 0:
            self.dx = BOX_SPEED
        if self.rect.top+BOX_SIZE > SCREEN_Y:
            self.dy = -BOX_SPEED
        if self.rect.top < 0:
            self.dy = BOX_SPEED
        self.rect.left += self.dx
        self.rect.top += self.dy
after few line of code where added box move inside given screen and coalide with screen borders
Tutorial Source

2009-09-07 Python PyGame Tutorial Box Object

There is new object Box. We can draw, mask and move it.Once you init it you can use it with simple interface

box = Box( position_x , position_y , size ,
(color_red,color_green,color_blue,color_alpha) )
moving box to new position. new position calculates x_new = x_old + x
box.move( add_x , add_y )
drawes box on the screen
box.draw()
draw black box on the screen
box.mask()

Tutorial Source

2009-08-31 Python PyGame Tutorial Image Loading

Draw some image and make for it

surface image = pygame.image.load("image_name.format") 

then copy image surface to screen
surface. screen.blit( source_surface , (position_x,position_y) )

Tutorial source

2009-08-23 Python PyGame Tutorial Event System

Now you can set application window. But there is one problem you have to terminate application by killing.
Adding event handling help us exit from application by clicking close button or pressing some other button.

for event in pygame.event.get():
if event.type == pygame.QUIT:
    runing = False

Now you can exit from application by clicking close button.
Event types
There are defined other event types pygame.(KEYUP, KEYDOWN, MOUSEMOTION, MOUSEBUTTONP, MOUSEBUTTONDOWN, VIDEORESIZE). All of these events described in pygame documentation
Tutorial source

2009-08-23 Python PyGame Tutorial Display Setting

First application and we opening window

screen = pygame.display.set_mode( (width_of_window ,height_of_window ) )

In future we will use screen for drawing.
Also there possible make full screen with value pygame.FULLSCREEN
it looks like:
pygame.display.set_mode( (width,height), pygame.FULLSCREEN )


Tutorial Source

2009-08-23 Python PyGame Tutorial

Python Pygame tutorial. This tutorial goal show how to make small and simple pygame pythone script that include all that is need for bigger application. Every tutorial part add only few new lines of code.
Moving Boxes
Goal
Make featured applications with boxes that coaliding one with another.
1. [Set Display]
2. [Event Sytem]
3. [Image loading]
4. [Box object]
5. [Box move]
6. [Boxes move]
7. [Randomnes]
8. [Fullscreen]