desarrollo de videojuegos con software libre

Download Desarrollo de videojuegos con software libre

If you can't read please download the document

Upload: carlos-zuniga

Post on 16-Apr-2017

907 views

Category:

Technology


4 download

TRANSCRIPT

Con software libre

Carlos Ziga

Desarrollo de videojuegos

@[email protected]

Diapositivas: http://goo.gl/DKJjO

Por qu Juegos 2d

Es un buen momento para juegos 2D

Smartphones y tablets

HTML5

Kickstarter

Plataformas de distribucin digitalGameolith

Desura

Ubuntu Software Center

Steam

Smartphones y Tablets

Por qu Juegos 2d

Todos los navegadores recientes soportan Canvas y/o WebGL

Y Por qu para Linux

Kickstarter, un sitio de crowd funding para proyectos creativos

Lista de juegos con soporte para Linux:Aura Tactics

Bacillus

Double Fine Adventure

Ensign 1

FTL: Faster Than Light

The Banner Saga

Wasteland 2

Y Por qu para Linux

Indiegogo, como Kickstarter pero internacional

Y Por qu para Linux

Sitio de distribucin digital de juegosEnfocado solamente a LinuxIniciado el 2011

Y Por qu para Linux

Sitio de distribucin digital de juegosIniciado en 2009Enfocado a Windows, MacOs y Linux

Alrededor de 150 juegos para Linux

Y Por qu para Linux

Software Center de Ubuntu

Y Por qu para Linux

Acaban de anunciar la versin de STEAM para Linux.Alrededor de 90 juegos en Steam ya cuentan con cliente nativo en Linux.Valve esta portando Source Engine con el juego Left 4 Dead 2.

Y Por qu para Linux

Humble BundleVenta de juegos para las 3 plataformas al precio que el cliente quiera pagar

Y Por qu para Linux

Y Por qu para Linux

Proporcin de usuarios de Linux similar a la de MacOS

Y Por qu para Linux

Usuarios de linux pagn un promedio ms elevado por los juegos

Por que usar
herramientas libres

No hay costos altos

No estn controlados por los fabricantes

Multi-plataforma

Licencias sin restricciones (LGPL, BSD, MIT)

Actualizaciones continuas

Por qu utilizar herramientas libres para hacer juegos

herramientas

http://pygame.org/

El ms conocido de las bibliotecas de juegos para PythonUtiliza SDLEn su seccin de Proyectos hay ms de 400 juegos con cdigo fuente para descargar

herramientas

https://love2d.org/

http://stabyourself.net/mari0/

Motor 2D desarrollado en C++, utiliza LUA como lenguaje de scriptingUtiliza OpenGL

herramientas

http://www.marsshooter.org/

http://sfml-dev.org/

SFMLDesarrollado en C++Bindings para muchos lenguajes

herramientas

http://code.google.com/p/playn/

PlayN, framework desarrollado por gente de Google.Permite exportar el juego a 4 plataformas:Html5

Flash

Android

IOS (beta)

Desktop con Java

Utiliza WebGL o Canvas segn el soporte del navegador

herramientas

http://chrome.angrybirds.com/

El port de AngryBirds para HTML5 tomo una semana

herramientas

Box2Dhttp://box2d.org/

Chipmunkhttp://code.google.com/p/chipmunk-physics/

Bibliotecas para fsicaBox2D utilizado por Angry Birds

+ herramientas

PythonPyglet http://pyglet.org/

Cocos2d http://cocos2d.org/

C#Tao Framework http://sourceforge.net/projects/taoframework/

C++Clanlib http://clanlib.org/

Allegro http://alleg.sourceforge.net/

+ herramientas

Grficos 2dInkscape (vectores) http://inkscape.org/

Gimp (bitmaps) http://gimp.org/

Grficos 3dBlender http://www.blender.org/

Makehuman http://makehuman.org/

AudioAudacity http://audacity.sourceforge.net/

Sfrx http://www.drpetter.se/project_sfxr.html

Un juego con PySFML

Pueden encontrar el cdigo en:

https://github.com/charlieman/ejemplo-pysfml

Un juego con PySFML

from PySFML import sf

