« Soya/Python game skel-2 » : différence entre les versions

Contenu supprimé Contenu ajouté
Création : <pre># -*- indent-tabs-mode: t -*- #! /usr/bin/python -O # Game Skeleton # Copyright (C) 2003-2004 Jean-Baptiste LAMY # # This program is free software; you can redistribute it and/or ...
 
Tavernierbot (discussion | contributions)
m Robot : Changement de type cosmétique
Ligne 13 :
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
# Soya gaming tutorial, lesson 2
Ligne 48 :
# Les actions disponibles
# Pour plus d'actions complexe, vous devez faire une sous classe "Action".
ACTION_WAIT = 0
ACTION_ADVANCE = 1
ACTION_ADVANCE_LEFT = 2
ACTION_ADVANCE_RIGHT = 3
ACTION_TURN_LEFT = 4
ACTION_TURN_RIGHT = 5
ACTION_GO_BACK = 6
ACTION_GO_BACK_LEFT = 7
ACTION_GO_BACK_RIGHT = 8
 
Ligne 68 :
"""Retourne l'action suivante"""
for event in soya.process_event():
if event[0] == sdlconst.KEYDOWN:
if (event[1] == sdlconst.K_q) or (event[1] == sdlconst.K_ESCAPE):
sys.exit() # Quit the game
elif event[1] == sdlconst.K_LEFT: self.left_key_down = 1
elif event[1] == sdlconst.K_RIGHT: self.right_key_down = 1
elif event[1] == sdlconst.K_UP: self.up_key_down = 1
elif event[1] == sdlconst.K_DOWN: self.down_key_down = 1
elif event[0] == sdlconst.KEYUP:
if event[1] == sdlconst.K_LEFT: self.left_key_down = 0
elif event[1] == sdlconst.K_RIGHT: self.right_key_down = 0
elif event[1] == sdlconst.K_UP: self.up_key_down = 0
elif event[1] == sdlconst.K_DOWN: self.down_key_down = 0
# Les gens disent que Python n'a pas de switch/select case et c'est faux !
Ligne 128 :
def begin_round(self):
"""Cette méthode est appellée par la MainLoop chaque fois qu'un round commence. Soya gère des rounds de 30ms par défaut, ceci signifie que le personnage sera -perform- à chaque action durant 30ms.
Actuellement, tous les round ne durent pas exactement 30ms, mais il retourne True à un point global de la vue. Exemple, 1000 rounds feront 1000 * 30ms."""
# Appel d'une nouvelle action venant d'un controlleur, et la commence.
Ligne 147 :
# Determination de la rotation du personnage
if action.action in (ACTION_TURN_LEFT, ACTION_ADVANCE_LEFT, ACTION_GO_BACK_LEFT):
self.rotation_speed = 5.0
elif action.action in (ACTION_TURN_RIGHT, ACTION_ADVANCE_RIGHT, ACTION_GO_BACK_RIGHT):
Ligne 153 :
# Determination de la vitesse du personnage
if action.action in (ACTION_ADVANCE, ACTION_ADVANCE_LEFT, ACTION_ADVANCE_RIGHT):
self.speed.z = -0.35
elif action.action in (ACTION_GO_BACK, ACTION_GO_BACK_LEFT, ACTION_GO_BACK_RIGHT):