TGC Codebase Backup



Db1 Type by DarkTy

2nd Dec 2006 4:05
Summary

Hallo! Learn how to make Array in Structure Type-Sub-Item-Element. No need file media , it is ok to run with DbClassic. :-) This proget view how to use Type , for make array for el



Description

I've made a example for make a structure type with sub element array
You can to exsperiment structure , reading data on screen and view 3d scene.

[UpKey ] = Select the previw Id
[DownKey] = Select the Next Id
[LeftKey] = Select the preview SubItem Id
[RightKey] = Select the next SubItem Id
[SpaceKey] = Reset Selection on First Id and 0 subItemId and NEW VALUES to variables Type

if you want to rallenty then hide Rem on line 278 of this code:
REM IF OkFreccia>=1 And OkFreccia<=4 Then OkFreccia=0 : wait 300

This is my first code for The Game Creator!!!



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    Rem *********************************************************************
REM PROGRAM 2006    BY Tonino (I'm DarkTy On The Italian Forum ,(Kataxia)
Rem *********************************************************************

Rem 1) Sorry for my English!!!

Rem ***************
Rem What this is ?
Rem *************************************************************************************************************
Rem this Program Use Structure Variable  as Type and made variable Type like a Array
Rem and use array SubElement of this Array Type
Rem It's Ok For version Db1 Classic , but I Want to know how is structur for sub element in Dbpro version
Rem Tank-You
Rem -------------------------------------------------------------------------------------------------------------
Rem Questo programma serve per mostrare come si utilzza la struttura type per dimensionare anche i sotto-elementi
Rem *************************************************************************************************************


REm ************
Rem How to use ?
REm **************************************************************************************************************
Rem This Example view Object Box for to rappresent index of structure (from 1 to 10)
Rem ...and use Object Sphere for to rappresent Sub-Element of structure (from 0 to 5)
Rem You Can select id from 1 to 10 whit key press to arrow key [UpKey() = iD + 1]  [DownKey = Id - 1]
Rem You Can select SUB-id-Element from 1 to 5 whit key press to arrow key [LeftLey() = Sub_iD - 1]  [RightKey() = Sub_Id - 1]
Rem Yuo can read data value in format text on the display , and view data color of sub element on 3d object
Rem --------------------------------------------------------------------------------------------------------------
Rem in questo esempio viene rappresentata graficamente la struttura type con oggetti plain per il nodo radice
Rem e con delle sfere per le variabili che hanno sotto-elementi
Rem Utilizzare le freccie per posizionarsi negli indici desiderati e [Spazio] per resettare.
REm **************************************************************************************************************

REMSTART

[INIZIO STRUTTURA]                                                        [BEGIN STRUTTURA]

Type MioTipo
     Id
     X
     Y
     Z
     QSubOggetti
     Id_SubOggetto(20)                       <<<< Sub Element1 ()
     Id_SubOggetto_Colore(20)                <<<< Sub Element2 ()
EnDType

[FINE-STrutura]                                                            [END STRUCTUR]

[Dimensionamento Struttura]

DimType MioTipo, Array(101)


REMEND

REMSTART
REM ****************************                         ***************
REM ****************************                         ***************
REM INDICE BLOCCHI DEL PROGRAMMA                         -Index Of Block
REM ****************************                         ***************
REM ****************************                         ***************
0001 IMPOSTATIONI INIZIALI                               -0001  Begin Impostation
0002 CREAZIONE DELLA MATRICE                             -0002  Make Matrix
0003 CREAZIONE OGGETTO DI COGNIZIONE                     -0003  Object Of Cognition (ghost sphere)
0004 DICHIARAZIONI E DIMENSIONAMENTI E TIPI              -0004  Declaration of Arrays,variables,Types
0005 ASSEGNAZIONE DEI VALORI AD UN ARRAY CON INDICE 0    -0005  Assign values to property array with index 0
0006 ENUMERAZIONI PER LE COSTANTI DI COLORE              -0006  Enumerations for costant of colours to use associate with variable type subItem
0007 PREPARAZIONE 10 IMMAGINI NUMERICHE                  -0007  Prepare texture for object "parent"  (Red = unselected Green=Selected Blue=..(Not used))
0008 >>>>>> POPOLA I VALORI DELLA STRUTTURA              -0008  >>>>> CALL LABEL PROCEDURE for Popolation of value arrays-type
0009 PREDISPOSIZIONI DELLE VARIABILI DI DEFAULT          -0009  Variables of Default , Id=0 , SubId1=0 , SubId2=0
0010 CICLO PRINCIPALE                                    -0010  PRINCIPAL CYCLE

     DO 0001 >>>>> VISUALIZZA IL TITOLO                       -DO 0001       CALL LABEL: View Title
     DO 0002 CONTROLLO UTENTE                                 -DO 0002       Control Utente
     DO 0002.0001 >>>>>> POPOLA I VALORI DELLA STRUTTURA      -DO 0002.0001  CALL LABEL:    Popolate the structure type with NEW values
     DO 0003 POSIZIONO LA SFERA FANTASMIZZATA SULLA SELEZIONE -Do 0003       Move gost sphere on Element Selected
     DO 0004 >>>>> AGGIORNAMENTO VISUALIZZAZIONE DATI         -DO 0004       CALL FUNCTION: Update View Data of Structure Type
     DO 0005 SINCRONIZZAZIONE DELLO SCHERMO                   -DO 0005       Update Syncronizzation of the screen

