entity system demo
Community Forums/Showcase/entity system demo
| ||
http://skn3.acsv.net/junk/entitydemo.zip I suddenly got motivation to work on my game so thought I would post this. Basically I have compiled "pieces" from about 6-7 different started (and dumped) games, into an engine. Currently there is: *a map class saves, loads and compresses a map file with either internal or external graphics. *engine class provides a runtime enviroment for any screen. simply extend the runtime object create a new instance and poitn the engine to it. *input class provides a 2 axis/ 6 button input method. the input object has extended mouse/keyboard/joypad objects. the class will handle key hit/down/tick and release automatically. *entity class simple to use extendable class that handles all entity position and rotating. supports parenting of objects and rotation/scale/position inheritance (see demo) I just thought my code was going to waste so Im compiling it. Each section of the engine is stand alone, so only the files you need have to be included. Well thats all very interesting, I just thought Id post it on here cos I was bored. lol. code for the demo: SuperStrict Framework BRL.GLMax2D Import BRL.Math Import BRL.LinkedList Import BRL.Random '------------------------------------------------------------------------------ ' imports '------------------------------------------------------------------------------ Import "libs/cmap.bmx" Import "libs/ccontrol.bmx" Import "libs/cengine.bmx" Import "libs/centity.bmx" '------------------------------------------------------------------------------ ' includes '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' constants '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' classes '------------------------------------------------------------------------------ Type clevel Extends cruntime Final 'fields Field map:cmap = CreateMap() 'methods Method Reset:Int() 'resets the level End Method Method Update:Int() 'updates the runtime of the level End Method End Type '------------------------------------------------------------------------------ ' main program '------------------------------------------------------------------------------ Local level:clevel = New clevel level.map.load("data/maps/test.map") Local control:ccontrol = New ckeyboard control.SetAxis(KEY_UP,KEY_LEFT,KEY_DOWN,KEY_RIGHT) control.SetButtons(KEY_Q,KEY_W) Local engine:cengine = New cengine engine.setruntime(level) engine.start() Local group:cgroup = New cgroup Local temp:Float Local tempent:centity Local ent_root:centity = New centity ent_root.setposition(320,240) ent_root.centerhotspot() group.addentity(ent_root) 'sky Local ent_sky:centity = New centity ent_sky.setposition(320,190) ent_sky.setsize(640,380) ent_sky.centerhotspot() ent_sky.setdebugcolor(163,221,243) ent_root.addchild(ent_sky) group.addentity(ent_sky) 'ground Local ent_ground:centity = New centity ent_ground.setposition(320,430) ent_ground.setsize(640,100) ent_ground.centerhotspot() ent_ground.setdebugcolor(0,255,0) ent_root.addchild(ent_ground) group.addentity(ent_ground) 'sun center Local ent_sun:centity = New centity ent_sun.setposition(90,90) ent_sun.setsize(75,75) ent_sun.setdebugcolor(255,231,31) ent_sun.centerhotspot() ent_root.addchild(ent_sun) group.addentity(ent_sun) 'sun beam container Local ent_sun_beam:centity = New centity ent_sun_beam.setposition(90,90) ent_sun_beam.setsize(0,0) ent_sun_beam.setdebugcolor(255,231,31) ent_sun_beam.centerhotspot() ent_sun.addchild(ent_sun_beam) group.addentity(ent_sun_beam) 'sun beam beams For temp = 0 Until 360 Step 45 tempent = New centity tempent.setposition(90+(Cos(temp)*45),90+(Sin(temp)*45)) tempent.setsize(45,10) tempent.setdebugcolor(255,243,145) tempent.setangle(temp) tempent.sethotspot(0,5) ent_sun_beam.addchild(tempent) group.addentity(tempent) Next 'items Local itemgroup:tlist = CreateList() For temp = 0 Until 360 Step 10 tempent = New centity tempent.setposition(Rand(10,620),Rand(10,460)) tempent.setsize(20,20) tempent.setdebugcolor(Rand(0,255),Rand(0,255),Rand(0,255)) tempent.setangle(Rnd(0,360)) tempent.centerhotspot() ent_root.addchild(tempent) group.addentity(tempent) itemgroup.addlast(tempent) Next 'ferris base Local ent_ferris:centity = New centity ent_ferris.setposition(320,255) ent_ferris.setsize(50,350) ent_ferris.setdebugcolor(170,131,64) ent_ferris.centerhotspot() ent_root.addchild(ent_ferris) group.addentity(ent_ferris) 'ferris wheel Local ent_ferris_wheel:centity = New centity ent_ferris_wheel.setposition(320,145) ent_ferris_wheel.setsize(100,100) ent_ferris_wheel.setdebugcolor(160,160,160) ent_ferris_wheel.centerhotspot() ent_root.addchild(ent_ferris_wheel) group.addentity(ent_ferris_wheel) 'ferris arms For temp = 0 Until 360 Step 60 'arm tempent = New centity tempent.setposition(320+(Cos(temp)*45),145+(Sin(temp)*45)) tempent.setsize(220,20) tempent.setdebugcolor(200,200,200) tempent.setangle(temp) tempent.sethotspot(0,10) ent_ferris_wheel.addchild(tempent) group.addentity(tempent) 'platform tempent = New centity tempent.setposition(320+(Cos(temp)*260),145+(Sin(temp)*260)) tempent.setsize(80,40) tempent.setdebugcolor(214,104,107) tempent.setangle(0) tempent.centerhotspot() tempent.inheritorientation = False ent_ferris_wheel.addchild(tempent) group.addentity(tempent) Next While KeyDown(KEY_ESCAPE) = False Cls control.update() 'user controlled changes If control.isup() ent_root.move(0,-2) If control.isdown() ent_root.move(0,2) If control.isleft() ent_root.move(-2,0) If control.isright() ent_root.move(2,0) If control.isbutton1() ent_root.turn(-2) If control.isbutton2() ent_root.turn(2) 'non user controlled changes ent_sun_beam.turn(3) ent_ferris_wheel.turn(-1) For tempent = EachIn itemgroup tempent.turn(1) Next group.update() engine.update() Flip Wend |
| ||
Sounds good, although seperating these things strictly in classes sounds very abstract to me. If I start things too abstract, then they never get anywhere. At the other hand some ugly huge spaghetti code sometimes is getting real effective. Must be the multidirectional linked spaghetti strings. But still: tho shall not spaghetti code. So: classes must be good after all. |