Author Topic: Archery!  (Read 6720 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
Archery!
« on: August 16, 2019, 05:41:14 pm »
Blast from the past! Archery is a remake of the game from 1985! Nearing completion, a preview\beta release.
Totally self contained, needing no extra files!(which is uncommon for me)

Do some practice shooting by yourself, play with a friend, or go head to head with the computer!

Code: QB64: [Select]
  1. 'Archery 1985 by Brain Blankenship
  2. '2019 Archery By Cobalt
  3. '8/13/2019|
  4. 'V0.4
  5. '-Sprites\Title\Options screens done
  6. 'V0.6
  7. '-Scoreboard done
  8. '-target movement done
  9. '-arrow movement done
  10. 'V0.7
  11. '-collision detection
  12. '8/14/2019
  13. 'V0.8
  14. 'player 2 frames
  15. 'Random site creation
  16. '8/15/2019
  17. 'v0.9
  18. 'Computer AI for player 2
  19. 'Computer vs computer possible
  20. '8/16/2019
  21. 'V1.0b
  22. 'Highscore file\list added
  23. 'Bug-Computer goes first in 1 player game fixed(Thanks Bplus!)
  24. 'Computer only play option added
  25. 'V1.0c
  26. 'Bug-Player 2 goes first in 2 player game fixed(Thanks TempodiBasic)
  27. 'Error- corrected ORIGNALLY to ORIGINALLY in title screen(Thanks TempodiBasic)
  28.  
  29. TYPE Position
  30.  Speed AS _BYTE
  31.  OrigX AS INTEGER
  32.  OrigY AS INTEGER
  33.  
  34. SCREEN _NEWIMAGE(640, 400, 32)
  35. _DELAY .125
  36. _TITLE "Archery 1985   v1.0c"
  37.  
  38. '-------------CONSTANTS----------------
  39. CONST TRUE = -1, FALSE = NOT TRUE
  40. CONST Black = &HFF000101~&, Cyan = &HFF01A0A0~&, Magenta = &HFF941090~&, OffWhite = &HFFC7C0C0~&, Green = &HFF1B9010~&, CtrWhite = &HFFCAC0C0~&
  41. '--------------------------------------
  42. '-------ARRAYS & SHARED VARIABLES------
  43. DIM SHARED Layer(10) AS LONG, Shots(1, 5, 2) AS _BYTE, HitSound$, QuitGame%%, ComputerOnly%%
  44. DIM SHARED Computer.Class, Player$(2), Flag AS _BYTE, Turn%%, Noise%%, Winner%%
  45. DIM SHARED Arrow AS Position, Target AS Position
  46. '--------------------------------------
  47. '---------------LAYERS-----------------
  48. Layer(0) = _DISPLAY
  49. Layer(1) = _NEWIMAGE(640, 400, 32) 'mix layer
  50. Layer(2) = _NEWIMAGE(320, 200, 32) 'Title Screen Layer
  51. Layer(3) = _NEWIMAGE(320, 200, 32) 'Sprite sheet layer
  52. Layer(4) = _NEWIMAGE(320, 200, 32) 'Collision layer
  53. Layer(5) = _NEWIMAGE(320, 200, 32) 'Extra/Scoreboard layer
  54. Layer(6) = _NEWIMAGE(320, 200, 32) 'Input layer/Prebuild layer
  55. Layer(7) = _NEWIMAGE(320, 200, 32) 'high score layer
  56. '--------------------------------------
  57. '-----------ARROW HIT SOUND------------
  58. PLAY "t230l64" 'setup sound play rate
  59. HitSound$ = "o1bagfedc"
  60. '--------------------------------------
  61. Draw_Sprites
  62. Draw_Title_Screen
  63. Title_Animation
  64. '-------Inital Values------------------
  65. Target.Speed = 1
  66. Target.Y = 0: Target.OrigY = 0
  67. Target.X = 309: Target.OrigX = 309
  68. Arrow.Speed = 0
  69. Arrow.OrigY = 135: Arrow.Y = Arrow.OrigY
  70. Arrow.OrigX = 69: Arrow.X = Arrow.OrigX
  71. ExitFlag%% = FALSE
  72. Turn%% = TRUE
  73. Computer.Class = 3 'skill level of computer(experimental)
  74. Noise%% = Computer_AI 'adds little randomness to computer shots
  75. '-------------MAIN LOOP----------------
  76.  ClearLayer Layer(5)
  77.  Game_Option_Screen
  78.  Scoreboard_Setup
  79.  MainGame
  80.  IF Calc_Score(0) >= Calc_Score(1) THEN Winner%% = 0 ELSE Winner%% = 1
  81.  HighScore_Screen
  82.  IF QuitGame%% THEN ExitFlag%% = TRUE
  83. LOOP UNTIL ExitFlag%%
  84. _DEST Layer(0)
  85. PRINT "Thank you for playing Archery 2019!"
  86. PRINT "leave any comments, suggestions, or bugs at:"
  87. PRINT "www.QB64.org/Forum/index.php?topic=1627.0"
  88. '--------------------------------------
  89.  
  90. FUNCTION Calc_Score~%% (Who%%)
  91.  Result~%% = 0
  92.  FOR F%% = 0 TO 4
  93.   FOR S%% = 0 TO 2
  94.    Result~%% = Result~%% + Shots(Who%%, F%%, S%%)
  95.   NEXT S%%
  96.  NEXT F%%
  97.  Calc_Score = Result~%%
  98.  
  99. SUB ClearLayer (L&)
  100.  _DEST L&
  101.  CLS
  102.  
  103. FUNCTION Collision_Check~%% (X%, Y%)
  104.  IF _SOURCE <> Layer(4) THEN _SOURCE Layer(4)
  105.  Result~%% = 0
  106.  FOR I%% = 0 TO 1
  107.   Test~& = POINT(25 + X% + I%%, Y% + 3)
  108.   R~%% = _RED32(Test~&)
  109.   IF R~%% = 255 THEN R~%% = 1
  110.   IF R~%% > 0 THEN Result~%% = R~%%: I%% = 5
  111.  NEXT I%%
  112.  Collision_Check = Result~%%
  113.  
  114. FUNCTION Computer_AI%% ()
  115.  Result%% = 0
  116.  SELECT CASE Computer.Class
  117.   CASE 1 'basic
  118.    Result%% = INT(RND * 28) - 10
  119.   CASE 2 'decent
  120.    Result%% = INT(RND * 24) - 8
  121.   CASE 3 'good
  122.    Result%% = INT(RND * 20) - 6
  123.   CASE 4 'hard
  124.    Result%% = INT(RND * 16) - 4
  125.   CASE 5 'Robin Hood unbeatable 150!
  126.    IF Arrow.OrigX MOD 2 THEN Result%% = 5 ELSE Result%% = 6
  127.  Computer_AI%% = Result%%
  128.  
  129. SUB Display_Scoreboard
  130.  _PUTIMAGE , Layer(5), Layer(6)
  131.  _DEST Layer(6)
  132.  _FONT 8
  133.  COLOR OffWhite
  134.  FOR P%% = 0 TO 1
  135.   FOR Flight%% = 0 TO 4
  136.    FOR Shot%% = 0 TO 2
  137.     LOCATE 4 + Shot%% + (P%% * 4), 12 + Flight%% * 4
  138.     PRINT Shots(P%%, Flight%%, Shot%%)
  139.    NEXT Shot%%
  140.   NEXT Flight%%
  141.  NEXT P%%
  142.  LOCATE 4, 32: PRINT Calc_Score(0)
  143.  LOCATE 8, 32: PRINT Calc_Score(1)
  144.  
  145.  _FONT 16
  146.  _DEST Layer(0)
  147.  
  148. SUB Draw_Sprites
  149.  ClearLayer Layer(3)
  150.  _DEST Layer(1)
  151.  'Original target draw /w color fix
  152.  DRAW "bm318,140c" + STR$(Cyan) + "d30l1u30l1d30u6l1c" + STR$(Magenta) + "u18l1d18l1u18d6l1c" + STR$(OffWhite) + "d6l1u6"
  153.  'original arrow draw /w color fix
  154.  DRAW "bm10,155c" + STR$(Cyan) + "r20l20c" + STR$(Magenta) + "h3f3g3e3c" + STR$(OffWhite) + "bm+2,+0h3f3g3e3c" + STR$(Magenta) + "bm+2,+0h3f3g3e3bm+15,-2c" + STR$(OffWhite) + "d4u1r1u2d1r1"
  155.  LINE (311, 155)-STEP(1, 0), CtrWhite
  156.  _DEST Layer(0)
  157.  _PUTIMAGE (0, 0), Layer(1), Layer(3), (310, 140)-STEP(8, 30) 'move target to sprite sheet
  158.  _PUTIMAGE (0, 32), Layer(1), Layer(3), (7, 152)-STEP(24, 6) 'move arrow to sprite sheet
  159.  _CLEARCOLOR _RGB32(0, 0, 0), Layer(3)
  160.  ClearLayer Layer(1)
  161.  
  162. SUB Draw_Title_Screen
  163.  _DEST Layer(1)
  164.  _FONT 8
  165.  COLOR OffWhite
  166.  PSET (0, 0), OffWhite
  167.  DRAW "bm41,70e30r10d30l8u12l8g12l11bm+34,-24d6l7e7bm+11,-5d30r8u15m+15,+15r10h18u12l14bm+4,+5d5r4u5l4"
  168.  DRAW "BM+20,-5r30d12l8u4l17f15r3u5r7d12l15h20u10r4bm+37,-0r8d10r8u10r8d30l8u10l8d10l8u30bm+30,-0r20d6l15d8r8d5l8d6r15d5l20u30"
  169.  DRAW "bm+26,-0d30r8u15m+15,+15r10h18u12l14bm+4,+5d5r4u5l4bm+17,-5d10f16d4r8u30l8d17h7u10l8"
  170.  DATA 46,90,129,150,180,206,243
  171.  FOR i%% = 1 TO 7
  172.   READ t%
  173.   PAINT (t%, 68), Magenta, OffWhite
  174.  NEXT i%%
  175.  LOCATE 17, 11: PRINT "Originally by:"
  176.  LOCATE 20, 16: PRINT "Brain Blankenship"
  177.  _FONT 16
  178.  _DEST Layer(0)
  179.  _PUTIMAGE (1, 0), Layer(1), Layer(2), (1, 0)-(319, 199)
  180.  _PUTIMAGE (310, 140), Layer(3), Layer(2), (0, 0)-STEP(7, 30) 'target
  181.  _CLEARCOLOR _RGB32(0, 0, 0), Layer(2)
  182.  ClearLayer Layer(1)
  183.  
  184. SUB Game_Option_Screen
  185.  _DEST Layer(5)
  186.  _FONT 8
  187.  COLOR OffWhite
  188.  PRINT "Instructions": PRINT
  189.  PRINT " Score as many  points as  possible by"
  190.  PRINT "  hitting  the   target  close  to  the"
  191.  PRINT "  center. Press the space bar to shoot."
  192.  PRINT "  You get three trys from each of  five"
  193.  PRINT "  sites, highest score wins. 3 to watch"
  194.  PRINT "  the computer battle it out."
  195.  PushScreen 5
  196.  _DELAY 3
  197.  PRINT "Number of Players(1/2[3])?"
  198.  PushScreen 5
  199.  DO: kbd$ = INKEY$: LOOP UNTIL kbd$ = "1" OR kbd$ = "2" OR kbd$ = "3"
  200.  IF kbd$ <> "3" THEN
  201.   Flag = Flag + 2 ^ (VAL(kbd$) - 1) 'set bit 0 if 1 player, bit 1 for 2 player
  202.   PRINT: PRINT "Enter player one's name :?"
  203.   Turn%% = TRUE
  204.   PushScreen 5
  205.   Player$(0) = Get_Player_Name(0)
  206.   _PRINTSTRING (212, 112), Player$(0)
  207.  
  208.   IF Flag AND 2 THEN
  209.    PRINT: PRINT "Enter player two's name :?"
  210.    PushScreen 5
  211.    Player$(1) = Get_Player_Name(1)
  212.    _PRINTSTRING (212, 128), Player$(1)
  213.   ELSE
  214.    PRINT: PRINT "           Play Computer ?"
  215.    PushScreen 5
  216.    DO: kbd$ = LCASE$(INKEY$): LOOP UNTIL kbd$ = "y" OR kbd$ = "n"
  217.    IF kbd$ = "y" THEN Flag = 4: Player$(1) = "Computer"
  218.   END IF
  219.   Player$(0) = "Computr1"
  220.   Player$(1) = "Computr2"
  221.   ComputerOnly%% = TRUE: Turn%% = FALSE 'watch the computer play itself!
  222.   Flag = 4 'set player 2 to computer(needed for computer only play)
  223.  _FONT 16
  224.  _DEST Layer(0)
  225.  ClearLayer Layer(1)
  226.  
  227. FUNCTION Get_Player_Name$ (Who%%)
  228.  DO
  229.   kbd$ = INKEY$
  230.   IF LEN(Result$) < 8 AND kbd$ >= CHR$(32) THEN Result$ = Result$ + kbd$
  231.   IF kbd$ = CHR$(8) THEN Result$ = LEFT$(Result$, LEN(Result$) - 1)
  232.   IF Who%% THEN _PRINTSTRING (212, 120), Result$ ELSE _PRINTSTRING (212, 104), Result$
  233.   PushScreen 5
  234.   _DELAY .025
  235.   IF Who%% THEN LINE (212, 128)-STEP(72, 8), Black, BF ELSE LINE (212, 112)-STEP(72, 8), Black, BF
  236.  LOOP UNTIL kbd$ = CHR$(13)
  237.  Get_Player_Name = Result$
  238.  
  239. SUB HighScore_Screen
  240.  _DEST Layer(7): CLS: _FONT 8
  241.  COLOR OffWhite
  242.  DIM C(5) AS _UNSIGNED LONG, Score.Name(11) AS STRING * 8, Score.Val(11) AS _UNSIGNED _BYTE
  243.  C(1) = Magenta: C(2) = Magenta: C(3) = Magenta: C(4) = OffWhite: C(5) = Cyan
  244.  CI%% = 1
  245.  '-----load previous scores(if any)------
  246.  IF _FILEEXISTS("Archery.dat") THEN
  247.   OPEN "Archery.dat" FOR INPUT AS #1
  248.   INPUT #1, Count%% 'how many scores recored
  249.   FOR i%% = 1 TO Count%%
  250.    INPUT #1, Score.Name(i%%)
  251.    INPUT #1, Score.Val(i%%)
  252.   NEXT i%%
  253.   CLOSE #1
  254.   OPEN "Archery.dat" FOR OUTPUT AS #1
  255.   OPEN "Archery.dat" FOR OUTPUT AS #1
  256.   Count%% = 0
  257.  '-----------------------------------------
  258.  '-------tack new score on bottom-------
  259.  Count%% = Count%% + 1
  260.  Score.Name(Count%%) = Player$(Winner%%)
  261.  Score.Val(Count%%) = Calc_Score(Winner%%)
  262.  '--------------------------------------
  263.  '------------Ultra basic sort----------
  264.  IF Count%% > 1 THEN
  265.   FOR i%% = 1 TO Count%%
  266.    FOR j%% = i%% TO Count%%
  267.     IF Score.Val(j%%) > Score.Val(i%%) THEN SWAP Score.Val(j%%), Score.Val(i%%): SWAP Score.Name(j%%), Score.Name(i%%)
  268.    NEXT j%%
  269.   NEXT i%%
  270.  '---------------------------------------
  271.  '--------------save scores--------------
  272.  IF Count%% = 11 THEN Count%% = 10 'drop lowest score
  273.  PRINT #1, Count%%
  274.  FOR i%% = 1 TO Count%%
  275.   PRINT #1, Score.Name(i%%)
  276.   PRINT #1, Score.Val(i%%)
  277.  NEXT i%%
  278.  '---------------------------------------
  279.  i%% = 0
  280.  DO
  281.   KBD$ = INKEY$
  282.   IF KBD$ = CHR$(27) THEN ExitFlag%% = TRUE: QuitGame%% = TRUE
  283.   IF UCASE$(KBD$) = "Y" THEN ExitFlag%% = TRUE
  284.   IF UCASE$(KBD$) = "N" THEN ExitFlag%% = TRUE: QuitGame%% = TRUE
  285.   'erase highscore list
  286.   IF UCASE$(KBD$) = "S" AND _FILEEXISTS("Archery.dat") THEN KILL "Archery.dat"
  287.   '---------box area----------
  288.   LINE (9 + i%%, 9 + i%%)-STEP(263 - i%% * 2, 138 - i%% * 2), C(CI%%), B
  289.   '---------------------------
  290.   i%% = i%% + 1
  291.   IF i%% = 9 THEN i%% = 0
  292.   CI%% = CI%% + 1
  293.   IF CI%% = 6 THEN CI%% = 1
  294.   FOR j%% = 1 TO Count%%
  295.    LOCATE 4 + j%%, 10: PRINT Score.Name(j%%); TAB(23 + 3 - LEN(LTRIM$(RTRIM$(STR$(Score.Val(j%%)))))); Score.Val(j%%)
  296.   NEXT j%%
  297.   LOCATE 22, 14: PRINT "Play Again?"
  298.   _PUTIMAGE , Layer(7), Layer(1), (0, 0)-STEP(319, 199)
  299.   _PUTIMAGE , Layer(1), Layer(0)
  300.   _DELAY .005
  301.  LOOP UNTIL ExitFlag%%
  302.  Reset_Game
  303.  _FONT 16
  304.  _DEST Layer(0)
  305.  
  306. SUB Move_Target
  307.  Target.Y = Target.Y + Target.Speed
  308.  _PUTIMAGE (Target.X, Target.Y), Layer(3), Layer(6), (0, 0)-STEP(8, 30) 'target
  309.  'collision layer
  310.  ClearLayer Layer(4)
  311.  _PUTIMAGE (Target.X, Target.Y), Layer(3), Layer(4), (0, 0)-STEP(8, 30) 'target
  312.  _PUTIMAGE (318, 0)-STEP(1, 199), Layer(5), Layer(4), (319, 0)-(319, 199) 'target
  313.  
  314. SUB Move_Arrow
  315.  Arrow.X = Arrow.X + Arrow.Speed
  316.  _PUTIMAGE (Arrow.X, Arrow.Y), Layer(3), Layer(6), (0, 32)-STEP(24, 6) 'arrow
  317.  
  318. SUB PushScreen (id%%)
  319.  _PUTIMAGE (0, 0)-STEP(639, 399), Layer(id%%), Layer(1), (0, 0)-STEP(319, 199)
  320.  _PUTIMAGE , Layer(1), Layer(0)
  321.  
  322. SUB New_Site
  323.  Arrow.OrigX = INT(RND * 240) + 10
  324.  Arrow.OrigY = INT(RND * 50) + 120
  325.  
  326. SUB Reset_Game
  327.  Reset_Shot 99, 99, 0 'reset frame and flight
  328.  FOR x%% = 0 TO 1 'reset score
  329.   FOR y%% = 0 TO 4
  330.    FOR z%% = 0 TO 2
  331.     Shots(x%%, y%%, z%%) = 0
  332.  NEXT z%%, y%%, x%%
  333.  
  334. SUB Reset_Shot (Shot%%, Shoot%%, Hit~%%)
  335.  STATIC Flight%%, Frame%%, Player%%
  336.  '-------assign score-------
  337.  Shots(Player%%, Frame%%, Flight%%) = Hit~%% MOD 16
  338.  '--------------------------
  339.  '-----increment flight-----
  340.  Flight%% = Flight%% + 1
  341.  IF Flight%% = 3 THEN '3 flights per frame
  342.   IF Flag AND 1 THEN
  343.    Frame%% = Frame%% + 1: Flight%% = 0: New_Site
  344.   END IF
  345.   IF Flag AND 2 OR Flag AND 4 THEN 'is there a second player or computer?
  346.    IF Player%% THEN 'player 2 just loosed, next frame for player 1
  347.     Player%% = 0: Frame%% = Frame%% + 1: Flight%% = 0: New_Site
  348.     IF NOT ComputerOnly%% THEN Turn%% = TRUE
  349.    ELSE 'let player 2 loose his first frame
  350.     IF Flag AND 4 THEN Turn%% = FALSE
  351.     Player%% = 1: Flight%% = 0
  352.    END IF
  353.   END IF
  354.  '--------------------------
  355.  Target.Y = Target.OrigY
  356.  Target.Speed = 1
  357.  Arrow.Y = Arrow.OrigY
  358.  Arrow.X = Arrow.OrigX
  359.  IF Shot%% = 99 AND Shoot%% = 99 THEN Flight%% = 0: Frame%% = 0
  360.  Shot%% = FALSE
  361.  Shoot%% = FALSE
  362.  IF Frame%% = 5 THEN Hit~%% = 99 ELSE Hit~%% = 0 'end game trigger
  363.  Noise%% = Computer_AI 'adds little randomness to computer shots
  364.  
  365. SUB Scoreboard_Setup
  366.  ClearLayer Layer(5)
  367.  _DEST Layer(5)
  368.  _FONT 8
  369.  COLOR OffWhite
  370.  LINE (1, 1)-STEP(300, 84), Cyan, B
  371.  LINE (2, 2)-STEP(298, 82), Magenta, B
  372.  LINE (3, 3)-STEP(296, 80), OffWhite, B
  373.  LINE (4, 4)-STEP(294, 78), Black, BF
  374.  LOCATE 2, 2: PRINT "Player    #1  #2  #3  #4  #5  Total"
  375.  LOCATE 4, 3: PRINT Player$(0)
  376.  LOCATE 8, 3: PRINT Player$(1)
  377.  LINE (319, 0)-(319, 199), Green, BF
  378.  _FONT 16
  379.  _DEST Layer(0)
  380.  
  381. SUB Title_Animation
  382.  _DEST Layer(5)
  383.  COLOR OffWhite
  384.  _DEST Layer(0)
  385.  _PRINTSTRING (4, 0), "UniKorn", Layer(5)
  386.  _PRINTSTRING (36, 16), "ProDucKions", Layer(5)
  387.  _PUTIMAGE (0, 0)-STEP(639, 400), Layer(5), Layer(1), (0, 0)-STEP(125, 39)
  388.  _PUTIMAGE (0, 0)-STEP(639, 399), Layer(1), Layer(0)
  389.  _PRINTSTRING (290, 350), "Presents", Layer(0)
  390.  _DELAY 2.5
  391.  ClearLayer Layer(5)
  392.  CLS
  393.  _PUTIMAGE (7 + i%, 152), Layer(3), Layer(5), (0, 32)-STEP(24, 6) 'arrow
  394.  _PUTIMAGE , Layer(2), Layer(5)
  395.  _PUTIMAGE (0, 0)-STEP(639, 399), Layer(5), Layer(1)
  396.  _PUTIMAGE , Layer(1), Layer(0)
  397.  _DELAY 1.5
  398.  FOR i% = 0 TO 279 STEP 2
  399.   _DELAY .02
  400.   _PUTIMAGE (8 + i%, 152), Layer(3), Layer(5), (0, 32)-STEP(24, 6) 'arrow
  401.   _PUTIMAGE , Layer(2), Layer(5) 'title layer
  402.   _PUTIMAGE (0, 0)-STEP(639, 399), Layer(5), Layer(1)
  403.   _PUTIMAGE , Layer(1), Layer(0)
  404.   ClearLayer Layer(5)
  405.  NEXT i%
  406.  PLAY HitSound$
  407.  _DELAY 1.5
  408.  _DEST Layer(0)
  409.  CLS
  410.  
  411. SUB MainGame
  412.  DO
  413.   '-----controls-----
  414.   KBD$ = INKEY$
  415.   IF KBD$ = CHR$(27) THEN ExitFlag%% = TRUE
  416.   IF Flag AND 1 OR Flag AND 2 THEN
  417.    IF KBD$ = CHR$(32) AND (NOT Shot%%) THEN Shoot%% = TRUE: Shot%% = TRUE
  418.   ELSE
  419.    IF NOT Turn%% THEN
  420.     IF Fire%% AND (NOT Shot%%) THEN Shoot%% = TRUE: Shot%% = TRUE: Fire%% = FALSE ': ExitFlag%% = TRUE
  421.    ELSE
  422.     IF KBD$ = CHR$(32) AND (NOT Shot%%) THEN Shoot%% = TRUE: Shot%% = TRUE
  423.    END IF
  424.   END IF
  425.   '-----------------
  426.  
  427.   '------Logic------
  428.   IF Shoot%% THEN Hit~%% = Collision_Check(Arrow.X, Arrow.Y)
  429.   IF Hit~%% AND Shoot%% THEN Shoot%% = FALSE: PLAY HitSound$
  430.   IF Shoot%% THEN Arrow.Speed = 3 ELSE Arrow.Speed = 0
  431.   IF Target.Y = 201 THEN Target.Speed = 0
  432.   IF Target.Y = 201 AND (NOT Shot%%) THEN Shot%% = TRUE 'if player doesn't shoot then they forefit
  433.   IF Target.Speed = 0 AND Shot%% AND (NOT Shoot%%) THEN Reset_Shot Shot%%, Shoot%%, Hit~%%: Fire%% = FALSE
  434.   SELECT CASE Hit~%% MOD 16
  435.    CASE 0 'in travel
  436.    CASE 11 'back stop
  437.     Hit~%% = 0
  438.    CASE ELSE 'hit target
  439.     Arrow.Y = Arrow.Y + 1
  440.   '-computer player-
  441.   Dist% = 309 - Arrow.OrigX '~how far to end of feild
  442.   Tim%% = Dist% \ 3 + Noise%% 'time from loose to hit+random factor
  443.   IF Target.Y + Tim%% >= Arrow.OrigY AND (NOT Shot%%) THEN Fire%% = TRUE
  444.   '-----------------
  445.  
  446.   '-Display update--
  447.   ClearLayer Layer(6)
  448.   Display_Scoreboard
  449.   Move_Target
  450.   Move_Arrow
  451.   PushScreen 6
  452.   '-----------------
  453.   IF Hit~%% = 99 THEN ExitFlag%% = TRUE 'game over
  454.   _DELAY .03
  455.  LOOP UNTIL ExitFlag%%
  456.  

not an exact copy of the original, having added small things like randomized shooting locations and potentially adjustable computer difficulty. and maybe should I get adventurous network play and score keeping!

This took way longer than it should typing 90% left handed only, I just couldn't sit on my arse doing nothing and while playing some old DOS games that made me want to write some code I bit the bullet and pecked a large potion single handedly, literally! Believe it or not the original game was written in basic and the source code is out there on github by the author. when I tried to pull it up it would only show in some encoded format but the strings where still readable so that saved me a huge amount of time trying to DRAW out the sprites and title(all done with DRAW command and PAINT!) It was supposedly written in something similar to GWBASIC not QB45 so why it has some kind of encoding I don't know, unless its some GitHub thing?(here is the original: https://github.com/inverted1/Archery) But I managed and here is the result so far.
 Give it a go. Let me know if it all works on newer QB64 builds.

for computer VS computer play you need to goto line 283 and comment out 'Turn%% = TRUE' as well as uncomment the line 70 and 71
adjusting Computer.Class varies how good the computer is, found a slight issue with level 5,which should always get 10s, as every so often it won't hit center. I can get it up to 4 out of 5 frames solid 10s but for some reason there are locations that the math doesn't work on.

Update 8-17-2019: fixed the computer player jump start Bplus found. Forgot to set player 1's turn flag.

Update II 8-17-2019: Fixed Player 2 line jumping(shooting first), and spelling error found by TempodiBasic.
« Last Edit: August 17, 2019, 05:14:19 pm by Cobalt »
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Archery!
« Reply #1 on: August 16, 2019, 07:26:34 pm »
Hi Cobalt,

I gave it a shot playing against the computer and it is hard to tell who is shooting, or specifically when I am up.

Also there seems to be a delay from time I press spacebar and when the arrow starts moving.

That name, Brain Blankenship, sounds familiar?

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Archery!
« Reply #2 on: August 16, 2019, 09:43:51 pm »
By the way, hi Cobolt!
You're not done when it works, you're done when it's right.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Archery!
« Reply #3 on: August 17, 2019, 12:12:09 am »
Also there seems to be a delay from time I press spacebar and when the arrow starts moving.
I haven't noticed it.

And I never gave any thought to identifying whos up, the original game doesn't but I might do something about it, maybe changing the color, back in those days with SCREEN 1 that would have been harder to pull off.

Hey Stxaxtic long time. Try the game?
Granted after becoming radioactive I only have a half-life!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Archery!
« Reply #4 on: August 17, 2019, 12:14:24 am »
I tried the game and kicked nuts. It was easy to discern whose turn it is - just look at the scoreboard and whoever's triplet isn't complete, it's still their turn.

Funny enough we have a guy named Lefty here now, so now I have to think of some other nickname... Cobalternative Hand?
You're not done when it works, you're done when it's right.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Archery!
« Reply #5 on: August 17, 2019, 02:41:47 am »
Cool game. At times it was a bit tricky to figure the timing to shoot, but once I got the hang of it, mongrel game changed the distance to shoot.... lol

Simple but addictive. Nicely done.

Quick question: I am familiar with "step" in a for-next loop but how does it work in putimage?
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Archery!
« Reply #6 on: August 17, 2019, 09:30:34 am »
OK when I tested playing, I answered 1 to players, yes to play against computer and I swear the code is shooting and filling out board under my name at least on first round which caused me to wonder and provide the feedback that I did. I tested this 5 times now and it shoots for me each time on first round.

If I go 1 player not against computer it works fine.

BTW cool start screen!
« Last Edit: August 17, 2019, 09:33:17 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Archery!
« Reply #7 on: August 17, 2019, 10:03:50 am »
OK I took another copy of the code from forum, just to triple check:
Code: QB64: [Select]
  1. 'Archery 1985 by Brain Blankenship
  2. '2019 Archery By Cobalt
  3. '8/13/2019|
  4. 'V0.4
  5. '-Sprites\Title\Options screens done
  6. 'V0.6
  7. '-Scoreboard done
  8. '-target movement done
  9. '-arrow movement done
  10. 'V0.7
  11. '-collision detection
  12. '8/14/2019
  13. 'V0.8
  14. 'player 2 frames
  15. 'Random site creation
  16. '8/15/2019
  17. 'v0.9
  18. 'Computer AI for player 2
  19. 'Computer vs computer possible
  20.  
  21. TYPE Position
  22.     X AS INTEGER
  23.     Y AS INTEGER
  24.     Speed AS _BYTE
  25.     OrigX AS INTEGER
  26.     OrigY AS INTEGER
  27.  
  28. SCREEN _NEWIMAGE(640, 400, 32)
  29. _DELAY .125
  30. _TITLE "Archery 1985   v0.9"
  31.  
  32. '-------------CONSTANTS----------------
  33. CONST TRUE = -1, FALSE = NOT TRUE
  34. CONST Black = &HFF000101~&, Cyan = &HFF01A0A0~&, Magenta = &HFF941090~&, OffWhite = &HFFC7C0C0~&, Green = &HFF1B9010~&, CtrWhite = &HFFCAC0C0~&
  35. '--------------------------------------
  36. '-------ARRAYS & SHARED VARIABLES------
  37. DIM SHARED Layer(10) AS LONG, Shots(1, 4, 2) AS _BYTE, HitSound$
  38. DIM SHARED Computer.Class, Player$(2), Flag AS _BYTE, Turn%%, Noise%%
  39. DIM SHARED Arrow AS Position, Target AS Position
  40. '--------------------------------------
  41. '---------------LAYERS-----------------
  42. Layer(0) = _DISPLAY
  43. Layer(1) = _NEWIMAGE(640, 400, 32) 'mix layer
  44. Layer(2) = _NEWIMAGE(320, 200, 32) 'Title Screen Layer
  45. Layer(3) = _NEWIMAGE(320, 200, 32) 'Sprite sheet layer
  46. Layer(4) = _NEWIMAGE(320, 200, 32) 'Collision layer
  47. Layer(5) = _NEWIMAGE(320, 200, 32) 'Extra/Scoreboard layer
  48. Layer(6) = _NEWIMAGE(320, 200, 32) 'Input layer/Prebuild layer
  49. '--------------------------------------
  50. '-----------ARROW HIT SOUND------------
  51. PLAY "t230l64" 'setup sound play rate
  52. HitSound$ = "o1bagfedc"
  53. '--------------------------------------
  54. Draw_Sprites
  55. Draw_Title_Screen
  56. Title_Animation
  57. Game_Option_Screen
  58. Scoreboard_Setup
  59. '-------Inital Values------------------
  60. Target.Speed = 1
  61. Target.Y = 0: Target.OrigY = 0
  62. Target.X = 309: Target.OrigX = 309
  63. Arrow.Speed = 0
  64. Arrow.OrigY = 135: Arrow.Y = Arrow.OrigY
  65. Arrow.OrigX = 69: Arrow.X = Arrow.OrigX
  66. ExitFlag%% = FALSE
  67. 'Turn%% = FALSE 'watch the computer play itself!
  68. 'Flag = 4'set player 2 to computer(needed for computer only play)
  69. Computer.Class = 3 'skill level of computer(experimental)
  70. Noise%% = Computer_AI 'adds little randomness to computer shots
  71. '-------------MAIN LOOP----------------
  72.  
  73.     '-----controls-----
  74.     KBD$ = INKEY$
  75.     IF KBD$ = CHR$(27) THEN ExitFlag%% = TRUE
  76.     IF Flag AND 1 OR Flag AND 2 THEN
  77.         IF KBD$ = CHR$(32) AND (NOT Shot%%) THEN Shoot%% = TRUE: Shot%% = TRUE
  78.     ELSE
  79.         IF NOT Turn%% THEN
  80.             IF Fire%% AND (NOT Shot%%) THEN Shoot%% = TRUE: Shot%% = TRUE: Fire%% = FALSE ': ExitFlag%% = TRUE
  81.         ELSE
  82.             IF KBD$ = CHR$(32) AND (NOT Shot%%) THEN Shoot%% = TRUE: Shot%% = TRUE
  83.         END IF
  84.     END IF
  85.     '-----------------
  86.  
  87.     '------Logic------
  88.     IF Shoot%% THEN Hit~%% = Collision_Check(Arrow.X, Arrow.Y)
  89.     IF Hit~%% AND Shoot%% THEN Shoot%% = FALSE: PLAY HitSound$
  90.     IF Shoot%% THEN Arrow.Speed = 3 ELSE Arrow.Speed = 0
  91.     IF Target.Y = 201 THEN Target.Speed = 0
  92.     IF Target.Y = 201 AND (NOT Shot%%) THEN Shot%% = TRUE 'if player doesn't shoot then they forefit
  93.     IF Target.Speed = 0 AND Shot%% AND (NOT Shoot%%) THEN Reset_Shot Shot%%, Shoot%%, Hit~%%: Fire%% = FALSE
  94.     SELECT CASE Hit~%% MOD 16
  95.         CASE 0 'in travel
  96.         CASE 11 'back stop
  97.             Hit~%% = 0
  98.         CASE ELSE 'hit target
  99.             Arrow.Y = Arrow.Y + 1
  100.     END SELECT
  101.     '-computer player-
  102.     Dist% = 309 - Arrow.OrigX '~how far to end of feild
  103.     Tim%% = Dist% \ 3 + Noise%% 'time from loose to hit+random factor
  104.     IF Target.Y + Tim%% >= Arrow.OrigY AND (NOT Shot%%) THEN Fire%% = TRUE
  105.     '-----------------
  106.  
  107.     '-Display update--
  108.     ClearLayer Layer(6)
  109.     Display_Scoreboard
  110.     Move_Target
  111.     Move_Arrow
  112.     PushScreen 6
  113.     '-----------------
  114.     ' LOCATE 1, 1: PRINT Arrow.OrigX; Arrow.OrigY; Target.Y + Tim%%; Dist%; Tim%%;
  115.     IF Hit~%% = 99 THEN ExitFlag%% = TRUE 'game over
  116.     _DELAY .03
  117. LOOP UNTIL ExitFlag%%
  118. '--------------------------------------
  119.  
  120. FUNCTION Calc_Score~%% (Who%%)
  121.     Result~%% = 0
  122.     FOR F%% = 0 TO 4
  123.         FOR S%% = 0 TO 2
  124.             Result~%% = Result~%% + Shots(Who%%, F%%, S%%)
  125.         NEXT S%%
  126.     NEXT F%%
  127.     Calc_Score = Result~%%
  128.  
  129. SUB ClearLayer (L&)
  130.     _DEST L&
  131.     CLS
  132.  
  133. SUB Display_Scoreboard
  134.     _PUTIMAGE , Layer(5), Layer(6)
  135.     _DEST Layer(6)
  136.     _FONT 8
  137.     COLOR OffWhite
  138.     FOR P%% = 0 TO 1
  139.         FOR Flight%% = 0 TO 4
  140.             FOR Shot%% = 0 TO 2
  141.                 LOCATE 4 + Shot%% + (P%% * 4), 12 + Flight%% * 4
  142.                 PRINT Shots(P%%, Flight%%, Shot%%)
  143.             NEXT Shot%%
  144.         NEXT Flight%%
  145.     NEXT P%%
  146.     LOCATE 4, 32: PRINT Calc_Score(0)
  147.     LOCATE 8, 32: PRINT Calc_Score(1)
  148.  
  149.     _FONT 16
  150.     _DEST Layer(0)
  151.  
  152. SUB Draw_Sprites
  153.     ClearLayer Layer(3)
  154.     _DEST Layer(1)
  155.     'Original target draw /w color fix
  156.     DRAW "bm318,140c" + STR$(Cyan) + "d30l1u30l1d30u6l1c" + STR$(Magenta) + "u18l1d18l1u18d6l1c" + STR$(OffWhite) + "d6l1u6"
  157.     'original arrow draw /w color fix
  158.     DRAW "bm10,155c" + STR$(Cyan) + "r20l20c" + STR$(Magenta) + "h3f3g3e3c" + STR$(OffWhite) + "bm+2,+0h3f3g3e3c" + STR$(Magenta) + "bm+2,+0h3f3g3e3bm+15,-2c" + STR$(OffWhite) + "d4u1r1u2d1r1"
  159.     LINE (311, 155)-STEP(1, 0), CtrWhite
  160.     _DEST Layer(0)
  161.     _PUTIMAGE (0, 0), Layer(1), Layer(3), (310, 140)-STEP(8, 30) 'move target to sprite sheet
  162.     _PUTIMAGE (0, 32), Layer(1), Layer(3), (7, 152)-STEP(24, 6) 'move arrow to sprite sheet
  163.     _CLEARCOLOR _RGB32(0, 0, 0), Layer(3)
  164.     ClearLayer Layer(1)
  165.  
  166. SUB Draw_Title_Screen
  167.     _DEST Layer(1)
  168.     _FONT 8
  169.     COLOR OffWhite
  170.     PSET (0, 0), OffWhite
  171.     DRAW "bm41,70e30r10d30l8u12l8g12l11bm+34,-24d6l7e7bm+11,-5d30r8u15m+15,+15r10h18u12l14bm+4,+5d5r4u5l4"
  172.     DRAW "BM+20,-5r30d12l8u4l17f15r3u5r7d12l15h20u10r4bm+37,-0r8d10r8u10r8d30l8u10l8d10l8u30bm+30,-0r20d6l15d8r8d5l8d6r15d5l20u30"
  173.     DRAW "bm+26,-0d30r8u15m+15,+15r10h18u12l14bm+4,+5d5r4u5l4bm+17,-5d10f16d4r8u30l8d17h7u10l8"
  174.     DATA 46,90,129,150,180,206,243
  175.     FOR i%% = 1 TO 7
  176.         READ t%
  177.         PAINT (t%, 68), Magenta, OffWhite
  178.     NEXT i%%
  179.     LOCATE 17, 11: PRINT "Orignally by:"
  180.     LOCATE 20, 16: PRINT "Brain Blankenship"
  181.     _FONT 16
  182.     _DEST Layer(0)
  183.     _PUTIMAGE (1, 0), Layer(1), Layer(2), (1, 0)-(319, 199)
  184.     _PUTIMAGE (310, 140), Layer(3), Layer(2), (0, 0)-STEP(7, 30) 'target
  185.     _CLEARCOLOR _RGB32(0, 0, 0), Layer(2)
  186.     ClearLayer Layer(1)
  187.  
  188. SUB Game_Option_Screen
  189.     _DEST Layer(5)
  190.     _FONT 8
  191.     COLOR OffWhite
  192.     PRINT "Instructions": PRINT
  193.     PRINT " Score as many  points as  possible by"
  194.     PRINT "  hitting  the   target  close  to  the"
  195.     PRINT "  center. Press the space bar to shoot."
  196.     PRINT "  You get three trys from each of  five"
  197.     PRINT "  sites, highest score wins."
  198.     PRINT
  199.     PushScreen 5
  200.     _DELAY 3
  201.     PRINT: PRINT: PRINT
  202.     PRINT "Number of Players(1/2)?"
  203.     PushScreen 5
  204.     DO: kbd$ = INKEY$: LOOP UNTIL kbd$ = "1" OR kbd$ = "2"
  205.     Flag = Flag + 2 ^ (VAL(kbd$) - 1) 'set bit 0 if 1 player, bit 1 for 2 player
  206.  
  207.     PRINT: PRINT "Enter player one's name :?"
  208.     PushScreen 5
  209.     Player$(0) = Get_Player_Name(0)
  210.     _PRINTSTRING (212, 104), Player$(0)
  211.  
  212.     IF Flag AND 2 THEN
  213.         PRINT: PRINT "Enter player two's name :?"
  214.         PushScreen 5
  215.         Player$(1) = Get_Player_Name(1)
  216.         _PRINTSTRING (212, 120), Player$(1)
  217.     ELSE
  218.         PRINT: PRINT "           Play Computer ?"
  219.         PushScreen 5
  220.         DO: kbd$ = LCASE$(INKEY$): LOOP UNTIL kbd$ = "y" OR kbd$ = "n"
  221.         IF kbd$ = "y" THEN Flag = 4: Player$(1) = "Computer"
  222.     END IF
  223.     _FONT 16
  224.     _DEST Layer(0)
  225.     ClearLayer Layer(1)
  226.  
  227. FUNCTION Get_Player_Name$ (Who%%)
  228.     DO
  229.         kbd$ = INKEY$
  230.         IF LEN(Result$) < 8 AND kbd$ >= CHR$(32) THEN Result$ = Result$ + kbd$
  231.         IF kbd$ = CHR$(8) THEN Result$ = LEFT$(Result$, LEN(Result$) - 1)
  232.         IF Who%% THEN _PRINTSTRING (212, 120), Result$ ELSE _PRINTSTRING (212, 104), Result$
  233.         PushScreen 5
  234.         _DELAY .025
  235.         IF Who%% THEN LINE (212, 120)-STEP(72, 8), Black, BF ELSE LINE (212, 104)-STEP(72, 8), Black, BF
  236.     LOOP UNTIL kbd$ = CHR$(13)
  237.     Get_Player_Name = Result$
  238.  
  239. SUB Move_Target
  240.     Target.Y = Target.Y + Target.Speed
  241.     _PUTIMAGE (Target.X, Target.Y), Layer(3), Layer(6), (0, 0)-STEP(8, 30) 'target
  242.     'collision layer
  243.     ClearLayer Layer(4)
  244.     _PUTIMAGE (Target.X, Target.Y), Layer(3), Layer(4), (0, 0)-STEP(8, 30) 'target
  245.     _PUTIMAGE (318, 0)-STEP(1, 199), Layer(5), Layer(4), (319, 0)-(319, 199) 'target
  246.  
  247. SUB Move_Arrow
  248.     Arrow.X = Arrow.X + Arrow.Speed
  249.     _PUTIMAGE (Arrow.X, Arrow.Y), Layer(3), Layer(6), (0, 32)-STEP(24, 6) 'arrow
  250.  
  251. SUB PushScreen (id%%)
  252.     _PUTIMAGE (0, 0)-STEP(639, 399), Layer(id%%), Layer(1), (0, 0)-STEP(319, 199)
  253.     _PUTIMAGE , Layer(1), Layer(0)
  254.  
  255. SUB Reset_Shot (Shot%%, Shoot%%, Hit~%%)
  256.     STATIC Flight%%, Frame%%, Player%%
  257.     '-------assign score-------
  258.     Shots(Player%%, Frame%%, Flight%%) = Hit~%% MOD 16
  259.     '--------------------------
  260.     '-----increment flight-----
  261.     Flight%% = Flight%% + 1
  262.     IF Flight%% = 3 THEN '3 flights per frame
  263.         IF Flag AND 1 THEN
  264.             Frame%% = Frame%% + 1: Flight%% = 0: New_Site
  265.         END IF
  266.         IF Flag AND 2 OR Flag AND 4 THEN 'is there a second player or computer?
  267.             IF Player%% THEN 'player 2 just loosed, next frame for player 1
  268.                 Player%% = 0: Frame%% = Frame%% + 1: Flight%% = 0: New_Site: Turn%% = TRUE
  269.             ELSE 'let player 2 loose his first frame
  270.                 IF Flag AND 4 THEN Turn%% = FALSE
  271.                 Player%% = 1: Flight%% = 0
  272.             END IF
  273.         END IF
  274.     END IF
  275.     '--------------------------
  276.     Target.Y = Target.OrigY
  277.     Target.Speed = 1
  278.     Arrow.Y = Arrow.OrigY
  279.     Arrow.X = Arrow.OrigX
  280.     Shot%% = FALSE
  281.     Shoot%% = FALSE
  282.     IF Frame%% = 5 THEN Hit~%% = 99 ELSE Hit~%% = 0 'end game trigger
  283.     Noise%% = Computer_AI 'adds little randomness to computer shots
  284.  
  285. FUNCTION Computer_AI%% ()
  286.     Result%% = 0
  287.     SELECT CASE Computer.Class
  288.         CASE 1 'basic
  289.             Result%% = INT(RND * 28) - 10
  290.         CASE 2 'decent
  291.             Result%% = INT(RND * 24) - 8
  292.         CASE 3 'good
  293.             Result%% = INT(RND * 20) - 6
  294.         CASE 4 'hard
  295.             Result%% = INT(RND * 16) - 4
  296.         CASE 5 'Robin Hood unbeatable 150!
  297.             IF Arrow.OrigX MOD 2 THEN Result%% = 5 ELSE Result%% = 6
  298.     END SELECT
  299.     Computer_AI%% = Result%%
  300.  
  301. SUB Scoreboard_Setup
  302.     ClearLayer Layer(5)
  303.     _DEST Layer(5)
  304.     _FONT 8
  305.     COLOR OffWhite
  306.     LINE (1, 1)-STEP(300, 84), Cyan, B
  307.     LINE (2, 2)-STEP(298, 82), Magenta, B
  308.     LINE (3, 3)-STEP(296, 80), OffWhite, B
  309.     LINE (4, 4)-STEP(294, 78), Black, BF
  310.     LOCATE 2, 2: PRINT "Player    #1  #2  #3  #4  #5  Total"
  311.     LOCATE 4, 3: PRINT Player$(0)
  312.     LOCATE 8, 3: PRINT Player$(1)
  313.     LINE (319, 0)-(319, 199), Green, BF
  314.     _FONT 16
  315.     _DEST Layer(0)
  316.  
  317. SUB Title_Animation
  318.     _DEST Layer(5)
  319.     COLOR OffWhite
  320.     _DEST Layer(0)
  321.     _PRINTSTRING (4, 0), "UniKorn", Layer(5)
  322.     _PRINTSTRING (36, 16), "ProDucKions", Layer(5)
  323.     _PUTIMAGE (0, 0)-STEP(639, 400), Layer(5), Layer(1), (0, 0)-STEP(125, 39)
  324.     _PUTIMAGE (0, 0)-STEP(639, 399), Layer(1), Layer(0)
  325.     _PRINTSTRING (290, 350), "Presents", Layer(0)
  326.     _DELAY 2.5
  327.     ClearLayer Layer(5)
  328.     CLS
  329.     _PUTIMAGE (7 + i%, 152), Layer(3), Layer(5), (0, 32)-STEP(24, 6) 'arrow
  330.     _PUTIMAGE , Layer(2), Layer(5)
  331.     _PUTIMAGE (0, 0)-STEP(639, 399), Layer(5), Layer(1)
  332.     _PUTIMAGE , Layer(1), Layer(0)
  333.     _DELAY 1.5
  334.     FOR i% = 0 TO 279 STEP 2
  335.         _DELAY .02
  336.         _PUTIMAGE (8 + i%, 152), Layer(3), Layer(5), (0, 32)-STEP(24, 6) 'arrow
  337.         _PUTIMAGE , Layer(2), Layer(5) 'title layer
  338.         _PUTIMAGE (0, 0)-STEP(639, 399), Layer(5), Layer(1)
  339.         _PUTIMAGE , Layer(1), Layer(0)
  340.         ClearLayer Layer(5)
  341.     NEXT i%
  342.     PLAY HitSound$
  343.     _DELAY 1.5
  344.     _DEST Layer(0)
  345.     CLS
  346.  
  347. FUNCTION Collision_Check~%% (X%, Y%)
  348.     IF _SOURCE <> Layer(4) THEN _SOURCE Layer(4)
  349.     Result~%% = 0
  350.     FOR I%% = 0 TO 1
  351.         Test~& = POINT(25 + X% + I%%, Y% + 3)
  352.         R~%% = _RED32(Test~&)
  353.         IF R~%% = 255 THEN R~%% = 1
  354.         IF R~%% > 0 THEN Result~%% = R~%%: I%% = 5
  355.     NEXT I%%
  356.     Collision_Check = Result~%%
  357.  
  358. SUB New_Site
  359.     Arrow.OrigX = INT(RND * 240) + 10
  360.     Arrow.OrigY = INT(RND * 50) + 120
  361.  
  362.  

Again if I choose 1 player and play against the copmuter, the game shoots for me on the first round.

If I press the spacebar early on first round, no response until the code decides to shoot the arrow, causing me at first to think there was a delay.

Do y'all think you are shooting on the first round against the computer?  ;-))

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Archery!
« Reply #8 on: August 17, 2019, 12:58:27 pm »
Hi Cobalt
fine remake!
Thanks to share code

@Bplus
Quote
Again if I choose 1 player and play against the copmuter, the game shoots for me on the first round.

If I press the spacebar early on first round, no response until the code decides to shoot the arrow, causing me at first to think there was a delay.

yes I have the same experience.... but You're right
 in main DO...LOOP there is a _delay
Code: QB64: [Select]
  1.   _DELAY .03
;)


Programming isn't difficult, only it's  consuming time and coffee

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Archery!
« Reply #9 on: August 17, 2019, 01:17:42 pm »
Nice game!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Archery!
« Reply #10 on: August 17, 2019, 01:20:35 pm »

Again if I choose 1 player and play against the copmuter, the game shoots for me on the first round.

If I press the spacebar early on first round, no response until the code decides to shoot the arrow, causing me at first to think there was a delay.

Do y'all think you are shooting on the first round against the computer?  ;-))

Haha, your right, I forgot one(1!) line of code, Turn%% = TRUE needs to be placed between line 69 and 70(or there abouts) to set player 1's turn when the game starts. Opps.

Quick question: I am familiar with "step" in a for-next loop but how does it work in putimage?

its just a different way to set coordinates, instead of having to state the exact pixel location you are simply telling it to STEP this far in X and this far in Y from the start point. it is also used in LINE. the only thing to remember is that the area includes the start point so if you needed, a LINE for example, to make a box that is 125x100 starting at point 10,10 you would 'LINE (10,10)-STEP(124,99),color~&,B'  kind of like thinking in base 0 terms. comes in handy if you have a lot of sprites and you know where they start and their size and dont want to have to do the math over and over to find the X2,Y2 pixel for each one. I don't believe there is any other advantage or anything.
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Archery!
« Reply #11 on: August 17, 2019, 01:50:59 pm »
Quote
Haha, your right, I forgot one(1!) line of code, Turn%% = TRUE needs to be placed between line 69 and 70(or there abouts) to set player 1's turn when the game starts. Opps.

Thanks for confirmation. If grammar police show up just remember you're right to remain silent.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Archery!
« Reply #12 on: August 17, 2019, 01:52:56 pm »
Yep you have already solved!
I find it!
Remming Turn%%= FALSE is the same that leaving it there because QB64 inizialite Turn%% to 0 so FALSE.

Great!
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Archery!
« Reply #13 on: August 17, 2019, 04:12:20 pm »
Sorry Cobalt

little mod

1. I have activated line 70
Code: QB64: [Select]
  1. 70 Turn%% = TRUE ' FALSE gives turn to play to Computer

2. I added i to "Orignally " on
Code: QB64: [Select]
  1. 188 LOCATE 17, 11: PRINT "Originally by:"

3. sorry but I like to make simpler (to simplify)
215  Flag = Flag + 2 ^ (VAL(kbd$) - 1) 'set bit 0 if 1 player, bit 1 for 2 player
but kbd$ can be 1 or 2 so VAL(kbd$)-1 can be 0 or 1 so  2^0= 1 2^1 = 2
and so if kbd$ = 1 then 2^(VAL(kbd$)-1)= 1 while if kbd$= 2 then 2^(VAL(kbd$)-1)= 2
so at the end
Code: QB64: [Select]
  1. 215 Flag = Flag +VAL(kbd$)

4. I think that this is clearer...
228 play computer against you?

5. scoreboard adjournment...inDisplay_Scoreboard
I cancel line 144 COLOR OffWhite  and I add an IF shots() THEN color ELSE color into the inner FOR NEXT to show score gained
while just after outer FOR NEXT I add istructions Color to show total scores

6.
about name of player
I find no funny to play with a void name so I give a default data if no name has been got with
IF Result$ = "" THEN Result$ = "Anonim" ' fine to be Anonimous for self_privacy

7.
about to show better what player must play
I saw that
a) Turn%% switches between TRUE and FALSE
b) name of player is written one time at startup
c) Human vs Computer let's play Human only as first play with these instructions
    LOCATE 4, 3: PRINT Player$(0)
    LOCATE 8, 3: PRINT Player$(1)
