Author Topic: Need some help with player movement..  (Read 6664 times)

0 Members and 1 Guest are viewing this topic.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Need some help with player movement..
« Reply #15 on: October 11, 2019, 09:33:39 am »
so _SETBIT is one of your innovations for QB64
and I am fear that we must wait just some time before we can go on trying your code after downloading the new version of QB64 from github that has into it your innovations!

Why not make a SUB setbit? What are SUBs for anyway? I guess Cobalt is probably using C bit shifting operations but it can all be done in pure QB.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Need some help with player movement..
« Reply #16 on: October 11, 2019, 03:22:43 pm »
@Cobalt

I can confirm that the issue is the sincronization between main loop and timer's events!

Here the Petr's code example converted to use a ON TIMER.... after some attempts and a glass of beer I have understood that the difficult to pass variable SHARED to Timer subroutine is the frequency of the timer's events...

so I solve the question with code working... the key is the ratio between time interval of timer's event (in the example .3) and time of delaying the main loop (in the example .1)

Code: QB64: [Select]
  1. CONST True = -1, False = NOT True
  2. DIM SHARED character_position AS INTEGER, TileLimit AS INTEGER, char_Step AS INTEGER
  3. DIM SHARED i AS STRING 'AS INTEGER
  4.  
  5. character_position = 160
  6. TileLimit = 30
  7.  
  8.  
  9. ON TIMER(t0, .3) Make_move ' time of event must be just a little more than delay in the main loop
  10. TIMER(t0) ON
  11.  
  12. DO UNTIL i = CHR$(27)
  13.     CLS
  14.     LINE (TileLimit, 0)-(TileLimit, 300), 14
  15.     LINE (character_position, 100)-(character_position + 32, 132), , B
  16.     _KEYCLEAR ' to clear keyboard buffer
  17.     i = "" ' to return in the WHILE WEND
  18.     WHILE i = "" ' this focus on take input
  19.         i = INKEY$
  20.         char_Step = 0 ' no movement
  21.         _LIMIT 50
  22.     WEND
  23.     IF i = "a" THEN char_Step = 1 ' movement to right
  24.     IF i = "z" THEN char_Step = -1 'movement to left
  25.     _DELAY .1 ' we need this to elaborate the input
  26.  
  27. SUB Make_move
  28.  
  29.     IF LEN(i) THEN
  30.         FOR Move = 1 TO 32 'character size = 32 pixels
  31.             ' stopping if it reaches the limit of movement (border of tale or other kind of limit)
  32.             IF character_position + char_Step <> TileLimit THEN character_position = character_position + char_Step
  33.             CLS
  34.             LINE (TileLimit, 0)-(TileLimit, 300), 14
  35.             LINE (character_position, 100)-(character_position + 32, 132), , B
  36.             _DELAY .01
  37.         NEXT
  38.     END IF
  39.  

Thanks to read

@ _Vince
I agree
it is a workaround.
Programming isn't difficult, only it's  consuming time and coffee

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Need some help with player movement..
« Reply #17 on: October 11, 2019, 09:14:23 pm »
Why not make a SUB setbit? What are SUBs for anyway? I guess Cobalt is probably using C bit shifting operations but it can all be done in pure QB.

I've a whole set of BIT handling routines on the platter, just can't get into Github to see about pushing them to QB64 yet.
just for ease of use and speed. but yes they can be reproduced in house too. Although I would rather put my effort elsewhere in a program.
Granted after becoming radioactive I only have a half-life!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Need some help with player movement..
« Reply #18 on: October 11, 2019, 09:37:26 pm »
Although thanks to your guys help, in giving me ideas and things to try I think I've finally got it!!! up way too late last night working it out, but it looks like it works, I've REMed the bithandling out for now if you guys want to try it, you'll need to Re-download the GAMEDATAV1b.dat file cause I had to modify things in it. but you can roam MOST of the world until I get the entry code setup to enter caves, castles, and towns.


okay I lied, I simply deleted that routine for now. (removed stray _SETBIT)

Don't know why that was so hard for me to get the movement working, but

Thanks guys.
« Last Edit: October 15, 2019, 01:14:37 pm by Cobalt »
Granted after becoming radioactive I only have a half-life!

FellippeHeitor

  • Guest
Re: Need some help with player movement..
« Reply #19 on: October 11, 2019, 10:52:32 pm »
Still a bunch of stray _SETBIT in this latest code block.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Need some help with player movement..
« Reply #20 on: October 13, 2019, 06:40:53 am »
yes _SETBIT showed at line 463 of code in QB64IDE
Programming isn't difficult, only it's  consuming time and coffee

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Need some help with player movement..
« Reply #21 on: October 13, 2019, 12:20:43 pm »
Still a bunch of stray _SETBIT in this latest code block.

Not sure I consider 1 a bunch?  If I'm holding 1 banana I don't think anybody is going to say  "look Cobalt is holding a bunch of bananas!"

the whole magic learning system is bit based. in reality though better than half of items in the game should be bit flag based.
Granted after becoming radioactive I only have a half-life!

FellippeHeitor

  • Guest
Re: Need some help with player movement..
« Reply #22 on: October 13, 2019, 05:58:02 pm »
Point is: code still not runnable by everyone.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Need some help with player movement..
« Reply #23 on: October 13, 2019, 08:41:34 pm »
Just swap in a function SetBit if you’re having issues:

FUNCTION SetBit (variable AS _INTEGER64, bit, toggle)
   b = bit - 1
   If toggle THEN
      SetBit = variable OR (2 ^ b)
   ELSE
      SetBit = variable AND NOT (2 ^ b)
   END IF
END FUNCTION

a = SetBit(a, 3, OFF) ‘Sets the third bit off
b = SetBit(b, 2, ON) ‘Sets the second bit on
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: Need some help with player movement..
« Reply #24 on: October 14, 2019, 02:36:07 am »
I've REMed the bithandling out for now if you guys want to try it

Point is: code shared by cobalt is not runnable as is. I’m not the one to adapt it.
« Last Edit: October 14, 2019, 08:01:16 am by FellippeHeitor »