JustDoesGames

Platform

Sep 25th, 2018 (edited)
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.32 KB | None | 0 0
  1. -- 0 = AIR --
  2. -- 1 = WALLS --
  3. -- 2 = DOORS --
  4. -- 3 = SPRITE --
  5.  
  6. x,y = term.getSize() -- Gets size of Current Computer Screen
  7. if x ~= 51 or y ~= 19 then
  8.     error("SCREEN SIZE NOT AVALIBLE. 51 BY 19") -- Gives error if screen is bigger or smaller than 51 by 19 (colored or not).
  9. end
  10. function cls() shell.run("clear") end -- Short way of clearing the screen
  11. sx = 1
  12. repeat
  13.     cls()
  14.     term.setCursorPos(sx,1)
  15.     print("Platformer Created by Just Does Games") -- splash screen. DO NOT REMOVE WITHOUT CONSENT FROM ME OR ELSE COPYRIGHT
  16.     print("Version 1.0.0")
  17.     sleep(.01) -- SAME FROM ABOVE APPLIES TO THIS LINE HERE TOO
  18.     sx = sx + 1
  19. until sx == 15
  20. repeat
  21.     cls()
  22.     term.setCursorPos(sx,1)
  23.     print("Platformer Created by Just Does Games") -- splash screen. DO NOT REMOVE WITHOUT CONSENT FROM ME OR ELSE COPYRIGHT
  24.     print("Version 1.0.0")
  25.     sleep(.01) -- SAME FROM ABOVE APPLIES TO THIS LINE HERE TOO
  26.     sx = sx - 1
  27. until sx == 0
  28. sleep(.5)
  29. cls() -- Ignore
  30. write("Error Code: ") -- Ignore This 2
  31. room_1 = { -- EACH ROOM HAS ITS OWN STAGE CODE. IN THIS CASE, YOU START IN "room_1". IF YOU GO BEYOND THE SCREEN SIZE, IT CHANGES TO ROOMS 2-5.
  32.     1,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, -- 1 = WALL  2 = DOOR.
  33.     2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, -- THE CODE ALLOWS THE COMPUTER TO PRINT THE MAP(S)
  34.     2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, -- OF WHATEVER YOU WANT
  35. -- Player position. CHANGE IF YOU WANT THE PLAYER TO START IN ANOTHER POSITION
  36. load_room = room_1 -- THIS IS THE ROOM THAT LOADS FIRST. CHANGE THIS IF YOU WANT TO LOAD IN A DIFFERENT ROOM AT THE START OF THE GAME
  37. LR = true -- Ignore this
  38. running = true
  39. function load(table)
  40.     if LR == true then -- This code prints the code on screen. WARNING: MAP DOES NOT UPDATE TO SAVE PROCESSING TIMES FOR PLAYER MOVEMENT
  41.         load_room = table
  42.         for i=1,#load_room do
  43.             if load_room[i] == 0 then -- CHECKS TO SEE IF ITS 0. IF SO THEN
  44.                 write(" ") -- DISPLAY A BLANK SLOT
  45.             elseif load_room[i] == 1 then -- CHECKS TO SEE IF ITS 1. IF SO THEN
  46.                 write("#") -- DISPLAY A WALL TILE
  47.             elseif load_room[i] == 2 then -- CHECKS TO SEE IF ITS 2. IF SO THEN
  48.                 write(".") -- DISPLAY A DOOR TILE
  49.             elseif load_room[i] == 3 then -- CHECKS TO SEE IF ITS 3. IF SO THEN
  50.                 write("*") -- DISPLAY SPRITE EXAMPLE
  51.             end
  52.         end
  53.     end
  54. end
  55. while running do -- main player functions and map transactions
  56.     term.setCursorPos(px,py) -- Ignore
  57.     write(" ") -- Ignore
  58.     term.setCursorPos(1,1) -- Ignore
  59.     load(load_room) -- Ignore
  60.     term.setCursorPos(px,py) -- Ignore
  61.     write("@") -- Ignore
  62.     a,i = os.pullEvent("key") -- Ignore
  63.     if i == 17 or i == 200 then
  64.         --if load_room[py * 51 - 51 + px] ~= 1 then
  65.             py = py - 1 -- MOVES PLAYER UP /\
  66.         --end
  67.        
  68.         if load_room[py * 51 - 51 + px] == 1 then -- CHECKS TO SEE IF CURRENTLY ON A 1 BLOCK BY USING THE AWSOME POINT TO ARRAY FORMULA I MADE! (playerx * screenx - screenx + playery)
  69.             py = py + 1 -- MOVES THE PLAYER DOWN \/
  70.         end
  71.     elseif i == 31 or i == 208 then
  72.         --if load_room[((py * 51 - 51)) + (px)] ~= 1 then
  73.             py = py + 1
  74.         --end
  75.        
  76.         if load_room[py * 51 - 51 + px] == 1 then -- CHECKS TO SEE IF CURRENTLY ON A 1 BLOCK BY USING THE AWSOME POINT TO ARRAY FORMULA I MADE! (playerx * screenx - screenx + playery)
  77.             py = py - 1
  78.         end
  79.     elseif i == 30 or i == 203 then
  80.         --if load_room[py * 51 - 51 + px] ~= 1 then
  81.             px = px - 1
  82.         --end
  83.        
  84.         if load_room[py * 51 - 51 + px] == 1 then -- CHECKS TO SEE IF CURRENTLY ON A 1 BLOCK BY USING THE AWSOME POINT TO ARRAY FORMULA I MADE! (playerx * screenx - screenx + playery)
  85.             px = px + 1
  86.         end
  87.     elseif i == 32 or i == 205 then
  88.         --if load_room[py * 51 - 51 + px] ~= 1 then
  89.             px = px + 1
  90.         --end
  91.        
  92.         if load_room[py * 51 - 51 + px] == 1 then -- CHECKS TO SEE IF CURRENTLY ON A 1 BLOCK BY USING THE AWSOME POINT TO ARRAY FORMULA I MADE! (playerx * screenx - screenx + playery)
  93.             px = px - 1
  94.         end
  95.     elseif i == 28 or i == 32 or i == 57 or i == 205 or i == 18 then -- CHECKS TO SEE IF PLAYER HIT A SELECTION KEY. I HAVE THIS AS THE EXIT KEYS FOR NOW
  96.         cls()
  97.         running = false
  98.     end
  99.    
  100.     if px > 50 or px < 2 then
  101.        
  102.         if px > 50 then
  103.             if load_room == room_1 then
  104.                 load(room_3)
  105.             else
  106.                 load(room_1)
  107.             end
  108.         else
  109.             if load_room == room_1 then
  110.                 load(room_5)
  111.             else
  112.                 load(room_1)
  113.             end
  114.         end
  115.        
  116.         if px > 50 then
  117.             px = px - 49
  118.         else
  119.             px = px + 49
  120.         end
  121.     elseif py > 18 or py < 2 then
  122.        
  123.         if py > 18 then
  124.             if load_room == room_1 then
  125.                 load(room_4)
  126.             else
  127.                 load(room_1)
  128.             end
  129.         else
  130.             if load_room == room_1 then
  131.                 load(room_2)
  132.             else
  133.                 load(room_1)
  134.             end
  135.         end
  136.        
  137.         if py > 18 then
  138.             py = py - 17
  139.         else
  140.             py = py + 17
  141.         end
  142.     end
  143. end
  144.  
  145. print("Thanks for using 2d Engine!")
Advertisement
Add Comment
Please, Sign In to add comment