Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have had a recent interest in functional programming and found it to be most appealing to me. However, coming from a OOP background i can't seem to wrap my head around some problems.

The main problem I am having trouble with is parallelism. I am thinking about writing a game functionally so that will be the basis of my example.

Lets say I have a Player class and update method (OOP paradigm here):

class Player(blah blah blah):
    blah blah
    void update(int delta):

If I want to make a bullet, assuming I have a Bullet class, i would do it as so:

if (keydown(SPACE)):
    spritebatchdrawlist.append(new Bullet(self.x, self.y))

Or something like that. However, in a functional language you don't have classes so I thought about how I would make a bullet functionally. Since I know how to draw a bullet flying across the screen using recursion (not gonna show it here) I thought that i could simply call a bullet method that would do its own thing and go where it should. However, if i call said Bullet method, it would stop executing the update method until it finished rendering the Bullet. So my question is this: Is it possible to "partially execute" the bullet method, leave it on the stack, and then execute the next recursive step the next run. I know this is possible with multithreading but I was wondering is you guys knew of a cleaner (and more hardware independent solution)

Thanks

share|improve this question
    
Who said you don't have classes in functional programming languages? –  Alex M. Sep 14 at 22:43
    
Haskell says so –  Asad-ullah Khan Sep 14 at 22:54
1  
    
Haskell isn't the be-all and end-all of functional programming languages –  Ell Sep 14 at 23:00
1  
So basically you're tigthing your hand with an outdated approach you don't even know the basics of, and you think this is a good gamedev question. Original. –  GameAlchemist 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.