Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: tom_mai78101 (posted 2014-04-05 13:34:39, viewed 353 times)

1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96   97   98   99   100   101   102   103   104   105   106   107   108   109   110   111   112   113   114   115   116   117   118   119  
private String[] tokens;
   private int tokenPointer;
   private int beginningPointer;
   private int firstLinePointer;
   private int secondLinePointer;
   private int totalStringPointer;
   private boolean firstLineFull;
   private boolean secondLineFull;
   private Map<Integer, Boolean> dialogs;
   private boolean next;
   private boolean nextTick;
   private int stringPointer;
   private byte tickSpeed;
   private byte arrowTickSpeed;
   private String dialogueText;
   private boolean showDialog;

   /**
    * Tells the Graphics object to draw text onto the screen.
    * 
    * <p>
    * There are many complicated situations where texts can overflow around the dialog boxes, causing it to show up glitchy. Using lots of
    * conditional checkings, I was able to confine the glitchiness down to a minimum.
    * 
    * <p>
    * In order to use this, this method must be placed somewhere where there is an easy way to pass the Graphics object to this. The Graphics object
    * is obtained by using getDrawGraphics() from the BufferStrategy, which is created from the Canvas AWT component.
    * 
    * @param graphics
    *            The Graphics object used for drawing texts using custom
    *            fonts.
    * @return Nothing.
    * 
    * */
   public void renderTextGraphics(Graphics g) {
      if (this.dialogueText != null && !this.dialogueText.isEmpty()) {
         //The game uses 8f FONT when shown on the screen. It is scaled by GAME_SCALE.
         //Text are drawn with positive X = RIGHT, positive Y = UP. Not the other way around.
         g.setColor(Color.black);
         g.setFont(Art.font.deriveFont(Font.PLAIN, 24f));
         if (this.totalStringPointer <= this.dialogueText.length()) {
            //Handles one word sentences only.
            if (this.stringPointer > this.dialogueText.length()) {
               this.stringPointer = this.dialogueText.length();
               this.next = true;
               g.drawString(this.dialogueText.substring(this.beginningPointer, this.beginningPointer + this.stringPointer), Dialogue.getDialogueTextStartingX(), Dialogue.getDialogueTextStartingY());
               return;
            }
            
            if (this.totalStringPointer == this.dialogueText.length()) {
               this.next = true;
               g.drawString(this.dialogueText.substring(this.beginningPointer, this.beginningPointer + this.firstLinePointer), Dialogue.getDialogueTextStartingX(), Dialogue.getDialogueTextStartingY());
               g.drawString(this.dialogueText.substring(this.beginningPointer + this.firstLinePointer, this.dialogueText.length()), Dialogue.getDialogueTextStartingX(), Dialogue.getDialogueTextSecondLineStartingY());
               return;
            }
            
            if (this.firstLineFull && this.secondLineFull) {
               this.next = true;
               g.drawString(this.dialogueText.substring(this.beginningPointer, this.beginningPointer + this.firstLinePointer), Dialogue.getDialogueTextStartingX(), Dialogue.getDialogueTextStartingY());
               g.drawString(this.dialogueText.substring(this.beginningPointer + this.firstLinePointer, this.beginningPointer + this.secondLinePointer), Dialogue.getDialogueTextStartingX(), Dialogue.getDialogueTextSecondLineStartingY());
               return;
            }
            
            //Handles more than one word.
            String text = this.tokens[this.tokenPointer];
            if (this.firstLinePointer + text.length() <= MAX_STRING_LENGTH) {
               if (this.stringPointer > text.length()) {
                  this.firstLinePointer += this.stringPointer;
                  this.secondLinePointer = this.firstLinePointer;
                  if (this.tokenPointer < this.tokens.length - 1) {
                     this.tokenPointer++;
                     this.stringPointer = 0;
                  }
                  //Short sentences.
                  if (this.totalStringPointer >= this.dialogueText.length() - 1) {
                     g.drawString(this.dialogueText.substring(this.beginningPointer, this.beginningPointer + this.firstLinePointer), Dialogue.getDialogueTextStartingX(), Dialogue.getDialogueTextStartingY());
                     return;
                  }
               }
            }
            else {
               this.firstLineFull = true;
            }
            if (this.firstLineFull) {
               if (this.secondLinePointer + text.length() < MAX_STRING_LENGTH * 2) {
                  if (this.stringPointer > text.length()) {
                     this.secondLinePointer += this.stringPointer;
                     if (this.tokenPointer < this.tokens.length - 1) {
                        this.tokenPointer++;
                        this.stringPointer = 0;
                     }
                  }
               }
               else {
                  this.secondLineFull = true;
               }
               g.drawString(this.dialogueText.substring(this.beginningPointer, this.beginningPointer + this.firstLinePointer), Dialogue.getDialogueTextStartingX(), Dialogue.getDialogueTextStartingY());
               if (!this.secondLineFull) {
                  if (this.secondLinePointer + text.length() < MAX_STRING_LENGTH * 2) {
                     g.drawString(this.dialogueText.substring(this.beginningPointer + this.secondLinePointer, this.beginningPointer + this.secondLinePointer + this.stringPointer), Dialogue.getDialogueTextStartingX(), Dialogue.getDialogueTextSecondLineStartingY());
                  }
               }
               else {
                  g.drawString(this.dialogueText.substring(this.beginningPointer + this.firstLinePointer, this.beginningPointer + this.secondLinePointer), Dialogue.getDialogueTextStartingX(), Dialogue.getDialogueTextSecondLineStartingY());
                  this.next = true;
               }
            }
            else {
               g.drawString(this.dialogueText.substring(this.beginningPointer, this.beginningPointer + this.firstLinePointer + this.stringPointer), Dialogue.getDialogueTextStartingX(), Dialogue.getDialogueTextStartingY());
            }
         }
         else {
            this.next = true;
            g.drawString(this.dialogueText.substring(this.beginningPointer, this.beginningPointer + this.firstLinePointer), Dialogue.getDialogueTextStartingX(), Dialogue.getDialogueTextStartingY());
            g.drawString(this.dialogueText.substring(this.beginningPointer + this.firstLinePointer, this.beginningPointer + this.secondLinePointer), Dialogue.getDialogueTextStartingX(), Dialogue.getDialogueTextSecondLineStartingY());
            return;
         }
      }
   }





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (35 views)
2014-07-24 01:59:36

Riven (33 views)
2014-07-23 21:16:32

Riven (21 views)
2014-07-23 21:07:15

Riven (24 views)
2014-07-23 20:56:16

ctomni231 (55 views)
2014-07-18 06:55:21

Zero Volt (47 views)
2014-07-17 23:47:54

danieldean (38 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!