demo.mod 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. MODULE demo;
  2. FROM tigr IMPORT TigrPtr,tigrWindow,tigrFree,tigrClosed, tigrClear, tigrUpdate, TPixelType,
  3. tigrLine, TK_ESCAPE, tigrKeyDown, tigrReadChar, tfont, tigrPrint,tigrFill,
  4. tigrCircle, tigrRect, tigrFillCircle, tigrTime, tigrError, tigrClip,
  5. tigrFillRect, tigrTextWidth, tigrTextHeight, tigrLoadImage, tigrReadFile,
  6. tigrBitmap, TIGR_2X, tigrSetPostFX, tigrMouse,tigrBlit, tigrBlitAlpha,
  7. tigrEncodeUTF8, TK_RIGHT,tigrKeyHeld, TK_SPACE, TK_LEFT;
  8. FROM helper IMPORT tigrRGB, tigrRGBA;
  9. FROM DynamicStrings IMPORT String, InitString;
  10. FROM InOut IMPORT Write, WriteLn, WriteCard,WriteString;
  11. FROM Delay IMPORT Delay;
  12. VAR
  13. standing : BOOLEAN;
  14. remaining : SHORTREAL;
  15. backdrop, screen : TigrPtr;
  16. squinkle : TigrPtr;
  17. greeting : String;
  18. prevx, prevy, prev : CARDINAL;
  19. chars : ARRAY[0..16] OF CHAR;
  20. tempString : String;
  21. n : CARDINAL;
  22. dt : SHORTREAL;
  23. x, y ,b : CARDINAL;
  24. message, message1 : String;
  25. c : CARDINAL;
  26. playerx, playery,
  27. playerxs, playerys : INTEGER;
  28. PROCEDURE update (dt : SHORTREAL);
  29. VAR
  30. oldx, oldy : INTEGER;
  31. BEGIN
  32. IF (remaining > 0.0) THEN
  33. remaining := remaining - dt;
  34. END;
  35. (* Read the keyboard and move the player. *)
  36. WriteString("Position départ ->");
  37. WriteCard(playerxs, 6); WriteString("**");WriteCard(playerys, 6); WriteLn;
  38. IF (standing OR (tigrKeyDown(screen, TK_SPACE) >0)) THEN
  39. playerys := playerys - 200;
  40. END;
  41. IF ((tigrKeyHeld(screen, TK_LEFT) > 0) OR (tigrKeyHeld(screen, ORD('a')) > 0)) THEN
  42. WriteString("Touche gauche"); WriteLn;
  43. playerxs := playerxs - 10;
  44. END;
  45. IF ((tigrKeyHeld(screen, TK_RIGHT) > 0) OR (tigrKeyHeld(screen, ORD('d')) > 0)) THEN
  46. WriteString("Toiuche droite"); WriteLn;
  47. playerxs := playerxs + 10;
  48. END;
  49. WriteString("Nouvelle Position ->");
  50. WriteCard(playerxs, 6); WriteString("**");WriteCard(playerys, 6); WriteLn;
  51. Delay(1000);
  52. END update;
  53. BEGIN
  54. standing := TRUE;
  55. remaining := 0.0;
  56. playerx := 160;
  57. playery := 200;
  58. playerxs := 0;
  59. playerys := 0;
  60. squinkle := tigrLoadImage("squinkle.png");
  61. IF ( squinkle = NIL) THEN
  62. tigrError(0, "Cannot load squinkle.png");
  63. END;
  64. (* Load some UTF-8 text. *)
  65. greeting := tigrReadFile("greeting.txt", 0);
  66. IF (greeting = NIL) THEN
  67. tigrError(0, "Cannot load greeting.txt");
  68. END;
  69. (* Make a window and an off-screen backdrop. *)
  70. screen := tigrWindow(320, 240, greeting, TIGR_2X);
  71. backdrop := tigrBitmap(screen^.w, screen^.h);
  72. (* Fill in the background. *)
  73. tigrClear(backdrop, tigrRGB(80, 180, 255));
  74. tigrFill(backdrop, 0, 200, 320, 40, tigrRGB(60, 120, 60));
  75. tigrFill(backdrop, 0, 200, 320, 3, tigrRGB(0, 0, 0));
  76. tigrLine(backdrop, 0, 201, 320, 201, tigrRGB(255, 255, 255));
  77. (* Enable post fx *)
  78. tigrSetPostFX(screen, 1.0, 1.0, 1.0, 2.0);
  79. prevx := 0;
  80. prevy := 0;
  81. prev := 0;
  82. (* Maintain a list of characters entered. *)
  83. FOR n := 0 TO 16 BY 1 DO
  84. chars[n] := "_";
  85. END;
  86. WHILE (NOT (tigrClosed(screen) > 0)) OR (tigrKeyDown(screen, TK_ESCAPE) > 0) DO
  87. (* Update the game. *)
  88. dt := tigrTime();
  89. update(dt);
  90. (* Read the mouse and draw lines when pressed. *)
  91. tigrMouse(screen, x, y, b );
  92. IF (b = 1) THEN
  93. IF (prev > 0) THEN
  94. tigrLine(backdrop, prevx, prevy, x, y, tigrRGB(0, 0, 0));
  95. END;
  96. prevx := x;
  97. prevy := y;
  98. prev := 1;
  99. ELSE
  100. prev := 0;
  101. END;
  102. (* Composite the backdrop and sprite onto the screen. *)
  103. tigrBlit(screen, backdrop, 0, 0, 0, 0, backdrop^.w, backdrop^.h);
  104. tigrBlitAlpha(screen, squinkle, playerx - INTEGER(squinkle^.w / 2), playery - INTEGER(squinkle^.h), 0, 0,
  105. squinkle^.w, squinkle^.h, 1.0);
  106. message := InitString("A D + SPACE");
  107. tigrPrint(screen, tfont, 10, 10, tigrRGBA(0C0H, 0D0H, 0FFH, 0C0H), greeting);
  108. tigrPrint(screen, tfont, 10, 222, tigrRGBA(0FFH, 0FFH, 0FFH, 0FFH), message);
  109. (* Grab any chars and add them to our buffer. *)
  110. LOOP
  111. c := tigrReadChar(screen);
  112. IF (c = 0) THEN
  113. EXIT;
  114. END;
  115. FOR n := 1 TO 16 DO
  116. chars[n - 1] := chars[n];
  117. END;
  118. chars[15] := CHR(c);
  119. END;
  120. Write(CHR(c));
  121. tigrUpdate(screen);
  122. END;
  123. (* (* Print out the character buffer too. *)
  124. FOR n := 0 TO 15 DO
  125. tempString := tigrEncodeUTF8(p, chars[n]);
  126. END;
  127. *p = 0;
  128. tigrPrint(screen, tfont, 160, 222, tigrRGB(255, 255, 255), "Chars: %s", tmp); *)
  129. tigrFree(squinkle);
  130. tigrFree(backdrop);
  131. tigrFree(screen);
  132. END demo.