Want to write Midp1.0-2.0 applications but don’t know java? no problem…

    I present to you the open source IDE MIDlet Pascal 3.0 beta 2, which allows you to write Midp1.0-2.0 applications in Pascal-like language.
    There are already two articles on the hub, but one is about the paid version, and the second is unsuccessful. I found articles after writing this.


    So MIDlet Pascal 3.0 is a direct descendant of MIDlet Pascal 2 , authored by Nikša Orlić. After version 2.02, the author of the program stopped working on improving Midlet Pascal. However, he stated that he agreed to transfer the source code to any person to continue development familiar with Java and C ++ (which is written in Midlet Pascal), with the proviso that the project will become open source and will develop. In September 2009, the source code for MIDletPascal was transferred to the Russian-speaking team boolean.name

    So, we need the latest current version with SourceForge .
    If you need to take the necessary libraries here , you need to put them in% MIDlet Pascal dir% / Libs. As a rule, with each library there is a% LibName% .txt file with a list of functions and a brief help on them.
    You will also need any of the java emulators. I use sjboy and kemulator (unfortunately, I did not find the official page of this emulator, so the link leads to the first file wash found).

    Attention when installing antiviruses can swear at some components (for example, my Dr.Web swore).
    Some versions of antivirus programs (Norton, McAfee, ...) report any program written in MidletPascal as the Trojan.Redbrowser.A virus.
    This is due to the fact that with the help of MidletPascal the RedBrowser Trojan was written secretly sending SMS messages.
    In version 3.0, it is planned to change the code of one of the classes to make it unlike previous programs and eliminate false positives of McAfee antivirus. Users of the current version are recommended to encrypt the finished program with some obfuscator, for example, JSink.

    therefore, before installation, add the installation path to the exceptions of your antivirus.

    So we have:
    MIDlet Pascal;
    A great desire to write something;
    Some free time.

    Since I am a happy owner of an old Nokia N70, I naturally write for it and the toy is designed for a resolution of 176x208.

    We launch MIDlet Pascal and we are greeted by the main window. Create a new project File> New> Project name and indicate the folder where it will be stored, attention should be made of Latin characters, otherwise the phone will swear at the wrong file format, but the emulators digest perfectly. In Project Managere, in the configuration section, we set our type of midlet, in our case Midp2.0 fullscreen.




    attention, do not try to edit project properties in Project Manager by



    clicking delete (this does not happen with the backspace;)) removes characters not from these fields but from the place where the cursor is in the editor window, in addition, data from these fields is still not saved to change them open the project file% project dir% /% project name% .mpproj with any text editor and edit as you like.

    We draw all the resources we need, to create the resources I used the free artweaver interface similar to the good old Photoshop .
    I got the following.

    All resources in the project are added through Project Manager> resource> add and saved in the% project dir% / res folder. If you use several configurations (for example, for different screen resolutions), then you can match all the resources of the desired configuration.

    Well, it remains to write the program code itself.

    Let's see what MIDlet Pascal actually offers us in terms of language:
    10 simple types 2 complex conditions logical operations cycles yes, case unfortunately no, I hope so far
    boolean
    char
    integer
    real
    string
    http
    resource
    image
    recordStore
    command



    record
    array



    if ... then ...


    and
    or
    xor
    not



    for … to … do (downto)
    while … do
    repeat … until



    Well, actually, all that is needed is there.

    We create a cycle in the main module that will track the keystroke, now we create everything through the same Project Manager as a separate unit and describe our buttons in the listing, of course, not all functions are listed. by the same principle, we will implement everything else, if possible, grouping similar code into one modules. Now about drawing the image, after placing any element on the screen, you need to call it updated by the repaint procedure, here is the implementation of Hello World, the drawText (text, x, y) procedure will put the text on the screen at the specified coordinates. if you want to display two labels then repaint Must be used at the very end to draw everything.

    program tag;

    function ProcessUserInput(AKeyCode : integer): boolean;
    begin
    //тут обрабатываем любые нужные нам кнопки
    ProcessUserInput := AKeyCode <> KE_KEY0;//исли нажат 0 то завершаем цикл
    end;

    begin

    repeat
    //вот он родимый
    until not ProcessUserInput(GetKeyPressed);
    end.






    unit Button;

    interface

    type
    TButton = record
    img : image;
    pos,num : integer;
    end;
    ...
    procedure Paint(AButton : TButton; pos : integer);
    procedure Init(AButton : TButton; ImgNumber : integer);
    ...

    implementation

    var
    bImg: image;

    procedure Init(AButton : TButton; ImgNumber : integer);
    begin
    AButton.img := LoadImage('/' + IntegerToString(ImgNumber) + '.png');
    AButton.num := ImgNumber;
    end;

    procedure Paint(AButton : TButton; pos: integer);
    begin
    AButton.pos := pos;
    DrawImage(bImg,PosToX(pos),PosToY(pos));
    DrawImage(AButton.img,PosToX(pos),PosToY(pos));
    end;

    initialization
    bImg := LoadImage('/back.png');//грузим задник
    end.







    Program HelloWorld;
    Begin
    drawText('Hello, world!', 5 ,5);
    repaint;
    delay(5000);
    end.



    Program HelloWorld;
    Begin
    drawText('Hello, world!', 5 ,5);
    drawText('And again!', 5 ,15);
    repaint;
    delay(5000);
    end.


    Since repaint is a rather resource-intensive procedure, it is recommended to call it when it is really necessary to redraw the screen.

    About optimization.
    If your code operates with any variables, it is recommended to use global ones, since local variables in procedures and functions consume significantly more resources.

    but back to our game, I got the following.
    The game can:
    generate a random game field,
    save and load the game field,
    voice actions; the
    ability to save settings;

    everything else can be implemented by yourself, room for optimization in the sea code;)



    links
    Sources of the game
    A selection of libraries (including those necessary for compiling the game)
    MIDlet Pascal page at SourceForge
    Russian community MIDlet Pascal MIDlet Pascal
    Help

    Also popular now: