Author Topic: _PUT Rotation Help  (Read 241 times)

Offline Zeppelin

  • Newbie
  • Posts: 43
    • Zeppelin Games ItchIo
_PUT Rotation Help
« on: December 05, 2019, 05:51:00 PM »
Hey Everyone,
Here's a piece I've been working on for awhile now but in the Infinite sub I'm trying to get the 'sword' to make a full rotation and end up under the character during the jump, but it seems to just keep spinning and stopping at random points. Not too sure what I'm doing wrong.
 
Code: QB64: [Select]
  1. '+-------------------+
  2. '        SLAY
  3. ' ZEPPELIN GAMES 2019
  4. '+-------------------+
  5.  
  6. _TITLE "SLAY" 'SET TITLE
  7. _FULLSCREEN 'SET FULLSCREEN
  8. SCREEN _NEWIMAGE(1200, 800, 32)
  9.  
  10. 'DECLARE VARIABLES
  11. 'SAVE DATA VARS
  12. DIM SHARED saveData$(1000)
  13.  
  14. 'PLAYER VARS
  15. DIM SHARED player%(100000)
  16. DIM SHARED sword%(100000)
  17. DIM SHARED player.health AS INTEGER
  18. DIM SHARED player.basehealth AS INTEGER
  19. DIM SHARED playerScale AS INTEGER
  20. playerScale = 15
  21.  
  22.  
  23. 'PLAYER STATS
  24. DIM SHARED stats.enemyskilled AS INTEGER
  25. DIM SHARED stats.totaldeaths AS INTEGER
  26.  
  27. 'SCREEN AND FORMATTING VARS
  28.  
  29.  
  30. 'GET THE SCREEN DIMSENSIONS
  31. w = _WIDTH
  32.  
  33. 'FONT DATA
  34.  
  35. 'SET THE COLOR
  36. col = _RGBA(255, 255, 255, 255)
  37.  
  38. 'START GAME
  39. LoadData
  40.  
  41. SUB LoadData
  42.     'LOAD SAVE DATA
  43.  
  44.     'LOAD PLAYER SPRITE
  45.     LoadSprite player%(), playerScale
  46.     LoadSprite sword%(), playerScale / 1.2
  47.  
  48.     IF _FILEEXISTS("SlayV4SaveData.txt") THEN 'SEE IF THE FILE EXISTS
  49.         OPEN "SlayV4SaveData.txt" FOR INPUT AS #1
  50.         DO UNTIL EOF(1) 'LOOP UNTIL END OF FILE
  51.             _LIMIT 60
  52.             filecount = filecount + 1 'COUNT AMOUNT OF LINES
  53.             LINE INPUT #1, file$
  54.             saveData$(filecount) = file$
  55.         LOOP
  56.         CLOSE #1
  57.  
  58.         IF filecount > 2 THEN
  59.             'PLAYER
  60.  
  61.             'DECRYPT NAME
  62.             NAME$ = ""
  63.             FOR n = 1 TO LEN(saveData$(1)) STEP 2
  64.                 NAME$ = NAME$ + CHR$(ASC(MID$(saveData$(1), n, 1)) - 4)
  65.             NEXT n
  66.  
  67.             'DECRYPT STATS
  68.             'HEALTH
  69.             health$ = ""
  70.             FOR n = 1 TO LEN(saveData$(2)) STEP 2
  71.                 health$ = health$ + CHR$(ASC(MID$(saveData$(2), n, 1)) - 4)
  72.             NEXT n
  73.  
  74.             player.NAME = UCASE$(NAME$) 'LOAD NAME
  75.             player.basehealth = VAL(health$) 'LOAD BASE HEALTH
  76.             player.health = player.basehealth 'SET PLAYER HEALTH
  77.             'SAVE DATA
  78.             save.POINT = VAL(saveData$(3)) 'LOAD SAVE POINT
  79.             'STATS
  80.             stats.enemyskilled = VAL(saveData$(4)) 'ENEMYS KILLED
  81.             stats.totaldeaths = VAL(saveData$(5)) 'TOTAL DEATHS
  82.         ELSE
  83.             CreateNewSave
  84.         END IF
  85.     ELSE
  86.         CreateNewSave
  87.     END IF
  88.  
  89.     'START GAME
  90.     _DELAY (1)
  91.     DrawLogo
  92.  
  93. SUB CreateNewSave
  94.     'CREATE NEW SAVE FILE
  95.     scaledText w / 2 - 65, h / 2 + 8, 16, _RGBA(255, 255, 255, 255), "Enter your name: "
  96.     DO
  97.         _LIMIT 60
  98.         LOCATE (h / 2 - 248) / fh + hf, (w / 2 - 50) / fw + fw: INPUT "", NAME$
  99.     LOOP UNTIL LEN(NAME$) > 1
  100.     IF LEN(NAME$) > 16 THEN
  101.         CLS
  102.         _PRINTSTRING (w / 2 - 150, h / 2), "Name length should be less than 16 characters"
  103.         _DELAY (2)
  104.         CLS
  105.         LoadData
  106.     END IF
  107.  
  108.     'SET VARS
  109.     player.NAME = UCASE$(NAME$)
  110.     player.health = 100
  111.  
  112.     save.POINT = 0
  113.     stats.enemyskilled = 0
  114.     stats.totaldeaths = 0
  115.  
  116.     'ENCRYPT SAVE DATA
  117.     'NAME
  118.     DIM nameArray$(16)
  119.     FOR n = 1 TO LEN(player.NAME)
  120.         nameArray$(n) = MID$(player.NAME, n, 1)
  121.     NEXT n
  122.  
  123.     FOR n = 1 TO LEN(player.NAME)
  124.         tempName$ = tempName$ + CHR$(ASC(nameArray$(n)) + 4)
  125.         tempName$ = tempName$ + CHR$(INT(RND * 100) + 100)
  126.     NEXT n
  127.  
  128.     NAME$ = tempName$
  129.  
  130.     'ENCRYPT STATS
  131.     'HEALTH
  132.     DIM healthArray$(5)
  133.     FOR n = 1 TO LEN(STR$(player.health))
  134.         healthArray$(n) = MID$(STR$(player.health), n, 1)
  135.     NEXT n
  136.  
  137.     FOR n = 1 TO LEN(STR$(player.health))
  138.         tempHealth$ = tempHealth$ + CHR$(ASC(healthArray$(n)) + 4)
  139.         tempHealth$ = tempHealth$ + CHR$(INT(RND * 100) + 100)
  140.     NEXT n
  141.  
  142.     'SAVE VARS TO TXT
  143.     OPEN "SlayV4SaveData.txt" FOR OUTPUT AS #1
  144.     'PLAYER
  145.     PRINT #1, NAME$
  146.     PRINT #1, tempHealth$
  147.     'SAVE DATA
  148.     PRINT #1, save.POINT
  149.     'STATS
  150.     PRINT #1, stats.enemyskilled
  151.     PRINT #1, stats.totaldeaths
  152.     CLOSE #1
  153.     CLS
  154.  
  155. SUB DrawLogo
  156.     'FADE LOGO IN
  157.     FOR n = 0 TO 255
  158.         'LIMIT FPS
  159.         _LIMIT 60
  160.  
  161.         LINE (w / 10 * 2, h / 10 * 7)-(w / 10 * 8, h / 10 * 8), _RGB(0, 0, 0), BF
  162.         scaledText w / 2, h / 2, 500, _RGBA32(255, 255, 255, n), "Z"
  163.         scaledText w / 2, h / 6 * 4.5, 50, _RGBA(255, 255, 255, n), "ZEPPELIN GAMES"
  164.         _DISPLAY
  165.     NEXT n
  166.  
  167.     scaledText w / 2, h / 2, 500, _RGBA32(255, 255, 255, 255), "Z"
  168.     scaledText w / 2, h / 6 * 4.5, 50, _RGBA32(255, 255, 255, 255), "ZEPPELIN GAMES"
  169.     _DISPLAY
  170.     _DELAY (3) 'WAIT A BIT
  171.  
  172.     'FADE THE LOGO AND TEXT OUT
  173.     FOR n = 0 TO 255
  174.         'LIMIT FPS
  175.         _LIMIT 60
  176.  
  177.         LINE (w / 10 * 2, h / 10 * 7)-(w / 10 * 8, h / 10 * 8), _RGB(0, 0, 0), BF
  178.         scaledText w / 2, h / 2, 500, _RGBA32(255, 255, 255, 255 - n), "Z"
  179.         scaledText w / 2, h / 6 * 4.5, 50, _RGBA(255, 255, 255, 255 - n), "ZEPPELIN GAMES"
  180.         _DISPLAY
  181.     NEXT n
  182.     CLS
  183.     _DISPLAY
  184.     DrawMenu
  185.  
  186. SUB DrawMenu
  187.     'FADE IN MENU SCREEN
  188.     DIM col AS LONG
  189.     col = _RGBA(255, 255, 255, 255)
  190.     'S
  191.     LINE (w / 10 * 2.75, h / 10 * 1.5)-(w / 10 * 3.5, h / 10 * 1.75), col, BF '1ST ACROSS
  192.     LINE (w / 10 * 2.75, h / 10 * 1.5)-(w / 10 * 3, h / 10 * 2.5), col, BF '1ST DOWN
  193.     LINE (w / 10 * 2.75, h / 10 * 2.5)-(w / 10 * 3.45, h / 10 * 2.75), col, BF '2ND ACROSS
  194.     LINE (w / 10 * 3.2, h / 10 * 2.75)-(w / 10 * 3.45, h / 10 * 2.9), col, BF '2ND DOWN
  195.     LINE (w / 10 * 3.2, h / 10 * 3.35)-(w / 10 * 3.45, h / 10 * 3.75), col, BF 'EXTENDED 2ND DOWN
  196.     LINE (w / 10 * 2.65, h / 10 * 3.75)-(w / 10 * 3.45, h / 10 * 4.1), col, BF '3RD ACROSS
  197.  
  198.     'L
  199.     LINE (w / 10 * 3.8, h / 10 * 1.5)-(w / 10 * 4.05, h / 10 * 2.65), col, BF '1ST DOWN
  200.     LINE (w / 10 * 3.8, h / 10 * 3.6)-(w / 10 * 4.05, h / 10 * 3.75), col, BF 'EXTENDED 1ST DOWN
  201.     LINE (w / 10 * 3.8, h / 10 * 3.75)-(w / 10 * 4.6, h / 10 * 4.1), col, BF '1ST ACROSS
  202.  
  203.     'A
  204.     LINE (w / 10 * 4.85, h / 10 * 1.5)-(w / 10 * 5.1, h / 10 * 2.7), col, BF 'LEFT DOWN
  205.     LINE (w / 10 * 4.85, h / 10 * 1.5)-(w / 10 * 5.75, h / 10 * 1.8), col, BF 'TOP LINE
  206.     LINE (w / 10 * 5.5, h / 10 * 1.5)-(w / 10 * 5.75, h / 10 * 2.7), col, BF 'RIGHT DOWN
  207.     LINE (w / 10 * 5.55, h / 10 * 1.5)-(w / 10 * 5.75, h / 10 * 2.9), col, BF 'RIGHT DOWN EDGE
  208.     LINE (w / 10 * 4.85, h / 10 * 2.4)-(w / 10 * 5.75, h / 10 * 2.65), col, BF 'MIDDLE LINE
  209.     LINE (w / 10 * 4.85, h / 10 * 3.5)-(w / 10 * 5.1, h / 10 * 4.1), col, BF 'EXTENDED LEFT DOWN
  210.     LINE (w / 10 * 5.5, h / 10 * 3.5)-(w / 10 * 5.75, h / 10 * 4.1), col, BF 'EXTENDED RIGHT DOWN
  211.     LINE (w / 10 * 5.55, h / 10 * 3.35)-(w / 10 * 5.75, h / 10 * 4.1), col, BF 'EXTENDED RIGHT DOWN EDGE
  212.  
  213.     'Y
  214.     LINE (w / 10 * 6, h / 10 * 1.5)-(w / 10 * 6.25, h / 10 * 2.75), col, BF 'LEFT DOWN
  215.     LINE (w / 10 * 6.75, h / 10 * 1.5)-(w / 10 * 7, h / 10 * 3), col, BF 'RIGHT DOWN
  216.     LINE (w / 10 * 6, h / 10 * 2.5)-(w / 10 * 7, h / 10 * 2.85), col, BF '1ST ACROSS
  217.     LINE (w / 10 * 6.75, h / 10 * 3.25)-(w / 10 * 7, h / 10 * 4.1), col, BF 'EXTENDED RIGHT DOWN
  218.     LINE (w / 10 * 6, h / 10 * 3.8)-(w / 10 * 7, h / 10 * 4.1), col, BF 'BOTTOM LINE
  219.  
  220.     'SWORD
  221.     LINE (w / 10 * 3, h / 10 * 3)-(w / 10 * 6.5, h / 10 * 3.25), col, BF 'HILT
  222.     LINE (w / 10 * 3.5, h / 10 * 2.5)-(w / 10 * 3.75, h / 10 * 3.75), col, BF 'Hand Guard
  223.     LINE (w / 10 * 3.75, h / 10 * 2.75)-(w / 10 * 4.75, h / 10 * 3.50), col, BF 'Blade First Layer
  224.     LINE (w / 10 * 4.75, h / 10 * 2.85)-(w / 10 * 5.5, h / 10 * 3.4), col, BF 'Blade 2nd Layer
  225.     LINE (w / 10 * 5.5, h / 10 * 3.10)-(w / 10 * 7, h / 10 * 3.15), col, BF 'Tip of Blade
  226.  
  227.     col = _RGBA(0, 0, 0, 255)
  228.     LINE (w / 10, h / 10 * 4.5)-(w, h / 10 * 7), col, BF 'CLEAR OPTIONS
  229.  
  230.     'SHOW ACCOUNT
  231.     _PRINTSTRING (5, 5), player.NAME
  232.  
  233.     'PRINT MENU OPTIONS
  234.     scaledText w / 2, h / 10 * 4.75, 25, _RGBA(255, 255, 255, 255), "SINGLE-PLAYER"
  235.     scaledText w / 2, h / 10 * 5.25, 25, _RGBA(255, 255, 255, 255), "MULTI-PLAYER"
  236.     scaledText w / 2, h / 10 * 5.75, 25, _RGBA(255, 255, 255, 255), "OPTIONS"
  237.     scaledText w / 2, h / 10 * 6.25, 25, _RGBA(255, 255, 255, 255), "QUIT"
  238.     scaledText w / 2, h / 10 * 9.5, 14, _RGBA(255, 255, 255, 255), "TIP: USE 'w' AND 's' TO NAVIGATE. PRESS 'ENTER' TO SELCT"
  239.  
  240.     'PICK MENU OPTION
  241.     opt = 0
  242.     col = _RGBA(0, 0, 0, 255)
  243.     DO
  244.         _LIMIT 60
  245.         LINE (w / 2 - 90, h / 10 * 4.5)-(w / 2 - 110, h / 10 * 7), col, BF 'CLEAR PAST POINTERS
  246.         _PRINTSTRING (w / 2 - 100, h / 10 * (4.6 + (0.52 * opt))), ">" 'DISPLAY POINTER
  247.         _DISPLAY 'REDUCE FLICKERING
  248.  
  249.         SELECT CASE INKEY$
  250.             CASE "s", "S" 'MOVE POINTER DOWN
  251.                 IF opt + 1 = 4 THEN
  252.                     opt = 0
  253.                 ELSE
  254.                     opt = opt + 1
  255.                 END IF
  256.  
  257.             CASE "w", "W" 'MOVE POINTER UP
  258.                 IF opt - 1 = -1 THEN
  259.                     opt = 3
  260.                 ELSE
  261.                     opt = opt - 1
  262.                 END IF
  263.  
  264.             CASE CHR$(13) 'ENTER KEY
  265.                 'SINGLE-PLAYER SELECTED
  266.                 IF opt = 0 THEN
  267.                     SinglePlayerMenu
  268.                 END IF
  269.  
  270.                 'MULTI-PLAYER SELECTED
  271.                 IF opt = 1 THEN
  272.                     MultiplayerGameMenu
  273.                 END IF
  274.  
  275.                 'OPTIONS SELETED
  276.                 IF opt = 2 THEN
  277.                     OptionsMenu
  278.                 END IF
  279.  
  280.                 'QUIT SELECTED
  281.                 IF opt = 3 THEN
  282.                     SYSTEM
  283.                 END IF
  284.         END SELECT
  285.     LOOP
  286.  
  287.  
  288. SUB OptionsMenu
  289.     LINE (w / 10, h / 10 * 4.5)-(w, h / 10 * 7), col, BF 'CLEAR OPTIONS
  290.     scaledText w / 2, h / 10 * 4.75, 25, _RGBA(255, 255, 255, 255), "INFO"
  291.     scaledText w / 2, h / 10 * 5.25, 25, _RGBA(255, 255, 255, 255), "RESET GAME"
  292.     scaledText w / 2, h / 10 * 5.75, 25, _RGBA(255, 255, 255, 255), "BACK"
  293.     scaledText w / 2, h / 10 * 9.5, 14, _RGBA(255, 255, 255, 255), "TIP: USE 'w' AND 's' TO NAVIGATE. PRESS 'ENTER' TO SELCT"
  294.  
  295.     opt = 0
  296.     DO
  297.         _LIMIT 60
  298.         LINE (w / 2 - 90, h / 10 * 4.5)-(w / 2 - 110, h / 10 * 7), col, BF 'CLEAR PAST POINTERS
  299.         _PRINTSTRING (w / 2 - 100, h / 10 * (4.6 + (0.52 * opt))), ">" 'DISPLAY POINTER
  300.  
  301.         _DISPLAY 'REDUCE FLICKERING
  302.  
  303.         SELECT CASE INKEY$
  304.             CASE "s", "S" 'MOVE POINTER DOWN
  305.                 IF opt + 1 = 3 THEN
  306.                     opt = 0
  307.                 ELSE
  308.                     opt = opt + 1
  309.                 END IF
  310.  
  311.             CASE "w", "W" 'MOVE POINTER UP
  312.                 IF opt - 1 = -1 THEN
  313.                     opt = 2
  314.                 ELSE
  315.                     opt = opt - 1
  316.                 END IF
  317.             CASE CHR$(13) 'ENTER PRESSED
  318.                 IF opt = 0 THEN 'GAME INFO
  319.                     LINE (0, h / 10 * 4.7)-(w, h), col, BF 'CLEAR OPTIONS
  320.                     scaledText w / 2, h / 10 * 4.75, 25, _RGBA(255, 255, 255, 255), "ZEPPELIN GAMES 2018"
  321.                     scaledText w / 2, h / 10 * 5.25, 25, _RGBA(255, 255, 255, 255), "SLAY V4"
  322.                     scaledText w / 2, h / 10 * 6.25, 25, _RGBA(255, 255, 255, 255), "ENEMIES KILLED: " + STR$(stats.enemyskilled)
  323.                     scaledText w / 2, h / 10 * 6.75, 25, _RGBA(255, 255, 255, 255), "TOTAL DEATHS: " + STR$(stats.totaldeaths)
  324.                     scaledText w / 2, h / 10 * 9.25, 14, _RGBA(255, 255, 255, 255), "PRESS ANY KEY TO CONTINUE"
  325.  
  326.                     _DISPLAY
  327.                     DO WHILE INKEY$ = ""
  328.                     LOOP
  329.                     LINE (0, h / 10 * 4.7)-(w, h), col, BF 'CLEAR OPTIONS
  330.                     OptionsMenu
  331.                 END IF
  332.                 IF opt = 1 THEN 'RESET GAME
  333.                     OPEN "SlayV4SaveData.txt" FOR OUTPUT AS #1
  334.                     PRINT #1, ""
  335.                     CLOSE #1
  336.                     CLS
  337.                     RUN "SLAY V4.exe"
  338.                 END IF
  339.                 IF opt = 2 THEN 'BACK
  340.                     DrawMenu
  341.                 END IF
  342.         END SELECT
  343.     LOOP
  344.  
  345. SUB SinglePlayerMenu
  346.     col = _RGBA(0, 0, 0, 255)
  347.     LINE (w / 10, h / 10 * 4.5)-(w, h / 10 * 7), col, BF 'CLEAR OPTIONS
  348.     scaledText w / 2, h / 10 * 4.75, 25, _RGBA(255, 255, 255, 255), "CAMPAIGN"
  349.     scaledText w / 2, h / 10 * 5.25, 25, _RGBA(255, 255, 255, 255), "INFINITE"
  350.     scaledText w / 2, h / 10 * 5.75, 25, _RGBA(255, 255, 255, 255), "BACK"
  351.     scaledText w / 2, h / 10 * 9.5, 14, _RGBA(255, 255, 255, 255), "TIP: USE 'w' AND 's' TO NAVIGATE. PRESS 'ENTER' TO SELCT"
  352.  
  353.     opt = 0
  354.     DO
  355.         _LIMIT 60
  356.         LINE (w / 2 - 90, h / 10 * 4.5)-(w / 2 - 110, h / 10 * 7), col, BF 'CLEAR PAST POINTERS
  357.         _PRINTSTRING (w / 2 - 100, h / 10 * (4.6 + (0.52 * opt))), ">" 'DISPLAY POINTER
  358.  
  359.         _DISPLAY 'REDUCE FLICKERING
  360.  
  361.         SELECT CASE INKEY$
  362.             CASE "s", "S" 'MOVE POINTER DOWN
  363.                 IF opt + 1 = 3 THEN
  364.                     opt = 0
  365.                 ELSE
  366.                     opt = opt + 1
  367.                 END IF
  368.  
  369.             CASE "w", "W" 'MOVE POINTER UP
  370.                 IF opt - 1 = -1 THEN
  371.                     opt = 2
  372.                 ELSE
  373.                     opt = opt - 1
  374.                 END IF
  375.             CASE CHR$(13) 'ENTER PRESSED
  376.                 IF opt = 0 THEN
  377.                     Campaign
  378.                 END IF
  379.                 IF opt = 1 THEN
  380.                     Infinite
  381.                 END IF
  382.                 IF opt = 2 THEN
  383.                     DrawMenu
  384.                 END IF
  385.         END SELECT
  386.     LOOP
  387.  
  388. 'CAMPAIGN - STORY
  389. SUB Campaign
  390.  
  391.  
  392. 'PRACTICE - GAMEMODE
  393. SUB Infinite
  394.     CLS
  395.     'DEFINE LOCAL VARS
  396.  
  397.     DIM health
  398.     DIM deltaTime
  399.  
  400.     DIM swordX
  401.     DIM swordY
  402.  
  403.     DIM swing
  404.     DIM angle
  405.  
  406.     playerSpeed = 500
  407.     jumpHeight = 150
  408.     health = 100
  409.     jump = 0
  410.     pX = _WIDTH / 2 - (playerScale * 2.5)
  411.     pY = _HEIGHT / 10 * 8
  412.  
  413.     swordX = pX
  414.     swordY = pY + (playerScale * 5)
  415.  
  416.     sTime = TIMER
  417.  
  418.     DO
  419.         _LIMIT 120
  420.         sTime = TIMER(0.001)
  421.         IF _KEYDOWN(100) THEN
  422.             pX = pX + playerSpeed / 100
  423.             IF pX > _WIDTH - (playerScale * 12) - 1 THEN pX = _WIDTH - (playerScale * 12) - 1
  424.         END IF
  425.         IF _KEYDOWN(97) THEN
  426.             pX = pX - playerSpeed / 100
  427.             IF pX < (playerScale * 12) THEN pX = (playerScale * 12)
  428.         END IF
  429.         IF _KEYDOWN(32) THEN
  430.             IF jump = 0 THEN
  431.                 jump = 1
  432.             END IF
  433.         END IF
  434.  
  435.         IF jump >= 1 THEN
  436.             IF pY > ((_HEIGHT / 10) * 8) - jumpHeight AND NOT jump = 2 THEN
  437.                 pY = pY - playerSpeed / 100
  438.  
  439.                 'Spin Sword
  440.                 swing = 1
  441.                 swordX = pX + ((playerScale * 6) * COS(_D2R(angle)))
  442.                 swordY = pY + ((playerScale * 6) * SIN(_D2R(angle)))
  443.             ELSE
  444.  
  445.                 IF pY <= (_HEIGHT / 10) * 8 THEN
  446.                     jump = 2
  447.                     pY = pY + playerSpeed / 100
  448.  
  449.                     'Spin Sword
  450.                     swing = 1
  451.                     swordX = pX + ((playerScale * 6) * COS(_D2R(angle)))
  452.                     swordY = pY + ((playerScale * 6) * SIN(_D2R(angle)))
  453.  
  454.                 ELSE
  455.                     jump = 0
  456.                     swing = 0
  457.                     pY = (_HEIGHT / 10) * 8
  458.                 END IF
  459.             END IF
  460.         END IF
  461.  
  462.         IF swing = 1 THEN
  463.             angle = angle + (jumpHeight / 100)
  464.         END IF
  465.  
  466.         LINE (pX - (playerScale * 10) - 10, pY - (playerScale * 12) - 10)-(pX + ((playerScale * 10) * 2) + 10, pY + (playerScale * 10) + 10), _RGB(0, 0, 0), BF
  467.  
  468.         PUT (pX, pY), player%()
  469.         PUT (swordX, swordY), sword%()
  470.         _DISPLAY
  471.  
  472.         eTime = TIMER(0.001)
  473.         deltaTime = eTime - sTime
  474.  
  475.     LOOP UNTIL health <= 0 OR INKEY$ = CHR$(27)
  476.     CLS
  477.     SaveGame
  478.     DrawMenu
  479.  
  480. 'MULTIPLAYER GAME MENU
  481. SUB MultiplayerGameMenu
  482.     LINE (w / 10, h / 10 * 4.7)-(w, h / 10 * 7), col, BF 'CLEAR OPTIONS
  483.     _PRINTSTRING (w / 2 - 40, h / 10 * 4.75), "LOCAL"
  484.     _PRINTSTRING (w / 2 - 34, h / 10 * 5.25), "LAN"
  485.     _PRINTSTRING (w / 2 - 37, h / 10 * 5.75), "BACK"
  486.  
  487.     opt = 0
  488.     DO
  489.         LINE (w / 2 - 58, h / 10 * 4.7)-(w / 2 - 70, h / 10 * 7), col, BF 'CLEAR PAST POINTERS
  490.         _PRINTSTRING (w / 2 - 65, h / 10 * (4.75 + (0.5 * opt))), ">" 'DISPLAY POINTER
  491.  
  492.         _DISPLAY 'REDUCE FLICKERING
  493.  
  494.         SELECT CASE INKEY$
  495.             CASE "s" 'MOVE POINTER DOWN
  496.                 IF opt + 1 = 3 THEN
  497.                     opt = 0
  498.                 ELSE
  499.                     opt = opt + 1
  500.                 END IF
  501.  
  502.             CASE "w" 'MOVE POINTER UP
  503.                 IF opt - 1 = -1 THEN
  504.                     opt = 2
  505.                 ELSE
  506.                     opt = opt - 1
  507.                 END IF
  508.             CASE CHR$(13) 'ENTER KEY
  509.                 IF opt = 0 THEN
  510.                     LocalMultiplayer
  511.                 ELSEIF opt = 1 THEN
  512.                     LANMultiplayer
  513.                 ELSEIF opt = 2 THEN
  514.                     DrawMenu
  515.                 END IF
  516.         END SELECT
  517.     LOOP UNTIL INKEY$ = CHR$(13)
  518.  
  519.  
  520. 'MULTIPLAYER ON SAME DEVICE
  521. SUB LocalMultiplayer
  522.  
  523.  
  524. 'MULTIPLAYER OVER WIFI CONNECTION
  525. SUB LANMultiplayer
  526.  
  527.  
  528.  
  529. SUB SaveGame
  530.     'SAVE VARS TO TXT
  531.     OPEN "SlayV4SaveData.txt" FOR OUTPUT AS #1
  532.     'PLAYER
  533.     PRINT #1, NAME$
  534.     PRINT #1, player.health
  535.     'SAVE DATA
  536.     PRINT #1, save.POINT
  537.     'STATS
  538.     PRINT #1, stats.enemyskilled
  539.     PRINT #1, stats.totaldeaths
  540.     CLOSE #1
  541.  
  542. SUB LoadSprite (sp%(), scale)
  543.     DIM sprite(4, 4)
  544.     FOR y = 0 TO 4
  545.         FOR x = 0 TO 4
  546.             READ sprite(x, y) 'Read the data
  547.         NEXT x
  548.     NEXT y
  549.  
  550.     FOR y = 0 TO 4 * scale STEP scale 'Factor in the scale
  551.         FOR x = 0 TO 4 * scale STEP scale
  552.             spriteCol = sprite(x / scale, y / scale)
  553.             LINE (x, y)-(x + scale, y + scale), _RGB(spriteCol * 255, spriteCol * 255, spriteCol * 255), BF 'Draw each pixel
  554.         NEXT x
  555.     NEXT y
  556.  
  557.     GET (0, 0)-(scale * 5, scale * 5), sp%()
  558.     CLS
  559.  
  560.     'Player Data
  561.     DATA 0,1,1,1,0
  562.     DATA 0,1,1,1,0
  563.     DATA 1,1,1,1,1
  564.     DATA 0,1,1,1,0
  565.     DATA 0,1,0,1,0
  566.  
  567.     'Sword Data
  568.     DATA 0,0,1,0,0
  569.     DATA 1,1,1,1,1
  570.     DATA 0,1,1,1,0
  571.     DATA 0,1,1,1,0
  572.     DATA 0,0,1,0,0
  573.  
  574. SUB scaledText (x, y, textHeight, K AS _UNSIGNED LONG, txt$)
  575.     fg = _DEFAULTCOLOR
  576.     'screen snapshot
  577.     cur& = _DEST
  578.     I& = _NEWIMAGE(8 * LEN(txt$), 16, 32)
  579.     _DEST I&
  580.     COLOR K, _RGBA32(0, 0, 0, 0)
  581.     _PRINTSTRING (0, 0), txt$
  582.     mult = textHeight / 16
  583.     xlen = LEN(txt$) * 8 * mult
  584.     _PUTIMAGE (x - .5 * xlen, y - .5 * textHeight)-STEP(xlen, textHeight), I&, cur&
  585.     COLOR fg
  586.     _FREEIMAGE I&