window = sf.RenderWindow(sf.VideoMode(640, 480), "Ejemplo 01")

while True: window.Clear() window.Display()

ej01.py

Cdigo mnimo necesario para usar SFMLCorre sobre un bucle infinito, el main loopSolo muestra una ventana que no responde a nadaHay que matar el proceso para cerrarla

Un juego con PySFML

from PySFML import sf

window = sf.RenderWindow(sf.VideoMode(640, 480), "Ejemplo 02")event = sf.Event()running = True

while running: while window.GetEvent(event): if event.Type == sf.Event.Closed: running = False

window.Clear() window.Display()

ej02.py

Le aadimos un recolector de eventos para poder cerrar la ventana y salir de la aplicacin

Un juego con PySFML

from PySFML import sfwindow = sf.RenderWindow(sf.VideoMode(640, 480), "Ejemplo 03")event = sf.Event()text = sf.String("Hola Flisol")running = True

while running: while window.GetEvent(event): if event.Type == sf.Event.Closed: running = False

window.Clear() window.Draw(text) window.Display()

ej03.py

Y ahora vemos como aadir texto con un sf.String

Un juego con PySFML

text = sf.String("Hola Flisol")text.SetSize(50)rect = text.GetRect()text.SetCenter(rect.GetWidth()/2,
rect.GetHeight()/2)text.SetPosition(320, 240)#...while running: while window.GetEvent(event): #... elif event.Type == sf.Event.KeyPressed: if event.Key.Code == sf.Key.Left: text.Move(-5, 0) if event.Key.Code == sf.Key.Right: text.Move(5, 0)

ej04.py

Podemos ver que el texto se puede modificar en tamao y posicin

Tambin aadimos cdigo para mover el texto pero vemos que su movimiento es algo errtico

Un juego con PySFML

#...while running: while window.GetEvent(event): if event.Type == sf.Event.Closed: running = False

inpt = window.GetInput() if inpt.IsKeyDown(sf.Key.Left): text.Move(-velocity * window.GetFrameTime(), 0)

if inpt.IsKeyDown(sf.Key.Right): text.Move(velocity * window.GetFrameTime(), 0)

ej05.py

Cambiamos el sistema de eventos de teclado. En lugar de esperar que el usuario presione una tecla, chequeamos si la tecla est presionada.

Esto nos da un movimiento ms fluido

Un juego con PySFML

ship_image = sf.Image()ship_image.LoadFromFile("ship.png")ship = sf.Sprite(ship_image)ship.SetPosition(320, 400)velocity = 100#...while running: #... inpt = window.GetInput() if inpt.IsKeyDown(sf.Key.Left): ship.Move(-velocity * window.GetFrameTime(), 0)

if inpt.IsKeyDown(sf.Key.Right): ship.Move(velocity * window.GetFrameTime(), 0)

ej06.py

Ahora vamos a utilizar una imagen en lugar de un texto.

La manera de manipularla es similar

Un juego con PySFML

class Ship(object): def __init__(self, x, y): self.image = sf.Image() self.image.LoadFromFile("ship.png") self.sprite = sf.Sprite(self.image) self.sprite.SetPosition(x, y) self.velocity = 100

def update(self, input_, delta): if input_.IsKeyDown(sf.Key.Left): self.sprite.Move(-self.velocity * delta, 0) if input_.IsKeyDown(sf.Key.Right): self.sprite.Move(self.velocity * delta, 0)

def draw(self, window): window.Draw(self.sprite)

ej07.py

El cdigo dentro del bucle se est volviendo algo complejo, as que utilizamos orientacin a objetos para separarlo. El manejo del juego no ha cambiado nada.

Un juego con PySFML

ship = Ship(320, 400)

#... while running: while window.GetEvent(event): if event.Type == sf.Event.Closed: running = False

input_ = window.GetInput() ship.update(input_, window.GetFrameTime())

window.Clear() ship.draw(window) window.Display()

ej07.py

Y ahora nuestro bucle queda ms corto y entendible

Un juego con PySFML

class Sprite(object): def __init__(self, image, x, y): self.image = sf.Image() self.image.LoadFromFile(image) self.sprite = sf.Sprite(self.image) self.sprite.SetPosition(x, y)

