Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (739)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (820)
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: jay4842 (posted 2016-11-01 19:04:52, viewed 1701 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   120   121   122   123   124   125   126   127   128   129   130   131   132   133   134   135   136   137   138   139   140   141   142   143   144   145   146   147   148   149   150   151   152   153   154   155   156   157   158   159   160   161   162   163   164   165   166   167   168   169   170   171   172   173   174   175   176   177   178   179   180   181   182   183   184   185   186   187   188   189   190   191   192   193   194   195   196   197   198   199   200   201   202   203   204   205   206   207   208   209   210   211   212   213   214   215   216   217   218   219   220   221   222   223   224   225   226   227   228   229   230   231   232   233   234   235   236   237   238   239   240   241   242   243   244   245   246   247   248   249   250   251   252   253   254   255   256   257   258   259   260   261   262   263   264   265   266   267   268   269   270   271   272   273   274   275   276   277   278   279   280   281   282   283   284   285   286   287   288   289   290   291   292   293   294   295   296   297   298   299   300   301   302   303   304   305   306   307   308   309   310   311   312   313   314   315   316   317   318   319   320   321   322   323   324   325   326   327   328   329   330   331   332   333   334   335   336   337   338   339   340   341   342   343   344   345   346   347   348   349   350   351   352   353   354   355   356   357   358   359   360   361   362   363   364   365   366   367   368   369   370   371   372   373   374   375   376   377   378   379   380   381   382   383   384   385   386   387   388   389   390   391   392   393   394   395   396   397   398   399   400   401   402   403   404   405   406   407   408   409   410   411   412   413   414   415   416   417   418   419   420   421   422   423   424   425   426   427   428   429   430   431   432   433   434   435   436   437   438   439   440   441   442   443   444   445   446   447   448   449   450   451   452   453   454   455   456   457   458   459   460   461   462   463   464   465   466   467   468   469   470   471   472   473   474   475   476   477   478   479   480   481   482   483   484   485   486   487   488   489   490   491   492   493   494   495   496   497   498   499   500   501   502   503   504   505   506   507   508   509   510   511   512   513   514   515   516   517   518   519   520   521   522   523   524   525   526   527   528   529   530   531   532   533   534   535   536   537   538   539   540   541   542   543   544   545   546   547   548   549   550   551   552   553   554   555   556   557   558   559   560   561   562   563   564   565   566   567   568   569   570   571   572   573   574   575   576   577   578   579   580   581   582   583   584   585   586   587   588   589   590   591   592   593   594   595   596   597   598   599   600   601   602   603   604   605   606   607   608   609   610   611   612   613   614   615   616   617   618   619   620   621   622   623   624   625   626   627   628   629   630   631   632   633   634   635   636   637   638   639   640   641   642   643   644   645   646   647   648   649   650   651   652   653   654   655   656   657   658   659   660   661   662   663   664   665   666   667   668   669   670   671   672   673   674   675   676   677   678   679   680   681   682   683   684   685   686   687   688   689   690   691   692   693   694   695   696   697   698   699   700   701   702   703   704   705   706   707   708   709   710   711   712   713   714   715   716   717   718   719   720   721   722   723   724   725   726   727   728   729   730   731   732   733   734   735   736   737   738   739   740   741   742   743   744   745   746   747   748   749   750   751   752   753   754   755   756   757   758   759   760   761   762   763   764   765   766   767   768   769   770   771   772   773   774   775   776   777   778   779   780   781   782   783   784   785   786   787   788   789   790   791   792   793   794   795   796   797   798   799   800   801   802   803   804   805   806   807   808   809   810   811   812   813   814   815   816   817   818   819   820   821   822   823   824   825   826   827   828   829   830   831   832   833   834   835   836   837   838   839   840   841   842   843   844   845   846   847   848   849   850   851   852   853   854   855   856   857   858   859   860   861   862   863   864   865   866   867   868   869   870   871   872   873   874   875   876   877   878   879   880   881   882   883   884   885   886   887   888   889   890   891   892   893   894   895   896   897   898   899   900   901   902   903   904   905   906   907   908   909   910   911   912   913   914   915   916   917   918   919   920   921   922   923   924   925   926   927   928   929   930   931   932   933   934   935   936   937   938   939   940   941   942   943   944   945   946   947   948   949   950   951   952   953   954   955   956   957   958   959   960   961   962   963   964   965   966   967   968   969   970   971   972   973   974   975   976   977   978   979   980   981   982   983   984   985   986   987   988   989   990   991   992   993   994   995  
package main;

import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Random;

import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JFrame;

import entity.player.HUD;
import entity.player.Player;
import particle.Particle;
import util.Flag;
import world.OverWorld;

//This is my main class where the input is taken
public class Game extends Canvas implements Runnable,KeyListener,MouseListener
{

   private static final long serialVersionUID = 1L;
   
   public static final int WIDTH = 800;
   public static final int HEIGHT = 600;
   public static final int SCALE = 1;
   public static int refresh = 0;
   public static int imageRefresh = 0;
   double Sx,Sy;
   public static final String NAME = "Sola Engine PRE ALPHA [build 2.22.0]";//depends on current build
   double scale = 2.0;
   boolean fullScreen = false;
   int x = 25,y = 25;
   public static int mx = 0, my = 0;
   public static boolean doScale = false;
   public static boolean loadGame = false, up = false, down = false ,right = false , left = false,reset = false,pause = false,saving = false;
   private JFrame frame;
   
   static String timeDate;
   
   public boolean running = (false);
   public static boolean night = false;
   boolean mainMenu = true;
   public int screenWait = 0,ticksCount = 0;
   public static int wait = 0;
   int transWait = 0;
   int load = 0;
   public static boolean mPressed = false,f10Pressed = false,jPressed = false,enterPressed = false,
         tabPressed = false,ePressed = false,kPressed = false,rPressed = false,escPressed = false,spacePressed = false,
         slashPressed = false,shiftPressed = false,f1Pressed = false,qPressed = false,yPressed = false,nPressed = false,
         wShift = false,aShift = false,sShift = false,dShift = false,shiftHeld = false,deletePressed = false,pPressed = false,
         onePressed = false, twoPressed = false, threePressed = false,fourPressed = false,cPressed = false,
         commaPressed = false,periodPressed = false;
   public static boolean lArrow = false,rArrow = false,uArrow = false,dArrow = false,f2Pressed = false,f3Pressed = false;
   public static String commandLine = "";
   public static boolean am = true;
   int mTimer = 0,f10Timer = 0,jTimer = 0,enterTimer = 0,lArrowTimer = 0,rArrowTimer = 0,
         uArrowTimer = 0,dArrowTimer = 0,tabTimer = 0,eTimer = 0,kTimer = 0,rTimer = 0,
         slashTimer = 0,escTimer = 0,pauseTime = 0,f1Timer = 0,shiftTimer = 0,qTimer = 0,
         yTimer = 0,nTimer = 0,wShiftTimer = 0,aShiftTimer = 0,sShiftTimer = 0,dShiftTimer = 0,
         f2Timer = 0,f3Timer = 0,deleteTimer = 0,oneTimer = 0,twoTimer = 0,threeTimer = 0,fourTimer = 0,
         cTimer = 0,pTimer = 0,spaceTimer = 0,periodTimer = 0, commaTimer = 0;
   
   private BufferedImage image = new BufferedImage(WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB);   
   @SuppressWarnings("unused")
   private int [] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();
   
   public static ArrayList<Particle> particles = new ArrayList<Particle>();
   
   public static Random rnd = new Random();
   
   int loadTime = 0;
   
   public static int min,sec,hrs = 8,day,month,year;
   
   DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy | HH:mm:ss");
   Calendar cal = Calendar.getInstance();
   
   public static boolean init =false,grid = false;
   ////////////////////////display stuff
   Rectangle rec; 
    
   
   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   int screenHeight = screenSize.height;
   int screenWidth = screenSize.width;
   ////////////////////world stuff
   //public static Player p  = new Player(12,11,0,56,0); //tutorial style
   public static Player p  = new Player(9,15,1,40,0); //normal style
   //public static Player p  = new Player(5,5,0,50,0); //the test map
   public static OverWorld o = new OverWorld();
   
   
   
   public static HUD hud = new HUD(p);
   
   
   BufferedImage menu;
   ///camera junk!
   int worldSizeX = 2500,worldSizeY = 2500;
   static int view = 128;
   int offsetMaxX = worldSizeX-view;
   int offsetMaxY = worldSizeY-view,offsetMinX = 0,offsetMinY = 0;
   
   public static int camX = 0;
   
   public static int camY = 0;
   
   public static boolean secondMark = false; // for optimize mainly
   int secondWait = 0;
   public static int frames = 0,ticks = 0;
   
   AudioPlayer player;
   
   AudioPlayer forest;
   AudioPlayer tundra;
   AudioPlayer waste;
   AudioPlayer home;
   
   //here all of the games flags will be defined to false
   boolean flag = false;
    public static ArrayList<Flag> flags = new ArrayList<Flag>();
   
    public static boolean scene = false;
   //this creates the JFrame window
   public Game()
   {
      //will add 50 flag spots
      for(int i = 0; i < 50; i++){
         flags.add(new Flag(false));
      }
      
      menu = ImageLoader.load("basicRes/main menu blur.png");
      
      System.out.println("Generating maps....");
      ////////// I can set all the variables here as well..
      setMinimumSize(new Dimension(WIDTH*SCALE,HEIGHT*SCALE));
      setMaximumSize(new Dimension(WIDTH*SCALE,HEIGHT*SCALE));
      setPreferredSize(new Dimension(WIDTH*SCALE,HEIGHT*SCALE));
      
      frame = new JFrame(NAME);
      frame.setSize(WIDTH, HEIGHT);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setLayout(new BorderLayout());
      
      frame.add(this,BorderLayout.CENTER);
      frame.pack();
      
      frame.setResizable(false);
      //frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
      frame.setLocationRelativeTo(null);
       
      addMouseListener(this);
      addKeyListener(this);
      setFocusable(true);
      frame.setVisible(true);
      
      //cal = Calendar.getInstance();
   
      timeDate = dateFormat.format(cal.getTime());
      
      /////////////////////////////////////////////////////
      try {
         player = new AudioPlayer("music/mainMenu_track1.aif");
         forest = new AudioPlayer("music/forestTrack_one.aif");
      } catch (UnsupportedAudioFileException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      } catch (LineUnavailableException e){
         e.printStackTrace();
      }
   }
   ////////////////////////////////////////////////////////
   private synchronized void start()
   {
      camX = p.getX()-view/2;
      camY = p.getY()-view/2;
      running = true;
      new Thread(this).start();
   }
   ////////////////////////////////////////////////////////
   @SuppressWarnings("unused")
   private synchronized void stop()
   {
      running = false;
   }
   
   /////////////////////////////////////////////////////////
   //Game loop
   public void run(){
      long lastTime = System.nanoTime();
      double nsPerTick = 1000000000D / 60D;//making the limit 60 updates per tick
      
      long lastTimer = System.currentTimeMillis();
      double delta = 0D;
      
      while (running){
         long now = System.nanoTime();
         delta += (now - lastTime) / nsPerTick;
         lastTime = now;
         boolean shouldRender = false;//for rendering
         
         while(delta >=1){
            tick();
            delta -= 1;
            ticks++;
            shouldRender = true;
         }
         
         try{
            Thread.sleep(2);
         }catch(InterruptedException e){
            e.printStackTrace();
         }
         
         if (shouldRender){
            render();
            frames++;
         }
         
         if (System.currentTimeMillis() - lastTimer >= 1000)
         {
            lastTimer += 1000;
            System.out.println(ticks + " ticks, " + frames + " frames");
            
            frames = 0;
            ticks = 0;
            //System.out.println(pause);
            if(!pause){
               
               //new time system
               if(!secondMark){//for optimization
                  secondMark = true;
                  secondWait = 10;
               }
               if(min < 60)min++;
               if(min == 60){
                  min = 0;
                  hrs++;
                  if(hrs == 24){
                     hrs = 0;
                     day++;
                     if(day > 31){
                        day = 1;
                        month++;
                        if(month > 12){
                           month = 1;
                           year++;
                        }
                     }
                  }
               }
            
               if(hrs > 6 && hrs < 20)night = false;
               else night = true;
               //System.out.println(day + "/" + month + "/" + year + "  time " + hrs + ":" + min + "." + sec);
               //System.out.println(dateFormat.format(cal.getTime()));
            }
         }
      }
      
   }
//////////////////////////////////////////////////////////////////////////////////////
   @SuppressWarnings({ "unused", "static-access" })
   public void tick(){
      if(sec < 60)sec++;
      if(sec >= 60)sec = 0;
      if(secondWait != 0)secondWait--;
      if(secondWait == 0)secondMark = false;
      long startTime = System.nanoTime();//debug stuff
      
      //System.out.println(getTimeDate().substring(13,15));
      int screenHeight = screenSize.height;
      int screenWidth = screenSize.width;
      rec = frame.getBounds();
      //System.out.println(screenHeight + " , " + screenWidth);
      //System.out.println(Math.max(18 - 5 + Math.random(), Math.ceil(4.6 * 3)));
      
      ///all updates here
      
      if(imageRefresh < 15)imageRefresh++;
      else imageRefresh = 0;
      if(p.loadTime != 0)p.loadTime--;
      if(!pause && !mainMenu && p.loadTime == 0){
         
         o.update();
         camX = (p.getX()-view*3)-5;
         camY = p.getY()-view*2-5;
         
         //sound stuff///////////////////////
         ////////////////////////////////////
      }
      //particle//////////////////////////////////////
      
      if(!pause){
         for(int i = 0; i <= particles.size() - 1;i++){
              if(particles.get(i).update())
                 particles.remove(i);
         }
      }
      //these are timers for key Input
      
      if(oneTimer != 0)oneTimer--;
      if(oneTimer == 0)onePressed = false;
      if(twoTimer != 0)twoTimer--;
      if(twoTimer == 0)twoPressed = false;
      if(threeTimer != 0)threeTimer--;
      if(threeTimer == 0)threePressed = false;
      if(fourTimer != 0)fourTimer--;
      if(fourTimer == 0)fourPressed = false;
      if(pTimer != 0)pTimer--;
      if(pTimer == 0)pPressed = false;
      if(periodTimer != 0)periodTimer--;
      if(periodTimer == 0)periodPressed = false;
      if(commaTimer != 0)commaTimer--;
      if(commaTimer == 0)commaPressed = false;
      
      if(wShiftTimer != 0)wShiftTimer --;
      if(wShiftTimer == 0)wShift = false;
      if(aShiftTimer != 0)aShiftTimer --;
      if(aShiftTimer == 0)aShift = false;
      if(sShiftTimer != 0)sShiftTimer --;
      if(sShiftTimer == 0)sShift = false;
      if(dShiftTimer != 0)dShiftTimer --;
      if(dShiftTimer == 0)dShift = false;
      if(mTimer != 0)mTimer--;
      if(mTimer == 0)mPressed = false;
      if(screenWait != 0)screenWait--;
      if(f10Timer!=0)f10Timer--;
      if(f10Timer == 0)f10Pressed = false;
      if(jTimer != 0)jTimer--;
      if(jTimer == 0)jPressed = false;
      if(nTimer != 0)nTimer--;
      if(nTimer == 0)nPressed = false;
      if(yTimer != 0)yTimer--;
      if(yTimer == 0)yPressed = false;
      if(qTimer != 0)qTimer--;
      if(qTimer == 0)qPressed = false;
      if(tabTimer != 0)tabTimer--;
      if(tabTimer == 0)tabPressed = false;
      if(wait != 0)wait--;
      if(refresh > 15)refresh = 0;
      if(kTimer != 0)kTimer--;
      if(kTimer == 0)kPressed = false;
      if(eTimer != 0)eTimer--;
      if(eTimer == 0)ePressed = false;
      if(rTimer != 0)rTimer--;
      if(rTimer == 0)rPressed = false;
      if(slashTimer != 0)slashTimer--;
      if(slashTimer ==0)slashPressed = false;
      if(escTimer != 0)escTimer--;
      if(escTimer == 0)escPressed = false;
      if(pauseTime != 0)pauseTime--;
      if(transWait != 0)transWait--;
      if(shiftTimer != 0)shiftTimer--;
      if(shiftTimer == 0)shiftPressed = false;
      if(f1Timer != 0)f1Timer--;
      if(f1Timer == 0)f1Pressed = false;
      if(lArrowTimer != 0)lArrowTimer--;
      if(lArrowTimer == 0)lArrow=false;
      if(rArrowTimer != 0)rArrowTimer--;
      if(rArrowTimer == 0)rArrow=false;
      if(uArrowTimer != 0)uArrowTimer--;
      if(uArrowTimer == 0)uArrow=false;
      if(dArrowTimer != 0)dArrowTimer--;
      if(dArrowTimer == 0)dArrow=false;
      if(enterTimer != 0)enterTimer--;
      if(enterTimer == 0)enterPressed = false;
      if(loadTime != 0)loadTime--;
      if(f2Timer != 0)f2Timer--;
      if(f2Timer == 0)f2Pressed = false;
      if(f3Timer != 0)f3Timer--;
      if(f3Timer == 0)f3Pressed = false;
      if(deleteTimer != 0)deleteTimer--;
      if(deleteTimer == 0)deletePressed = false;
      if(cTimer != 0)cTimer--;
      if(cTimer == 0)cPressed = false;
      if(spaceTimer != 0)spaceTimer--;
      if(spaceTimer == 0)spacePressed = false;
      
      
      if(saving && wait == 0)saving = false;
      
      /////////////
      if(!init && !mainMenu){
         
         init = true;
      }
      
      if(mainMenu){
         player.playLoop();
      }
      
      if(!mainMenu && player.started){
         player.audioClip.loop(0);
         player.audioClip.stop();
         player.audioClip.close();
      }
      long endTime = System.nanoTime();
      double seconds = (double)(endTime - startTime) / 1000000000.0;
      //System.out.println("Took "+seconds+ " seconds"); 
   }
//////////////////////////////////////////////////////////////////////////////////////
   //@SuppressWarnings("static-access")
   @SuppressWarnings({ "static-access" })
   public void render(){
      BufferStrategy bs = getBufferStrategy();
      if (bs == null){
         createBufferStrategy(3);
         return;
      }
      Graphics g = bs.getDrawGraphics();
      Graphics2D g2d = (Graphics2D)g;
      //System.out.println((float)(WIDTH/getWidth()));
      ////////////////////////////////////////////////////////////////////////////
      //if(doScale)g2d.setTransform(AffineTransform.getScaleInstance((double)(WIDTH / JFrame.MAXIMIZED_HORIZ),(double)(HEIGHT / JFrame.MAXIMIZED_VERT)));
      g2d.scale(getXscale(), getYscale());
      if(doScale)g2d.scale((1.7),(1.4));
      g2d.translate(-camX, -camY);
      ////////////////////////////////////////////////////////////////////////
      ////here is where all things are rendered
      g2d.setColor(new Color(65,140,193));
      g2d.fillRect(0, 0, getScreenWidth()*2, getScreenHeight()*2);
      
      /////////////////////////////////////////////////////////////////////////
      if(!mainMenu){
         o.render(g2d);
      //where menus are renderd
         
         if(p.isCloseToTrans())p.renderE(g);
         
         if(p.showHud){
            hud.render(g2d, p);
         }
         
         if(p.menuOpen())p.getMenu().render(g2d, p.getX(), p.getY());
      //////////////////////////////////////////
         
         if(pause){
            g.setColor(Color.black);
            g.drawString("PAUSED",p.getX()-330,p.getY()-80);
         }
      }
      if(mainMenu)renderMain(g2d);
      //p.render(g);
      
      //////////////////////////////////
      for(int i = 0; i < particles.size(); i ++){
         particles.get(i).render(g2d);
      }
      //grid
      if(grid){
         g.setColor(new Color(0,0,0,100));
         for(int i = 0; i < 100; i ++){
            for(int j = 0; j < 100; j ++){
               g.drawRect(i * 64,j*64,64,64);
               //g.drawString("(" + i + "," + j + ")",i*64,j*64);
            }
         }
      }
      
      
      ///
      /////////////////////////////////////////////////////////////////////////
      rec = new Rectangle(0,0,getScreenWidth(),getScreenHeight());
      //BufferedImage bufferedImage = new BufferedImage(rec.width, rec.height,BufferedImage.TYPE_INT_ARGB);
       g2d.dispose();
      bs.show();
      //////////////////////////////////////////////////////////////////////////
      
   }
   ////////////////////////////////////////////////////////////////////////////
   public void keyPressed(KeyEvent e){
      int key = e.getKeyCode();
      if(key == KeyEvent.VK_W)
         up = true;
      if(key == KeyEvent.VK_A)
         left = true;
      if(key == KeyEvent.VK_S)
         down = true;
      if(key == KeyEvent.VK_D)
         right = true;
      ////////////////////////
      if(key == KeyEvent.VK_SHIFT){
         shiftHeld = true;
      }
      
   }
   /////////////////////////////////////////////////////////////
   public void keyReleased(KeyEvent e) {
      int key = e.getKeyCode();
      
      if(key == KeyEvent.VK_W){
         up = false;
         //Player.walking = false;
      }
         
      if(key == KeyEvent.VK_A){
         left = false;
         //Player.walking = false;
      }
         
      if(key == KeyEvent.VK_S){
         down = false;
         //Player.walking = false;
      }
         
      if(key == KeyEvent.VK_D){
         right = false;
         //Player.walking = false;
      }
         
      //key released is mostly used
      if(key == KeyEvent.VK_E){
         ePressed = true;
         eTimer = 3;
         System.out.println("ePressed");
         
         
      }
      if(key == KeyEvent.VK_K){
         kPressed = true;
         kTimer = 15;
         System.out.println("kPressed");
      }
      if(key == KeyEvent.VK_J){
         jPressed = true;
         jTimer = 1;
         System.out.println("jPressed");
         
      }
      if(key == KeyEvent.VK_R){
         rPressed = true;
         rTimer = 2;
         System.out.println("rPressed");
      }
      if(key == KeyEvent.VK_DELETE){
         deletePressed = true;
         deleteTimer = 1;
         System.out.println("deletePressed");
      }
      if(key == KeyEvent.VK_ESCAPE){
         commandLine = "";
         escPressed = true;
         escTimer = 2;
         
         
         System.out.println("escPressed");
         commandLine = "";
      }
      
      if(key == KeyEvent.VK_P){
         pPressed = true;
         pTimer = 5;
         if(pause && pauseTime == 0)pause = false;
         else if(!pause){pause = true; pauseTime = 25;}
         
      }
      
      if(key == KeyEvent.VK_SLASH){
         slashPressed = true;
         //cmd = true;
         slashTimer = 2;
         System.out.println("slashPressed");
      }
      if(key == KeyEvent.VK_ENTER){
         
         //doCommand(commandLine);
         enterPressed = true;
         enterTimer = 2;
         System.out.println("EnterPressed");
         
      }
      if(key == KeyEvent.VK_SPACE){
         spacePressed = true;
         spaceTimer = 2;
         System.out.println("Space Pressed");
      }
      if(key == KeyEvent.VK_SHIFT){
         shiftHeld = false;
         shiftPressed = true;
         shiftTimer = 2;
         System.out.println("Shift Pressed");
      }
      if(key == KeyEvent.VK_F1){
         f1Pressed = true;
         f1Timer = 5;
         System.out.println("f1 Pressed");
      }
      if(key == KeyEvent.VK_F2){
         f2Pressed = true;
         f2Timer = 2;
         System.out.println("f2Pressed");
      }
      if(key == KeyEvent.VK_F3){
         f3Pressed = true;
         f3Timer = 2;
         System.out.println("f3Pressed");
      }
      
      if(key == KeyEvent.VK_COMMA){
         commaPressed = true;
         commaTimer = 2;
         System.out.println("comma pressed");
      }
      if(key == KeyEvent.VK_PERIOD){
         periodPressed = true;
         periodTimer = 2;
         System.out.println("periodPressed");
      }
      
      if(key == KeyEvent.VK_F10){
         f10Pressed = true;
         f10Timer = 1;
         
         if(fullScreen && screenWait == 0){
            setNormalScreen();
            screenWait = 15;
         
         }
         if(!fullScreen && screenWait == 0){
            setFullScreen();
            screenWait = 15;
         }
         
         System.out.println("f10Pressed");
      }
      if(key == KeyEvent.VK_I){
         tabPressed = true;
         tabTimer = 2;
         System.out.println("tabPressed");
      }
      if(key == KeyEvent.VK_LEFT){
         lArrow=true;
         lArrowTimer = 2;
         System.out.println("left pressed");
      }
      if(key == KeyEvent.VK_RIGHT){
         rArrow=true;
         rArrowTimer = 2;
         System.out.println("right pressed");
      }
      if(key == KeyEvent.VK_UP){
         uArrow=true;
         uArrowTimer = 2;
         System.out.println("up pressed");
      }
      if(key == KeyEvent.VK_DOWN){
         dArrow=true;
         dArrowTimer = 2;
         System.out.println("down pressed");
      }
      if(key == KeyEvent.VK_Q){
         qPressed = true;
         qTimer = 2;
         System.out.println("qPressed");
      }
      if(key == KeyEvent.VK_Y){
         yPressed = true;
         yTimer = 2;
         System.out.println("yPressed");
      }
      if(key == KeyEvent.VK_N){
         nPressed = true;
         nTimer = 2;
         System.out.println("nPressed");
      }
      if(key == KeyEvent.VK_M){ 
         mPressed = true;
         mTimer = 2;
         System.out.println("mPressed");
      }
      
      if(key == KeyEvent.VK_1){
         onePressed = true;
         oneTimer = 2;
         System.out.println("onePressed");
      }
      
      if(key == KeyEvent.VK_2){
         twoPressed = true;
         twoTimer = 2;
         System.out.println("twoPressed");
      }
      
      if(key == KeyEvent.VK_3){
         threePressed = true;
         threeTimer = 2;
         System.out.println("threePressed");
      }
      
      if(key == KeyEvent.VK_4){
         fourPressed= true;
         fourTimer = 2;
         System.out.println("fourPressed");
      }
      
      if(key == KeyEvent.VK_C){
         cPressed = true;
         cTimer = 1;
         System.out.println("cPressed");
      }
   }
   public void keyTyped(KeyEvent e) {
      //int key = e.getKeyCode();
      
      
   }
   
   ////////////////////////////////////////////
   public static Rectangle getRenderBounds(){
      if(doScale)return new Rectangle(p.getX()-WIDTH,p.getY()-HEIGHT,WIDTH*3,HEIGHT*3);
      else return new Rectangle(p.getX()-555,p.getY()-450,1000,860);
   }
   public static Rectangle getUpdateBounds(){
      return new Rectangle(p.getX()-(64*6)*4,p.getY()-(64*6)*4,(64*18)*4,(64*15)*4);
   }
   ///////////////////////////////////////////////
   public static void reset(){
      reset = true;
   }
   /////////////////////////////////////////////
    public void addParticle(boolean bool){
         int dx,dy;
         if(bool){
             dx = (int) (Math.random()*5);
             dy = (int) (Math.random()*5);
         }
         else{
             dx = (int) (Math.random()*-5);
             dy = (int) (Math.random()*-5);
         }
         int size = (int) (Math.random()*14);
         int life = (int) Math.random()*(100)+75;
         particles.add(new Particle(mx,my,dx,dy,size,life,Color.red));
     }
   
   public void mouseClicked(MouseEvent m){
      if(!fullScreen){
         mx = m.getX() - 340+ p.getX();
         my = m.getY() - 200+p.getY();
      }else{
         mx = m.getX() - 600+ p.getX();
         my = m.getY() - 200+p.getY();
      }
      
      addParticle();addParticle();addParticle();addParticle();addParticle();addParticle();
      addParticle();addParticle();addParticle();addParticle();addParticle();addParticle();
      addParticle();addParticle();addParticle();addParticle();addParticle();addParticle();
      addParticle();addParticle();addParticle();addParticle();addParticle();addParticle();
      
   }
   
   
   public void mouseEntered(MouseEvent arg){
      
   }
   
   public void mouseExited(MouseEvent arg){
      
   }
   
   public void mousePressed(MouseEvent arg){
      
      
   }
   
   public void mouseReleased(MouseEvent arg){
      
      
   }
   ////////////////////////////////////////////////////////////////////////////////
   //particle methods here!
   /////////////////////////////////////////////////////////////////////////////
   public static void addParticle(Particle p){
      particles.add(p);
   }
   /////////////////////////////////////////////////////////////////
   public static void addParticle(){//play with this method
        Particle p = new Particle(mx,my,0,0,0,0,Color.orange);
        p.setVel(random(5),random(5));
        p.setAcc(random(.03),random(.03));
        p.setLife(randomPlus(30)+5);
        p.setSize(randomPlus(25)+5, randomPlus(25)+5);
        p.setMaxSize(5,5);
        p.setGrowth(random(1), random(1));
        p.setUltSize(true);
        particles.add(p);
    }
   public static void addParticle(int x, int y){//play with this method
        Particle p = new Particle(x,y,0,0,0,0,Color.red);
        p.setVel(random(5),random(5));
        p.setAcc(random(.03),random(.03));
        p.setLife(randomPlus(30)+5);
        p.setSize(randomPlus(25)+5, randomPlus(25)+5);
        p.setMaxSize(5,5);
        p.setGrowth(random(1), random(1));
        p.setUltSize(true);
        particles.add(p);
    }
   public static void addParticle(int x, int y, Color c){//play with this method
        Particle p = new Particle(x,y,0,0,0,0,c);
        p.setVel(random(5),random(5));
        p.setAcc(random(.03),random(.03));
        p.setLife(randomPlus(30)+5);
        p.setSize(randomPlus(25)+5, randomPlus(25)+5);
        p.setMaxSize(5,5);
        p.setGrowth(random(1), random(1));
        p.setUltSize(true);
        particles.add(p);
    }
   public static void addParticle(int x, int y,int life, Color c){//play with this method
        Particle p = new Particle(x,y,0,0,0,0,c);
        p.setVel(random(5),random(5));
        p.setAcc(random(.03),random(.03));
        p.setLife(randomPlus(life)+5);
        p.setSize(randomPlus(25)+5, randomPlus(25)+5);
        p.setMaxSize(5,5);
        p.setGrowth(random(1), random(1));
        p.setUltSize(true);
        particles.add(p);
    }
   public static void addParticle(int x, int y,int size){//play with this method
        Particle p = new Particle(x,y,0,0,0,0,Color.red);
        p.setVel(random(5),random(5));
        p.setAcc(random(.03),random(.03));
        p.setLife(randomPlus(30)+5);
        p.setSize(randomPlus(25)+5, randomPlus(25)+5);
        p.setMaxSize(size,size);
        p.setGrowth(random(1), random(1));
        p.setUltSize(true);
        particles.add(p);
    }
   public static void addParticle(int x, int y, Color c,int size){//play with this method
        Particle p = new Particle(x,y,0,0,0,0,c);
        p.setVel(random(5),random(5));
        p.setAcc(random(.03),random(.03));
        p.setLife(randomPlus(30)+5);
        p.setSize(randomPlus(25)+5, randomPlus(25)+5);
        p.setMaxSize(size,size);
        p.setGrowth(random(1), random(1));
        p.setUltSize(true);
        particles.add(p);
    }
   //////////////////////////////////////////////////////
   public static double random( double num ){//random method may not be the best
        return (num * 2)  * rnd.nextDouble() - num;
    }
 
    public static double randomPlus( double num ){//return only a positive number
        double temp = ((num * 2)  * rnd.nextDouble()) - num;
        if( temp < 0 )
            return temp * -1;
        else
            return temp;
    }
    //////end of particle methodes
    
    ////////////////////////////////////////////////////////////////////////////////
    //okay this is going to be all the add effects methods
    
    public static void addExplosion1(int x, int y){
       addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);
       addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);
       addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);
       addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);
       addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);
       addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);
       addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);
       addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);
       addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);
       addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);
       addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);addParticle(x,y,10,Color.orange);
    }
    public static void addExplosion2(int x, int y){
       addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);
       addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);
       addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);
       addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);
       addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);
       addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);
       addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);
       addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);addParticle(x,y,10,Color.cyan);
    }
    ///////////////
    public static void addBlood(int x, int y, Color c){
       addParticle(x,y,4,c);addParticle(x,y,4,c);addParticle(x,y,4,c);addParticle(x,y,4,c);
       addParticle(x,y,4,c);addParticle(x,y,4,c);addParticle(x,y,4,c);addParticle(x,y,4,c);
    }
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //scale methode
    public void Scale (double X, double Y) {
        Sx = X;
        Sy = Y;
      } 
    
    ////////////////////////////////////////////////////////////
    public void renderMain(Graphics g){
       //int load = 0;
       int x = p.getX() - 255;
       int y = p.getY() - 256;
       
       g.setFont(new Font("Tahoma",Font.PLAIN,35));
       g.drawImage(menu,x + 205,y + 206,menu.getWidth()+50,menu.getHeight()+50,null);
       g.setColor(Color.white);
       g.drawString("[WIP] The Dark Iron Tower", x + 218,y + 250);
       
       
       g.drawString("Enter", x + 225, y + 387);
       g.drawString("Shift", x + 225, y + 467);
       g.drawString(" New Game",x + 320, y + 387);
       g.drawString(" Load Game",x + 320, y + 467);
       
       g.drawRect(x + 218,y + 350,100,50);
       g.drawRect(x + 218,y + 430,100,50);
       
       g.fillRect(x + 225,y + 550,load,50);
       ////////////////////////////////////////////////////
       //events
       
       if(enterPressed && load == 0){
          load = 300;
          
       }
       if(shiftPressed && load == 0){
          load = 300;
          loadGame = true;
       }
       
       if(load > 0){
          load-=3;
          if(load == 0)mainMenu = false;
          
       }
       
    }
    
    public int getScreenWidth(){return screenWidth;}
    public int getScreenHeight(){return screenHeight;}
    
    public void setFullScreen(){//its not actually a fullscreen but i'll get there
       if(!fullScreen){
          //frame.setExtendedState(JFrame.MAXIMIZED_BOTH); 
          frame.setVisible(true);
          //1280x720
          frame.setSize(1280, 800);
          frame.setLocation(0, 0);
          fullScreen = true;
          doScale = true;
       }
    }
    public void setNormalScreen(){
       if(fullScreen){
          frame.setSize(WIDTH,HEIGHT+25);
          frame.setLocationRelativeTo(null);
          fullScreen = false;
          doScale = false;
       }
    }
    
    public static String getTimeDate(){return timeDate;}
    
    public double getXscale(){
       return (frame.getWidth() / WIDTH);
    }
    
    public double getYscale(){
       return (frame.getHeight() / (HEIGHT+25));
    }
   ////////////////////////////////////////////////
   public static void main(String args[]){
      new Game().start();
   
   }
}





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
 
Ecumene (57 views)
2017-09-30 02:57:34

theagentd (80 views)
2017-09-26 18:23:31

cybrmynd (187 views)
2017-08-02 12:28:51

cybrmynd (185 views)
2017-08-02 12:19:43

cybrmynd (192 views)
2017-08-02 12:18:09

Sralse (203 views)
2017-07-25 17:13:48

Archive (767 views)
2017-04-27 17:45:51

buddyBro (902 views)
2017-04-05 03:38:00

CopyableCougar4 (1452 views)
2017-03-24 15:39:42

theagentd (1327 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!