Author Topic: 2D - "Entity System"  (Read 1352 times)

Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
2D - "Entity System"
« on: 2012-Jun-15 »
Hi guys,

would you be interested in a "2D Entity System" where you can easily create an entity like in the 3D Entity System and then use powerful functions to move / rotate them?

An example code with 10 boxes moving relative to there parents would look like this:
Code: GLBasic [Select]
// --------------------------------- //
// Project: 2DEntity
// Start: Friday, June 15, 2012
// IDE Version: 10.202

SYSTEMPOINTER TRUE //enable the system pointer

//grab a test sprite
LOCAL spr% = GENSPRITE()
DRAWRECT 0,0,10,10,RGB(255,0,0)
GRABSPRITE spr,0,0,10,10

//---INIT ENTITY STUFF---
LOCAL es2D AS T2DEntitySystem //create a new entity system

LOCAL boxes[] //entity array

//create 10 entities in a line
FOR i%=0 TO 9
        LOCAL box% = es2D.CreateEntity(i * 30, 0, 0)
        es2D.SetTexture(box, spr)
       
        IF i > 0 THEN es2D.SetParent(i, i-1) //the entity before is now the parent of this entity
        DIMPUSH boxes[], box
NEXT

LOCAL angle# = .0

//---MAIN LOOP---
WHILE TRUE
        LOCAL mx,my,b1,b2
        MOUSESTATE mx,my,b1,b2
       
        //move the angle with the mouse buttons ;)
        angle = 0
        IF b1 THEN angle = 1
        IF b2 THEN angle = -1
       
        FOR i%=0 TO 9
                es2D.Rotate(boxes[i], angle*i/10)
        NEXT
       
        es2D.SetPosition(boxes[0],mx-5,my-5)
       
        es2D.DrawSystem() //draw the whole system with only one command :)
        SHOWSCREEN
WEND
 

The result would look like the demo in the attachments :good::

[attachment deleted by admin]

Offline kaotiklabs

  • Dr. Type
  • ****
  • Posts: 313
  • Spain is diferent
    • View Profile
Re: 2D - "Entity System"
« Reply #1 on: 2012-Jun-15 »
Yeah, it would be very good for even manage game menus with transitions easily.

Is a great idea.
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
Re: 2D - "Entity System"
« Reply #2 on: 2012-Jun-15 »
Maybe monday I will upload a first version of the system!

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3365
  • Integrated Brain
    • View Profile
Re: 2D - "Entity System"
« Reply #3 on: 2012-Jun-15 »
Hi backslider sounds very interesting!!! a lot of work, but I think can be very usefull if it´s easy to use...

Thanks for yours works!!!