domingo, 13 de maio de 2012

Workshop Desenvolvendo Space Invaders com o Flex SDK - UCL

Eu e meu amigo Vitor de Azevedo demos um workshop de três horas na UCL com o título: "Desenvolvendo Space Invaders com o Flex SDK". Como eu prometi, aqui estão os slides e os códigos exemplo
Quaisquer dúvidas que vocês tiverem não esqueçam de faze-las nos comentários!

segunda-feira, 2 de abril de 2012

Downloading all links from a page

You can use the best part of two worlds (Javascript and Python) to rapidly download all the links from a page. As an example, I'm download all the files from this page http://www.inf.ufes.br/~alberto/proc-par/index.html

First, using chrome, open the Developer Console (Ctrl+Shift+J), now click in Console.

Now, using some js do:

links = document.getElementsByTagName('a');
for(var i=0;i<links.length;i++) { console.log(links[i].href); }


And you should get something like this:
http://www.inf.ufes.br/~alberto/proc-par/programa_processamento_paralelo-2012-1.doc
http://www.inf.ufes.br/~alberto/proc-par/Lista_de_Exercicios_de_Processamento_Paralelo.doc
http://www.inf.ufes.br/~alberto/proc-par/Lista_de_Exercicios_de_Processamento_Paralelo2.doc
http://www.inf.ufes.br/~alberto/proc-par/avaliacao_da_aprendizagem-mestrado.doc
http://www.inf.ufes.br/~alberto/proc-par/aula1.doc
http://www.inf.ufes.br/~alberto/proc-par/aula2.doc
http://www.inf.ufes.br/~alberto/proc-par/aula3.doc
...

Copy and paste it into a python file:

links = """
And you should get something like this:
http://www.inf.ufes.br/~alberto/proc-par/programa_processamento_paralelo-2012-1.doc
http://www.inf.ufes.br/~alberto/proc-par/Lista_de_Exercicios_de_Processamento_Paralelo.doc
http://www.inf.ufes.br/~alberto/proc-par/Lista_de_Exercicios_de_Processamento_Paralelo2.doc
http://www.inf.ufes.br/~alberto/proc-par/avaliacao_da_aprendizagem-mestrado.doc
http://www.inf.ufes.br/~alberto/proc-par/aula1.doc
http://www.inf.ufes.br/~alberto/proc-par/aula2.doc
http://www.inf.ufes.br/~alberto/proc-par/aula3.doc
....
"""

# Finally download the files

import urllib
links = page.split()
for link in links:
   filename = link.split('/')[-1]
   print 'downloading', filename
   urllib.urlretrieve(link, filename)

Result:


>>>
downloading programa_processamento_paralelo-2012-1.doc
downloading Lista_de_Exercicios_de_Processamento_Paralelo.doc
downloading Lista_de_Exercicios_de_Processamento_Paralelo2.doc
downloading avaliacao_da_aprendizagem-mestrado.doc
downloading aula1.doc
downloading aula2.doc
downloading aula3.doc
downloading aula4.doc
downloading aula5.doc
downloading aula6.doc
downloading Cs252s06-lec04-cache-alberto.ppt
downloading Cs252s06-lec07-dynamic-sched-alberto.ppt
downloading Cs252s06-lec08-dynamic-schedB-alberto.ppt
downloading Cs252s06-lec09-limitsSMT-alberto.ppt
downloading L16-Vector-alberto.pptx
downloading L17-VectorII-alberto.pptx
downloading sbac-tutorial-cuda-15.ppt
downloading Slides%20-%20Chapter%203-Alberto.ppt
downloading Slides%20-%20Chapter%204-Alberto.ppt
downloading Slides%20-%20Chapter%205-alberto.ppt
downloading Slides%20-%20Chapter%206-alberto.ppt
downloading Cs252s06-lec12-SMP-alberto.ppt
downloading Cs252s06-lec13-sharedaddress-alberto.ppt
downloading openmp-ntu-vanderpas.pdf
downloading openmp-spec25.pdf
>>>


Remember that it saves the files on where the python script is located.

sexta-feira, 16 de março de 2012

Explorando a mecânica de Diamond Dash e Bejeweled

Pequeno experimento de hoje para fazer um jogo similar a Diamond Dash


Granja Maluca

Modelando inimigos usando Máquinas de Estado.
O uso da função exp para ajuste de dificuldade



quinta-feira, 2 de fevereiro de 2012

Approximating damping calculations using Taylor expansions in physics simulation

