Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 26

Thread: Goto, Sprites... help! =0

  1. #11

    Goto, Sprites... help! =0

    As cronodragon said

    Probably the reason MP doesn't have it, is because the Java virtual machine doesn't allow it :?[/quote][quote]

    Interesting point...think that answers why no labels or gotos...i'm a novice at Java by the way, but this sounds like why...
    Determined to crack this programming lark...

  2. #12

    Goto, Sprites... help! =0

    I know there are better and more appropriate ways to create midlets.
    But for me this is a hobby, and MP and his friends allow me to recycle old memories of basic programming (waiting days with more spare time to deepen the knowledge of prg languages...)
    Here is a small prg I found in a russian (?) forum, as free (public) attachment (it's a simply calculator):

    program NewProject;

    var
    okCommand,sqrCommand,sqrtCommand,IntToHexCommand,q uitCommand,
    sinCommand,cosCommand,tanCommand,lnCommand,clicked :command;
    IntField:integer;
    str:string;
    intvalue:integer;
    screenWidth, screenHeight: integer;
    r:real;

    procedure welcomeScreen;
    var

    textToDisplay : string;
    textXPos : integer;
    textYPos : integer;
    keyCode : integer;
    begin
    setColor(255, 255, 255);
    screenWidth := getWidth;
    screenHeight := getHeight;
    fillRect(0, 0, screenWidth, screenHeight);
    setColor(0, 0, 255);
    setFont(FONT_FACE_PROPORTIONAL, FONT_STYLE_BOLD, FONT_SIZE_MEDIUM);
    textToDisplay := 'Numeric Converter';
    textXPos := (screenWidth - getStringWidth(textToDisplay)) div 2;
    textYPos := (screenHeight - getStringHeight(textToDisplay)) / 2;
    drawText(textToDisplay, textXPos, textYPos);
    textYPos := textYPos + getStringHeight(textToDisplay);
    setColor(0, 0, 0);
    setFont(FONT_FACE_PROPORTIONAL, FONT_STYLE_PLAIN, FONT_SIZE_SMALL);
    textToDisplay := 'Created by Voyager';
    textXPos := (screenWidth - getStringWidth(textToDisplay)) div 2;
    drawText(textToDisplay, textXPos, textYPos);
    textYPos := textYPos + getStringHeight(textToDisplay);
    textToDisplay := 'Press any key';
    textXPos := (screenWidth - getStringWidth(textToDisplay)) div 2;
    drawText(textToDisplay, textXPos, textYPos);
    repaint;
    repeat
    keyCode := getKeyClicked;
    until keyCode <0> 0 then
    begin
    i := IntValue;
    while i>0 do
    begin
    j := i mod 16;
    if (j<10) then
    s := Chr(Ord('0') + j) + s;
    else
    s := Chr(Ord('A') + (j - 10)) + s;
    i := i div 16;
    end;
    end;
    if Digits <1>0 do
    begin
    s := '0' + s;
    i := i - 1;
    end;
    IntToHex := s;
    end;

    Function RealToString(r:real; width:integer):string;
    var s1,s2:string;pre:string;
    begin
    pre:='';
    if r<0>5 then width:=5;
    if frac(r)>=0.5 then s1:=integertostring(Trunc(r)-1) else s1:=integertostring(Trunc(r));if frac(r)=1/10 then s1:=integertostring(stringtointeger(s1)-1);
    if width<=0 then s2:='' else s2:='.'+integertostring(trunc(Trunc(frac(r)*pow(10 ,width))));
    if frac(r)=0 then s1:=integertostring(stringtointeger(s1)+1);
    if r=0 then RealToString:='0' else RealToString:=pre+s1+s2;
    end;

    function SqrF(str:string): string;
    begin
    intvalue:=StringToInteger(str);
    SqrF:=IntegerToString(sqr(intvalue));
    end;

    function SqrtF(str:string): string;
    begin
    intvalue:=StringToInteger(str);
    SqrtF:=RealToString(sqrt(intvalue),5);
    end;

    function SinF(str:string): string;
    begin
    intvalue:=StringToInteger(str);
    r:=toRadians(intvalue);
    SinF:=RealToString(sin(r),5);
    end;

    function CosF(str:string): string;
    begin
    intvalue:=StringToInteger(str);
    r:=toRadians(intvalue);
    CosF:=RealToString(cos(r),5);
    end;

    function TanF(str:string): string;
    begin
    intvalue:=StringToInteger(str);
    r:=toRadians(intvalue);
    TanF:=RealToString(tan(r),5);
    end;

    function LnF(str:string): string;
    begin
    intvalue:=StringToInteger(str);
    LnF:=RealToString(log(intvalue),5);
    end;

    begin
    welcomeScreen;
    okCommand := createCommand('OK', CM_SCREEN, 1);
    sqrCommand := createCommand('Sqr', CM_SCREEN, 1);
    sqrtCommand := createCommand('Sqrt', CM_SCREEN, 1);
    IntToHexCommand := createCommand('Hex', CM_SCREEN, 1);
    lnCommand := createCommand('Ln', CM_SCREEN, 1);
    sinCommand := createCommand('Sin', CM_SCREEN, 1);
    cosCommand := createCommand('Cos', CM_SCREEN, 1);
    tanCommand := createCommand('Tan', CM_SCREEN, 1);
    quitCommand := createCommand('Quit', CM_EXIT, 1);
    showForm;
    IntField := formAddTextField('Insert a number:', '', 10, TF_NUMERIC);
    repeat
    addCommand(sqrCommand);
    addCommand(sqrtCommand);
    addCommand(IntToHexCommand);
    addCommand(lnCommand);
    addCommand(sinCommand);
    addCommand(cosCommand);
    addCommand(tanCommand);
    addCommand(quitCommand);
    repeat
    clicked := getClickedCommand;
    delay(100);
    until (clicked <> emptyCommand);
    if(clicked=quitCommand) then halt;
    removeCommand(sqrCommand);
    removeCommand(sqrtCommand);
    removeCommand(IntToHexCommand);
    removeCommand(lnCommand);
    removeCommand(sinCommand);
    removeCommand(cosCommand);
    removeCommand(tanCommand);
    removeCommand(quitCommand);
    str := (formGetText(IntField));
    showCanvas;
    setColor(255, 255, 255);
    fillRect(0, 0, screenWidth, screenHeight);
    setColor(0, 0, 255);
    If clicked=IntToHexCommand then drawText(IntToHex(stringtointeger(str),8 ), 5, 5)
    else If clicked=sqrCommand then drawText(SqrF(str), 5, 5)
    else If clicked=sqrtCommand then drawText(SqrtF(str), 5, 5)
    else If clicked=sinCommand then drawText(SinF(str), 5, 5)
    else If clicked=cosCommand then drawText(CosF(str), 5, 5)
    else If clicked=tanCommand then drawText(TanF(str), 5, 5)
    else If clicked=lnCommand then drawText(LnF(str), 5, 5)
    else drawText('Invalid command', 5, 5);
    repaint;
    addCommand(okCommand);
    addCommand(quitCommand);
    repeat
    clicked := getClickedCommand;
    delay(100);
    until (clicked <> emptyCommand);
    removeCommand(okCommand);
    removeCommand(quitCommand);
    formSetText(IntField,'');
    showForm;
    until clicked = quitCommand;
    halt;
    end

    I found it very instructive to learn how to use procedure, functions, repeat-until, ifs conditions etc. without missing GOTO statement. A procedure is used for presentation. Main repeat-until cycle contains secondary one (which call the relative functions) ...until prg is halted.

  3. #13

    Goto, Sprites... help! =0

    That looks a good example...sure I can learn something from it too...I tried it but got a bug on line 44...will look into that when less tired!

    Interesting in what you say; I do this as a hobby too...but would not mind actually taking it a little further...

    Well, if you got any other great examples or any other questions then post them here...I’m a novice and keen to learn – but will try and answer...or maybe the other PASCAL stalwarts could help us out if we both get stuck!
    Determined to crack this programming lark...

  4. #14

    Goto, Sprites... help! =0

    For your information, I just started a tool to port Object Pascal programs to virtual machines. But I don't know how much time it will take. It will support J2ME, Flash 8 Player, Flash 9 Player, and probably .NET.

    Regards!
    -Marco

  5. #15

    Goto, Sprites... help! =0

    The error is probably in this line:

    If clicked=IntToHexCommand then drawText(IntToHex(stringtointeger(str), 8 ), 5, 5)

    I had to put a space (" ") between "8" and ")" cause if joined they result as emoticon ( ).
    Anyway here's the link where I grabbed the prgm:
    http://voyager.alfamoon.com/forum/to...rum=3&topic=42
    Cronodragon, we'll stay tuned, keep us informed.

  6. #16

    Goto, Sprites... help! =0

    The error is probably in this line:

    If clicked=IntToHexCommand then drawText(IntToHex(stringtointeger(str), 8 ), 5, 5)

    I had to put a space (" ") between "8" and ")" cause if joined they result as emoticon ( ).
    Anyway here's the link where I grabbed the prgm:
    http://voyager.alfamoon.com/forum/to...rum=3&topic=42
    Cronodragon, we'll stay tuned, keep us informed.

  7. #17

    Goto, Sprites... help! =0

    Wow cronodragon that sounds a really good idea...best of luck in coding that one! Yep and update here!

    Hello gain Deckard70...

    Thanks for that link...I got it up and running ok...I don't know if you noticed - but when you translate the page in Google it also shows this link;

    http://209.85.135.104/translate_c?hl...3D42%26hl%3Den

    It has demo code here of an up market 'Hello World' type application...

    (and no not this type of one
    10 PRINT "HELLO WORLD"
    20 GOTO 10

    ...just had to get the GOTO on here for old times sake :-)

    ...but also on there is a tank demo of moving the thing around the screen...might help us both ...eh?
    Determined to crack this programming lark...

  8. #18

    Goto, Sprites... help! =0

    :shock:
    Thanks! These little codes can really help us to learn the wisdom of MP language!
    ..Wondering how to find more sample codes, I tried this search on Google:
    Midletpascal+begin+var+procedure+(...any MP command)
    This resulted many simply routines added in various forums around the world, some strange ftp link.. and one thing above all: MP has (had) many fans in Russia!

  9. #19

    Goto, Sprites... help! =0

    It is a shame their website is dead...it had some examples of a Tetris type game and a Minesweeper type game...and they gave you the code as well...

    Have you seen Savage's BlitzBomber example? It just shows what you can do with this....make a professional, polished product...like you said before there are other ways of creating MIDlets...it's a clever bit of software with basic (or should that be BASIC?) programming knowledge...

    I must admit examples are hard to find, but if I find any other examples out there then I'll stick them on here...

    MIDlet Pascal may well be "dead" but so is Elvis...and he still lives on...

    :-)
    Determined to crack this programming lark...

  10. #20

    Goto, Sprites... help! =0

    MidlElvis Pascal is back!
    Here are some more russian pages (translated).
    Interesting how they explain the program structure

    http://translate.google.com/translat...&hl=it&ie=UTF8

    http://translate.google.com/translat...&hl=it&ie=UTF8

Page 2 of 3 FirstFirst 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •