uqbar-project / wollok

Wollok Programming Language
GNU General Public License v3.0
60 stars 16 forks source link

Allow a character to say something not necessary triggered by the keyboard #488

Closed javierfernandes closed 8 years ago

javierfernandes commented 8 years ago

Currently there's only one way to make the character say something

keys.onPress("P").characterSay [ "Mensaje de prueba!"]

But for some games, I want to say something when for, example a character collides with another one. Fore example for pacman, I want a bubble saying "you lost" when it hits a ghost

javierfernandes commented 8 years ago

Is there currently a way ? @PalumboN

Juancete commented 8 years ago

At the moment there's no way.

The Key object has a onPress method that returns a ProtoKeyListener. This last Class splits the characterSay and do actions methods. (May be we can join those to one single method because both receive a closure).

There's no objecto to manage the collision. It's simply coded by calling a method in wgame object, like:

wgame.whenCollideDo(sokoban, [ e | sokoban.empuja(e) ])

if whenCollideDo returns a ProtoKeyListener (renamed to ProtoListener) it's an option?

@PalumboN @javierfernandes What do you all think?

javierfernandes commented 8 years ago

Well the thing is that the piece of code will be kind of buried in my domain. Checkout https://github.com/javierfernandes/wollok-wakman/blob/master/src/wacman.wlk

I have a whenCollide call to wgame, but to get to the point where I need to say something, it goes through a series of callbacks (double dispatch). So having the "say" function at the whenCollide level, will make it harder.

I think for the moment we can just add it as a method on a place which is accesible from anywhere. So two options (where "this" is a character)

Most global

wgame.say(this, "hello")    

More local

posicion.say(this, "hello")    // even better, would be to avoid the this here if the position has state and knows the character. But well
PalumboN commented 8 years ago

Now we can do it using mixings. Do you like it?

javierfernandes commented 8 years ago

Yes, implemented as a mixin sounds good. It's not merged neither into "dev" nor "dev-1.4" yet. I'll timeout and merge it in 1.4 in a while.

Also we should think on how this will affect a student that doesn't know what a mixin is.