def draw(self, window): window.Draw(self.sprite)

class Ship(Sprite): def __init__(self, x, y): super(Ship, self).__init__("ship.png", x, y) self.velocity = 150 #...

ej08.py

Ahora vamos a crear ms objetos, como todos los personajes tienen partes similares, las colocamos en una clase padre de donde hereda nuestra nave

Un juego con PySFML

class Invader(Sprite): def __init__(self, x, y): super(Invader, self).__init__("alien.png", x, y) self.x_velocity = 100 self.y_velocity = 10 self.going_right = True self.going_down = False self.initial_x = x self.y_distance = 0 self.sprite.SetColor(sf.Color.Green) self.count = 0

def update(self, delta): #...

ej08.py

Y creamos as nuestra clase Invader que tambin heredar de Sprite

Un juego con PySFML

def update(self, delta): x_pos, y_pos = self.sprite.GetPosition() x, y = 0, 0

if not self.going_down: if x_pos > self.initial_x + 50 or \ x_pos < self.initial_x - 50: self.going_right = not self.going_right self.count = (self.count +1) % 5

x = self.x_velocity * (self.going_right * 2 -1) * delta

if self.count == 4: self.going_down = True

if self.going_down: y = self.y_velocity * delta self.y_distance += y if self.y_distance > 3: self.going_down = False self.y_distance = 0

self.sprite.Move(x, y)

ej08.py

Este es el cdigo para actualizar al Invader, bsicamente hace que se mueva de lado a lado y baje cada cierto tiempo

Un juego con PySFML

aliens = [] for i in range(8): for j in range(4): aliens.append(Invader(100 + i*50, 30 + j*50)) #... while running: #... input_ = window.GetInput() delta = window.GetFrameTime() ship.update(input_, delta) for alien in aliens: alien.update(delta)

window.Clear() for alien in aliens: alien.draw(window) window.Display()

ej08.py

Luego aadimos una cantidad de Invaders a nuestro juego y los actualizamos y dibujamos en nuestro bucle principal

Un juego con PySFML

class Sprite(object): #... def get_rect(self): x, y = self.sprite.GetPosition() return sf.FloatRect(x - self.width/2, y - self.height/2, x + self.width/2, y + self.height/2)

#... def die(self): self.dead = True

ej09.py

Vamos a aadir las balas, y para eso necesitamos detectar colisiones entre objetos.El mtodo get_rect crear un objeto sf.FloatRect que podemos usar luego para detectar Intersecciones con otros FloatRects o Colisiones con puntos especficos

Un juego con PySFML

class Bullet(Sprite): def __init__(self, ship): x, y = ship.sprite.GetPosition() super(Bullet, self).__init__("bullet.png", x, y) self.velocity = -300

def update(self, aliens, delta): self.sprite.Move(0, self.velocity * delta) rect = self.get_rect() for alien in aliens: if rect.Intersects(alien.get_rect()): alien.die() self.die()

ej09.py

Aadimos la clase bullet.Su mtodo update es ms simple que el de los Invaders, solamente se mueve hacia arriba y luego chequea si ha tocado a algun Invader

Un juego con PySFML

bullets = [] #... while running: while window.GetEvent(event): if event.Type == sf.Event.Closed: running = False elif event.Type == sf.Event.KeyPressed and \ event.Key.Code == sf.Key.Space: bullets.append(Bullet(ship))

for alien in aliens: alien.update(delta) aliens = filter(lambda x: not x.dead, aliens)

ej09.py

Luego lo aadimos al bucle principal de la misma manera que hicimos con los Invaders.Chequeamos el evento de presionar la Barra Espaciadora y creamos una nueva bala.Luego chequeamos los Invaders y quitamos los que estan muertos

Un juego con PySFML

#... while running: #... for bullet in bullets: bullet.update(aliens, delta) bullets = filter(lambda x: not x.dead, bullets)

window.Clear() ship.draw(window) for alien in aliens: alien.draw(window) for bullet in bullets: bullet.draw(window) window.Display()

ej09.py

Continuando en el bucle principal, actualizamos las balas y chequeamos si alguna ha muerto

Un juego con PySFML

