Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Constructive advice? In MY /prog/??!

Name: anon4help !!SMc+oRp3hlfrttZ 2011-02-27 3:36

Hey /prog/. I'm making a game engine.

I'm using C++ as my main language, maybe with a bit of LUA.
My goal is to make a simple verticle shooter, but with complex bullet patterns and smart enemies as entities.
If any of you played Touhou, you've got a pretty good idea.
I'm using DirectX as my main graphics and sound implementation, and everything was pretty easy so far.

But the problem lies with the actual management of making the game itself. I have two problems.

The first is, implementing yielding. I tried a Shmup maker with C-like syntax called 'Danmakufu', and it had some pretty clever design, but not enough power. Anyway, it had a cool little feature called "yield", in which it suspends a 'task' created by you, the scripter. See, the objects are already pre-made withing structs, and all I had to do was simply define how they behaved in a structure. A mainLoop for each object is run every frame, and a seperate thread called "Initialize" is run once throughout the per lifetime of the object(s). Most of the time, I'd put tasks up in Initialize, and put in yields to synchronize things like motions and bullet fire the entire script. What yield does, is delay everything within that thread, below that yield, for one frame. It looks like it works by giving up the thread's timeslice for the rest of that frame, and exists the thread. Now, using a return function in windows essentially does the same thing, except when you use the return function, the thread's scope is destroyed and we cannot re-enter it from where we left off like yield does in Danmakufu.

And that's where I have my problem.
My second problem, is how would I go about properly giving objects a behavior, an artificial inteligence? Since my entities are objects, they inherit things like XY coordinates on the screen, textures, vertices, direction, all that stuff. But setting all of those is as easy as passing a few arguments in parameters. EntityObject[indexnum].xpos=40 would easily set the X value to 40 for the object with the vale of indexnum. Passing behaviors isn't as easy, because I'd want to pass multiple functions to it. The most efficient way I can think of solving it is by passing a pointer to a text document in which has all the functions written out already. EntityObject.pointertoTextforBehav="behavior.txt", in which behavior.txt would have things written in it like {EntitySetX(50); yield(50);-wait 50 frames ShootCurtainFire();-done after the waiting


so what would be the best way about solving this sort of thing?

Name: anon4help !!SMc+oRp3hlfrttZ 2011-02-27 4:26

>>7

>You can't have TOUHOU-QUALITY patterns without them.

Actually, I can. If you've ever tried Danmakufu, it's unbelievably easy. And it's also so in any language.
All I'd have to do to spawn bullets in a circle around a given boss is make a function that spawns a bullet (which I've already done) and another to return a given object's data, like XY coordinates.

For example, in Danmakufu code:

FireBullets();

task FireBullets(){
let ang=0; let x=GetX(); let y=GetY(); let speed=1.5; let bullettype=whatever;

loop(infinite){
loop(30){
CreateShot01(x+10*cos(ang),y+10*sin(ang),speed,ang,bullettype);
ang+=360/30;
}
ang+=1;
loop(4){yield;}
}

}

///the above fires bullets in a circle around a given entity. The circle spirals, making the scene looks like its twirling

It's just as easy to do in C++, and the code is pretty obvious. replacing data type int/float for let, replacing task for void, and using for/while for loop() loop types. It's very easy.
The only problem is exiting the scope everytime yield is called so it goes back to the infinite game loop and updates the next object/bullet/whatever. My best guess is that it does this by multithreading and uses a framecounter and sleep() function that suspends the thread until next frame.

But there's still the problem of actually assigning the object this sort of behavior. I want to be able to write it in a text document of some sort and make it as easy as creating an Entity with a function like CreateEnemy("Behavior.txt");, in which this creates one object that inherits the stuff written there.


Well, it doesn't seam to do much good asking here, seeing you're trying to prevent me from writing in the language. I didn't come to ask what I should write code in. I asked how I can get structures to inherit "behaviors" and run them, in which they are updated every frame in an infinite loop.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List