so for player 1 we must set Turn%% true and for player 2 we must set Turn%% false
where? In the SUB that adjourn the scoreboard!

Code: QB64: [Select]
  1. 'Archery 1985 by Brain Blankenship
  2. '2019 Archery By Cobalt
  3. '8/13/2019|
  4. 'V0.4
  5. '-Sprites\Title\Options screens done
  6. 'V0.6
  7. '-Scoreboard done
  8. '-target movement done
  9. '-arrow movement done
  10. 'V0.7
  11. '-collision detection
  12. '8/14/2019
  13. 'V0.8
  14. 'player 2 frames
  15. 'Random site creation
  16. '8/15/2019
  17. 'v0.9
  18. 'Computer AI for player 2
  19. 'Computer vs computer possible
  20.  
  21. TYPE Position
  22.     X AS INTEGER
  23.     Y AS INTEGER
  24.     Speed AS _BYTE
  25.     OrigX AS INTEGER
  26.     OrigY AS INTEGER
  27.  
  28. SCREEN _NEWIMAGE(640, 400, 32)
  29. _DELAY .125
  30. _TITLE "Archery 1985   v0.9"
  31.  
  32. '-------------CONSTANTS----------------
  33. CONST TRUE = -1, FALSE = NOT TRUE
  34. CONST Black = &HFF000101~&, Cyan = &HFF01A0A0~&, Magenta = &HFF941090~&, OffWhite = &HFFC7C0C0~&, Green = &HFF1B9010~&, CtrWhite = &HFFCAC0C0~&
  35. '--------------------------------------
  36. '-------ARRAYS & SHARED VARIABLES------
  37. DIM SHARED Layer(10) AS LONG, Shots(1, 4, 2) AS _BYTE, HitSound$
  38. DIM SHARED Computer.Class, Player$(2), Flag AS _BYTE, Turn%%, Noise%%
  39. DIM SHARED Arrow AS Position, Target AS Position
  40. '--------------------------------------
  41. '---------------LAYERS-----------------
  42. Layer(0) = _DISPLAY
  43. Layer(1) = _NEWIMAGE(640, 400, 32) 'mix layer
  44. Layer(2) = _NEWIMAGE(320, 200, 32) 'Title Screen Layer
  45. Layer(3) = _NEWIMAGE(320, 200, 32) 'Sprite sheet layer
  46. Layer(4) = _NEWIMAGE(320, 200, 32) 'Collision layer
  47. Layer(5) = _NEWIMAGE(320, 200, 32) 'Extra/Scoreboard layer
  48. Layer(6) = _NEWIMAGE(320, 200, 32) 'Input layer/Prebuild layer
  49. '--------------------------------------
  50. '-----------ARROW HIT SOUND------------
  51. PLAY "t230l64" 'setup sound play rate
  52. HitSound$ = "o1bagfedc"
  53. '--------------------------------------
  54. Draw_Sprites
  55. Draw_Title_Screen
  56. Title_Animation
  57. Game_Option_Screen
  58. Scoreboard_Setup
  59. '-------Inital Values------------------
  60. Target.Speed = 1
  61. Target.Y = 0: Target.OrigY = 0
  62. Target.X = 309: Target.OrigX = 309
  63. Arrow.Speed = 0
  64. Arrow.OrigY = 135: Arrow.Y = Arrow.OrigY
  65. Arrow.OrigX = 69: Arrow.X = Arrow.OrigX
  66. ExitFlag%% = FALSE
  67. Turn%% = TRUE ' FALSE 'watch the computer play itself!
  68. 'Flag = 4'set player 2 to computer(needed for computer only play)
  69. Computer.Class = 3 'skill level of computer(experimental)
  70. Noise%% = Computer_AI 'adds little randomness to computer shots
  71. '-------------MAIN LOOP----------------
  72.  
  73.     '-----controls-----
  74.     KBD$ = INKEY$
  75.     IF KBD$ = CHR$(27) THEN ExitFlag%% = TRUE
  76.     IF Flag AND 1 OR Flag AND 2 THEN ' if player 1 or 2 is human
  77.         IF KBD$ = CHR$(32) AND (NOT Shot%%) THEN Shoot%% = TRUE: Shot%% = TRUE
  78.     ELSE ' when player 2 is computer and Flag is 4
  79.         IF NOT Turn%% THEN
  80.             IF Fire%% AND (NOT Shot%%) THEN Shoot%% = TRUE: Shot%% = TRUE: Fire%% = FALSE ': ExitFlag%% = TRUE
  81.         ELSE
  82.             IF KBD$ = CHR$(32) AND (NOT Shot%%) THEN Shoot%% = TRUE: Shot%% = TRUE
  83.         END IF
  84.     END IF
  85.     '-----------------
  86.  
  87.     '------Logic------
  88.     IF Shoot%% THEN Hit~%% = Collision_Check(Arrow.X, Arrow.Y)
  89.     IF Hit~%% AND Shoot%% THEN Shoot%% = FALSE: PLAY HitSound$
  90.     IF Shoot%% THEN Arrow.Speed = 3 ELSE Arrow.Speed = 0
  91.     IF Target.Y = 201 THEN Target.Speed = 0
  92.     IF Target.Y = 201 AND (NOT Shot%%) THEN Shot%% = TRUE 'if player doesn't shoot then they forefit
  93.     IF Target.Speed = 0 AND Shot%% AND (NOT Shoot%%) THEN Reset_Shot Shot%%, Shoot%%, Hit~%%: Fire%% = FALSE
  94.     SELECT CASE Hit~%% MOD 16
  95.         CASE 0 'in travel
  96.         CASE 11 'back stop
  97.             Hit~%% = 0
  98.         CASE ELSE 'hit target
  99.             Arrow.Y = Arrow.Y + 1
  100.     END SELECT
  101.     '-computer player-
  102.     Dist% = 309 - Arrow.OrigX '~how far to end of feild
  103.     Tim%% = Dist% \ 3 + Noise%% 'time from loose to hit+random factor
  104.     IF Target.Y + Tim%% >= Arrow.OrigY AND (NOT Shot%%) THEN Fire%% = TRUE
  105.     '-----------------
  106.  
  107.     '-Display update--
  108.     ClearLayer Layer(6)
  109.     Display_Scoreboard
  110.     Move_Target
  111.     Move_Arrow
  112.     PushScreen 6
  113.     '-----------------
  114.     ' LOCATE 1, 1: PRINT Arrow.OrigX; Arrow.OrigY; Target.Y + Tim%%; Dist%; Tim%%;
  115.     IF Hit~%% = 99 THEN ExitFlag%% = TRUE 'game over
  116.     _DELAY .03
  117. LOOP UNTIL ExitFlag%%
  118. '--------------------------------------
  119.  
  120. FUNCTION Calc_Score~%% (Who%%)
  121.     Result~%% = 0
  122.     FOR F%% = 0 TO 4
  123.         FOR S%% = 0 TO 2
  124.             Result~%% = Result~%% + Shots(Who%%, F%%, S%%)
  125.         NEXT S%%
  126.     NEXT F%%
  127.     Calc_Score = Result~%%
  128.  
  129. SUB ClearLayer (L&)
  130.     _DEST L&
  131.     CLS
  132.  
  133. SUB Display_Scoreboard
  134.     _PUTIMAGE , Layer(5), Layer(6)
  135.     _DEST Layer(6)
  136.     _FONT 8
  137.     FOR P%% = 0 TO 1
  138.         FOR Flight%% = 0 TO 4
  139.             FOR Shot%% = 0 TO 2
  140.                 IF Shots(P%%, Flight%%, Shot%%) = 0 THEN COLOR OffWhite ELSE COLOR Magenta
  141.                 LOCATE 4 + Shot%% + (P%% * 4), 12 + Flight%% * 4
  142.                 PRINT Shots(P%%, Flight%%, Shot%%)
  143.             NEXT Shot%%
  144.         NEXT Flight%%
  145.     NEXT P%%
  146.     COLOR Green
  147.     IF Flag = 4 OR Flag = 1 THEN ' one player alone or versus computer
  148.         IF Turn%% THEN
  149.             LOCATE 4, 3: PRINT Player$(0)
  150.         ELSE
  151.             LOCATE 8, 3: PRINT Player$(1)
  152.         END IF
  153.     ELSEIF Flag = 2 THEN 'human vs human
  154.  
  155.     END IF
  156.    
  157.     LOCATE 4, 32: PRINT Calc_Score(0)
  158.     LOCATE 8, 32: PRINT Calc_Score(1)
  159.     COLOR OffWhite
  160.     _FONT 16
  161.     _DEST Layer(0)
  162.  
  163. SUB Draw_Sprites
  164.     ClearLayer Layer(3)
  165.     _DEST Layer(1)
  166.     'Original target draw /w color fix
  167.     DRAW "bm318,140c" + STR$(Cyan) + "d30l1u30l1d30u6l1c" + STR$(Magenta) + "u18l1d18l1u18d6l1c" + STR$(OffWhite) + "d6l1u6"
  168.     'original arrow draw /w color fix
  169.     DRAW "bm10,155c" + STR$(Cyan) + "r20l20c" + STR$(Magenta) + "h3f3g3e3c" + STR$(OffWhite) + "bm+2,+0h3f3g3e3c" + STR$(Magenta) + "bm+2,+0h3f3g3e3bm+15,-2c" + STR$(OffWhite) + "d4u1r1u2d1r1"
  170.     LINE (311, 155)-STEP(1, 0), CtrWhite
  171.     _DEST Layer(0)
  172.     _PUTIMAGE (0, 0), Layer(1), Layer(3), (310, 140)-STEP(8, 30) 'move target to sprite sheet
  173.     _PUTIMAGE (0, 32), Layer(1), Layer(3), (7, 152)-STEP(24, 6) 'move arrow to sprite sheet
  174.     _CLEARCOLOR _RGB32(0, 0, 0), Layer(3)
  175.     ClearLayer Layer(1)
  176.  
  177. SUB Draw_Title_Screen
  178.     _DEST Layer(1)
  179.     _FONT 8
  180.     COLOR OffWhite
  181.     PSET (0, 0), OffWhite
  182.     DRAW "bm41,70e30r10d30l8u12l8g12l11bm+34,-24d6l7e7bm+11,-5d30r8u15m+15,+15r10h18u12l14bm+4,+5d5r4u5l4"
  183.     DRAW "BM+20,-5r30d12l8u4l17f15r3u5r7d12l15h20u10r4bm+37,-0r8d10r8u10r8d30l8u10l8d10l8u30bm+30,-0r20d6l15d8r8d5l8d6r15d5l20u30"
  184.     DRAW "bm+26,-0d30r8u15m+15,+15r10h18u12l14bm+4,+5d5r4u5l4bm+17,-5d10f16d4r8u30l8d17h7u10l8"
  185.     DATA 46,90,129,150,180,206,243
  186.     FOR i%% = 1 TO 7
  187.         READ t%
  188.         PAINT (t%, 68), Magenta, OffWhite
  189.     NEXT i%%
  190.     LOCATE 17, 11: PRINT "Originally by:"
  191.     LOCATE 20, 16: PRINT "Brain Blankenship"
  192.     _FONT 16
  193.     _DEST Layer(0)
  194.     _PUTIMAGE (1, 0), Layer(1), Layer(2), (1, 0)-(319, 199)
  195.     _PUTIMAGE (310, 140), Layer(3), Layer(2), (0, 0)-STEP(7, 30) 'target
  196.     _CLEARCOLOR _RGB32(0, 0, 0), Layer(2)
  197.     ClearLayer Layer(1)
  198.  
  199. SUB Game_Option_Screen
  200.     _DEST Layer(5)
  201.     _FONT 8
  202.     COLOR OffWhite
  203.     PRINT "Instructions": PRINT
  204.     PRINT " Score as many  points as  possible by"
  205.     PRINT "  hitting  the   target  close  to  the"
  206.     PRINT "  center. Press the space bar to shoot."
  207.     PRINT "  You get three trys from each of  five"
  208.     PRINT "  sites, highest score wins."
  209.     PRINT
  210.     PushScreen 5
  211.     _DELAY 3
  212.     PRINT: PRINT: PRINT
  213.     PRINT "Number of Players(1/2)?"
  214.     PushScreen 5
  215.     DO: kbd$ = INKEY$: LOOP UNTIL kbd$ = "1" OR kbd$ = "2"
  216.     Flag = Flag + VAL(kbd$) 'Flag = Flag + 2 ^ (VAL(kbd$) - 1) 'set bit 0 if 1 player, bit 1 for 2 player
  217.  
  218.     PRINT: PRINT "Enter player one's name :?"
  219.     PushScreen 5
  220.     Player$(0) = Get_Player_Name(0)
  221.     _PRINTSTRING (212, 104), Player$(0)
  222.  
  223.     IF Flag AND 2 THEN
  224.         PRINT: PRINT "Enter player two's name :?"
  225.         PushScreen 5
  226.         Player$(1) = Get_Player_Name(1)
  227.         _PRINTSTRING (212, 120), Player$(1)
  228.     ELSE
  229.         PRINT: PRINT " Do you play against computer?"
  230.         PushScreen 5
  231.         DO: kbd$ = LCASE$(INKEY$): LOOP UNTIL kbd$ = "y" OR kbd$ = "n"
  232.         IF kbd$ = "y" THEN
  233.             Flag = 4: Player$(1) = "Computer"
  234.         ELSE
  235.             Player$(1) = "Nobody"
  236.         END IF
  237.     END IF
  238.     _FONT 16
  239.     _DEST Layer(0)
  240.     ClearLayer Layer(1)
  241.  
  242. FUNCTION Get_Player_Name$ (Who%%)
  243.     DO
  244.         kbd$ = INKEY$
  245.         IF LEN(Result$) < 8 AND kbd$ >= CHR$(32) THEN Result$ = Result$ + kbd$
  246.         IF kbd$ = CHR$(8) THEN Result$ = LEFT$(Result$, LEN(Result$) - 1)
  247.         IF Who%% THEN _PRINTSTRING (212, 120), Result$ ELSE _PRINTSTRING (212, 104), Result$
  248.         PushScreen 5
  249.         _DELAY .025
  250.         IF Who%% THEN LINE (212, 120)-STEP(72, 8), Black, BF ELSE LINE (212, 104)-STEP(72, 8), Black, BF
  251.     LOOP UNTIL kbd$ = CHR$(13)
  252.     IF Result$ = "" THEN Result$ = "Anonim" ' fine to be Anonimous for self_privacy
  253.     Get_Player_Name = Result$
  254.  
  255. SUB Move_Target
  256.     Target.Y = Target.Y + Target.Speed
  257.     _PUTIMAGE (Target.X, Target.Y), Layer(3), Layer(6), (0, 0)-STEP(8, 30) 'target
  258.     'collision layer
  259.     ClearLayer Layer(4)
  260.     _PUTIMAGE (Target.X, Target.Y), Layer(3), Layer(4), (0, 0)-STEP(8, 30) 'target
  261.     _PUTIMAGE (318, 0)-STEP(1, 199), Layer(5), Layer(4), (319, 0)-(319, 199) 'target
  262.  
  263. SUB Move_Arrow
  264.     Arrow.X = Arrow.X + Arrow.Speed
  265.     _PUTIMAGE (Arrow.X, Arrow.Y), Layer(3), Layer(6), (0, 32)-STEP(24, 6) 'arrow
  266.  
  267. SUB PushScreen (id%%)
  268.     _PUTIMAGE (0, 0)-STEP(639, 399), Layer(id%%), Layer(1), (0, 0)-STEP(319, 199)
  269.     _PUTIMAGE , Layer(1), Layer(0)
  270.  
  271. SUB Reset_Shot (Shot%%, Shoot%%, Hit~%%)
  272.     STATIC Flight%%, Frame%%, Player%%
  273.     '-------assign score-------
  274.     Shots(Player%%, Frame%%, Flight%%) = Hit~%% MOD 16
  275.     '--------------------------
  276.     '-----increment flight-----
  277.     Flight%% = Flight%% + 1
  278.     IF Flight%% = 3 THEN '3 flights per frame
  279.         IF Flag AND 1 THEN
  280.             Frame%% = Frame%% + 1: Flight%% = 0: New_Site
  281.         END IF
  282.         IF Flag AND 2 OR Flag AND 4 THEN 'is there a second player or computer?
  283.             IF Player%% THEN 'player 2 just loosed, next frame for player 1
  284.                 Player%% = 0: Frame%% = Frame%% + 1: Flight%% = 0: New_Site: Turn%% = TRUE
  285.             ELSE 'let player 2 loose his first frame
  286.                 IF Flag AND 4 THEN Turn%% = FALSE
  287.                 Player%% = 1: Flight%% = 0
  288.             END IF
  289.         END IF
  290.     END IF
  291.     '--------------------------
  292.     Target.Y = Target.OrigY
  293.     Target.Speed = 1
  294.     Arrow.Y = Arrow.OrigY
  295.     Arrow.X = Arrow.OrigX
  296.     Shot%% = FALSE
  297.     Shoot%% = FALSE
  298.     IF Frame%% = 5 THEN Hit~%% = 99 ELSE Hit~%% = 0 'end game trigger
  299.     Noise%% = Computer_AI 'adds little randomness to computer shots
  300.  
  301. FUNCTION Computer_AI%% ()
  302.     Result%% = 0
  303.     SELECT CASE Computer.Class
  304.         CASE 1 'basic
  305.             Result%% = INT(RND * 28) - 10
  306.         CASE 2 'decent
  307.             Result%% = INT(RND * 24) - 8
  308.         CASE 3 'good
  309.             Result%% = INT(RND * 20) - 6
  310.         CASE 4 'hard
  311.             Result%% = INT(RND * 16) - 4
  312.         CASE 5 'Robin Hood unbeatable 150!
  313.             IF Arrow.OrigX MOD 2 THEN Result%% = 5 ELSE Result%% = 6
  314.     END SELECT
  315.     Computer_AI%% = Result%%
  316.  
  317. SUB Scoreboard_Setup
  318.     ClearLayer Layer(5)
  319.     _DEST Layer(5)
  320.     _FONT 8
  321.     COLOR OffWhite
  322.     LINE (1, 1)-STEP(300, 84), Cyan, B
  323.     LINE (2, 2)-STEP(298, 82), Magenta, B
  324.     LINE (3, 3)-STEP(296, 80), OffWhite, B
  325.     LINE (4, 4)-STEP(294, 78), Black, BF
  326.     LOCATE 2, 2: PRINT "Player    #1  #2  #3  #4  #5  Total"
  327.     LOCATE 4, 3: PRINT Player$(0)
  328.     LOCATE 8, 3: PRINT Player$(1)
  329.     LINE (319, 0)-(319, 199), Green, BF
  330.     _FONT 16
  331.     _DEST Layer(0)
  332.  
  333. SUB Title_Animation
  334.     _DEST Layer(5)
  335.     COLOR OffWhite
  336.     _DEST Layer(0)
  337.     _PRINTSTRING (4, 0), "UniKorn", Layer(5)
  338.     _PRINTSTRING (36, 16), "ProDucKions", Layer(5)
  339.     _PUTIMAGE (0, 0)-STEP(639, 400), Layer(5), Layer(1), (0, 0)-STEP(125, 39)
  340.     _PUTIMAGE (0, 0)-STEP(639, 399), Layer(1), Layer(0)
  341.     _PRINTSTRING (290, 350), "Presents", Layer(0)
  342.     _DELAY 2.5
  343.     ClearLayer Layer(5)
  344.     CLS
  345.     _PUTIMAGE (7 + i%, 152), Layer(3), Layer(5), (0, 32)-STEP(24, 6) 'arrow
  346.     _PUTIMAGE , Layer(2), Layer(5)
  347.     _PUTIMAGE (0, 0)-STEP(639, 399), Layer(5), Layer(1)
  348.     _PUTIMAGE , Layer(1), Layer(0)
  349.     _DELAY 1.5
  350.     FOR i% = 0 TO 279 STEP 2
  351.         _DELAY .02
  352.         _PUTIMAGE (8 + i%, 152), Layer(3), Layer(5), (0, 32)-STEP(24, 6) 'arrow
  353.         _PUTIMAGE , Layer(2), Layer(5) 'title layer
  354.         _PUTIMAGE (0, 0)-STEP(639, 399), Layer(5), Layer(1)
  355.         _PUTIMAGE , Layer(1), Layer(0)
  356.         ClearLayer Layer(5)
  357.     NEXT i%
  358.     PLAY HitSound$
  359.     _DELAY 1.5
  360.     _DEST Layer(0)
  361.     CLS
  362.  
  363. FUNCTION Collision_Check~%% (X%, Y%)
  364.     IF _SOURCE <> Layer(4) THEN _SOURCE Layer(4)
  365.     Result~%% = 0
  366.     FOR I%% = 0 TO 1
  367.         Test~& = POINT(25 + X% + I%%, Y% + 3)
  368.         R~%% = _RED32(Test~&)
  369.         IF R~%% = 255 THEN R~%% = 1
  370.         IF R~%% > 0 THEN Result~%% = R~%%: I%% = 5
  371.     NEXT I%%
  372.     Collision_Check = Result~%%
  373.  
  374. SUB New_Site
  375.     Arrow.OrigX = INT(RND * 240) + 10
  376.     Arrow.OrigY = INT(RND * 50) + 120
  377.  

