Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (755)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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: wreed12345 (posted 2013-03-24 15:07:07, viewed 194 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  
package com.reed.birdseye;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Array;

public class GameMain {
   int middleX, middleY;
   boolean move;
   private float levelX;
   private float levelY;
   boolean up, down, left, right;
   boolean inHouse;
   int playerSpeed;
   BitmapFont font;
   //Farm farm;
   //Water water;
   Resource resource;
   
   public void onCreate(){
      middleX = Gdx.graphics.getWidth() / 2 - 16;
      middleY = Gdx.graphics.getHeight() / 2 - 24;
      move = true;
      levelX = -500;
      levelY = -500;
      up = false;
      down = false;
      left = false;
      right = false;
      inHouse = false;
      playerSpeed = 2;
      font = new BitmapFont();
      //farm = new Farm();
      //water = new Water();
      resource = new Resource();
   }
   
   // pretty much just player movement here
   public void update() {
      if (move) {
         if (!inHouse) {
            if ((Gdx.input.isKeyPressed(Keys.W))) {
               levelY -= playerSpeed;
               up = true;
            } else
               up = false;
            if ((Gdx.input.isKeyPressed(Keys.A))) {
               levelX += playerSpeed;
               left = true;
            } else
               left = false;
            if ((Gdx.input.isKeyPressed(Keys.S))) {
               levelY += playerSpeed;
               down = true;
            } else
               down = false;
            if ((Gdx.input.isKeyPressed(Keys.D))) {
               levelX -= playerSpeed;
               right = true;
            } else
               right = false;
         } else {
            if ((Gdx.input.isKeyPressed(Keys.W))) {
               middleY += playerSpeed;
               up = true;
            } else
               up = false;
            if ((Gdx.input.isKeyPressed(Keys.A))) {
               middleX -= playerSpeed;
               left = true;
            } else
               left = false;
            if ((Gdx.input.isKeyPressed(Keys.S))) {
               middleY -= playerSpeed;
               down = true;
            } else
               down = false;
            if ((Gdx.input.isKeyPressed(Keys.D))) {
               middleX += playerSpeed;
               right = true;
            } else
               right = false;
         }
      }
      if (right)
         Assets.mainChar = Assets.rightChar;
      if (left)
         Assets.mainChar = Assets.leftChar;
      if (up)
         Assets.mainChar = Assets.upChar;
      if (down)
         Assets.mainChar = Assets.downChar;
      
      //farm.closeEnoughToFarm();
      //farm.farmTimer();
      
   }
   
   public void draw(SpriteBatch batch) {
      //System.out.println(levelX);
      batch.draw(Assets.level, levelX, levelY);
      resource.x = 800;
      resource.y = 800;
      resource.doResource(batch);
      if (inHouse)
         batch.draw(Assets.houseIn, 0, 0);
      else {
         //Top menu stuff
         batch.draw(Assets.itemSelector, 230, 465);
         batch.draw(Assets.material, 240, 470);
         batch.draw(Assets.tree, 330, 470, 50, 60);
         batch.draw(Assets.corn, 420, 470, 35, 60);
         batch.draw(Assets.bucket, 495, 470, 52, 56);
         amountOfStoneString = Integer.toString(amountOfStone);
         font.draw(batch, amountOfStoneString, 240, 530);
         amountOfWoodString = Integer.toString(amountOfWood);
         font.draw(batch, amountOfWoodString, 320, 530);
         //farm.cornCountString = Integer.toString(farm.cornCount);
         //font.draw(batch, farm.cornCountString, 405, 530);
         amountOfWaterString = Integer.toString(amountOfWater);
         font.draw(batch, amountOfWaterString, 488, 530);
         
         
         
         //draw trees and minerals
         //resourceArrayEstablisher(batch);
         //treeArrayEstablisher(batch);
      }
      if (move)
         batch.draw(Assets.mainChar, middleX, middleY);
   }
   
   //private Array<Resource> resourceArray = new Array<Resource>();
/*
   void resourceArrayEstablisher(SpriteBatch batch) {
      for (int i = 0; i < 5; i++){
         resourceArray.add(new Resource());
      }

      resourceArray.get(0).x = 800;
      resourceArray.get(0).y = 800;
      resourceArray.get(1).x = 1200;
      resourceArray.get(1).y = 1200;
      resourceArray.get(2).x = 800;
      resourceArray.get(2).y = 1200;
      resourceArray.get(3).x = 1200;
      resourceArray.get(3).y = 800;
      resourceArray.get(4).x = 500;
      resourceArray.get(4).y = 1000;

      for (int i = 0; i < 5; i++) {
         resourceArray.get(i).doResource(batch);
      }
   }*/
   /*
   static Array<Tree> treeArray = new Array<Tree>();
   static int amountOfTrees = 2;
   static int currentTree = 2;

   void treeArrayEstablisher(SpriteBatch batch) {
      for (int i = 0; i < amountOfTrees; i++)
         treeArray.add(new Tree());

      treeArray.get(0).x = 400;
      treeArray.get(0).y = 700;
      treeArray.get(1).x = 300;
      treeArray.get(1).y = 300;

      for (int i = 0; i < amountOfTrees; i++) {
         treeArray.get(i).treePlacer(batch);
      }
   }
   */
   final int distanceFromMaterial = 100;
   int amountOfStone = 0;
   String amountOfStoneString;

   int amountOfWood = 0;
   String amountOfWoodString;
   
   int amountOfWater = 0;
   String amountOfWaterString;
   
   void houseEntrance(SpriteBatch batch, int x, int y) {
      if (!inHouse) {
         batch.draw(Assets.house, levelX + x, levelY + y);
         if ((Math.sqrt((levelX + x - middleX) * (levelX + x - middleX)
               + (levelY + y - middleY) * (levelY + y - middleY)) < distanceFromMaterial)) {
            font.draw(batch, "Press B to Enter...", 50, 50);
            if (Gdx.input.isKeyPressed(Keys.B))
               inHouse = true;
         }
      } else {
         font.draw(batch, "Press ESCAPE to Exit", 50, 50);
         if (Gdx.input.isKeyPressed(Keys.ESCAPE)) {
            middleX = Gdx.graphics.getWidth() / 2 - 16;
            middleY = Gdx.graphics.getHeight() / 2 - 16;
            inHouse = false;
         }
      }
   }
   
   public float getLevelX() {
      //System.out.println("getX called");
      return levelX;
   }

   public void setLevelX(float levelX) {
      this.levelX = levelX;
   }

   public float getLevelY() {
      //System.out.println("getY called");
      return levelY;
   }

   public void setLevelY(float levelY) {
      this.levelY = levelY;
   }
}





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
 
DesertCoockie (36 views)
2018-05-13 18:23:11

nelsongames (82 views)
2018-04-24 18:15:36

nelsongames (74 views)
2018-04-24 18:14:32

ivj94 (755 views)
2018-03-24 14:47:39

ivj94 (85 views)
2018-03-24 14:46:31

ivj94 (626 views)
2018-03-24 14:43:53

Solater (101 views)
2018-03-17 05:04:08

nelsongames (182 views)
2018-03-05 17:56:34

Gornova (408 views)
2018-03-02 22:15:33

buddyBro (1068 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

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
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!