Author Topic: World Explorer BETA  (Read 3224 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
World Explorer BETA
« on: November 28, 2021, 02:03:25 pm »
The counter part of the World Builder program. A quick Demo of how the maps created with the World Builder program are used.

The Explore-able area is limited to roughly 16x16 for this quick demo. Still some slight hiccups with the layering effect.

Arrow Keys move the player
Space bar interacts with a few areas on screen.

I hope to include the addition of Interactive areas on the screen to be create-able within the World Builder program itself. but as for now they are hard coded in the World Explorer program and will show up even in other maps at the moment.

Sample Map included, but you can make one with the latest World Builder program, to try your own map you must simply change line 49 to the name of your map.

Code: QB64: [Select]
  1. TYPE World_Tiles
  2.  Id AS INTEGER 'ground
  3.  Deco AS INTEGER 'decorations(trees\bushes\ect)
  4.  Lay3 AS INTEGER 'a third layer of map tiles
  5.  Walkable AS _BYTE 'can player walk on this tile?
  6.  
  7. TYPE Player_Data
  8.  World_X AS _UNSIGNED INTEGER 'world size is 0-65535 tiles^2 (4,294,967,295 tiles total)
  9.  World_Y AS _UNSIGNED INTEGER
  10.  Local_X AS INTEGER
  11.  Local_Y AS INTEGER
  12.  Direction AS _BYTE
  13.  Frame AS _BYTE
  14.  
  15. SCREEN _NEWIMAGE(840, 640, 32)
  16. _TITLE "World Explorer V1.0"
  17.  
  18. CONST Key_Right = 19712, Key_Left = 19200, Key_Up = 18432, Key_Down = 20480
  19. CONST Key_Space = 32, Key_Enter = 13
  20. CONST Down = 0, Left = 1, Right = 2, Up = 3, InterAct = 4
  21. CONST TRUE = -1, FALSE = NOT TRUE
  22.  
  23. DIM SHARED Layer(16) AS LONG, World(255, 255) AS World_Tiles
  24. DIM SHARED P AS Player_Data, Yo%%
  25.  
  26. Layer(0) = _DISPLAY
  27. Layer(1) = _NEWIMAGE(840, 640, 32) 'composite layer
  28. 'Layer(2) = _LOADIMAGE("linear_tiles.bmp", 32) 'world tiles
  29. Layer(3) = _NEWIMAGE(840, 640, 32)
  30. 'Layer(4) = _LOADIMAGE("Character3.bmp", 32) 'world tiles
  31. Layer(5) = _NEWIMAGE(840, 640, 32)
  32.  
  33. MFI_Loader "WorldExplorer.MFI"
  34.  
  35. _CLEARCOLOR _RGB32(0), Layer(2)
  36. _CLEARCOLOR _RGB32(0), Layer(3)
  37. _CLEARCOLOR _RGB32(0), Layer(5)
  38. _CLEARCOLOR _RGB32(43, 133, 133), Layer(4)
  39. P.World_X = 0
  40. P.World_Y = 0
  41. P.Local_X = 32
  42. P.Local_Y = 32
  43.  
  44. Load_it "take2"
  45.  
  46. Draw_World_Area
  47.  
  48.  
  49.  SELECT CASE Get_Input
  50.   CASE Down
  51.    Moving%% = TRUE
  52.    P.Direction = Down
  53.    IF P.Local_Y < 600 THEN P.Local_Y = P.Local_Y + 1
  54.    IF Collision_World THEN P.Local_Y = P.Local_Y - 1
  55.   CASE Left
  56.    Moving%% = TRUE
  57.    P.Direction = Left
  58.    IF P.Local_X > 2 THEN P.Local_X = P.Local_X - 1
  59.    IF Collision_World THEN P.Local_X = P.Local_X + 1
  60.   CASE Right
  61.    Moving%% = TRUE
  62.    P.Direction = Right
  63.    IF P.Local_X < 600 THEN P.Local_X = P.Local_X + 1
  64.    IF Collision_World THEN P.Local_X = P.Local_X - 1
  65.   CASE Up
  66.    Moving%% = TRUE
  67.    P.Direction = Up
  68.    IF P.Local_Y > 2 THEN P.Local_Y = P.Local_Y - 1
  69.    IF Collision_World THEN P.Local_Y = P.Local_Y + 1
  70.   CASE InterAct
  71.    _DELAY .1
  72.    InterActions
  73.    P.Frame = 0
  74.    Moving%% = FALSE
  75.  IF Moving%% THEN Animate_Character
  76.  
  77.  _PUTIMAGE , Layer(3), Layer(1)
  78.  Draw_Character 0, 0, P.Frame
  79.  _PUTIMAGE , Layer(5), Layer(1)
  80.  _PUTIMAGE , Layer(1), Layer(0)
  81.  ClearLayer Layer(1)
  82.  _LIMIT 60
  83.  IF INKEY$ = CHR$(27) THEN ExitFlag%% = -1
  84. LOOP UNTIL ExitFlag%%
  85.  
  86. SUB Animate_Character
  87.  STATIC Frame%%
  88.  Frame%% = Frame%% + 1
  89.  IF Frame%% = 15 THEN P.Frame = P.Frame + 1: Frame%% = 0
  90.  IF P.Frame = 4 THEN P.Frame = 0
  91.  
  92. SUB Draw_World_Area
  93.  FOR Y%% = 0 TO 19
  94.   FOR X%% = 0 TO 19
  95.    Draw_Sprite X%%, Y%%, World(P.World_X + X%%, P.World_Y + Y%%).Id
  96.    IF World(P.World_X + X%%, P.World_Y + Y%%).Deco THEN
  97.     Draw_Deco_Sprite X%%, Y%%, World(P.World_X + X%%, P.World_Y + Y%%).Deco, Layer(3)
  98.    END IF
  99.    IF World(P.World_X + X%%, P.World_Y + Y%%).Lay3 THEN
  100.     Draw_Deco_Sprite X%%, Y%%, World(P.World_X + X%%, P.World_Y + Y%%).Lay3, Layer(5)
  101.    END IF
  102.   NEXT X%%
  103.  NEXT Y%%
  104.  
  105. SUB Draw_Sprite (X%%, Y%%, id%)
  106.  _PUTIMAGE (X%% * 32, Y%% * 32), Layer(2), Layer(3), (0 + id% * 32, 0)-STEP(31, 31)
  107.  
  108. SUB Draw_Deco_Sprite (x%%, y%%, id%, L&)
  109.  _PUTIMAGE (x%% * 32, y%% * 32), Layer(2), L&, (0 + id% * 32, 0)-STEP(31, 31)
  110.  
  111. SUB Load_it (File$)
  112.  F = FREEFILE
  113.  IF File$ = "" THEN File$ = "Defualt"
  114.  File$ = LTRIM$(RTRIM$(File$)) 'no spaces allowed
  115.   IF _FILEEXISTS(File$+".MAP") = FALSE THEN PRINT File$ + ".MAP is missing.": END
  116.  OPEN File$ + ".MAP" FOR BINARY AS #F 'Save
  117.  GET #F, , World()
  118.  CLOSE #F
  119.  
  120. SUB Draw_Character (x%%, y%%, id%)
  121.  _PUTIMAGE (P.Local_X + x%% * 32, P.Local_Y + y%% * 32), Layer(4), Layer(1), (0 + id% * 32, 0 + 48 * P.Direction)-STEP(30, 47)
  122.  
  123. FUNCTION Get_Input%% ()
  124.  Result%% = TRUE '-1 for no input
  125.  ' IF _KEYDOWN(ESC_Key) THEN Result%% = ESC
  126.  IF _KEYDOWN(Key_Up) THEN Result%% = Up
  127.  IF _KEYDOWN(Key_Down) THEN Result%% = Down
  128.  IF _KEYDOWN(Key_Left) THEN Result%% = Left
  129.  IF _KEYDOWN(Key_Right) THEN Result%% = Right
  130.  IF _KEYDOWN(Key_Space) THEN Result%% = InterAct
  131.  Get_Input%% = Result%%
  132.  
  133. SUB ClearLayer (L&)
  134.  _DEST L&
  135.  CLS
  136.  
  137. SUB ClearLayerTrans (L&)
  138.  _DEST L&
  139.  CLS , 0
  140.  
  141. FUNCTION Collision_World%%
  142.  Result%% = TRUE
  143.  SELECT CASE P.Direction 'adjust collision detection point based on direction of travel
  144.   CASE Down
  145.    Yo%% = 1
  146.   CASE Up
  147.    Yo%% = 1
  148.   CASE Left
  149.    Yo%% = 1
  150.   CASE Right
  151.    Yo%% = 1
  152.  IF World(Tile(P.Local_X + 16), Tile(P.Local_Y + 0) + Yo%%).Walkable THEN Result%% = FALSE
  153.  
  154.  _PUTIMAGE (650, 100)-STEP(63, 16), Layer(1), Layer(3), (700, 500)-STEP(32, 16)
  155.  _PRINTSTRING (650, 100), STR$(Tile(P.Local_X + 16)) + STR$(Tile(P.Local_Y) + Yo%%), Layer(3)
  156.  Collision_World = Result%%
  157.  
  158. FUNCTION Tile% (value%)
  159.  Result% = value% \ 32
  160.  Tile = Result%
  161.  
  162. SUB InterActions
  163.  SELECT CASE P.Direction
  164.   CASE Up
  165.    IF Tile(P.Local_X + 16) = 1 AND Tile(P.Local_Y) - 1 + Yo%% = 6 THEN 'sign post
  166.     tmp& = _COPYIMAGE(Layer(0))
  167.     _KEYCLEAR
  168.     _DEST Layer(1)
  169.     DO
  170.      _PUTIMAGE , tmp&, Layer(1)
  171.      LINE (P.Local_X + 32, P.Local_Y + 16)-STEP(191, 40), _RGBA32(112, 32, 192, 144), BF
  172.      _PRINTSTRING (P.Local_X + 42, P.Local_Y + 26), "This is a sign post.", Layer(1)
  173.      _PUTIMAGE , Layer(1), Layer(0)
  174.      _LIMIT 60
  175.      IF Get_Input <> TRUE THEN ExitFlag%% = TRUE
  176.     LOOP UNTIL ExitFlag%%
  177.     _KEYCLEAR
  178.     _FREEIMAGE tmp&
  179.     _DEST Layer(0)
  180.    END IF
  181.  
  182.    IF Tile(P.Local_X + 16) = 1 AND Tile(P.Local_Y) - 1 + Yo%% = 13 THEN 'Grave Stone
  183.     tmp& = _COPYIMAGE(Layer(0))
  184.     _KEYCLEAR
  185.     _DEST Layer(1)
  186.     DO
  187.      _PUTIMAGE , tmp&, Layer(1)
  188.      LINE (P.Local_X + 32, P.Local_Y + 16)-STEP(191, 48), _RGBA32(112, 32, 192, 144), BF
  189.      _PRINTSTRING (P.Local_X + 42, P.Local_Y + 26), "Here lies: Cobalt", Layer(1)
  190.      _PRINTSTRING (P.Local_X + 42, P.Local_Y + 42), "33AE - 121AE", Layer(1)
  191.      _PUTIMAGE , Layer(1), Layer(0)
  192.      _LIMIT 60
  193.      IF Get_Input <> TRUE THEN ExitFlag%% = TRUE
  194.     LOOP UNTIL ExitFlag%%
  195.     _KEYCLEAR
  196.     _FREEIMAGE tmp&
  197.     _DEST Layer(0)
  198.    END IF
  199.  
  200.    IF Tile(P.Local_X + 16) = 7 AND Tile(P.Local_Y) - 1 + Yo%% = 11 THEN 'Front door
  201.     tmp& = _COPYIMAGE(Layer(0))
  202.     _KEYCLEAR
  203.     _DEST Layer(1)
  204.     DO
  205.      _PUTIMAGE , tmp&, Layer(1)
  206.      LINE (P.Local_X + 32, P.Local_Y + 16)-STEP(191, 48), _RGBA32(112, 32, 192, 144), BF
  207.      _PRINTSTRING (P.Local_X + 42, P.Local_Y + 26), "'Knock Knock...'", Layer(1)
  208.      _PRINTSTRING (P.Local_X + 42, P.Local_Y + 42), "There is no answer.", Layer(1)
  209.      _PUTIMAGE , Layer(1), Layer(0)
  210.      _LIMIT 60
  211.      IF Get_Input <> TRUE THEN ExitFlag%% = TRUE
  212.     LOOP UNTIL ExitFlag%%
  213.     _KEYCLEAR
  214.     _FREEIMAGE tmp&
  215.     _DEST Layer(0)
  216.    END IF
  217.  
  218.    IF Tile(P.Local_X + 16) = 6 AND Tile(P.Local_Y) - 1 + Yo%% = 4 THEN 'Well
  219.     tmp& = _COPYIMAGE(Layer(0))
  220.     _KEYCLEAR
  221.     _DEST Layer(1)
  222.     DO
  223.      _PUTIMAGE , tmp&, Layer(1)
  224.      LINE (P.Local_X + 32, P.Local_Y + 16)-STEP(191, 48), _RGBA32(112, 32, 192, 144), BF
  225.      _PRINTSTRING (P.Local_X + 42, P.Local_Y + 26), "It is a well.", Layer(1)
  226.      _PRINTSTRING (P.Local_X + 42, P.Local_Y + 42), "Wow it is deep!", Layer(1)
  227.      _PUTIMAGE , Layer(1), Layer(0)
  228.      _LIMIT 60
  229.      IF Get_Input <> TRUE THEN ExitFlag%% = TRUE
  230.     LOOP UNTIL ExitFlag%%
  231.     _KEYCLEAR
  232.     _FREEIMAGE tmp&
  233.     _DEST Layer(0)
  234.    END IF
  235.  
  236.  
  237. SUB MFI_Loader (FN$)
  238.  DIM Size(128) AS LONG, FOffset(128) AS LONG
  239.   IF _FILEEXISTS(FN$) = FALSE THEN PRINT FN$ + " is missing. This file needs downloaded": END
  240.  GET #1, , c~%% 'retrieve number of files
  241.  FOR I~%% = 1 TO c~%%
  242.   GET #1, , FOffset(I~%%)
  243.   GET #1, , Size(I~%%)
  244.   FOffset&(I~%%) = FOffset&(I~%%) + 1
  245.  NEXT I~%%
  246.  
  247.  Layer(2) = LoadGFX(FOffset(1), Size(1)) 'tiles
  248.  Layer(4) = LoadGFX(FOffset(2), Size(2)) 'characters
  249.  
  250.  CLOSE #1
  251.  IF _FILEEXISTS("temp.dat") THEN KILL "temp.dat"
  252.  
  253. FUNCTION LoadGFX& (Foff&, Size&)
  254.  IF _FILEEXISTS("temp.dat") THEN KILL "temp.dat"
  255.  OPEN "temp.dat" FOR BINARY AS #3
  256.  dat$ = SPACE$(Size&)
  257.  GET #1, Foff&, dat$
  258.  PUT #3, , dat$
  259.  CLOSE #3
  260.  LoadGFX& = _LOADIMAGE("temp.dat", 32)
  261.  

* Take2.MAP (Filesize: 448 KB, Downloads: 222)
* WorldExplorer.MFI (Filesize: 486.07 KB, Downloads: 218)
Granted after becoming radioactive I only have a half-life!