0010 LOOP

0011 *ETICHETTE*                                         -0011 *LABELS*
      E_0001 E_POPOLAMENTO_STRUTTURA:                           E_0001 E_POPOLAMENTO_STRUTTURA:
      E_0002 E_Visualizza_Titolo:                               E_0002 E_Visualizza_Titolo:

0012 *FUNZIONI*                                          -0012 *FUNCTIONS*
      F_0001 FuNCTION VisualizzaProprieta                       F_0001 FuNCTION VisualizzaProprieta
            (IdSelezionato,SubIdSelezionato1,                          (IdSelezionato,SubIdSelezionato1,
             SubIdSelezionato2)                                         SubIdSelezionato2)
REM ****************************                         ***************




REMEND

REM *****
REM   1 *
REM =====================
REM IMPOSTATIONI INIZIALI  - Begin Impostation
REM =====================
Set Display mode 1024,768,32
Sync Rate 1000
Sync on
SET TEXT OPAQUE
SET TEXT FONT "verdana"
SET TEXT SIZE 20

Backdrop On
Color BackDrop 0
AutoCam Off
Randomize Timer()

REM *****
REM   2 *
REm =======================
REM CREAZIONE DELLA MATRICE - Make Matrix
REm =======================
MAKE MATRIX 1,50,50,10,10

REM *****
REM   3 *
REM ===============================
REM CREAZIONE OGGETTO DI COGNIZIONE  -  Object Of Cognition (ghost sphere)
REM ===============================
IdSferaSelezione=1000
MAKE OBJECT SPHERE IdSferaSelezione,5
Ghost Object on IdSferaSelezione

REM *****
REM   4 *
REM ======================================
REM DICHIARAZIONI E DIMENSIONAMENTI E TIPI
REM ======================================

TYPE MioTipo
     Id
     X
     Y
     Z
     QSubOggetti
     Id_SubOggetto(20)
     Id_SubOggetto_Colore(20)
EndType

DimType MioTipo, Array(101)

REM ATTENZIONE!!!

REm *************************
REM DarkBasic Classic:                IMPORTANTE!!! -  IMPORTANT!!!     DB1Classic
REm *************************
Rem DimType MioTipo, Array(101)
REm ---------------------------

REm *************************
REM DarkBasic PRo:
REm *************************
REM Dim Array(101) as MioTipo         IMPORTANTE!!! -  IMPORTANT!!!     DB Pro
Rem -------------------------

Rem Ma/But i/The   sub element in DbPro ????



REM *****
REM   5 *
REM ================================================
REM ASSEGNAZIONE DEI VALORI AD UN ARRAY CON INDICE 0  - Assign values to property array with index 0
REM ================================================
Rem [Esempio della struttura riempita con metodo diretto e in manuale]
Array(0).Id=0                             :Rem Indica l'id di riconoscimento dell'oggetto 3D da creare
Array(0).X=0                              :Rem Indica La coordinata X 3D dell'oggetto con id = Array(0).Id Quindi X = Array(0).X
Array(0).Y=0                              :Rem Indica La coordinata Y 3D dell'oggetto con id = Array(0).Id Quindi Y = Array(0).Y
Array(0).Z=0                              :Rem Indica La coordinata Z 3D dell'oggetto con id = Array(0).Id Quindi Z = Array(0).Z
For b=1 to 10
    Array(0).Id_SubOggetto(B) = 0
    Array(0).Id_SubOggetto_Colore(B) = 0
Next B
Array(0).QSubOggetti=0


