[Haskell-cafe] Improving event management in elerea

jean legrand kkwweett at yahoo.fr
Wed Aug 12 23:23:21 EDT 2009


Hi Haskellers,
I've written a new version of the breakout elerea-example where mouse is replaced by LEFT and RIGHT keys 

http://hpaste.org:80/fastcgi/hpaste.fcgi/view?id=8159

and I have two questions.

1) my event function (line 79) returns a new signal and takes 3 arguments : an initial signal and a Bool signal which triggers when to apply the transform function given as a third argument. The body of the event function uses two calls to the sampler function. Is it possible to write this body with a unique call to sampler ?

2) this event function is used to link a keypress with a transformation of the position of the player. It is thus called two times (lines 91 and 94), one for each one of the two keys LEFT and RIGHT. Thanks to the ability to compose a new Bool signal from other ones, it is possible to define a guard for the transform function during the calls to event (lines 92 and 95 : the incrementation (decrementation) is only doable when the player abscissa is less than 0.6 (more than -0.8)). 
Nevertheless, during the game, I noticed some discrepancy with this ideal description : try to go to an extreme side (several hits of the LEFT key for instance until the player hits the left side) then go back in the opposite direction before hitting the opposite side (three hits of the RIGHT key for instance) then the first key pressing corresponding to the opposite of the opposite direction (i.e the initial LEFT direction) has no effect. Do you understand why ?

Thanks


      


More information about the Haskell-Cafe mailing list