I was happily following Game Physics Engine Development Book when I came across the damping approximation. Without any real explanations we got this 2 lines of code:
// Impose drag.
velocity *= real_pow(damping, duration);
An equation that involves a power of t, I freaked out. How is this possible? And then, researching a little about this I tried to understand how to numerical approximate the friction equation F = -cv. Researching more, I started to explore Box2D code, when I finnaly got a reasonable explanation, but still, there was some magical steps. Time to get my calculus books from the shelf.


This can be coded in as3 as:
velocity.scaleBy(1 - damping*duration);

It's always nice when you have the opportunity to use the stuff you learned in your undergrad course. I still don't understand the power of t thing, but I can accept this solution.

quarta-feira, 1 de fevereiro de 2012

How to make a High Scores board to your Flash game using Google App Engine - Part 1

In this tutorial you will learn how to make an online high scores board to your flash game using Google App Engine infrastructure. It'll be a two posts tutorial, on this first you'll build the server in Python and in the second post the client in AS3.

First, you need to install Python 2.5 and Google App Engine. Both sites are full of tutorials on how to do this in many operating systems.

Google App Engine is a platform for developing and hosting web applications. So, to make things easier, our flash game will interact with our app as it were a web site. How can we do this? Using the UrlRequest and UrlLoader classes

I'm not going to cover more than the really necessary part of Google App Engine framework for making a high scores board. Let's examine these data storage examples of Google's page
from google.appengine.ext import db

class Greeting(db.Model):
    author = db.UserProperty()
    content = db.StringProperty(multiline=True)
    date = db.DateTimeProperty(auto_now_add=True)
We can easily adapt this to our needs:
class Score(db.Model):
     name = db.StringProperty()
     points = db.IntegerProperty()  

This one is bit more confusing, but if you have some experience with web development you can understand why we can turn this
class Guestbook(webapp.RequestHandler):
    def post(self):
      guestbook_name = self.request.get('guestbook_name')
      greeting = Greeting(parent=guestbook_key(guestbook_name))

      if users.get_current_user():
        greeting.author = users.get_current_user()

      greeting.content = self.request.get('content')
      greeting.put()
      self.redirect('/?' + urllib.urlencode({'guestbook_name': guestbook_name}))

to this
class SendScore(webapp.RequestHandler):
    def post(self):
        score = Score()

        score.name = self.request.get('name')
        score.points = int(self.request.get('points'))
        score.put()

        self.response.out.write('ok')

This last snippet is going to get the variables name and points from a urlrequest and save them on Score database. For more explanations on this check the original example.

And finally, we need to list the first nth players (in this case, 15):
class MainHandler(webapp.RequestHandler):
    def get(self):
        #self.response.out.write('Hello world 2!')

        scores = db.GqlQuery("SELECT * FROM Score ORDER BY points DESC LIMIT 15")

        for score in scores:
            self.response.out.write(score.name)
            self.response.out.write('\t')
            self.response.out.write(str(score.points))
            self.response.out.write('\n')

def main():
    application = webapp.WSGIApplication([('/', MainHandler),
                                          ('/sendscore', SendScore)],
                                         debug=True)
    run_wsgi_app(application)


if __name__ == '__main__':
    main()
It's very straightforward if you know some SQL and Python. The characters \t and \n are used to parse the data in as3. It's done. In the next part we'll learn how to communicate with this server through as3 using the flash.net API.

domingo, 29 de janeiro de 2012

Portfolio


games

Fui responsável pelo game design e toda a programação deste jogo. Este jogo foi feito utilizando o framework de desenho PIXI.


Physiojoy - Therapeutic - Game Developer
Neste jogo fui responsável pela implementação de parte da lógica de jogo, e também da integração com Kinect, este projeto é feito com a engine Unity.


Hotpark é um advergame para facebook. Fui responsável pela implementação do gameplay utilizando flixel, um detalhe interessante foi o 3D falso que foi usado controlando o tamanho dos objetos, além disto também animei as interfaces por código. Neste jogo também fiz a integração com facebook e o highscore.


Este foi um experimento que fiz para implementar o algoritmo de inteligência artificial minimax. 


Metamorphosis foi um jogo que eu e um amigo fizemos em 48 horas para um desafio online, ele foi responsável pela arte e parte do level design e eu pelo game design e programação, foi utilizada a engine flixel.

demos
Este demo foi um trabalho da matéria computação gráfica do meu curso de ciência da computação. Nesta demonstração tive que implementar um loader de .obj, além da lógica de skybox e movimentação da nave.


Este foi um experimento para aplicar um algoritmo de busca em profundidade. Também gostei das cores que escolhi.