$$ \newcommand{\floor}[1]{\left\lfloor{#1}\right\rfloor} \newcommand{\ceil}[1]{\left\lceil{#1}\right\rceil} \renewcommand{\mod}{\,\mathrm{mod}\,} \renewcommand{\div}{\,\mathrm{div}\,} \newcommand{\metar}{\,\mathrm{m}} \newcommand{\cm}{\,\mathrm{cm}} \newcommand{\dm}{\,\mathrm{dm}} \newcommand{\litar}{\,\mathrm{l}} \newcommand{\km}{\,\mathrm{km}} \newcommand{\s}{\,\mathrm{s}} \newcommand{\h}{\,\mathrm{h}} \newcommand{\minut}{\,\mathrm{min}} \newcommand{\kmh}{\,\mathrm{\frac{km}{h}}} \newcommand{\ms}{\,\mathrm{\frac{m}{s}}} \newcommand{\mss}{\,\mathrm{\frac{m}{s^2}}} \newcommand{\mmin}{\,\mathrm{\frac{m}{min}}} \newcommand{\smin}{\,\mathrm{\frac{s}{min}}} $$

Prijavi problem


Obeleži sve kategorije koje odgovaraju problemu

Još detalja - opišite nam problem


Uspešno ste prijavili problem!
Status problema i sve dodatne informacije možete pratiti klikom na link.
Nažalost nismo trenutno u mogućnosti da obradimo vaš zahtev.
Molimo vas da pokušate kasnije.

Interaction

In the PyGame programs we have seen so far, the user could not affect their execution, aside from ending the program. We can compare this kind of programs to watching movies - the user is essentially a viewer.

In the next section, we will deal with programs in which the user has an active role and can influence the running of the program using a mouse and a keyboard. There are two basic ways for our program to “know” when the user has made an action.

  • One way is to read the status of the mouse and keyboard. From the code we can ask what is the current position of the mouse, whether any key is being pressed and the like.

  • Another way is to use system events. Any user action (pressing a mouse button or a keyboard key, releasing a key, moving the mouse, etc.) is an event, and in the programs we can obtain information about such events and respond to them.

In this chapter, we will familiarize with both of these ways that enable our programs to respond to user actions.