I made a small Example of My Old Game Engine Concept

Started by Hardcoal, June 24, 2024, 07:58:24

Previous topic - Next topic

Hardcoal

Ive made a Max Gui version of my old engine.. that used to run on Xors 3D
I wanted to share my concept and see you guys thoughts about it.

so the engine has a 'MainEngine' runner and it run its objects.

there is one extender called ElementExtender_class  that each object needs it

here is an example of an object

Type SpaceShip_Type Extends ElementExtender_Class

Field HorSpeed:DataCell_Type = AddDataCell(Self, 2)
Field VertSpeed:DataCell_Type = AddDataCell(Self, 2)
Field CircleSize:DataCell_Type = AddDataCell(Self, 20)

Method privatePlay()
SetColor(255, 0, 0)
DrawOval(X, Y, CircleSize.Float_Data, CircleSize.Float_Data)
DrawText ("Use WASD", X - 30, Y - 30)
If KeyDown(KEY_D) Then X = X + HorSpeed.Float_Data
If KeyDown(KEY_A) Then X = X - HorSpeed.Float_Data
If KeyDown(KEY_W) Then Y = Y - VertSpeed.Float_Data
If KeyDown(KEY_S) Then Y = Y + VertSpeed.Float_Data
End Method

End Type

you can change the datacell value in real time and each datacell name is being read automatically by the system after running

This is the most basic concept of what i actually done..
and if people like it, i will make it more complex and show what It can actually achieve

(In my most complex version you can make objects inside objects, and so on, built In Acceleration. real time graphic Parameters Editing)


here is the full code (made into a single file)

Strict
 
Import maxgui.Drivers  'Turn on Import on the Lib
Import brl.basic
Import rigz.Math

Import brl.reflection
Import brl.eventqueue
Import brl.max2d

EnablePolledInput()

Graphics 800, 600

'Display

Global Win_Gad:TGadget = CreateWindow("Test", 10, 10, 500, 600)

CreateLabel("Choose Element to change its Parameters", 10, 10, 300, 25, Win_Gad)
Global Combo:TGadget = CreateComboBox(10, 40, 200, 30, Win_Gad)

Global Panel:TGadget = CreatePanel(10, 100, 300, 400, Win_Gad)
Global DCDisplayList:TList = CreateList()

'Create

   'Engine

Global MaxEng:MaxEngine_Type = New MaxEngine_Type

   'Elements Examples
   
MaxEng.CreateNewElement(New SpaceShip_Type)

Local Bullet:ElementExtender_Class = MaxEng.CreateNewElement(New ShootBullet_Type)
AddBehaviorToElement(Bullet, New RandomMove_Behave)

Repeat

PollEvent()
Cls

MaxEng.EngPlay()

Delay(5)
Flip

Until KeyHit(KEY_SPACE) Or WindowClosedPressed(Win_Gad) Or KeyHit(KEY_ESCAPE)


'----------General-----------'

Function WindowClosedPressed(Window:TGadget)
Return EventID() = EVENT_WINDOWCLOSE And EventSource() = Window
End Function

'------------Engine----------'

Type MaxEngine_Type

Field ClassesList:TList = CreateList()
Field CurrentElement:ElementExtender_Class

Method EngPlay()

   'Elements Play
   
For Local Class:ElementExtender_Class = EachIn classeslist

  Class.PrivatePlay()
For Local Bhv:ElementExtender_Class = EachIn Class.BehaviorList
Bhv.PrivatePlay()
Next

Next

   'Element Data Display

   'Element Selector
   
Local SName:String = GetSelectedComboItemName(Combo)
If SName <> "" Then
ClearDCDisplay()
CurrentElement = GetClassByName(SName)
ChargeClassDisplay(CurrentElement)
End If

   'Elements Display
   
If CurrentElement <> Null Then

DrawText("CurrentElement Name: " + CurrentElement.name, 10, 10)

   'Change Values

Local Cntr
For Local TF:DCDisplayCell_Type = EachIn DCDisplayList

If TextAreaMouseLeftHit(TF.TextArea) Then SetGadgetText(TF.TextArea, "")

If GadgetEnterPressed(TF.TextArea) Then
DataCell_Type(CurrentElement.DataCellsList.ValueAtIndex(Cntr)).Float_Data = GadgetText(TF.TextArea).ToFloat()
End If

Cntr = Cntr + 1
Next

End If

End Method

Method ChargeClassDisplay(Class:ElementExtender_Class)

   'Create Display
   
Local Cntr
For Local DC:DataCell_Type = EachIn Class.DataCellsList
Local TF:DCDisplayCell_Type = New DCDisplayCell_Type
ListAddLast(DCDisplayList, TF)
TF.label = CreateLabel ("", 20, Cntr * 30, 100, 25, Panel)
TF.TextArea = CreateTextField(120, Cntr * 30, 200, 25, Panel)
SetGadgetSensitivity(TF.TextArea, SENSITIZE_ALL)
SetGadgetText(TF.TextArea, DC.Float_Data)
Cntr = Cntr + 1
Next

   'Charge DC Names
   
Local TFCntr
For Local TargetFld:TField = EachIn TTypeId.ForObject(Class).EnumFields()
If TargetFld.TypeId().name() = "DataCell_Type" Then
SetGadgetText(DCDisplayCell_Type(DCDisplayList.ValueAtIndex(TFCntr)).label, TargetFld.name())
TFCntr = TFCntr + 1
End If
Next

End Method

Method ClearDCDisplay()
For Local TF:DCDisplayCell_Type = EachIn DCDisplayList
FreeGadget(TF.label)
FreeGadget(TF.TextArea)
Next
ClearList(DCDisplayList)
End Method