Be patient with my imagination

Thanks to share
« Last Edit: August 17, 2019, 04:17:16 pm by TempodiBasic »
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Archery!
« Reply #14 on: August 17, 2019, 04:31:06 pm »
But this doesn't work when there are two humans! Turn%% is always true and Flag is always 2!
I must find where is the information of the current player....

Yep it is here.... in Reset_Shot SUB that has into a STATIC Player%%....

now I append at the end of global variables this
Code: QB64: [Select]

and at initialization before main DO...LOOP this
Code: QB64: [Select]
  1. Playing = 0

and into SUB  Reset_Shot as last line of code before END SUB this
Code: QB64: [Select]
  1.  Playing = Player%%  

and in SUB Dysplay_Scoreboard

this
Code: QB64: [Select]
  1.     IF Playing = 0 THEN
  2.         LOCATE 4, 3: PRINT Player$(0)
  3.     ELSE
  4.         LOCATE 8, 3: PRINT Player$(1)
  5.     END IF

and deleting this

Code: QB64: [Select]
  1.    IF Flag = 4 OR Flag = 1 THEN ' one player alone or versus computer
  2.         IF Turn%% THEN
  3.             LOCATE 4, 3: PRINT Player$(0)
  4.         ELSE
  5.             LOCATE 8, 3: PRINT Player$(1)
  6.         END IF
  7.     ELSEIF Flag = 2 THEN 'human vs human
  8.  
  9.     END IF

