SHARE
TWEET

Untitled

a guest Apr 24th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import java.text.DateFormat;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Date;
  5.  
  6. import hsa_ufa.*;
  7.  
  8. public class game {
  9.  
  10.     static DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
  11.     static Date date = new Date();
  12.    
  13.     final static String WINDOWNAME = "Game Test";
  14.    
  15.     static Console c = new Console(WINDOWNAME + " " + dateFormat.format(date) + " EST");
  16.  
  17.     static int[][] level1CollisionArray = {{0,0,320,32},{0,288,320,32},{0,32,32,256},{288,32,32,256}};
  18.     static int[][][][] level1MapArray = {
  19.            
  20.             {
  21.                     { { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 } },
  22.                     { { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 } },
  23.                     { { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 } },
  24.                     { { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 } },
  25.                     { { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 } },
  26.                     { { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 } },
  27.                     { { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 } },
  28.                     { { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 } },
  29.                     { { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 } },
  30.                     { { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 }, { 16 } },
  31.                                                             },
  32.             {
  33.                     { { 12, 1 }, { 2, 1 }, { 2, 1 }, { 2, 1 }, { 2, 1 }, { 2, 1 }, { 2, 1 }, { 2, 1 }, { 2, 1 }, { 14, 1 } },
  34.                     { { 1, 1 }, {}, {}, {}, {}, {}, {}, {}, {}, { 1, 1 } },
  35.                     { { 1, 1 }, {}, {}, {}, {}, {}, {}, {}, {}, { 1, 1 } },
  36.                     { { 1, 1 }, {}, {}, {}, {}, {}, {}, {}, {}, { 1, 1 } },
  37.                     { { 1, 1 }, {}, {}, {}, {}, {}, {}, {}, {}, { 1, 1 } },
  38.                     { { 1, 1 }, {}, {}, {}, {}, {}, {}, {}, {}, { 1, 1 } },
  39.                     { { 1, 1 }, {}, {}, {}, {}, {}, {}, {}, {}, { 1, 1 } },
  40.                     { { 1, 1 }, {}, {}, {}, {}, {}, {}, {}, {}, { 1, 1 } },
  41.                     { { 1, 1 }, {}, {}, {}, {}, {}, {}, {}, {}, { 1, 1 } },
  42.                     { { 13, 1 }, { 2, 1 }, { 2, 1 }, { 2, 1 }, { 2, 1 }, { 2, 1 }, { 2, 1 }, { 2, 1 }, { 2, 1 }, { 15, 1 } }
  43.                                                                 }
  44.                
  45.                                 };
  46.    
  47.    
  48.     static tile fence00 = new tile("tiles/fence_00.png", c, 32, 32);
  49.     static tile fence01 = new tile("tiles/fence_01.png", c, 32, 32);
  50.     static tile fence02 = new tile("tiles/fence_02.png", c, 32, 32);
  51.     static tile fence03 = new tile("tiles/fence_03.png", c, 32, 32);
  52.     static tile fence04 = new tile("tiles/fence_04.png", c, 32, 32);
  53.     static tile fence05 = new tile("tiles/fence_05.png", c, 32, 32);
  54.     static tile fence06 = new tile("tiles/fence_06.png", c, 32, 32);
  55.     static tile fence07 = new tile("tiles/fence_07.png", c, 32, 32);
  56.     static tile fence08 = new tile("tiles/fence_08.png", c, 32, 32);
  57.     static tile fence09 = new tile("tiles/fence_09.png", c, 32, 32);
  58.     static tile fence10 = new tile("tiles/fence_10.png", c, 32, 32);
  59.     static tile fence11 = new tile("tiles/fence_11.png", c, 32, 32);
  60.     static tile fence12 = new tile("tiles/fence_12.png", c, 32, 32);
  61.     static tile fence13 = new tile("tiles/fence_13.png", c, 32, 32);
  62.     static tile fence14 = new tile("tiles/fence_14.png", c, 32, 32);
  63.     static tile fence15 = new tile("tiles/fence_15.png", c, 32, 32);
  64.     static tile grass = new tile("tiles/grass.png", c, 32, 32);
  65.     static tile player00 = new tile("tiles/player_00.png", c, 32, 32);
  66.     static tile player01 = new tile("tiles/player_01.png", c, 32, 32);
  67.     static tile player02 = new tile("tiles/player_02.png", c, 32, 32);
  68.     static tile player03 = new tile("tiles/player_03.png", c, 32, 32);
  69.     static tile player04 = new tile("tiles/player_04.png", c, 32, 32);
  70.     static tile player05 = new tile("tiles/player_05.png", c, 32, 32);
  71.     static tile player06 = new tile("tiles/player_06.png", c, 32, 32);
  72.     static tile player07 = new tile("tiles/player_07.png", c, 32, 32);
  73.     static tile player08 = new tile("tiles/player_08.png", c, 32, 32);
  74.     static tile player09 = new tile("tiles/player_09.png", c, 32, 32);
  75.    
  76.     static tile[] playerWalkDown = {player00, player04, player00, player05};
  77.     static tile[] playerWalkLeft = {player02, player08, player02, player08};
  78.     static tile[] playerWalkUp = {player01, player06, player01, player07};
  79.     static tile[] playerWalkRight = {player03, player09, player03, player09};
  80.    
  81.     static tile[] tileset = {fence00, fence01, fence02, fence03, fence04, fence05, fence06, fence07, fence08, fence09, fence10, fence11, fence12, fence13, fence14, fence15, grass};
  82.    
  83.     static level level1 = new level(level1MapArray, 10, 10, tileset, 32, level1CollisionArray, c);
  84.    
  85.     static player mainPlayer = new player(playerWalkDown, playerWalkLeft, playerWalkUp, playerWalkRight, player00, player02, player01, player03);
  86.    
  87.     public static void main(String[] args) throws InterruptedException {
  88.        
  89.        
  90.         // TODO Auto-generated method stub
  91.         int lastPressed = 0;
  92.         int playerX = 64;
  93.         int playerY = 64;
  94.        
  95.         long lastTime = System.currentTimeMillis();
  96.         long lastLoop = System.currentTimeMillis();
  97.        
  98.         while (true) {
  99.             if (System.currentTimeMillis() - lastLoop > 40) {
  100.                    
  101.                 lastLoop = System.currentTimeMillis();
  102.                 synchronized(c) {
  103.                 level1.renderTilemap();
  104.                 level1.debugCollisions();
  105.                 mainPlayer.render(playerX, playerY);
  106.                 }
  107.                
  108.                 if (c.isKeyDown(Console.VK_DOWN)) {
  109.                     mainPlayer.setAnimationState(0);
  110.                     for (int i = 0; i < level1CollisionArray.length; i++) {
  111.                         if (playerX < level1CollisionArray[i][0] + level1CollisionArray[i][2] && playerX + 32 > level1CollisionArray[i][0] && playerY + 2 < level1CollisionArray[i][1] + level1CollisionArray[i][3] && playerY + 32 > level1CollisionArray[i][1]) {
  112.                             System.out.println("COLLIDE");
  113.                         } else {
  114.                             playerY = playerY + 2;
  115.                         }
  116.                     }
  117.                     mainPlayer.setIdling(false);
  118.                 }
  119.                 if (c.isKeyDown(Console.VK_LEFT)) {
  120.                     mainPlayer.setAnimationState(1);
  121.                     for (int i = 0; i < level1CollisionArray.length; i++) {
  122.                         if (playerX - 2 < level1CollisionArray[i][0] + level1CollisionArray[i][2] && playerX + 32 > level1CollisionArray[i][0] && playerY < level1CollisionArray[i][1] + level1CollisionArray[i][3] && playerY + 32 > level1CollisionArray[i][1]) {
  123.                             System.out.println("COLLIDE");
  124.                         } else {
  125.                             playerX = playerX - 2;
  126.                         }
  127.                     }
  128.                     mainPlayer.setIdling(false);
  129.                 }
  130.                 if (c.isKeyDown(Console.VK_UP)) {
  131.                     mainPlayer.setAnimationState(2);
  132.                     for (int i = 0; i < level1CollisionArray.length; i++) {
  133.                         if (playerX < level1CollisionArray[i][0] + level1CollisionArray[i][2] && playerX + 32 > level1CollisionArray[i][0] && playerY - 2 < level1CollisionArray[i][1] + level1CollisionArray[i][3] && playerY + 32 > level1CollisionArray[i][1]) {
  134.                             System.out.println("COLLIDE");
  135.                         } else {
  136.                             playerY = playerY - 2;
  137.                         }
  138.                     }
  139.                     mainPlayer.setIdling(false);
  140.                 }
  141.                 if (c.isKeyDown(Console.VK_RIGHT)) {
  142.                     mainPlayer.setAnimationState(3);
  143.                     for (int i = 0; i < level1CollisionArray.length; i++) {
  144.                         if (playerX < level1CollisionArray[i][0] + level1CollisionArray[i][2] && playerX + 2 + 32 > level1CollisionArray[i][0] && playerY < level1CollisionArray[i][1] + level1CollisionArray[i][3] && playerY + 32 > level1CollisionArray[i][1]) {
  145.                             System.out.println("COLLIDE");
  146.                         } else {
  147.                             playerX = playerX + 2;
  148.                         }
  149.                     }
  150.                     mainPlayer.setIdling(false);
  151.                 }
  152.                 if (c.isKeyDown(Console.VK_DOWN) != true && c.isKeyDown(Console.VK_LEFT) != true && c.isKeyDown(Console.VK_UP) != true && c.isKeyDown(Console.VK_RIGHT) != true) {
  153.                     mainPlayer.setIdling(true);
  154.                 }
  155.                
  156.                 if (System.currentTimeMillis() - lastTime > 300) {
  157.                     mainPlayer.switchAnims();
  158.                     lastTime = System.currentTimeMillis();
  159.                 }
  160.            
  161.             }
  162.         }
  163.     }
  164.  
  165. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top