Thanks,
Zep
+[--->++<]>+.+++[->++++<]>.[--->+<]>+.-[---->+<]>++.+[->+++<]>+.+++++++++++.----------.[--->+<]>----.+[---->+<]>+++.---[->++++<]>.------------.+.++++++++++.+[---->+<]>+++.+[->+++<]>++.[--->+<]>+.[->+++<]>+.++++++++++.+.>++++++++++.

Offline bplus

  • Forum Resident
  • Posts: 4568
  • B+ nots
Re: _PUT Rotation Help
« Reply #1 on: December 06, 2019, 01:29:10 AM »
Hi Mark,

Never used GET and PUT but if you want to try more updated way to rotate images:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. scale = 10
  3.  
  4. DIM sprite(4, 4)
  5. FOR y = 0 TO 4
  6.     FOR x = 0 TO 4
  7.         READ sprite(x, y) 'Read the data
  8.     NEXT x
  9.  
  10. FOR y = 0 TO 4 * scale STEP scale 'Factor in the scale
  11.     FOR x = 0 TO 4 * scale STEP scale
  12.         spriteCol = sprite(x / scale, y / scale)
  13.         LINE (x, y)-(x + scale, y + scale), _RGB32(spriteCol * 255, spriteCol * 255, spriteCol * 255), BF 'Draw each pixel
  14.     NEXT x
  15. sword& = _NEWIMAGE(50, 50, 32)
  16. _PUTIMAGE , 0, sword&, (0, 0)-(scale * 5, scale * 5)
  17. FOR a = 0 TO 360
  18.     CLS
  19.     x = _WIDTH / 2 + 100 * COS(_D2R(a + 90))
  20.     y = _HEIGHT / 2 + 100 * SIN(_D2R(a + 90))
  21.     RotoZoom2 x, y, sword&, 1, 1, 2 * a
  22.     _DISPLAY
  23.     _LIMIT 60
  24. FOR a = 0 TO 360
  25.     CLS
  26.     x = _WIDTH / 2 + 100 * COS(_D2R(a + 90))
  27.     y = _HEIGHT / 2 + 100 * SIN(_D2R(a + 90))
  28.     RotoZoom2 x, y, sword&, 1, a / 360, 4 * a
  29.     _DISPLAY
  30.     _LIMIT 60
  31.  
  32. FOR a = 0 TO 360
  33.     CLS
  34.     x = _WIDTH / 2 + 100 * COS(_D2R(a + 90))
  35.     y = _HEIGHT / 2 + 100 * SIN(_D2R(a + 90))
  36.     RotoZoom2 x, y, sword&, 1 - a / 720, a / 360, 8 * a
  37.     _DISPLAY
  38.     _LIMIT 60
  39. d = 1: a = 0: l = 100
  40. WHILE _KEYDOWN(27) = 0
  41.     CLS
  42.     a = a + d
  43.     IF a > 360 THEN a = 360: d = -d
  44.     IF a < 0 THEN a = 0: d = -d
  45.     RotoZoom2 _WIDTH / 2, _HEIGHT / 2, sword&, (360 - a) / 360, 1, 1
  46.     _DISPLAY
  47.     IF l < 2000 THEN l = l * 1.5
  48.     _LIMIT l
  49.  
  50. 'Sword Data
  51. DATA 0,0,1,0,0
  52. DATA 1,1,1,1,1
  53. DATA 0,1,1,1,0
  54. DATA 0,1,1,1,0
  55. DATA 0,0,1,0,0
  56.  
  57. SUB RotoZoom2 (X AS LONG, Y AS LONG, Image AS LONG, xScale AS SINGLE, yScale, Rotation AS SINGLE)
  58.     DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
  59.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
  60.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  61.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  62.     sinr! = SIN(-Rotation / 57.2957795131): cosr! = COS(-Rotation / 57.2957795131)
  63.     FOR i& = 0 TO 3
  64.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * xScale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * yScale + Y
  65.         px(i&) = x2&: py(i&) = y2&
  66.     NEXT
  67.     _MAPTRIANGLE (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  68.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  69.  
  70.  

For Rotozoom2:
x, y places the image center
image is the handle&
On X scale: 0 to 1 and back to 0 spins on y axis,
ON Y scale: 0 to 1 and back to 0 spins on x axis
On Rotation (Degrees) : 0 to 360 and on spins on z axis
use negatives for opposite direction


Offline Zeppelin

  • Newbie
  • Posts: 43
    • Zeppelin Games ItchIo
Re: _PUT Rotation Help
« Reply #2 on: December 06, 2019, 02:08:56 AM »
Thanks bPlus,
Your method seems alot more efficient.

Zep
+[--->++<]>+.+++[->++++<]>.[--->+<]>+.-[---->+<]>++.+[->+++<]>+.+++++++++++.----------.[--->+<]>----.+[---->+<]>+++.---[->++++<]>.------------.+.++++++++++.+[---->+<]>+++.+[->+++<]>++.[--->+<]>+.[->+++<]>+.++++++++++.+.>++++++++++.