Skip to content

Commit

Permalink
update description
Browse files Browse the repository at this point in the history
  • Loading branch information
bletvaska committed May 24, 2019
1 parent 3d652a4 commit 802fc04
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 50 deletions.
97 changes: 48 additions & 49 deletions doc/hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,69 @@ yourself.
Game Loop Hooks
---------------

A typical game loop looks a bit like this::
Typická herná slučka vyzerá takto::

while game_has_not_ended():
process_input()
update()
draw()

Input processing is a bit more complicated, but Pygame Zero allows you to
easily define the ``update()`` and ``draw()`` functions within your game
module.
Spracovanie vstupu je trochu komplikovanejšie, ale Pygame Zero umožňuje jednoducho definovať funkcie ``update()`` a ``draw()`` v module vašej hry.

.. function:: draw()

Called by Pygame Zero when it needs to redraw your game window.

``draw()`` must take no arguments.

Funkcia je volaná knižnicou Pygame Zero, keď potrebuje prekresliť okno vašej hry.
``draw()`` nesmie mať žiadne argumenty.
Pygame Zero attempts to work out when the game screen needs to be redrawn
to avoid redrawing if nothing has changed. On each step of the game loop
it will draw the screen in the following situations:

* If you have defined an ``update()`` function (see below).
* If a clock event fires.
* If an input event has been triggered.

One way this can catch you out is if you attempt to modify or animate
something within the draw function. For example, this code is wrong: the
alien is not guaranteed to continue moving across the screen::

def draw():
alien.left += 1
alien.draw()

The correct code uses ``update()`` to modify or animate things and draw
simply to paint the screen::

def draw():
alien.draw()

def update():
alien.left += 1

.. function:: update() or update(dt)

Called by Pygame Zero to step your game logic. This will be called
repeatedly, 60 times a second.

There are two different approaches to writing an update function.

In simple games you can assume a small time step (a fraction of a second)
has elapsed between each call to ``update()``. Perhaps you don't even care
how big that time step is: you can just move objects by a fixed number of
pixels per frame (or accelerate them by a fixed constant, etc.)

A more advanced approach is to base your movement and physics calculations
on the actual amount of time that has elapsed between calls. This can give
smoother animation, but the calculations involved can be harder and you
must take more care to avoid unpredictable behaviour when the time steps
grow larger.

To use a time-based approach, you can change the update function to take a
single parameter. If your update function takes an argument, Pygame Zero
will pass it the elapsed time in seconds. You can use this to scale your
movement calculations.
.. function:: update() alebo update(dt)

Called by Pygame Zero to step your game logic. This will be called repeatedly, 60 times a second.
Funkcia je volaná knižnicou Pygame Zero na vykonanie kroku hernej logiky
vašej hry. Bude volaná opakovane 60 krát za sekundu.

Pri písaní tejto funkcie je možné použiť dva rozličné prístupy.

V jednoduchých hrách môžete predpokladať, že medzi každým volaním funkcie ``update()``
ubehol krátky časový úsek (zlomok sekundy). Jeho veľkosť vás možno vôbec nebude
zaujímať: len budete posúvať objekty o pevný počet pixelov každý snímok (alebo ich
budete zrýchlovať o pevnú konštantu, atď.)

Pokročilejší prístup znamená založiť váš pohyb a fyzické výpočty na skutočnom
množstve času, ktorý uplynul medzi jednotlivými volaniami. To umožní, aby boli
animácie plynulejšie, ale potrebné výpočty na ich dosiahnutie môžu byť
náročnejšie a musíte dávať väčší pozor, aby ste sa vyhli nepredvídateľnému
správaniu, keď sa začnú časové úseky zväčšovať.

Pre použitie prístupu založeného na čase je potrebné upraviť funkciu tak, aby
obsahovala jeden parameter. V tom prípade ho Pygame Zero odovzdá funkcii vo
forme uplynutého času v sekundách. To môžete využiť na správne nastavenie
výpočtov vašich pohybov.


Event Handling Hooks
Expand All @@ -87,13 +86,13 @@ be happy to call any of these variations of an ``on_mouse_down`` function::

def on_mouse_down():
print("Mouse button clicked")

def on_mouse_down(pos):
print("Mouse button clicked at", pos)

def on_mouse_down(button):
print("Mouse button", button, "clicked")

def on_mouse_down(pos, button):
print("Mouse button", button, "clicked at", pos)

Expand All @@ -104,7 +103,7 @@ can use, as described below.
.. function:: on_mouse_down([pos], [button])

Called when a mouse button is depressed.

:param pos: A tuple (x, y) that gives the location of the mouse pointer
when the button was pressed.
:param button: A :class:`mouse` enum value indicating the button that was
Expand All @@ -113,7 +112,7 @@ can use, as described below.
.. function:: on_mouse_up([pos], [button])

Called when a mouse button is released.

:param pos: A tuple (x, y) that gives the location of the mouse pointer
when the button was released.
:param button: A :class:`mouse` enum value indicating the button that was
Expand All @@ -122,7 +121,7 @@ can use, as described below.
.. function:: on_mouse_move([pos], [rel], [buttons])

Called when the mouse is moved.

:param pos: A tuple (x, y) that gives the location that the mouse pointer
moved to.
:param rel: A tuple (delta_x, delta_y) that represent the change in the
Expand All @@ -142,7 +141,7 @@ To handle mouse drags, use code such as the following::
.. function:: on_key_down([key], [mod], [unicode])

Called when a key is depressed.

:param key: An integer indicating the key that was pressed (see
:ref:`below <buttons-and-keys>`).
:param unicode: Where relevant, the character that was typed. Not all keys
Expand All @@ -154,7 +153,7 @@ To handle mouse drags, use code such as the following::
.. function:: on_key_up([key], [mod])

Called when a key is released.

:param key: An integer indicating the key that was released (see
:ref:`below <buttons-and-keys>`).
:param mod: A bitmask of modifier keys that were depressed.
Expand All @@ -163,13 +162,13 @@ To handle mouse drags, use code such as the following::
.. function:: on_music_end()

Called when a :ref:`music track <music>` finishes.

Note that this will not be called if the track is configured to loop.


.. _buttons-and-keys:

Buttons and Keys
Tlačidlá a klávesy
''''''''''''''''

Built-in objects ``mouse`` and ``keys`` can be used to determine which buttons
Expand All @@ -182,7 +181,7 @@ Note that mouse scrollwheel events appear as button presses with the below

A built-in enumeration of buttons that can be received by the
``on_mouse_*`` handlers.

.. attribute:: LEFT
.. attribute:: MIDDLE
.. attribute:: RIGHT
Expand All @@ -193,7 +192,7 @@ Note that mouse scrollwheel events appear as button presses with the below

A built-in enumeration of keys that can be received by the ``on_key_*``
handlers.

.. attribute:: BACKSPACE
.. attribute:: TAB
.. attribute:: CLEAR
Expand Down Expand Up @@ -335,7 +334,7 @@ Additionally you can access a set of constants that represent modifier keys:

Constants representing modifier keys that may have been depressed during
an ``on_key_up``/``on_key_down`` event.

.. attribute:: LSHIFT
.. attribute:: RSHIFT
.. attribute:: SHIFT
Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Welcome to Pygame Zero
======================

Pygame Zero je na tvorbu hier bez boilerplate.
Pygame Zero je knižnica na rýchlu tvorbu hier.

Knižnica je určená na použitie vo vzdelávaní, aby učitelia mohli vyučovať základy programovania bez nutnosti vysvetľovať Pygame API alebo písať hernú slučku.

Expand Down

0 comments on commit 802fc04

Please sign in to comment.