REM *****
REM   6 *
REM ======================================
REM ENUMERAZIONI PER LE COSTANTI DI COLORE , CON RIFERIMENTO AL SOTTO-ELEMENTO :  - Enumerations for costant of colours to use associate with variable type subItem
REM ======================================   Id_SubOggetto_Colore(..)               Id_SubOggetto_Colore(..)
DIM Colore(20)
Colore(1)=RGB(0,255,0)
Colore(2)=RGB(255,0,0)
Colore(3)=RGB(0,255,0)
Colore(4)=RGB(0,0,255)
Colore(5)=RGB(255,255,0)
Colore(6)=RGB(255,0,255)
Colore(7)=RGB(0,255,255)
Colore(8)=RGB(255,255,255)
Colore(9)=RGB(100,100,100)
Colore(10)=RGB(RND(255),RND(255),RND(255))

REM *****
REM   7 *
REM ==================================
REM PREPARAZIONE 10 IMMAGINI NUMERICHE
REM ==================================
FOR a=1 to 10
    REM Immagine per Texture [Rossa]
    CLS RGB(255,0,0)
    Ink Rgb(255,255,0),0
    PRINT STR$(A)
    Get Image A,0,0,100,40
    REM Immagine per Texture [Verde]
    CLS RGB(0,255,0)
    Ink Rgb(255,255,255),0
    PRINT STR$(A)
    Get Image A+10,0,0,100,40
    REM Immagine per Texture [Blu]
    CLS RGB(0,0,255)
    Ink Rgb(255,255,255),0
    PRINT STR$(A)
    Get Image A+20,0,0,100,40
NEXT a

REM *****
REM   8 *
REM ======================================
REM >>>>>> POPOLA I VALORI DELLA STRUTTURA
REM ======================================
GOSUB E_POPOLAMENTO_STRUTTURA

REM *****
REM   9 *
REM ==========================================
REM PREDISPOSIZIONI DELLE VARIABILI DI DEFAULT   - Variables of Default
REM ==========================================
IdSelezionato=1      :Rem Indica l'ndice della struttura
SubIdSelezionato1=0  :Rem Indica l'indice del sub_array
SubIdSelezionato2=0  :Rem Non Usato - I've not Used