Now we wait Cobalt for news about autoplay Computer vs Computer and Infinite play following his initial declarations.

Thanks to share

PS
here the new mod code
Code: QB64: [Select]
  1. 'Archery 1985 by Brain Blankenship
  2. '2019 Archery By Cobalt
  3. '8/13/2019|
  4. 'V0.4
  5. '-Sprites\Title\Options screens done
  6. 'V0.6
  7. '-Scoreboard done
  8. '-target movement done
  9. '-arrow movement done
  10. 'V0.7
  11. '-collision detection
  12. '8/14/2019
  13. 'V0.8
  14. 'player 2 frames
  15. 'Random site creation
  16. '8/15/2019
  17. 'v0.9
  18. 'Computer AI for player 2
  19. 'Computer vs computer possible
  20.  
  21. TYPE Position
  22.     X AS INTEGER
  23.     Y AS INTEGER
  24.     Speed AS _BYTE
  25.     OrigX AS INTEGER
  26.     OrigY AS INTEGER
  27.  
  28. SCREEN _NEWIMAGE(640, 400, 32)
  29. _DELAY .125
  30. _TITLE "Archery 1985   v0.9"
  31.  
  32. '-------------CONSTANTS----------------
  33. CONST TRUE = -1, FALSE = NOT TRUE
  34. CONST Black = &HFF000101~&, Cyan = &HFF01A0A0~&, Magenta = &HFF941090~&, OffWhite = &HFFC7C0C0~&, Green = &HFF1B9010~&, CtrWhite = &HFFCAC0C0~&
  35. '--------------------------------------
  36. '-------ARRAYS & SHARED VARIABLES------
  37. DIM SHARED Layer(10) AS LONG, Shots(1, 4, 2) AS _BYTE, HitSound$
  38. DIM SHARED Computer.Class, Player$(2), Flag AS _BYTE, Turn%%, Noise%%
  39. DIM SHARED Arrow AS Position, Target AS Position
  40. DIM SHARED Playing AS INTEGER ' who is playing? Only the variable
  41. '--------------------------------------
  42. '---------------LAYERS-----------------
  43. Layer(0) = _DISPLAY
  44. Layer(1) = _NEWIMAGE(640, 400, 32) 'mix layer
  45. Layer(2) = _NEWIMAGE(320, 200, 32) 'Title Screen Layer
  46. Layer(3) = _NEWIMAGE(320, 200, 32) 'Sprite sheet layer
  47. Layer(4) = _NEWIMAGE(320, 200, 32) 'Collision layer
  48. Layer(5) = _NEWIMAGE(320, 200, 32) 'Extra/Scoreboard layer
  49. Layer(6) = _NEWIMAGE(320, 200, 32) 'Input layer/Prebuild layer
  50. '--------------------------------------
  51. '-----------ARROW HIT SOUND------------
  52. PLAY "t230l64" 'setup sound play rate
  53. HitSound$ = "o1bagfedc"
  54. '--------------------------------------
  55. Draw_Sprites
  56. Draw_Title_Screen
  57. Title_Animation
  58. Game_Option_Screen
  59. Scoreboard_Setup
  60. '-------Inital Values------------------
  61. Target.Speed = 1
  62. Target.Y = 0: Target.OrigY = 0
  63. Target.X = 309: Target.OrigX = 309
  64. Arrow.Speed = 0
  65. Arrow.OrigY = 135: Arrow.Y = Arrow.OrigY
  66. Arrow.OrigX = 69: Arrow.X = Arrow.OrigX
  67. ExitFlag%% = FALSE
  68. Turn%% = TRUE ' FALSE 'watch the computer play itself!
  69. 'Flag = 4'set player 2 to computer(needed for computer only play)
  70. Computer.Class = 3 'skill level of computer(experimental)
  71. Noise%% = Computer_AI 'adds little randomness to computer shots
  72. Playing = 0
  73. '-------------MAIN LOOP----------------
  74.  
  75.     '-----controls-----
  76.     KBD$ = INKEY$
  77.     IF KBD$ = CHR$(27) THEN ExitFlag%% = TRUE
  78.     IF Flag AND 1 OR Flag AND 2 THEN ' if player 1 or 2 is human
  79.         IF KBD$ = CHR$(32) AND (NOT Shot%%) THEN Shoot%% = TRUE: Shot%% = TRUE
  80.     ELSE ' when player 2 is computer and Flag is 4
  81.         IF NOT Turn%% THEN
  82.             IF Fire%% AND (NOT Shot%%) THEN Shoot%% = TRUE: Shot%% = TRUE: Fire%% = FALSE ': ExitFlag%% = TRUE
  83.         ELSE
  84.             IF KBD$ = CHR$(32) AND (NOT Shot%%) THEN Shoot%% = TRUE: Shot%% = TRUE
  85.         END IF
  86.     END IF
  87.     '-----------------
  88.  
  89.     '------Logic------
  90.     IF Shoot%% THEN Hit~%% = Collision_Check(Arrow.X, Arrow.Y)
  91.     IF Hit~%% AND Shoot%% THEN Shoot%% = FALSE: PLAY HitSound$
  92.     IF Shoot%% THEN Arrow.Speed = 3 ELSE Arrow.Speed = 0
  93.     IF Target.Y = 201 THEN Target.Speed = 0
  94.     IF Target.Y = 201 AND (NOT Shot%%) THEN Shot%% = TRUE 'if player doesn't shoot then they forefit
  95.     IF Target.Speed = 0 AND Shot%% AND (NOT Shoot%%) THEN Reset_Shot Shot%%, Shoot%%, Hit~%%: Fire%% = FALSE
  96.     SELECT CASE Hit~%% MOD 16
  97.         CASE 0 'in travel
  98.         CASE 11 'back stop
  99.             Hit~%% = 0
  100.         CASE ELSE 'hit target
  101.             Arrow.Y = Arrow.Y + 1
  102.     END SELECT
  103.     '-computer player-
  104.     Dist% = 309 - Arrow.OrigX '~how far to end of feild
  105.     Tim%% = Dist% \ 3 + Noise%% 'time from loose to hit+random factor
  106.     IF Target.Y + Tim%% >= Arrow.OrigY AND (NOT Shot%%) THEN Fire%% = TRUE
  107.     '-----------------
  108.  
  109.     '-Display update--
  110.     ClearLayer Layer(6)
  111.     Display_Scoreboard
  112.     Move_Target
  113.     Move_Arrow
  114.     PushScreen 6
  115.     '-----------------
  116.     ' LOCATE 1, 1: PRINT Arrow.OrigX; Arrow.OrigY; Target.Y + Tim%%; Dist%; Tim%%;
  117.     IF Hit~%% = 99 THEN ExitFlag%% = TRUE 'game over
  118.     _DELAY .03
  119. LOOP UNTIL ExitFlag%%
  120. '--------------------------------------
  121.  
  122. FUNCTION Calc_Score~%% (Who%%)
  123.     Result~%% = 0
  124.     FOR F%% = 0 TO 4
  125.         FOR S%% = 0 TO 2
  126.             Result~%% = Result~%% + Shots(Who%%, F%%, S%%)
  127.         NEXT S%%
  128.     NEXT F%%
  129.     Calc_Score = Result~%%
  130.  
  131. SUB ClearLayer (L&)
  132.     _DEST L&
  133.     CLS
  134.  
  135. SUB Display_Scoreboard
  136.     _PUTIMAGE , Layer(5), Layer(6)
  137.     _DEST Layer(6)
  138.     _FONT 8
  139.     FOR P%% = 0 TO 1
  140.         FOR Flight%% = 0 TO 4
  141.             FOR Shot%% = 0 TO 2
  142.                 IF Shots(P%%, Flight%%, Shot%%) = 0 THEN COLOR OffWhite ELSE COLOR Magenta
  143.                 LOCATE 4 + Shot%% + (P%% * 4), 12 + Flight%% * 4
  144.                 PRINT Shots(P%%, Flight%%, Shot%%)
  145.             NEXT Shot%%
  146.         NEXT Flight%%
  147.     NEXT P%%
  148.     COLOR Green
  149.     IF Playing = 0 THEN
  150.         LOCATE 4, 3: PRINT Player$(0)
  151.     ELSE
  152.         LOCATE 8, 3: PRINT Player$(1)
  153.     END IF
  154.  
  155.     LOCATE 4, 32: PRINT Calc_Score(0)
  156.     LOCATE 8, 32: PRINT Calc_Score(1)
  157.     COLOR OffWhite
  158.     _FONT 16
  159.     _DEST Layer(0)
  160.  
  161. SUB Draw_Sprites
  162.     ClearLayer Layer(3)
  163.     _DEST Layer(1)
  164.     'Original target draw /w color fix
  165.     DRAW "bm318,140c" + STR$(Cyan) + "d30l1u30l1d30u6l1c" + STR$(Magenta) + "u18l1d18l1u18d6l1c" + STR$(OffWhite) + "d6l1u6"
  166.     'original arrow draw /w color fix
  167.     DRAW "bm10,155c" + STR$(Cyan) + "r20l20c" + STR$(Magenta) + "h3f3g3e3c" + STR$(OffWhite) + "bm+2,+0h3f3g3e3c" + STR$(Magenta) + "bm+2,+0h3f3g3e3bm+15,-2c" + STR$(OffWhite) + "d4u1r1u2d1r1"
  168.     LINE (311, 155)-STEP(1, 0), CtrWhite
  169.     _DEST Layer(0)
  170.     _PUTIMAGE (0, 0), Layer(1), Layer(3), (310, 140)-STEP(8, 30) 'move target to sprite sheet
  171.     _PUTIMAGE (0, 32), Layer(1), Layer(3), (7, 152)-STEP(24, 6) 'move arrow to sprite sheet
  172.     _CLEARCOLOR _RGB32(0, 0, 0), Layer(3)
  173.     ClearLayer Layer(1)
  174.  
  175. SUB Draw_Title_Screen
  176.     _DEST Layer(1)
  177.     _FONT 8
  178.     COLOR OffWhite
  179.     PSET (0, 0), OffWhite
  180.     DRAW "bm41,70e30r10d30l8u12l8g12l11bm+34,-24d6l7e7bm+11,-5d30r8u15m+15,+15r10h18u12l14bm+4,+5d5r4u5l4"
  181.     DRAW "BM+20,-5r30d12l8u4l17f15r3u5r7d12l15h20u10r4bm+37,-0r8d10r8u10r8d30l8u10l8d10l8u30bm+30,-0r20d6l15d8r8d5l8d6r15d5l20u30"
  182.     DRAW "bm+26,-0d30r8u15m+15,+15r10h18u12l14bm+4,+5d5r4u5l4bm+17,-5d10f16d4r8u30l8d17h7u10l8"
  183.     DATA 46,90,129,150,180,206,243
  184.     FOR i%% = 1 TO 7
  185.         READ t%
  186.         PAINT (t%, 68), Magenta, OffWhite
  187.     NEXT i%%
  188.     LOCATE 17, 11: PRINT "Originally by:"
  189.     LOCATE 20, 16: PRINT "Brain Blankenship"
  190.     _FONT 16
  191.     _DEST Layer(0)
  192.     _PUTIMAGE (1, 0), Layer(1), Layer(2), (1, 0)-(319, 199)
  193.     _PUTIMAGE (310, 140), Layer(3), Layer(2), (0, 0)-STEP(7, 30) 'target
  194.     _CLEARCOLOR _RGB32(0, 0, 0), Layer(2)
  195.     ClearLayer Layer(1)
  196.  
  197. SUB Game_Option_Screen
  198.     _DEST Layer(5)
  199.     _FONT 8
  200.     COLOR OffWhite
  201.     PRINT "Instructions": PRINT
  202.     PRINT " Score as many  points as  possible by"
  203.     PRINT "  hitting  the   target  close  to  the"
  204.     PRINT "  center. Press the space bar to shoot."
  205.     PRINT "  You get three trys from each of  five"
  206.     PRINT "  sites, highest score wins."
  207.     PRINT
  208.     PushScreen 5
  209.     _DELAY 3
  210.     PRINT: PRINT: PRINT
  211.     PRINT "Number of Players(1/2)?"
  212.     PushScreen 5
  213.     DO: kbd$ = INKEY$: LOOP UNTIL kbd$ = "1" OR kbd$ = "2"
  214.     Flag = Flag + VAL(kbd$) 'Flag = Flag + 2 ^ (VAL(kbd$) - 1) 'set bit 0 if 1 player, bit 1 for 2 player
  215.  
  216.     PRINT: PRINT "Enter player one's name :?"
  217.     PushScreen 5
  218.     Player$(0) = Get_Player_Name(0)
  219.     _PRINTSTRING (212, 104), Player$(0)
  220.  
  221.     IF Flag AND 2 THEN
  222.         PRINT: PRINT "Enter player two's name :?"
  223.         PushScreen 5
  224.         Player$(1) = Get_Player_Name(1)
  225.         _PRINTSTRING (212, 120), Player$(1)
  226.     ELSE
  227.         PRINT: PRINT " Do you play against computer?"
  228.         PushScreen 5
  229.         DO: kbd$ = LCASE$(INKEY$): LOOP UNTIL kbd$ = "y" OR kbd$ = "n"
  230.         IF kbd$ = "y" THEN
  231.             Flag = 4: Player$(1) = "Computer"
  232.         ELSE
  233.             Player$(1) = "Nobody"
  234.         END IF
  235.     END IF
  236.     _FONT 16
  237.     _DEST Layer(0)
  238.     ClearLayer Layer(1)
  239.  
  240. FUNCTION Get_Player_Name$ (Who%%)
  241.     DO
  242.         kbd$ = INKEY$
  243.         IF LEN(Result$) < 8 AND kbd$ >= CHR$(32) THEN Result$ = Result$ + kbd$
  244.         IF kbd$ = CHR$(8) THEN Result$ = LEFT$(Result$, LEN(Result$) - 1)
  245.         IF Who%% THEN _PRINTSTRING (212, 120), Result$ ELSE _PRINTSTRING (212, 104), Result$
  246.         PushScreen 5
  247.         _DELAY .025
  248.         IF Who%% THEN LINE (212, 120)-STEP(72, 8), Black, BF ELSE LINE (212, 104)-STEP(72, 8), Black, BF
  249.     LOOP UNTIL kbd$ = CHR$(13)
  250.     IF Result$ = "" THEN Result$ = "Anonim" ' fine to be Anonimous for self_privacy
  251.     Get_Player_Name = Result$
  252.  
  253. SUB Move_Target
  254.     Target.Y = Target.Y + Target.Speed
  255.     _PUTIMAGE (Target.X, Target.Y), Layer(3), Layer(6), (0, 0)-STEP(8, 30) 'target
  256.     'collision layer
  257.     ClearLayer Layer(4)
  258.     _PUTIMAGE (Target.X, Target.Y), Layer(3), Layer(4), (0, 0)-STEP(8, 30) 'target
  259.     _PUTIMAGE (318, 0)-STEP(1, 199), Layer(5), Layer(4), (319, 0)-(319, 199) 'target
  260.  
  261. SUB Move_Arrow
  262.     Arrow.X = Arrow.X + Arrow.Speed
  263.     _PUTIMAGE (Arrow.X, Arrow.Y), Layer(3), Layer(6), (0, 32)-STEP(24, 6) 'arrow
  264.  
  265. SUB PushScreen (id%%)
  266.     _PUTIMAGE (0, 0)-STEP(639, 399), Layer(id%%), Layer(1), (0, 0)-STEP(319, 199)
  267.     _PUTIMAGE , Layer(1), Layer(0)
  268.  
  269. SUB Reset_Shot (Shot%%, Shoot%%, Hit~%%)
  270.     STATIC Flight%%, Frame%%, Player%%
  271.     '-------assign score-------
  272.     Shots(Player%%, Frame%%, Flight%%) = Hit~%% MOD 16
  273.     '--------------------------
  274.     '-----increment flight-----
  275.     Flight%% = Flight%% + 1
  276.     IF Flight%% = 3 THEN '3 flights per frame
  277.         IF Flag AND 1 THEN
  278.             Frame%% = Frame%% + 1: Flight%% = 0: New_Site
  279.         END IF
  280.         IF Flag AND 2 OR Flag AND 4 THEN 'is there a second player or computer?
  281.             IF Player%% THEN 'player 2 just loosed, next frame for player 1
  282.                 Player%% = 0: Frame%% = Frame%% + 1: Flight%% = 0: New_Site: Turn%% = TRUE
  283.             ELSE 'let player 2 loose his first frame
  284.                 IF Flag AND 4 THEN Turn%% = FALSE
  285.                 Player%% = 1: Flight%% = 0
  286.             END IF
  287.         END IF
  288.     END IF
  289.     '--------------------------
  290.     Target.Y = Target.OrigY
  291.     Target.Speed = 1
  292.     Arrow.Y = Arrow.OrigY
  293.     Arrow.X = Arrow.OrigX
  294.     Shot%% = FALSE
  295.     Shoot%% = FALSE
  296.     IF Frame%% = 5 THEN Hit~%% = 99 ELSE Hit~%% = 0 'end game trigger
  297.     Noise%% = Computer_AI 'adds little randomness to computer shots
  298.     Playing = Player%%
  299.  
  300. FUNCTION Computer_AI%% ()
  301.     Result%% = 0
  302.     SELECT CASE Computer.Class
  303.         CASE 1 'basic
  304.             Result%% = INT(RND * 28) - 10
  305.         CASE 2 'decent
  306.             Result%% = INT(RND * 24) - 8
  307.         CASE 3 'good
  308.             Result%% = INT(RND * 20) - 6
  309.         CASE 4 'hard
  310.             Result%% = INT(RND * 16) - 4
  311.         CASE 5 'Robin Hood unbeatable 150!
  312.             IF Arrow.OrigX MOD 2 THEN Result%% = 5 ELSE Result%% = 6
  313.     END SELECT
  314.     Computer_AI%% = Result%%
  315.  
  316. SUB Scoreboard_Setup
  317.     ClearLayer Layer(5)
  318.     _DEST Layer(5)
  319.     _FONT 8
  320.     COLOR OffWhite
  321.     LINE (1, 1)-STEP(300, 84), Cyan, B
  322.     LINE (2, 2)-STEP(298, 82), Magenta, B
  323.     LINE (3, 3)-STEP(296, 80), OffWhite, B
  324.     LINE (4, 4)-STEP(294, 78), Black, BF
  325.     LOCATE 2, 2: PRINT "Player    #1  #2  #3  #4  #5  Total"
  326.     LOCATE 4, 3: PRINT Player$(0)
  327.     LOCATE 8, 3: PRINT Player$(1)
  328.     LINE (319, 0)-(319, 199), Green, BF
  329.     _FONT 16
  330.     _DEST Layer(0)
  331.  
  332. SUB Title_Animation
  333.     _DEST Layer(5)
  334.     COLOR OffWhite
  335.     _DEST Layer(0)
  336.     _PRINTSTRING (4, 0), "UniKorn", Layer(5)
  337.     _PRINTSTRING (36, 16), "ProDucKions", Layer(5)
  338.     _PUTIMAGE (0, 0)-STEP(639, 400), Layer(5), Layer(1), (0, 0)-STEP(125, 39)
  339.     _PUTIMAGE (0, 0)-STEP(639, 399), Layer(1), Layer(0)
  340.     _PRINTSTRING (290, 350), "Presents", Layer(0)
  341.     _DELAY 2.5
  342.     ClearLayer Layer(5)
  343.     CLS
  344.     _PUTIMAGE (7 + i%, 152), Layer(3), Layer(5), (0, 32)-STEP(24, 6) 'arrow
  345.     _PUTIMAGE , Layer(2), Layer(5)
  346.     _PUTIMAGE (0, 0)-STEP(639, 399), Layer(5), Layer(1)
  347.     _PUTIMAGE , Layer(1), Layer(0)
  348.     _DELAY 1.5
  349.     FOR i% = 0 TO 279 STEP 2
  350.         _DELAY .02
  351.         _PUTIMAGE (8 + i%, 152), Layer(3), Layer(5), (0, 32)-STEP(24, 6) 'arrow
  352.         _PUTIMAGE , Layer(2), Layer(5) 'title layer
  353.         _PUTIMAGE (0, 0)-STEP(639, 399), Layer(5), Layer(1)
  354.         _PUTIMAGE , Layer(1), Layer(0)
  355.         ClearLayer Layer(5)
  356.     NEXT i%
  357.     PLAY HitSound$
  358.     _DELAY 1.5
  359.     _DEST Layer(0)
  360.     CLS
  361.  
  362. FUNCTION Collision_Check~%% (X%, Y%)
  363.     IF _SOURCE <> Layer(4) THEN _SOURCE Layer(4)
  364.     Result~%% = 0
  365.     FOR I%% = 0 TO 1
  366.         Test~& = POINT(25 + X% + I%%, Y% + 3)
  367.         R~%% = _RED32(Test~&)
  368.         IF R~%% = 255 THEN R~%% = 1
  369.         IF R~%% > 0 THEN Result~%% = R~%%: I%% = 5
  370.     NEXT I%%
  371.     Collision_Check = Result~%%
  372.  
  373. SUB New_Site
  374.     Arrow.OrigX = INT(RND * 240) + 10
  375.     Arrow.OrigY = INT(RND * 50) + 120
  376.  
Programming isn't difficult, only it's  consuming time and coffee