Recent Posts
Xeda Elnara 19 Feb 2013 13:07
Xeda Elnara

Moderator

FA

Guest

In preparation for TI-Concours, I picked up my TI-89t and tried to make a few programs with it. Among other things, I made a tilemap engine, so I thought I would share the code and explain the parts.

First, let's take a look at how indirection works. If you have an argument that requires a variable name, you can indirectly refer to it with a string. For example, you can draw a picture on the graph screen named sprite0 like this:

"sprite0"→string
RclPic #string,0,0

In that example, 'string' had the variable name and we used the indirection symbol '#' to tell the program to use the string as the variable name. This will do the same thing:
RclPic sprite0,0,0

If you are familiar with the string() command, then you are probably coming up with all sorts of ideas already. For example, say you had a bunch of sprites named sprite0,sprite1,sprite2,… and you wanted to draw a sprite based on an input number:

"sprite"&string(num)→string
RclPic #string,0,0

Or to optimise this a little:
RclPic #("sprite"&string(num)),0,0

Now if 'num' holds the sprite number to draw, it will draw the appropriate sprite. Using this, we can make a tilemap engine that uses a matrix to hold the tile numbers and uses 8x8 tiles:
For a,1,8     ;8 tiles tall
For b,1,8     ;8 tiles wide
RclPic #("sprite"&string(tilemap[a,b])),shift(a,3),shift(b,3)
EndFor
EndFor

tilemap[a,b] is used to access each matrix element and shift(a,3) basically multiplies the value of a by 8. A more memory efficient way of storing tilemaps, though, is to use strings. For example, if you start your sprite index at sprite1 instead of sprite0, you can convert your matrix to 1-byte char() strings and then add them all together. So the conversion code:
""→str0
For a,1,8
For b,1,8
str0+char(tilemap[a,b])→str0
EndFor
EndFor

Then to draw your tilemap, you can use the inverse function of char()— ord():
0→c
For a,1,8
For b,1,8
c+1→c
RclPic #("sprite"&string(ord(mid(str0,c,1)))),shift(a,3),shift(b,3)
EndFor
EndFor

Or probably better:
For a,0,63
RclPic #("sprite"&string(ord(mid(str0,a+1,1)))),8*int(a/8),8*mod(a,8)
EndFor
Attached is a screenshot taken using CalcCapture. I tested it and unfortunately, the screenshot is about half the speed that it actually runs at, so keep that in mind!
TileMapEx0.GIF
This program is a little different from the code that is posted in that it uses another level of indirection. It takes two inputs for the name of the tileset and the name of the tilemap, so it is meant to be a general tilemap engine.

Attachment: TileMapEx0.GIF

Xeda Elnara 12 Feb 2013 18:25
Xeda Elnara

Moderator

FA

Guest

There are still a few weeks left to register! Currently the BASIC (z80) category has 12 contestants. 8 are from France, 3 are from the US, and 1 is from Belgium. Last year the topics were Tic-Tac-Toe, Tron, and a personal project. We won't find out what the topic is until the start of the competition, either :D

In the Axe category, there are 7 contestants, 4 from France, 2 from the US, and 1 from Belgium (yay, powers of two!). Last year the topics were making a grayscale image editor, making Snake, and a personal project.

In z80 Assembly, there are 6 competitors. 4 are from France, 1 is myself from the USA, and 1 is from Belgium. By the way, ben_g is the guy from Belgium in each of these categories so far.

For nSpire Lua, there are 4 competitors including 2 from the US, and 2 from Belgium (Jim Bauwens, the brother of Stefan Bauwens, and Nick).

Finally, for TI-BASIC (68K), it still just Stefan and I D:

Really, y'all should join if you can, it will be great fun. I would feel sorry for the judges, but they have been working hard to get a bunch of people to compete :D I think last year they had three NSpire CX calculators from their sponsors to give to the first place winners in each category (there were three categories) and I think there were similar prizes for the second, and third places, and some goodies for fourth and fifth. I don't know if they have this for this time around, but regardless, you get to compete with people from different countries o__o Isn't that awesome?