class Ship(Sprite): def __init__(self, x, y): #... self.score = 0 self.bullet_rest = sf.Clock()

#... def score_up(self, points): self.score += points

ej10.py

Ya que podemos matar Invaders, vamos a aadir el puntajeTambin vamos a limitar el nmero de balas que podemos lanzar por segundo

Un juego con PySFML

class Bullet(Sprite): #...

def update(self, aliens, ship, delta): self.sprite.Move(0, self.velocity * delta) rect = self.get_rect()

for alien in aliens: if rect.Intersects(alien.get_rect()): alien.die() self.die() ship.score_up(10)

ej10.py

Modificamos la clase Bullet para que aada puntos a la nave cuando mate a un Invader

Un juego con PySFML

score = sf.String("Score: ") score.SetSize(30) score.SetPosition(5, 5) #... while running: while window.GetEvent(event): if event.Type == sf.Event.Closed: running = False elif event.Type == sf.Event.KeyPressed and \ event.Key.Code == sf.Key.Space: if ship.bullet_rest.GetElapsedTime() > 0.5: bullets.append(Bullet(ship)) ship.bullet_rest.Reset()

ej10.py

Luego creamos el objeto score que es un sf.StringTambin chequeamos que no haya lanzado una bala desde hace 0.5 segundos para permitir lanzar otra

Un juego con PySFML

score = sf.String("Score: ") score.SetSize(30) score.SetPosition(5, 5) #... while running: while window.GetEvent(event): if event.Type == sf.Event.Closed: running = False elif event.Type == sf.Event.KeyPressed and \ event.Key.Code == sf.Key.Space: if ship.bullet_rest.GetElapsedTime() > 0.5: bullets.append(Bullet(ship)) ship.bullet_rest.Reset()

ej10.py

Luego creamos el objeto score que es un sf.StringTambin chequeamos que no haya lanzado una bala desde hace 0.5 segundos para permitir lanzar otra

Un juego con PySFML

#... while running: #... score.SetText("Score: %d" % ship.score)

window.Clear() ship.draw(window) for alien in aliens: alien.draw(window) for bullet in bullets: bullet.draw(window) window.Draw(score) window.Display()

ej10.py

Luego simplemente cambiamos el texto y lo mostramos

Un juego con PySFML

class Invader(Sprite): #... def update(self, ship, delta): #... if self.get_rect().Intersects(ship.get_rect()): ship.die() self.die()

class Bullet(Sprite): #... def update(self, aliens, ship, delta): #... if rect.Intersects(ship.get_rect()): ship.die() self.die()

ej11.py

Tambin chequeamos si la bala o el Invader se chocan con la nave y si lo hacen los matamos

Un juego con PySFML

while running: #... for alien in aliens: alien.update(ship, delta) if alien.bullet_rest.GetElapsedTime() > 5 \
and random() < 0.001: bullets.append(Bullet(alien, False)) aliens = filter(lambda x: not x.dead, aliens) #...

ej11.py

Aadimos el cdigo para que los Invaders tambin puedan disparar, cada uno podr disparar despus de 5 segundos y con una probabilidad de 0.1%

Un juego con PySFML

while running: #... if not aliens: print "Ganaste!" print "Tu puntaje es de: %s" % ship.score running = False

if ship.dead: print "Fin del juego" print "Tu puntaje es de: %s" % ship.score running = False #...

ej11.py

Finalmente chequeamos si ya no hay aliens para determinar que el usuario a ganado o si la nave ha muerto para determinar que ha perdido

Concursos

http://pyweek.org/

El siguiente inicia la prxima semana (06/05/2012)

Individual o por equipos1 semanaJuegos hechos en PythonJuegos en torno a un tema

Concursos

http://ludumdare.com/

Individual48 horasCualquier biblioteca es permitidaCada 4 mesesJuegos en torno a un tema

Concursos

http://lpc.opengameart.org/

Concurso de opengameart.orgPrimero concurso de grficosSegundo concurso de juegos utilizando esos grficosJuegos estilo RPG

Concursos

http://latam.square-enix.com/

Concurso de Square EnixBuscan gente para trabajar con ellosInnovacin en video juegosJuegos para Smartphones y navegador web

Gracias

Preguntas?