Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lâchons le web et faisons du jeu !

MrJmad
September 21, 2014

Lâchons le web et faisons du jeu !

Présentation rapide de trois outils pour développer des jeux vidéos en python

MrJmad

September 21, 2014
Tweet

More Decks by MrJmad

Other Decks in Programming

Transcript

  1. 1 import sys, pygame 2 pygame.init() 3 4 size =

    width, height = 320, 240 5 speed = [2, 2] 6 black = 0, 0, 0 7 8 screen = pygame.display.set_mode(size) 9 10 ball = pygame.image.load("ball.bmp") 11 ballrect = ball.get_rect() 12 13 while 1: 14 for event in pygame.event.get(): 15 if event.type == pygame.QUIT: sys.exit() 16 17 ballrect = ballrect.move(speed) 18 if ballrect.left < 0 or ballrect.right > width: 19 speed[0] = -speed[0] 20 if ballrect.top < 0 or ballrect.bottom > height: 21 speed[1] = -speed[1] 22 23 screen.fill(black) 24 screen.blit(ball, ballrect) 25 pygame.display.flip() Pygame exemple
  2. clock = pygame.time.Clock() while 1: clock.tick(30) for event in pygame.event.get():

    if event.type == pygame.QUIT: sys.exit() ballrect = ballrect.move(speed) if ballrect.left < 0 or ballrect.right > width: speed[0] = -speed[0] if ballrect.top < 0 or ballrect.bottom > height: speed[1] = -speed[1] screen.fill(black) screen.blit(ball, ballrect) pygame.display.flip() Gestion du framerate
  3. key = pygame.key.get_pressed() if key[pygame.K_LEFT]: ships_x -= 10 if key[pygame.K_RIGHT]:

    ships_x += 10 key = pygame.key.get_pressed() if key[pygame.K_UP]: ships_y -= 10 if key[pygame.K_DOWN]: ships_y += 10 Clavier et souris Événements souris MOUSEBUTTONDOWN MOUSEBUTTONUP MOUSEMOTION
  4. Groupe de sprite et collisions Grouper les sprites pour grouper

    les traitements Collisions entre un sprite et un groupe for bomb in sprite.spritecollide(player, bombs, 1): boom_sound.play() Explosion(bomb, 0) Définition de la fonction : spritecollide(sprite, group, dokill) -> list
  5. Map TMX Utilisation de PyTMX pour récupérer ses maps https://github.com/bitcraft/PyTMX

    from pytmx import load_pygame tmxdata = load_pygame("map.tmx") image = tmx_data.get_tile_image(x, y, layer) screen.blit(image, position) props = txmdata.get_tile_properties(x, y, layer) props = tmxdata.get_tile_properties_by_gid(tile_gid)
  6. image bg meadow = "meadow.jpg" image bg uni = "uni.jpg"

    image sylvie smile = "sylvie_smile.png" image sylvie surprised = "sylvie_surprised.png" define s = Character('Sylvie', color="#c8ffc8") define m = Character('Me', color="#c8c8ff") label start: scene bg meadow show sylvie smile "I'll ask her..." m "Um... will you..." m "Will you be my artist for a visual novel?" show sylvie surprised "Silence." "She is shocked, and then..." show sylvie smile s "Sure, but what is a \"visual novel?\"" Langage très descriptif
  7. python: player_health = max(player_health - damage, 0) if enemy_vampire: enemy_health

    = min(enemy_health + damage, enemy_max_health) Utilisation de python Pour l'initialisation init python: def auto_voice_function(ident): return "voice/" + ident + ".ogg" config.auto_voice = auto_voice_function if persistent.endings is None: persistent.endings = set() init 1 python: # The bad ending is always unlocked. persistent.endings.add("bad_ending")
  8. Moteur de création de jeu En clic clic. Utilisation de

    machine à état Script python Blender Game Engine
  9. Certaines captures d'écran du BGE Proviennent du livre Blender pour

    le jeu vidéo de FlossManuals FR http://fr.flossmanuals.net/blender-pour-le-jeu-v ideo Source des images