REM *****
REM  10 *
REM ================
REM CICLO PRINCIPALE - PRINCIPAL CYCLE
REM ================
DO
    REM *******
    REM  DO 1 *
    REM ==========================
    REM >>>>> VISUALIZZA IL TITOLO - View Title
    REM ==========================
    Gosub E_Visualizza_Titolo

    REM *******
    REM  DO 2 *
    REM ================
    REM CONTROLLO UTENTE - Control Utent
    REM ================
    A$=Inkey$()
    If a$=" "
       IdSelezionato=1     :Rem Reset Id
       SubIdSelezionato1=0 :Rem Reset SubId1
       SubIdSelezionato2=0 :Rem RESET SubId2
       REM *********
       REM  DO 2.1 *
       REM ======================================
       REM >>>>>> POPOLA I VALORI DELLA STRUTTURA  - Popolate strutture Type With NEW Values
       REM ======================================
       GOSUB E_POPOLAMENTO_STRUTTURA
    ENDIF
    REM [CONTROL SUB ELEMENT] - [Controllo Del SUB ELEMENTO]
    If LeftKey()=1    THEN OkFreccia=3 : SubIdSelezionato1=SubIdSelezionato1 - 1             :If SubIdSelezionato1 < 0  Then SubIdSelezionato1 = 0
    If RightKey()=1  THEN OkFreccia=4 : SubIdSelezionato1=SubIdSelezionato1 + 1             :If SubIdSelezionato1 >Array(IdSelezionato).QSubOggetti  Then SubIdSelezionato1=Array(IdSelezionato).QSubOggetti

    REM [CONTROL ELEMENT] - [Controllo Dell'ELEMENTO]
    If UpKey()=1  THEN OkFreccia=1 : IdSelezionato=IdSelezionato-1:SubIdSelezionato1=0   :If IdSelezionato<1 Then IdSelezionato=1
    If DownKey()=1 THEN OkFreccia=2 : IdSelezionato=IdSelezionato+1:SubIdSelezionato1=0   :If IdSelezionato>10 Then IdSelezionato=10

    REM IF OkFreccia>=1 And OkFreccia<=4 Then OkFreccia=0 : wait 300

    Text 20,400,"IdSelezionato = " + STR$(IdSelezionato)
    Text 20,420,"SubIdSelezionato1 = " + STR$(SubIdSelezionato1)
    Text 20,440,"SubIdSelezionato2 = " + STR$(SubIdSelezionato2)

    REM *******
    REM  DO 3 *
    REm ================================================
    REM POSIZIONO LA SFERA FANTASMIZZATA SULLA SELEZIONE - Move gost sphere on Element Selected
    REm ================================================
    X=Array(IdSelezionato).X
    Y=Array(IdSelezionato).Y
    Z=Array(IdSelezionato).Z + SubIdSelezionato1*5
    Position OBJECT IdSferaSelezione,X,Y,Z

    REM *******
    REM  DO 4 *
    REM ========================================
    REM >>>>> AGGIORNAMENTO VISUALIZZAZIONE DATI - Update View Data of Structure Type
    REM ========================================
    VisualizzaProprieta(IdSelezionato,SubIdSelezionato1,SubIdSelezionato2)

    REM *******
    REM  DO 5 *
    REM ==============================
    REM SINCRONIZZAZIONE DELLO SCHERMO
    REM ==============================
    SYNC
LOOP

REM **************
REM FINE PROGRAMMA - END Of Program
REM **************
END

REM ******
REM   11 *
REm ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ########
REM ETICHETTE - Labels           - ETICHETTE - Labels - ETICHETTE - Labels - ETICHETTE - Labels - ETICHETTE - Labels - ETICHETTE - Labels
REm ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ########


REm ******
REM  E_1 *
REm ******
E_POPOLAMENTO_STRUTTURA:
REM ===========================================================
REM POPOLAMENTO DEI VALORI DELLA STRUTTURA DELLA VARIABILE TYPE - Fill Value of The Structure
REM ===========================================================
For a=1 to 10
    Rem [Oggetto Radice] - Object Parent
    If Object Exist(A)<>1
       Make Object Plain A,2,5                                           :Rem CREA l'Oggetto radice
       XRotate Object A,90
       Texture Object A,A
    Endif
    REM [ELIMINO Gli Oggetti Posseduti Esistenti] - Delete Existing Object Possesed by Object Parent
    For c=0 to 5
        IdOggetto = Array(a).Id_SubOggetto(C)                       :Rem Numero Oggetto - Number Object
        If IdOggetto>0
           If Object Exist(IdOggetto)=1
              DELETE OBJECT IdOggetto
           ENdif
        ENDIF
    NEXT C


    Rem [NUOVE Proprieta Type] - NEW VALUE'S Variables Type
    Array(A).Id=a                                                        :Rem Proprieta Id
    Array(A).X=A*5                                                       :Rem Proprieta X
    Array(A).Y=0                                                         :Rem Proprieta Y
    Array(A).Z=1                                                         :Rem Proprieta Z
    Array(A).QSubOggetti=Rnd(5)
    PosiTion Object Array(a).Id,Array(A).X,Array(A).Y,Array(A).Z         :Rem Posizione dell'oggetto Radice

    REM ==============================
    REM POPOLAZIONE DELLE SubProprieta - Fill Value of The Sub_Structure
    REM ==============================
    FOR B=1 To Array(A).QSubOggetti
        Array(a).Id_SubOggetto(b)=500+(A*10)+B                           :Rem Proprieta  Id     SubOggetto associato
        Array(a).Id_SubOggetto_Colore(b)=RND(9)+1                        :Rem Proprieta  Colore SubOggetto associato

        Rem [CREO Oggetti Associati] - MAKE OBJECT Associated Sub Object (not Limbs)
        IdOggetto = Array(a).Id_SubOggetto(b)                            :Rem Numero Oggetto - Number Object
        If Object Exist(IdOggetto)<>1
           Make Object Sphere Array(a).Id_SubOggetto(b),3                :Rem CREA loggetto membro (sfera in colonna) [NO LIMBS!!! But Object Possession]
        EndIf
        Rem [Posiziono Gli Oggetti sfera] - [positon speheres]
        PosiTion Object Array(a).Id_SubOggetto(b) , Array(A).X,Array(A).Y,Array(A).Z*(B*5) :Rem Posizionamento dei SubOggetti
        IdColore=Array(a).Id_SubOggetto_Colore(b)
        COLOR Object  Array(a).Id_SubOggetto(b) , COLORE(IdColore)              :Rem Colorazione del Sub Oggetto
        Rem [Camera]
        POSITION CAMERA 100,50,0                                                :Rem Posizione Camera
        POINT CAMERA 50,0,0                                                     :Rem Puntamento Camera
        Rem =====================
        Rem Aggiornamento Schermo  - Update Screen
        Rem =====================
        SYNC
    NEXT B
NExt A

RETURN

REM --------------------------------------------------------------------------------------------------------------------------------------

REm ******
REM  E_2 *
REm ******
E_Visualizza_Titolo:
  REM ======
  REM TITOLO - Title
  REM ======
  SET TEXT SIZE 40
  SET TEXT TO BOLD
  CENTER TEXT SCREEN WIDTH()/2,20,"TYPE ARRAY & SUB-ITEM-TYPE-ARRAY"
  CENTER TEXT SCREEN WIDTH()/2,60,"For DB1 Classic"
  SET TEXT SIZE 16
  Ink Rgb(0,0,255),0
  TEXT 900,700,"Tonino-DarkTy"
  TEXT 20,730,"[UpKey] = Id - 1     [DownKey] = id + 1    [LeftKey] = Sub_Id - 1   [RightKey] = Sub_Id + 1  [SPACE] = *** RESET - NEW *** "

RETURN


REM --------------------------------------------------------------------------------------------------------------------------------------


REm ******
REM   12 *
REm ******
REm ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ########
REM FUNZIONI - Functions - FUNZIONI - Functions FUNZIONI - Functions FUNZIONI - Functions - FUNZIONI - Functions - FUNZIONI - Functions
REm ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## ########


Rem ******
REM  F_1 *
Rem ******
FuNCTION VisualizzaProprieta(IdSelezionato,SubIdSelezionato1,SubIdSelezionato2)

Rem ********
REM  F_1.1 *
Rem ********
REM ===================================
REM Visualizza IdSelezionato in [VERDE] - Text and Texture GREEN For ID selected And RED for unselected
REM ===================================
FOr a=1 to 10
    Texture OBJECT A,A



    IF A=IdSelezionato
       TEXTURE OBJECT A,A+10  :Rem Colore Verde per IdSelezionato    -    Green Color For Id Selected

       REM Box Di Sub_selezione
       Ink Rgb(30,30,90),0
       BOX 600 , 500+20*SubIdSelezionato1 + 2 ,   1000 , 500+20*SubIdSelezionato1 + 16

       REm Info Sub_Array
       SET TEXT OPAQUE
       INK RGB(255,0,0),0
       Text 430,160+20*a,"ID = " + STR$(A) + "  "

       INK RGB(0,255,0),0
       Text 600,500,"QElementi = " + STR$(Array(a).QSubOggetti) + "       "




       Rem ********
       REM  F_1.2 *
       Rem ********
       REM ====================================
       REM VISUALIZZO I DATI DEI SOTTO ELEMENTI - Sub_Element view text data
       REM ====================================
       FOR B=1 To Array(a).QSubOggetti

           INK RGB(0,255,0),0
           TEXT 600,500+20*B,"Id"+STR$(b)+" = " + STR$(Array(a).Id_SubOggetto(B))
           INK Colore(Array(a).Id_SubOggetto_Colore(B)),0  :REM <<<   INK COLORE (VALORE_SOTTOELEMENTO),0
           TEXT 800,500+20*B,"Colore"+STR$(b)+" = " + STR$(Array(a).Id_SubOggetto_Colore(B))
           LINE 600,500+20*B,1000,500+20*b

       NEXT B
    ENDIF
    SET TEXT TRANSPARENT
NEXT A


Id    = IdSelezionato
SubId1 = SubIdSelezionato1
SubId2 = SubIdSelezionato2

Rem ********
REM  F_1.3 *
Rem ********
REM ========================
REm INTERFACCIA UTENTE [GUI]
REM ========================
REM ----------------------------------------------
Y=100:Ink RGB(255,255,0),0
TEXT 20,Y+20,"Array(Id).Id = " + STR$(Array(Id).Id)                                                         :REM <<< ID Principale
TEXT 20,Y+40,"Array(Id).X  = " + STR$(Array(Id).X)                                                          :REM <<< X
TEXT 20,Y+60,"Array(Id).Y  = " + STR$(Array(Id).Y)                                                          :REM <<< Y
TEXT 20,Y+80,"Array(Id).Z  = " + STR$(Array(Id).Z)                                                          :REM <<< Z
TEXT 20,Y+100,"Array(Id).QSubOggetti = " + STR$(Array(Id).QSubOggetti)                                      :REM <<< Quantita Sub Elementi
TEXT 20,Y+120,"Array(Id).Id_SubOggetto(SubId1) = " + STR$(Array(Id).Id_SubOggetto(SubId1))                  :REM <<< SUB ID 1
TEXT 20,Y+140,"Array(Id).Id_SubOggetto_Colore(SubId2) = " + STR$(Array(Id).Id_SubOggetto_Colore(SubId2))    :REM <<< SUB ID 2
REM ----------------------------------------------


ENDFUNCTION

REM --------------------------------------------------------------------------------------------------------------------------------------