Method CreateNewElement:ElementExtender_Class(Class:ElementExtender_Class)
Class.name = TTypeId.ForObject(Class).name() + " " + ClassesList.count()
ListAddLast(ClassesList, Class)
AddGadgetItem(Combo, Class.name)
CurrentElement = Class
Return Class
End Method

Method GetClassByName:ElementExtender_Class(ClassName:String)
For Local c:ElementExtender_Class = EachIn ClassesList
If c.name = ClassName Then Return c
Next
End Method

End Type

   'Main Element Extender

Type ElementExtender_Class

Field name:String

Field PlayThis:ElementExtender_Class = Self

   'Common Data
   
Field X:Float = 200
Field Y:Float = 200

Field BehaviorList:TList = CreateList()

Field DataCellsList:TList = CreateList()
Method PrivatePlay() Abstract

End Type

Type DataCell_Type

Field name:String

   'Data
   
Field Float_Data:Float
Field Int_Data
Field String_Data:String

Field DataCellRemark$

End Type

Type DCDisplayCell_Type
Field CD:DataCell_Type
Field label:TGadget
Field TextArea:TGadget
End Type

   'Other Functions
   
Function AddBehaviorToElement(Element:ElementExtender_Class, Behavior:ElementExtender_Class)
Behavior.PlayThis = Element
ListAddLast(Element.BehaviorList, Behavior)
End Function

Function AddDataCell:DataCell_Type(Class:ElementExtender_Class, FloatData:Float)
Local NDC:DataCell_Type = New DataCell_Type
ndc.Float_Data = FloatData
ListAddLast(Class.DataCellsList, NDC)
Return NDC
End Function

'----------PreMade Elements [Examples]-----------'

Type SpaceShip_Type Extends ElementExtender_Class

Field HorSpeed:DataCell_Type = AddDataCell(Self, 2)
Field VertSpeed:DataCell_Type = AddDataCell(Self, 2)
Field CircleSize:DataCell_Type = AddDataCell(Self, 20)

Method privatePlay()
SetColor(255, 0, 0)
DrawOval(X, Y, CircleSize.Float_Data, CircleSize.Float_Data)
DrawText ("Use WASD", X - 30, Y - 30)
If KeyDown(KEY_D) Then X = X + HorSpeed.Float_Data
If KeyDown(KEY_A) Then X = X - HorSpeed.Float_Data
If KeyDown(KEY_W) Then Y = Y - VertSpeed.Float_Data
If KeyDown(KEY_S) Then Y = Y + VertSpeed.Float_Data
End Method

End Type

Type ShootBullet_Type Extends ElementExtender_Class

Field StartX:DataCell_Type = AddDataCell(Self, 200)
Field StartY:DataCell_Type = AddDataCell(Self, 300)
Field XSpeed:DataCell_Type = AddDataCell(Self, 2)
Field YSpeed:DataCell_Type = AddDataCell(Self, 0)

Method New()
X = StartX.float_data
Y = StartY.float_data
End Method

Method privatePlay()
SetColor(0, 255, 0)
DrawRect(X, Y, 10, 10)
X = X + XSpeed.float_data
If X > 1000 Then X = 0
End Method

End Type

   '--Behaviors--'
   
    Type RandomMove_Behave Extends ElementExtender_Class

Field RandomNess:DataCell_Type = AddDataCell(Self, 1)

Method privatePlay()
            PlayThis.X = PlayThis.X + Rnd (-RandomNess.Float_Data, RandomNess.Float_Data)
PlayThis.Y = PlayThis.Y + Rnd (-RandomNess.Float_Data, RandomNess.Float_Data)
End Method

End Type

'Max Gui Commands

Function SelectTreeViewItem(Branch:TGadget, BIndex = 1)
SelectGadgetItem(Branch, BIndex)
End Function

Function GetSelectedComboItemName:String(ComboBox:TGadget)
Select EventID()
        Case EVENT_GADGETACTION
            If EventSource() = ComboBox
                Local SelectedItem:String = GadgetText(ComboBox)
                Return SelectedItem
            EndIf
    End Select
    End Function

Function TextAreaMouseLeftHit(TA:TGadget)
Return EventID() = 1026 And EventSource() = TA And EventData() = 1
End Function

Function GadgetEnterPressed(TA:TGadget)
Return EventID() = 8200 And EventSource() = ta
End Function


Some of the things I've done:   https://itch.io/profile/hardcoal  [I keep improving them btw]
My Google Drive https://drive.google.com/drive/folders/1vOgkOxA_YwdMaomM2-K4NQh0mpwgpkii?usp=drive_link

Baggey

Where do you get Import rigz.Math from? :-X

Kind Regards Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on Acer 24" . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

SToS

Quote from: Baggey on June 25, 2024, 18:48:02Where do you get Import rigz.Math from? :-X

Baggey, you really need to learn how to use a search engine! :))
https://github.com/peterigz/rigz.mod

Baggey


QuoteBaggey, you really need to learn how to use a search engine! :))
https://github.com/peterigz/rigz.mod 

Yeah! ::)

Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on Acer 24" . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

Hardcoal

Im rebuilding my own Game maker again.
but this time much quicker, simpler . different approach
so outcomes suppose to be quick.

I took all my lessons from the previous attempt.
lets see if ill make it this time
Some of the things I've done:   https://itch.io/profile/hardcoal  [I keep improving them btw]
My Google Drive https://drive.google.com/drive/folders/1vOgkOxA_YwdMaomM2-K4NQh0mpwgpkii?usp=drive_link