Omnimaga
Calculator Community => TI Calculators => TI-BASIC => Topic started by: saintrunner on February 17, 2012, 06:57:25 pm
-
: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~
-
This isn't the whole code, but this is how I generally do the key/movement portion.
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.)
-
cool thanks :)
edit: hmmm doesn't seem to work
-
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.
-
It works now thanks!
could you explain it?
-
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.
-
just the ordering of the stuff has me slightly confused, but I bet if I look at it more, I will figure it out
-
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 ???
-
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.
-
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
-
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.
-
Okay, I found it
Here it is, strait from TI-BASIC Developer:
: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
-
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)
-
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:
-
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.
-
Maybe, I think they would stay about the same. The List code really doesn't have much collision detection anyways, just the min max trick
Anyways, I'm starting to understand just how brilliant this code is... it is amazing how it works :)
But isn't it faster to do Repeat Ans:getKey:End:Ans->G ?
-
Can someone explain how I can do collision?
-
Where it has either A+(getKey stuff)->A and B+(getkey stuff)->B, or the x and y versions,
just add min(8,max(1,
to the Y axis variable
and min(16,max(1,
to the X axis variable
should work :)
-
um, can you show me that in the first code DJ posted? Thats the one I'm using
-
ClrHome
4->X
5->Y
Repeat G=45
Repeat G
getkey->G
End
Output(X,Y,"
min(16,max(1,Y-(G=24)+(G=26->Y
min(8,max(1,X-(G=25)+(G=34->X
Output(X,Y,"@
End
ClrHome
Stop
There you go! :)
EDIT: if you need me to, I can explain it for you
-
Note that this is only for collision on the screen sides, though.
-
Note that this is only for collision on the screen sides, though.
Yes, but it should work for any sized rectangle (aka no walls in the middle of the screen :P )
-
Well thanks, but I was looking for collision with predrawn things. Like if I had on the screen a question mark, I wouldn't want to run through it
-
Here is a way to do that:
"
0ANYTHING000000 //Take out the newlines, of course, so the interpreter doesn't freak out
0 0
0 0
0 :) 0
00WORKS!!!1!100 ->Str1 //You can make the map bigger for more space to move
ClrHome
2->X
2->Y
Output(1,1,Str1
Repeat G=45
Repeat G
getkey->G
End
Output(X,Y,"
Y-(G=24)(sub(Str1,1,(X-1)16+Y-1) = "_")+(G=26)(sub(Str1,1,(X-1)16+Y+1) = "_->Y
X-(G=25)(sub(Str1,1,(X-2)16+Y) ="_")+(G=34)(sub(Str1,1,16X+Y+1) = "_->X
Output(X,Y,"@
End
ClrHome
Stop
I just kinda threw that together, but it should work. It looks into Str1 to check if the space it is moving to is empty :)
It uses DJ's code, so you can easily modify it to this
-
I'll try it out thanks
-
my ASCII world use something like that, I think.
However, mine has a 3 walkable tiles :D (And it's kinda slow :\ )
-
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.
Do you mean Repeat max(K={24,25,26,34}) ?
-
my ASCII world use something like that, I think.
However, mine has a 3 walkable tiles :D (And it's kinda slow :\ )
That sounds like more fun to program :P
-
it didn't work ???
-
which part does it throw errors?
EDIT: maybe G is 45 BEFORE the loops starts. to prevent that, add DelVarG before Repeat G.
-
Did you try the matrix-based version I sent you? Or do you just want to do a string-based mapper?
-
not sure, just says invalidDim
-
what are your x and y values right now?
-
Set them both to 2
-
which part does it throw errors?
EDIT: maybe G is 45 BEFORE the loops starts. to prevent that, add DelVarG before Repeat G.
Repeat loops always go through once no matter what, so that shouldn't be the problem.
-
they are
-
Did you try the matrix-based version I sent you? Or do you just want to do a string-based mapper?
Matrix tilemapping will be definitely faster. However, the size when the map gets kinda big..../me shudders
which part does it throw errors?
EDIT: maybe G is 45 BEFORE the loops starts. to prevent that, add DelVarG before Repeat G.
Repeat loops always go through once no matter what, so that shouldn't be the problem.
Crap. I totally forgot about that. D:
EDIT: Optimization and fix :D
chattahippie got his sub( argument mixed up XD
"
0ANYTHING000000 //Take out the newlines, of course, so the interpreter doesn't freak out
0 0
0 0
0 :) 0
00WORKS!!!1!100 ->Str1 //You can make the map bigger for more space to move
ClrHome
2->X
2->Y
Output(1,1,Str1
Repeat G=45
Repeat G
getkey->G
End
Output(X,Y,"
Y-(G=24 and sub(Str1,16X-17+Y,1) = "_")+(G=26 and sub(Str1,16X-15+Y,1) = "_->Y
X-(G=25 and sub(Str1,16X-32+Y,1) ="_")+(G=34 and sub(Str1,16X+Y+1,1) = "_->X
Output(X,Y,"@
End
ClrHome
Stop
-
chattahippie got his sub( argument mixed up XD
I just noticed as well D:
getting rusty on my TIBASIC
-
getting rusty on my TIBASIC
That's why I practice TI-BASIC XD/me is rusty on his Axe. D:
-
getting rusty on my TIBASIC
That's why I practice TI-BASIC XD/me is rusty on his Axe. D:
[dramatic music backing]lol, the thing is, I still practice TI-BASIC too! D:[/dramatic music backing]
I'm making a (simple) snake game as well as my axe game
but the thing is, Im not using sub( yet :P
-
IT WORKS! Thanks so much! any way to make it so it tests certain 'tiles' ?
edit: bug....if you have a tile too your right you can't move down!
-
IT WORKS! Thanks so much! any way to make it so it tests certain 'tiles' ?
Just check sub(Str1,(X-1)16+Y,1)
It will return the character you are standing on
and from there, you can have them do different things
But note, the code provided to check for collision will not allow you to stand on anything other than spaces, so you will have to adjust for that
-
theres a bug, if you have a tile to your right you can't move down, also do I change the current subs with the above or do I just add it before?
-
My code (and Yeong's "fixed" code :P ) had a small bug, this should work better:
"
0ANYTHING000000 //Take out the newlines, of course, so the interpreter doesn't freak out
0 0
0 0
0 :) 0
00WORKS!!!1!100 ->Str1 //You can make the map bigger for more space to move
ClrHome
2->X
2->Y
Output(1,1,Str1
Repeat G=45
Repeat G
getkey->G
End
Output(X,Y,"
Y-(G=24 and sub(Str1,16X-17+Y,1) = "_")+(G=26 and sub(Str1,16X-15+Y,1) = "_->Y
X-(G=25 and sub(Str1,16X-32+Y,1) ="_")+(G=34 and sub(Str1,16X+Y,1) = "_->X
Output(X,Y,"@
"example for event
If sub(Str1,16X-32+Y,1)="E
Then
"Event stuff here"
End
End
ClrHome
Stop
There was a +1 in the wrong place :P
For the example I put in there, it will check the tile above to see if it is an "E"
I wouldn't use this way for too many events though, it will cause a speed loss for each event you add
-
Thanks so much :) you all have helped so much
-
Thanks so much :) you all have helped so much
Glad to help :D
EDIT: 300 post!
-
By the way I like your avatar
-
Did you try the matrix-based version I sent you? Or do you just want to do a string-based mapper?
Matrix tilemapping will be definitely faster. However, the size when the map gets kinda big..../me shudders
Yeah he might be forced to rely on XCOPY or Doors CS's Zcopy function. X.x. A 12x8 matrix in storage format (in the code) is between 250 and 350 KB large, so if your game got 200 maps (even less than Metroid II), it won't even get close to fit in RAM. In addition to that such matrix in matrix file format takes around 1 KB of RAM. They're much faster for collision detection, though.
-
Did you try the matrix-based version I sent you? Or do you just want to do a string-based mapper?
Matrix tilemapping will be definitely faster. However, the size when the map gets kinda big..../me shudders
Yeah he might be forced to rely on XCOPY or Doors CS's Zcopy function. X.x. A 12x8 matrix in storage format (in the code) is between 250 and 350 KB large, so if your game got 200 maps (even less than Metroid II), it won't even get close to fit in RAM. In addition to that such matrix in matrix file format takes around 1 KB of RAM. They're much faster for collision detection, though.
if it doesn't fit in your RAM, couldn't you just use noshell and archive it?
-
It doesn,t work like that. You can't just run an archived BASIC program from another one and any BASIC file has to be under 22 KB large or so to even launch at all. Even with Noshell, DCS, Mirage, etc, you'll still get an ERR:ARCHIVED error.
-
wow! it would be that big! well, I don't think if I made a BASIC game, I would use that many maps anyways :P And even if I did make a BASIC game, I doubt it would be ANY where close to how AMAZING your games are! You are my BASIC hero :)
-
Lol thanks. But yeah most of my games ended up pretty big since in the past so many other games were too short. D: (they usually used one pic per map)
-
My code (and Yeong's "fixed" code :P ) had a small bug
I only fixed your sub( stuff :P
-
My code (and Yeong's "fixed" code :P ) had a small bug
I only fixed your sub( stuff :P
lol I know, I was joking, I know it was my fault
-
be careful with making string-based map, because as the string gets longer, the more "bottom" you're in a map, the slower it gets since BASIC checks from the beginning of the string to the end of the string for the sub( routine
-
Yeah true that's an issue too. I recommend splitting the maps in 128 character chunks or something. Smaller strings are easier to work with anyway since the PRGM editor is 16x7, so you don't need a map editor at all.