Author Topic: BASIC movement  (Read 12121 times)

0 Members and 3 Guests are viewing this topic.

Offline saintrunner

  • Custom Spriter: You ask it! I'll Make it!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1787
  • Rating: +115/-11
  • Flogging Molly
    • View Profile
    • Jonny K Music
BASIC movement
« on: February 17, 2012, 06:57:25 pm »
Code: [Select]
:ClrHome
:4→X
:5→Y
:
:Lbl A
:Output(X,Y,"@"
:While 1
:getKey→G
:While G=0
:getKey→G
:End
:If G=24
:Then
:Output(X,Y," "
:Y-1→Y
:Goto A
:End
:
:If G=25
:Then
:Output(X,Y," "
:X-1→X
:Goto A
:End
:
:If G=26
:Then
:Output(X,Y," "
:Y+1→Y
:Goto A
:End
:
:If G=34
:Then
:Output(X,Y," "
:X+1→X
:Goto A
:End
:
:
:If G=45
:Then
:ClrHome
:Stop
:End
:
:If G≠24 or 25 or 26 or 34
:Goto A
:End

can someone help me with this? I feel there is a more effective way to code movement. ???

Thanks

~saint~
My Sprites Thread   :Updated often :) for your viewing pleasure

GAMES:

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: BASIC movement
« Reply #1 on: February 17, 2012, 07:23:49 pm »
This isn't the whole code, but this is how I generally do the key/movement portion.

Code: [Select]
ClrHome
4->X
5->Y
Repeat G=45
Repeat G
getkey->G
End
Output(X,Y,"
Y-(G=24)+(G=26->Y
X-(G=25)+(G=34->X
Output(X,Y,"@
End
ClrHome
Stop

I'm betting someone will come up with that one Δlist trick in response to this, but I coded BASIC mostly years before that trick was made popular, so I don't know how it works and if it's any faster.

(Note, don't use Goto inside Then/Else/While/Repeat/For. This causes memory leaks, which slows down the program then ERR:MEMORY after a while.)
« Last Edit: February 17, 2012, 07:42:50 pm by DJ_O »

Offline saintrunner

  • Custom Spriter: You ask it! I'll Make it!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1787
  • Rating: +115/-11
  • Flogging Molly
    • View Profile
    • Jonny K Music
Re: BASIC movement
« Reply #2 on: February 17, 2012, 07:27:14 pm »
cool thanks :)

edit: hmmm doesn't seem to work
« Last Edit: February 17, 2012, 07:35:03 pm by saintrunner »
My Sprites Thread   :Updated often :) for your viewing pleasure

GAMES:

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: BASIC movement
« Reply #3 on: February 17, 2012, 07:38:06 pm »
It doesn't? ??? What does happen?

Can you show me how you typed the code in wabbitemu? Just to make sure you typed it right.

Offline saintrunner

  • Custom Spriter: You ask it! I'll Make it!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1787
  • Rating: +115/-11
  • Flogging Molly
    • View Profile
    • Jonny K Music
Re: BASIC movement
« Reply #4 on: February 17, 2012, 07:42:15 pm »
It works now thanks!

could you explain it?
My Sprites Thread   :Updated often :) for your viewing pleasure

GAMES:

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: BASIC movement
« Reply #5 on: February 17, 2012, 08:11:06 pm »
It would be a bit hard to explain actually, is there any part in particular you might need help to understand ? According to IRC you understood the Y+stuff->Y part.

Offline saintrunner

  • Custom Spriter: You ask it! I'll Make it!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1787
  • Rating: +115/-11
  • Flogging Molly
    • View Profile
    • Jonny K Music
Re: BASIC movement
« Reply #6 on: February 17, 2012, 08:20:57 pm »
just the ordering of the stuff has me slightly confused, but I bet if I look at it more, I will figure it out
My Sprites Thread   :Updated often :) for your viewing pleasure

GAMES:

Offline chattahippie

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +27/-0
  • Super Member! :D
    • View Profile
Re: BASIC movement
« Reply #7 on: February 17, 2012, 08:36:58 pm »
I'm betting someone will come up with that one Δlist trick in response to this, but I coded BASIC mostly years before that trick was made popular, so I don't know how it works and if it's any faster.
What is this trick? I've never heard of it ???

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: BASIC movement
« Reply #8 on: February 17, 2012, 09:07:34 pm »
It involves storing 24, 25, 26 and 34 in a list then doing Δlist or something for the movement, which is even smaller than my code. It was on TI-BASIC Developer somewhere.

Offline chattahippie

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +27/-0
  • Super Member! :D
    • View Profile
Re: BASIC movement
« Reply #9 on: February 17, 2012, 09:11:16 pm »
Cool!  I was messing around with ∆List (I looked it up in TI-BASIC developer), trying to figure out said trick, and although I couldn't figure it out, I did manage to make a start to a snake game (the kind where you eat pellets to grow)

Not really anything significant (I've seen the game millions of times :P ), but I was amazed how easy it actually was to make (I had no clue beforehand how to make the tail) :D

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: BASIC movement
« Reply #10 on: February 17, 2012, 09:13:55 pm »
If you manage to get the grasp of the trick in question, could you do some test or something? I wonder how its speed compares with my code.

As for snake I had an hard time making one before because no tutorial were available and the tail caused some glitches sometimes. For example when the apple/star appeared directly on the tail, it disappeared or something.

Offline chattahippie

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +27/-0
  • Super Member! :D
    • View Profile
Re: BASIC movement
« Reply #11 on: February 17, 2012, 09:16:24 pm »
Okay, I found it
Here it is, strait from TI-BASIC Developer:
Code: [Select]
:4→A
:8→B
:Repeat K=21
:getKey→K
:If Ans
:Output(A,B," // 1 space
:min(8,max(1,A+sum(Δlist(Ans={25,34→A
:min(16,max(1,B+sum(Δlist(K={24,26→B
:Output(A,Ans,"X
:End
Now, it is time to speed crunch!

Okay, here are my results:
DJ, your code is a little faster than theirs, and is 87 bytes (the version I made had no ClrHome and Stop)
The ∆List trick is 96 bytes, but also calculated if the character was at the border for almost no speed difference (slightly slower)

So, I would go with your version for without edge testing, but if you want to have testing for almost no speed drop, use the ∆List code
« Last Edit: February 17, 2012, 09:24:56 pm by chattahippie »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: BASIC movement
« Reply #12 on: February 17, 2012, 09:25:35 pm »
Actually I got rid of min(8,max(1, and min(16,max(1, because my code above had no detection for if the character goes out of the screen, but a better speed test would be to add the old method of checking to my code (if the char goes out, then it reverts the increase/decrease)

Offline chattahippie

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +27/-0
  • Super Member! :D
    • View Profile
Re: BASIC movement
« Reply #13 on: February 17, 2012, 09:31:16 pm »
Okay, I removed the min max from the List program, which shaved it down to 83 bytes, and they are both so fast, it's hard to tell which one is faster D:

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: BASIC movement
« Reply #14 on: February 17, 2012, 09:46:13 pm »
Ah ok lol. X.x I guess the slowdown might not be too bad then. Plus by removing the stuff it's slightly smaller. I assume with collision detection it's much smaller if we compare both routines with it.