Tutorial 2 Part 1

We will now be looking at some slightly more advanced features of DXC; music, mouse pointers and collisions. First we will load a MIDI file and play it.

  • Download this zip file containing the sprite sheet, background and music for this project (zip file.zip (269kb)) and extract the contents into a single directory on your hard drive eg "c:\TSS DX-Creator\tutorial2\"

  • In DXC, create a new project in the same directory as the above files. In the banks window, create a new image and select "background.bmp". If you're not sure how to do these things then make sure you read the first tutorial.

  • Create another new image and select the sprite sheet "baby.bmp".

  • Now create a new sequence. Select the baby sprite sheet and enter the following values : Sprite X = 100 (the width of each frame), Sprite Y = 100 (the height of each frame), Sprite Count = 200 (there are 200 frames in total), X Count = 10 (there are 10 frames on each line in the sprite sheet).

  • Now enter the code below into the editor or copy and paste it out of this text file.

    If you run this project you should see a baby dancing in the middle of the screen.


    //TUTORIAL 2

    //DEFINE VARIABLES

    Global KEYPRESS$

    //DEFINE PROCEDURES
    DefProc INIT_DISPLAY()
    DefProc CREATE_SPRITES()

    //---- START MAIN CODE ----

    //CALL THE PROCEDURE TO CREATE THE SCREEN

    INIT_DISPLAY()

    //CALL THE PROCEDURE TO CREATE THE SPRITES
    CREATE_SPRITES()

    //START LOOP - THIS LOOP WILL REPEAT UNTIL A KEY IS PRESSED
    Repeat

      KEYPRESS$ = Inkey$()
      Update Display

    Until KEYPRESS$ > ""

    //THE INIT_DISPLAY PROCEDURE CREATES A SCREEN AND A PLANE
    Procedure INIT_DISPLAY()

      Create Map 640,480,1,1 In Bank 50 //CREATE A MAP IN BANK 50
      Set Tile 0,0,1 Using Bank 50 //CREATE A TILE USING A BACKGROUND IMAGE IN BANK 1
      Create Plane 1 Using Bank 50 //CREATE PLANE 1 USING THE MAP IN BANK 50
      //CHANGE THE TRANSPARENCY OF THE SPRITE TO AN UNUSED OR BACKGROUND COLOUR
      Set Bitmap 2 Transparency To 0,0,255

    EndProc

    //THIS PROCEDURE WILL CREATE THE SPRITE
    Procedure CREATE_SPRITES()

      Create Sprite 1,256,176 Using Bank 3 //CREATE SPRITE #1 AT 256,176 USING THE SEQUENCE IN BANK 3
      Sprite On 1 //ENABLE THE SPRITE
      Sprites On //NOW TURN ON THE SPRITE SYSTEM

    EndProc

    EndProg


  • We now need to add the code to play the MIDI music.

    Create a new procedure at the bottom of the code (but before the EndProg statement) called LOAD_MUSIC(). Type in the Synthload command with the name of the music file. You should now have the following code :

    //LOAD MIDI MUSIC
    Procedure LOAD_MUSIC() EndProc


    Add the command "SynthCommand(MIDI_Play)" before the Repeat Until loop to play the music. Remember to add the "DefProc LOAD_MUSIC()" underneath the other DefProc statements and to call the procedure at the beginning of the main program loop "LOAD_MUSIC()".

    When you run this project now, you should see a baby dancing in the middle of the screen with the music playing.

    You should see this baby dancing in the middle of your screen


    If you wish to use MODs instead of MIDI music, replace the "SynthLoad" command with "ModPlayerLoad("music.Mod",11,True)" (11 is the audio quality the music should be played at, in this case top quality, and True is whether or not to loop the music). Replace the "SynthCommand(MIDI_Play)" with "ModPlayerCommand(MOD_Play)".

    Note: MOD files can only be 4 channel.

    Next Page