PixelChipCode

Type out and push up text effect in GameMaker

Oct 24th, 2024 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Type out text and push up by oliver @pixelchipcode
  2.  
  3. // Create Event
  4. max_lines = 23;        // Maximum number of lines to show
  5. line_height = 20;      // Pixels between lines
  6. text_x = 10;          // Starting X position for all text
  7. text_y = 30;          // Starting Y position for first line
  8.  
  9. // Variables for typing effect
  10. displayed_lines = [];  // Lines that are fully typed and displayed
  11. current_line = 0;     // Which line we're currently typing
  12. char_index = 1;       // Position in current line
  13. type_speed = 1.25;    // Characters per step
  14.  
  15. // Function to reset everything to initial state
  16. function restart_sequence() {
  17.     displayed_lines = [];  // Clear displayed lines
  18.     current_line = 0;     // Back to first line
  19.     char_index = 1;       // Reset character position
  20. }
  21.  
  22.  
  23. // Array of all the text to display - keeping exact code formatting
  24. all_text = [
  25.     "REM Quantum Transference Protocol v2.7.1",
  26.     "MODE 7 : REM Minimal output mode for system interaction",
  27.     "VDU 23, 1, 0;0;0;0; : REM Clear screen for initialization",
  28.     "PRINT \"Quantum Transference System v2.7.1\"",
  29.     "PRINT \"Secure Access Granted\"",
  30.     "PRINT \"-------------------------------------------------\"",
  31.     "PRINT \"Establishing baseline calibration metrics...\"",
  32.     "REM Calibrate for quantum entanglement threshold",
  33.     "PRINT \"Calibrating spatial coordinates and gravitational\"",
  34.     "PRINT \"constants...\"",
  35.     "FOR delay% = 1 TO 2000: NEXT delay% : REM Simulate calibration time",
  36.     "PRINT \"Baseline metrics established.\"",
  37.     "PRINT \"Gravitational constants stable.\"",
  38.     "PRINT \"Quantum distortion: Nominal.\"",
  39.     "PRINT \"-------------------------------------------------\"",
  40.     "REM Input coordinates for quantum transference",
  41.     "PRINT \"Input target spatial coordinates (X, Y, Z):\"",
  42.     "INPUT x%, y%, z%",
  43.     "REM Verifying validity of input coordinates",
  44.     "IF x% < -1000 OR x% > 1000 OR y% < -1000 OR y% > 1000 OR z% < -1000 OR z% > 1000 THEN",
  45.     "PRINT \"ERROR: Invalid spatial coordinates.\"",
  46.     "PRINT \"Reinitializing protocol...\""
  47. ];
  48.  
  49. restart_sequence();
  50.  
  51.  
  52. // Step Event
  53. // First, check for restart key
  54. if keyboard_check_pressed(ord("P")) {
  55.     restart_sequence();
  56. }
  57.  
  58. if (current_line < array_length(all_text)) {
  59.     // Get the line we're currently typing
  60.     var target_text = all_text[current_line];
  61.    
  62.     // Add one character at a time
  63.     if (char_index <= string_length(target_text)) {
  64.         char_index += type_speed;
  65.     } else {
  66.         // Line is complete
  67.         array_push(displayed_lines, target_text);
  68.        
  69.         // If we're beyond max_lines, remove oldest line
  70.         if (array_length(displayed_lines) > max_lines) {
  71.             array_delete(displayed_lines, 0, 1);
  72.         }
  73.        
  74.         // Move to next line
  75.         current_line += 1;
  76.         char_index = 1;
  77.     }
  78. }
  79.  
  80. // Draw Event
  81. // Draw completed lines
  82. for (var i = 0; i < array_length(displayed_lines); i++) {
  83.     draw_text(text_x, text_y + (i * line_height), displayed_lines[i]);
  84. }
  85.  
  86. // Draw current line being typed (if we're not done)
  87. if (current_line < array_length(all_text)) {
  88.     var current_text = string_copy(all_text[current_line], 1, char_index);
  89.     draw_text(text_x, text_y + (array_length(displayed_lines) * line_height), current_text);
  90. }
Tags: gml gameMaker
Advertisement
Add Comment
Please, Sign In to add comment