EDIT: Also, if you have difficulty with the French stuff that they haven't translated yet, you can ask here or use Google Translate. I should theoretically understand the French >.>

Attachment:

bsch2734 11 Feb 2013 19:20
bsch2734

Member


Guest

One small note:
"or" and "and" can be replaced with addition and multiplication, respectively

So
If G=72 and Y-L+31
becomes
If (G=72)(Y-L+31

and
If N=1 or N=93
becomes
If (N=1)+(N=93

These increase size but also offer a marginal increase in speed

If max(N={1,93
can also replace
If N=1 or N=93
for the same size, though I do not know which is faster

Attachment:

Habstinat 09 Feb 2013 03:38
Habstinat

Included page "member:habstinat" does not exist (create it now)


Guest

Thank you so much for your optimizations. I really can't express how much this means to me; I'm ecstatic to try them out.

I just realized I forgot to mention trick shots. The ball /does/ move at an angle, but you have to set it off first with a trick shot executed by moving the paddle exactly one pixel away from the ball when you hit the ball. It's kind of hard to explain but really easy to understand once you do it once. I made it this way purposefully to give skilled players an edge; once you start a trick shot ball it can't be undone until the next ball. It's also impossible to score anything in Challenge Mode without using trick shots. If you didn't know about them, you probably weren't having much fun :P

Attachment:

Habstinat 09 Feb 2013 03:34
Habstinat

Included page "member:habstinat" does not exist (create it now)


Guest

Thank you so so much for your optimizations. I really can't express how much I appreciate it; I'm literally ecstatic right now.

Also, I may have forgotten to mention this, but the ball does move at an angle, but you have to "set it off" first by moving the paddle exactly one pixel away from the ball. This is kind of hard to explain until you do it once. I made it this way on purpose to give skilled players an edge; they'll have the precision to set off trick shots and once a trick shot is off, it can't be undone until the next ball. Haha, if you were playing without knowing that you probably weren't having a lot of fun :P

Attachment:

Xeda Elnara 09 Feb 2013 01:47
Xeda Elnara

Moderator

FA

Guest

I am going through and optimising some of your code and I can tell a bunch of it was well thought out :D
There are a handful of common optimisations that I can suggest:

  • Instead of using ~L+32 (I am assuming ~ is negative), you can use 32-L to save a byte
  • You can drop ending quotes and parentheses
  • To elaborate on what Silver said, DelVar is two bytes, so 0→Q is the same size as DelVar Q. However, DelVar and the other memory functions have a cool trick where you don't need to use a newline for the next command, saving a byte! For example, instead of this:
0→Q
1→P
---or---
DelVar Q
1→P

(both are the same size) You can do this:
DelVar Q1→P

Which is one byte less and essentially does the same thing.
  • Disp has a cool trick like Text( where each additional argument is treated like a new Disp. For example:
Disp "YOU LOSE..."
Disp "YOUR SCORE:"

Can instead be:
Disp "YOU LOSE...","YOUR SCORE:

Pretty neat, right?
  • One random trick optimisation was with this line:
If G=72 and Y-L+32≠1

I changed it in my head to:
If G=72 and Y-L+32-1

Which can be optimised to save two bytes:
If G=72 and Y-L+31

I am weird, so my methods are awkward. If you want to do the more logical version of my solution:
If G=72 and Y-L+32≠1
---use some algebra---
If G=72 and Y-L+32-32≠1-32
If G=72 and Y-L≠~31
---get rid of that negtive sign, it is using an unnecessary byte D: ---
If G=72 and Y-L+L≠~31+L
If G=72 and Y≠L-31

Yay :3 (I am in a math optimisy mood, sorry).
  • Often Repeat is more useful than While (in my opinion) because you don't need to set the variables before the loop. When I started learning TI-BASIC, I actually never learned what While did until I joined this site and saw people using it. I just found Repeat and figured out how it worked and I like it .-.

Here is how I convoluted it:

DelVar CDelVar P"      ;6 spaces here
Menu(Ans+"PONG"+Ans,"TWO PLAYER",2,"PRACTICE",P,"CHALLENGE",C,"QUIT",Q
Lbl C
1→C
2→U
Lbl P
1→P
Lbl 2
DelVar VDelVar WDelVar SDelVar T4→L
32→O
48→N
DelVar EDelVar Q1→D
StoreGDB 0
1→Xmin
95→Xmax
FnOff 
AxesOff
ClrDraw
If C or P
Then
Vertical 1
Vertical 2
End
Horizontal (-)10
Horizontal 10
For(I,1,93,92
For(J,32-L,L+32,1
Pxl-On(J,I
End
End
Repeat Q
getKey→G
If G
Then
If G=72 and Y-L+31
Then
Y-1→Y
Pxl-On(Y-L+32,1
Pxl-Off(Y+L+33,1
Else
If G=92 and Y+L≠29
Then
Y+1→Y
Pxl-On(Y+L+32,1
Pxl-Off(Y-L+31,1
Else
If G=45
Then
ClrHome
Disp "GAME PAUSED","[ENTER]: RESUME","[CLEAR]: QUIT
Repeat 30=abs(Ans-75
getKey
End
If Ans=45
1→Q
Else
If G=74 and T-L+31
Then
T-1→T
Pxl-On(T-L+32,93
Pxl-Off(T+L+33,93
Else
If G=94 and T+L≠29
Then
T+1→T
Pxl-On(T+L+32,93
Pxl-Off(T-L+31,93
End
End
End
End
End
End
N→A
O→B
If N=1 or N=93
Then
If not(C
Then
ClrHome
If N=1
V+1→V
If N=93
W+1→W
Disp "LEFT SCORE:
Output(1,13,V
Disp "RIGHT SCORE:
Output(2,14,W
Pause 
If V>9
Then
Disp "LEFT WINS!
1→Q
End
If W>9
Then
Disp "RIGHT WINS!
1→Q
End
32→O
DelVar E48→N
Else
ClrHome
Disp "YOU LOSE...","YOUR SCORE:
Output(2,13,U
If U>|LPONG(1
U→|LPONG(1
Disp "HIGH SCORE:
Output(3,13,|LPONG(1
Pause 
1→Q
End
End
If pxl-Test(O,N+D
Then
If C and U>2
Then
Vertical U-1
Vertical U
U+1→U
End
~D→D
Else
If pxl-Test(O+1,N+D
Then
~1→E
If N=2 or N=92
Then
~D→D
If C
Then
Vertical U-1
Vertical U
U+1→U
End
End
End
If pxl-Test(O-1,N+D
Then
1→E
If N=2 or N=92
~D→D
End
End
O+E→O
N+D→N
Pxl-Off(B,A
Pxl-On(O,N
End
Lbl Q
RecallGDB 0
ClrHome

I gave it a try and I like how you implemented the two player mode. Also, should the pixel be moving at an angle or just back and forth? If you want, I can put together a simple Pong engine so that you can compare it :D

Attachment:

Silver Phantom 09 Feb 2013 00:31
Silver Phantom

Member


Guest

instead of 0→(variable) try delvar variable

Attachment:

Habstinat 08 Feb 2013 23:59
Habstinat

Included page "member:habstinat" does not exist (create it now)


Guest

Oh jeez, looks like you can't edit posts on this forum. Well, regardless, the PONG.8Xp file is attached. I didn't mean to cross it out in the previous post.

Attachment: PONG.8Xp

Habstinat 08 Feb 2013 23:52
Habstinat

Included page "member:habstinat" does not exist (create it now)


Guest

I'll add programs to this thread as I see fit. Feedback, optimization, and high scores to beat are welcomed (I always try to fit some sort of scoring system in most of my games).

-PONG.8Xp-
Notes:
This is a fully featured pong game, complete with multiplayer, a practice mode, and a "challenge" mode in which the player must hit the ball against a wall that continues to move closer to the paddle until the player misses the ball, at which point his score will be tallied and recorded.
Controls:
[7]: Move the left paddle up one pixel
[1]: Move the left paddle down one pixel
[9]: Move the right paddle up one pixel
[3]: Move the right paddle down one pixel
[CLEAR]: Pause the game, or exit the game if paused
[ENTER]: Resume the game if paused
Hacks:
- The "L" variable can be changed to alter the length of both paddles divided by two.
Catches:
- It's still not as fast as I'd like it to be.
- The two player mode is still kind of crippled by the fact that only one one key press can be caught by getKey at a time.
- Ball movement is rather simplistic, and once you hit a trick shot, there's no way to counter that except returning it.
- You have to mash the number pad to move the paddle because only the arrow keys can be held. I'm not sure if I like it that way or not.
My high score:
71 for Challenge Mode. I'll admit, I haven't tried that hard.

0->C
0->P
Menu("      PONG      ","TWO PLAYER",2,"PRACTICE",P,"CHALLENGE",C,"QUIT",Q)
Lbl C
1->C
2->U
Lbl P
1->P
Lbl 2
0->V
0->W
0->S
0->T
4->L
32->O
48->N
0->E
1->D
0->Q
StoreGDB 0
1->Xmin
95->Xmax
FnOff 
AxesOff
ClrDraw
If C or P
Then
Vertical 1
Vertical 2
End
Horizontal ~10
Horizontal 10
For(I,1,93,92)
For(J,~L+32,L+32,1)
Pxl-On(J,I)
End
End
While not(Q)
getKey->G
If G
Then
If G=72 and Y-L+32!=1
Then
Y-1->Y
Pxl-On(Y-L+32,1)
Pxl-Off(Y+L+33,1)
Else
If G=92 and Y+L+32!=61
Then
Y+1->Y
Pxl-On(Y+L+32,1)
Pxl-Off(Y-L+31,1)
Else
If G=45
Then
ClrHome
Disp "GAME PAUSED"
Disp "[ENTER]: RESUME"
Disp "[CLEAR]: QUIT"
While not(F)
getKey->G
If G=45
Then
1->Q
1->F
End
If G=105
1->F
End
0->G
0->F
Else
If G=74 and T-L+32!=1
Then
T-1->T
Pxl-On(T-L+32,93)
Pxl-Off(T+L+33,93)
Else
If G=94 and T+L+32!=61
Then
T+1->T
Pxl-On(T+L+32,93)
Pxl-Off(T-L+31,93)
End
End
End
End
End
End
N->A
O->B
If N=1 or N=93
Then
If not(C)
Then
ClrHome
If N=1
V+1->V
If N=93
W+1->W
Disp "LEFT SCORE:"
Output(1,13,V)
Disp "RIGHT SCORE:"
Output(2,14,W)
Pause 
If V>9
Then
Disp "LEFT WINS!"
1->Q
End
If W>9
Then
Disp "RIGHT WINS!"
1->Q
End
32->O
48->N
0->E
Else
ClrHome
Disp "YOU LOSE..."
Disp "YOUR SCORE:"
Output(2,13,U)
If U>|LPONG(1)
U->|LPONG(1)
Disp "HIGH SCORE:"
Output(3,13,|LPONG(1))
Pause 
1->Q
End
End
If pxl-Test(O,N+D)
Then
If C and U>2
Then
Vertical U-1
Vertical U
U+1->U
End
~D->D
Else
If pxl-Test(O+1,N+D)
Then
~1->E
If N=2 or N=92
Then
~D->D
If C
Then
Vertical U-1
Vertical U
U+1->U
End
End
End
If pxl-Test(O-1,N+D)
Then
1->E
If N=2 or N=92
~D->D
End
End
O+E->O
N+D->N
Pxl-Off(B,A)
Pxl-On(O,N)
End
Lbl Q
RecallGDB 0
ClrHome

My other games will be added shortly.

Attachment:

Xeda Elnara 08 Feb 2013 21:04
Xeda Elnara

Moderator

FA

Guest

Haha, oops, sorry XD I am used to adding things to the end of Str1 instead of putting things before it x_x

Attachment:

Xeda Elnara 08 Feb 2013 21:03
Xeda Elnara

Moderator

FA

Guest

Oh, sorry, I misread something and thought that you wanted it at the end of the string, sorry. You could add this to the end of my code to remedy that:

sub(Ans,5B+1,int(B

My code assumes that the input might not be a multiple of 5 digits.

Attachment:

Anonymous 08 Feb 2013 20:43
Anonymous

Included page "member:anonymous" does not exist (create it now)


Guest
" →  Str0
.2length(Str1→B
For(A,1,B
0
For(C,-4,0
2Ans+expr(sub(Str1,5A+C,1
End
Str0+sub("ZYXWVUTSRQPONMLKJIHGFEDCBA",Ans-5,1→Str0
End

It stores it to Str0.

Attachment:

AriMB 08 Feb 2013 17:51
AriMB

Included page "member:arimb" does not exist (create it now)


Guest

Xeda Elnara's code works, but it adds the answer to the end of the input. how could that be fixed?

Attachment:

AriMB 08 Feb 2013 17:44
AriMB

Included page "member:arimb" does not exist (create it now)


Guest

yet again…above post is mine

Attachment:

Anonymous 08 Feb 2013 17:43
Anonymous

Included page "member:anonymous" does not exist (create it now)


Guest

it almost works, just need to make this small change

"0→Str1
While A
sub("0123456789ABCDEF",1+16fPart(A/16),1)+Str1→Str1
iPart(A/16→A
End
If Str1≠"0
sub(Str1,**1**,length(Str1)-1

Attachment:

bsch2734 08 Feb 2013 13:51
bsch2734

Member


Guest

Yes, I think we've all been there before XD

Attachment:

Xeda Elnara 07 Feb 2013 20:01
Xeda Elnara

Moderator

FA

Guest

I believe you want a command to convert decimal to hexadecimal? You can do this, where A is the number to convert:

"0→Str1
While A
sub("0123456789ABCDEF",1+16fPart(A/16),1)+Str1→Str1
iPart(A/16→A
End
If Str1≠"0
sub(Str1,2,length(Str1)-1

Hopefully that works ^^'

Attachment:

Xeda Elnara 07 Feb 2013 19:56
Xeda Elnara

Moderator

FA

Guest
.2length(Str1→B
For(A,1,B
0
For(C,-4,0
2Ans+expr(sub(Str1,5A+C,1
End
Str1+sub("ZYXWVUTSRQPONMLKJIHGFEDCBA",Ans-5,1→Str1
End

I am sure there is a faster and smaller way, but I think that works (I didn't test it).

Attachment:

AriMB 07 Feb 2013 17:44
AriMB

Included page "member:arimb" does not exist (create it now)


Guest

Does anyone know how to convert from numeral to hexadecimal? I have a TI-83+ which does not have the ▶Hex command. Please help

Attachment:

AriMB 07 Feb 2013 17:29
AriMB

Included page "member:arimb" does not exist (create it now)


Guest

Lat's see…my best program is probably either my own version of snake or a blackjack program I wrote. I became interested in programming originally because I was lazy and did not feel like remembering all of the math and science formulas. And I'm terrible at optimizing because…I'm terrible at optimizing (my programs are all like 10x longer than they would be if they were optimized). An example of what some of my early programs were (like when I had never even heard of optimizing).

If A=1
then
disp "1"
end
if A=2
then
disp "2"
end
if a=3
then
disp "3"
if a=4
then
disp "4"
end
etc.

Attachment:

page 1 of 8123...78next »
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Noncommercial 2.5 License.