Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: Toctave on April 14, 2014, 09:39:41 am
-
Hi guys!
I recently created a game in axe, you probably know it, it's 2048.
So here's the code with as much comments as I thought were needed, don't hesitate about asking me about a part of it if it's not clear enough.
Variables :
Pic** : Sprites and Bitmaps
I, J, K : Counters for the For( loops in movements subroutines
L1 : Pointer to the game table. I store the cells as their power of 2 (e. g. 2 is 1, 64 is 6, and 2048 is 11)
appvA : 20 bytes appvar to save the current game table, score, and high score
Q : Pointer to appvA
theta : If it's non zero, at least one cell has moved (helps to know when to create new cells)
N : limit variable, explained below
V : Value of the evaluated cell
T : Value of the targetted cell
.A2048
.Sprite for the Tiles
[FF818181818181FF]->Pic0
[FF818199998181FF]->Pic1
[FF8189B99D9181FF]->Pic2
[FF81FF8181FF81FF]->Pic3
[FF81BDA5A5BD81FF]->Pic4
[FFA5FFA5A5FFA5FF]->Pic5
[FF9999FFFF9999FF]->Pic6
[FFC3A59999A5C3FF]->Pic7
[FFC3BDBDBDBDC3FF]->Pic8
[FFFFC3DBDBC3FFFF]->Pic9
[FFFFFFE7E7FFFFFF]->Pic10
[FFABD5ABD5ABD5FF]->Pic11
[FFFFFFFFFFFFFFFF]->Pic12
.Logo Bitmap
Data(40,16)->Pic0A
[FFFFF0FF00818190818081819F8180F999999980F999999980819981818081998181809F99F999809F99F9998081818981808181898180FFFF8FFF807FFF87FF80000000000000000000000000000000]
.Help screen Bitmaps
Data(16,56)->Pic0B
[FF00810081609910992081408170FF000000FF0081008940B9509D7091108110FF000000FF008100FF7081508170FF508170FF000000FF008100BD23A564A527BD258177FF000000FF00A500FF66A511A522FF14A567FF000000FF0099009934FF45FF7799519971FF00000000000000]
Data(24,56)->Pic0C
[0000FF0000C304CEA50C2A99044E99048AA50EEEC30000FF0000000000FF0000C30CE6BD0288BD04CEBD082ABD0ECEC30000FF0000000000FF0000FF0E4CC308C2DB0C44DB0248C30CEEFF0000FF0000000000FF0000FF44C8FFCA2AE74A4EE74A82FFE4E2FF0000FF0000000000FF0000ABC48ED52AAAAB4AEED58A2AABE42ED50000FF0000000000FF0000FF84E6FFAAA8FFEAEEFF2A2AFF24CEFF0000FF000000000000000000]
DiagnosticOff
ExprOn
Full
Fill(L1,16,0)
0->I->J->K
.Default value for the NEW subroutine, see below
1->{L1+16}
.Create or load an appvar for the game table
UnArchive "appvA"
!If GetCalc("appvA"
GetCalc("appvA",20)->Q
R()
Else
GetCalc("appvA")->Q
End
.Recover last session
LOAD()
.Main Loop
Repeat getKey(15)
If getKey
If getKey(1)
DOWN()
End
If getKey(2)
LEFT()
End
If getKey(3)
RIGHT()
End
If getKey(4)
UP()
End
If getKey(55)
R()
End
If getKey(54)
H()
End
End
D()
End
If S>{Q+18}^^r
S->{Q+18}^^r
End
SAVE()
Return
Lbl DOWN
.By default, no move has been done
0->theta
.Check all columns (J)
For(J,0,3)
3->N
For(K,1,3)
.K is used to make a For( loop with I from 3 to 1
.X is the address of the target cell, it's by default the cell below the evaluated one
3-K->I+1->X
.If the evaluated cell contains a number
If {4*I+J+L1}->V!=0
.Main loop to find a target position
.Find a cell with the same value as the evaluated cell
.or an obstacle
.or X reaches the limit
Repeat {4*X+J+L1}->T=V or (T!=V and (T!=0)) or (X=N)
X++
End
{4*X+J+L1}->T
.If an obstacle was found, the target cell is one row upwards
If T!=V and (T!=0)
X--
End
.If any movement is made (target cell is different from evaluated cell)
If X!=I
.If target cell is empty
If {4*X+J+L1}=0
V->{4*X+J+L1}
Else
.If we're there, the target cell value needs to be increased
V+1->{4*X+J+L1}
.And the limit value goes upwards (see in the message for more information)
X-1->N
e^(V+1)+S->S
End
.Empty the evaluated cell and tell the program a move has been made
0->{4*I+J+L1}
theta++
End
End
End
End
.If at least one move has been made, create a new cell
If theta
NEW()
End
Return
Lbl LEFT
0->theta
For(J,0,3)
0->N
For(I,1,3)
If {4*J+I+L1}->V!=0
I-1->X
Repeat {4*J+X+L1}->T=V or (T!=V and (T!=0)) or (X=N)
X--
End
{4*J+X+L1}->T
If T!=V and (T!=0)
X++
End
If X!=I
If {4*J+X+L1}=0
V->{4*J+X+L1}
Else
V+1->{4*J+X+L1}
X+1->N
e^(V+1)+S->S
End
0->{4*J+I+L1}
theta++
End
End
End
End
If theta
NEW()
End
Return
Lbl RIGHT
0->theta
For(J,0,3)
3->N
For(K,1,3)
3-K->I+1->X
If {4*J+I+L1}->V!=0
Repeat {4*J+X+L1}->T=V or (T!=V and (T!=0)) or (X=N)
X++
End
If (T!=V and (T!=0))
X--
End
If X!=I
If {4*J+X+L1}=0
V->{4*J+X+L1}
Else
X-1->N
V+1->{4*J+X+L1}
e^(V+1)+S->S
End
0->{4*J+I+L1}
theta++
End
End
End
End
If theta
NEW()
End
Return
Lbl UP
0->theta
For(J,0,3)
0->N
For(I,1,3)
I-1->X
If {4*I+J+L1}->V!=0
Repeat {4*X+J+L1}->T=V or (T!=V and (T!=0)) or (X=N)
X--
End
{4*X+J+L1}->T
If T!=V and (T!=0)
X++
End
If X!=I
If {4*X+J+L1}=0
V->{4*X+J+L1}
Else
X+1->N
V+1->{4*X+J+L1}
e^(V+1)+S->S
End
0->{4*I+J+L1}
theta++
End
End
End
End
If theta
NEW()
End
Return
Lbl SAVE
Copy(L1,Q,16)
S->{Q+16}^^r
Return
Lbl LOAD
Copy(Q,L1,16)
{Q+16}^^r->S
Return
Lbl NEW
.L is set to 16 so the new cell position changes everytime
16->L
Repeat {L1+L}=0
rand^16->L
End
rand^6/5+1->{L1+L}
Return
Lbl R
0->S
Fill(L1,16,0
NEW()
NEW()
Return
Lbl H
.Clear the screen and draw the help bitmaps
ClrDraw
Tangent(20,5,Pic0B)
Tangent(52,5,Pic0C)
DispGraph^^r
Text(58,58,"by Toctave"
Repeat getKey
End
ClrDraw^^r^^r
Return
.Subroutine to easily create rectangles for the scores and game table itself, r1 to r4 is the same as for the Rect( command, r5 is used to tell how the corners will look
Lbl RECT
HLine({r2},{r1}-{r5},{r1}+{r3}+{r5}
HLine({r2}+{r4},{r1}-{r5},{r1}+{r3}+{r5}
VLine({r1},{r2}-{r5},{r2}+{r4}+{r5}
VLine({r1}+{r3},{r2}-{r5},{r2}+{r4}+{r5}
Return
.No need to explain here I think
Lbl D
Tangent(32,3,Pic0A
For(I,0,15)
L1+I->P
I^4*9+31->F
I/4*9+21->G
If {P}=1
Pt-On(F,G,Pic1)
ElseIf {P}=2
Pt-On(F,G,Pic2)
ElseIf {P}=3
Pt-On(F,G,Pic3)
ElseIf {P}=4
Pt-On(F,G,Pic4)
ElseIf {P}=5
Pt-On(F,G,Pic5)
ElseIf {P}=6
Pt-On(F,G,Pic6)
ElseIf {P}=7
Pt-On(F,G,Pic7)
ElseIf {P}=8
Pt-On(F,G,Pic8)
ElseIf {P}=9
Pt-On(F,G,Pic9)
ElseIf {P}=10
Pt-On(F,G,Pic10)
ElseIf {P}=11
Pt-On(F,G,Pic11)
ElseIf {P}=12
Pt-On(F,G,Pic12)
Else
Pt-On(F,G,Pic0)^^r
End
End
RECT(29,19,38,38,1
RECT(70,21,24,14,~1
RECT(70,38,24,14,~1
DispGraphClrDraw^^r
Text(72,22,"Score:"
Text(73,28,S>Dec
Text(75,39,"Best:"
Text(73,45,{Q+18}^^r>Dec
About the N variable :
The problem was that when going Left for example, with 3 as a limit, the program was doing this :
[8,4,4,0]=>[0,0,0,16]
with steps : [8,4,4,0]=>[8,4,0,4]=>[8,0,0,8]=>[0,0,0,16]
Now, it does the following :
[8,4,4,0]=>[0,0,8,8]
[8,4,4,0]=>[8,4,0,4]=>[8,0,0,8]=>Set the limit to the third cell (targetted cell was fourth, limit is target-1) => [0,0,8,8] (the 8 stopped at the third cell because the limit was reached
And here's a gif, as you can see the Text is laggy and causes the grayscale to look bad, and I have no idea how to fix this, if anyone could help that could be great.
(http://www.omnimaga.org/index.php?action=dlattach;topic=21011.0;attach=17322;image)
Here's a gif without the text to show how fast it should be :
(http://www.omnimaga.org/index.php?action=dlattach;topic=21011.0;attach=17323;image)
Controls :
Arrows to swipe in a direction
2nd to show the help screen
mode to reset the game
Clear to quit
-
I see you use different pointers for your sprites. Instead you should use only one and use pointer offsets for that. Ie with only one command you do :
pt-on(x,y,id*8+PicX)
-
oh i had this issue too in my game,
i haven't read the whole code, but it has to do with updating the main, or back buffer iirc
just play around with clrdraw and you should be able to fix it
also, you should introduce yourself to the forum here: http://www.omnimaga.org/introduce-yourself!/ (http://www.omnimaga.org/introduce-yourself!/)
I see you use different pointers for your sprites. Instead you should use only one and use pointer offsets for that. Ie with only one command you do :
pt-on(x,y,id*8+PicX)
or you could do that, i think that would fix it too
Edit Sorunome: Merged double-posts
-
Double post = D:
-
That game is looking nice so far! So many good-quality 2048 clones out there :)
-
Thanks Sorumone, Streetwalrus this seems like a good idea, however how should I initialize this PicX? By putting "-> {PicX + 1,2,3,4...}" instead of "-> Pic1, Pic2, Pic3, Pic4..."?
About the text issue, I think I know why it does this. It's because there's no way to write Text on the buffer only, and in a fast enough way. I think drawing Text is just horribly slow :( . What do you mean exactly by "play around with ClrDraw"?
-
i'm not quite sure how to say this, but i think you should look at when to update the main/back buffers
like not updating every freaking second, but only if there is something to actually update
-
No, just remove all the pointers after all the sprites but the first. Then use Pic0 instead of PicX. ;)
-
Ok that's done, now I'm trying to solve that text problem.
On an unrelated note, how do I avoid Garbage Collecting everytime I compile my program?
-
have enough archive on your calc, which one are you using?
-
I have a TI-83+ (fr), and it says I have 86651 bytes of free archive...
-
then you shouldn't get so many garbage collect messages
it's not a big deal right?
-
Try manually GCing.
-
oh yeah, that could help too
-
Try manually GCing.
Yeah sure I should try that WTF are they talking about...
-
try garbage collecting from the catalog [2nd][0] and then garbage collect
-
Lol. I meant GarbageCollecting of course. :P
-
:ninja:
-
Ok that worked, thanks.
However, about the Text again, my Buffer actualisation (is that even a word in english?) needs to be in a fast enough loop to show grayscale, loop which the text slows down a lot... Maybe I'll try to actualise (...) the text only when needed.
-
that's what i've been trying to tell you
i had the same issue when i was programming in axe a while ago
-
Yeah, only refresh (English for actualiser) the text when needed. Or get rid of it altogether if you can.
-
Well you talked about updating (that's the god damn word :w00t: ) the buffers, not the text only. Anyway, now i understood.
Edit : ninja'd my sidenote...
Edit 2 : Get Rid of it? like using sprites to display the text?
-
well, good luck with programming :D
i would love to see this project finished (and actually have a stable version of 2048 on my calc :P)
-
I saw one with animations and stuff, though I think the graphics weren't as schlick as mine tbh :D
-
well, after actually downloading the game and trying it, i must say that the greyscale text isn't that bad :)
you should implement game over too though
-
Yeah Game Over should be good, but it's hard to implement I think (best way to do it I think would be comparing the actuale game table and what would happen after every possible move). And my problem is not the color of the text but mostly the color of the empty cells (compare the two gifs in my first post, first grayscale looks blurry and moving).
So I tried to update (!) the text only when the score changes, it works BUT only shows the score for a fraction of a second, since the screen is then cleared with a Cleardraw :/
-
Instead you could check for contiguous areas on the grid. That's easier.
-
if block next to block 1 = block 1
then: not game over
something like this?
-
Yeah. Basically if all four neighbours of each block are different from it, you lost. You also need to make sure that there's no empty blocks.
-
if block next to block 1 = block 1
or block next to block 1 = NaB (not a block :P)
then: not game over
-
You mean something like this?
LOOP
-If any cell is zero, stop loop, game not over
-If block0=block1 or block1=block5 or block1=block2 or... stop loop
-If loop goes to the block15 without finding any of the above, game over
ENDLOOP
-
yeah basically :)
but the blocks on the side only need to check those sides which actually contain spaces for blocks
-
Well if every block checks his bottom and left every bound will be checked
-
Yup pretty much.
While you need at most two checks per tile, you need to check 15 of them. Not the last one.
-
Except ones from the bottom row and right column shouldn't check their right/bottom. Gotta
write program that down.
-
HI AGAIN GUYS!
(sorry my happiness is exploding)
So the game's all done, thanks to pikachu and the walrus for the help. Here's a gif of how it works :
(http://www.omnimaga.org/index.php?action=dlattach;topic=21011.0;attach=17334;image)
and here's the code :
.A2048
[FF818181818181FF]->Pic0
[FF818199998181FF]
[FF8189B99D9181FF]
[FF81FF8181FF81FF]
[FF81BDA5A5BD81FF]
[FFA5FFA5A5FFA5FF]
[FF9999FFFF9999FF]
[FFC3A59999A5C3FF]
[FFC3BDBDBDBDC3FF]
[FFFFC3DBDBC3FFFF]
[FFFFFFE7E7FFFFFF]
[FFABD5ABD5ABD5FF]
[FFFFFFFFFFFFFFFF]
DeltaList(40,16)->Pic1
[FFFFF0FF00818190818081819F8180F999999980F999999980819981818081998181809F99F999809F99F9998081818981808181898180FFFF8FFF807FFF87FF80000000000000000000000000000000]
DiagnosticOff
ExprOn
Full
Fix 5
Fill(L1,16,0)
0->I->J->K
1->{L1+16}
UnArchive "|vA"
!If GetCalc("|vA"
GetCalc("|vA",20)->Q
R()
Else
GetCalc("|vA")->Q
End
LOAD()
GUI()
Repeat getKey(15)
If getKey
If getKey(1)
DOWN()
End
If getKey(2)
LEFT()
End
If getKey(3)
RIGHT()
End
If getKey(4)
UP()
End
If getKey(55)
R()
End
If getKey(54)
H()
End
GO()
If S>{Q+18}^^r
S->{Q+18}^^r
End
If S!=W
TEXT()
S->W
End
End
D()
End
SAVE()
ClrDraw^^r^^r
Return
Lbl DOWN
0->theta
For(J,0,3)
3->N
For(K,1,3)
3-K->I+1->X
If {4*I+J+L1}->V!=0
Repeat {4*X+J+L1}->T=V or (T!=V and (T!=0)) or (X=N)
X++
End
{4*X+J+L1}->T
If T!=V and (T!=0)
X--
End
If X!=I
If {4*X+J+L1}=0
V->{4*X+J+L1}
Else
V+1->{4*X+J+L1}
X-1->N
e^(V+1)+S->S
End
0->{4*I+J+L1}
theta++
End
End
End
End
If theta
N()
End
Return
Lbl LEFT
0->theta
For(J,0,3)
0->N
For(I,1,3)
If {4*J+I+L1}->V!=0
I-1->X
Repeat {4*J+X+L1}->T=V or (T!=V and (T!=0)) or (X=N)
X--
End
{4*J+X+L1}->T
If T!=V and (T!=0)
X++
End
If X!=I
If {4*J+X+L1}=0
V->{4*J+X+L1}
Else
V+1->{4*J+X+L1}
X+1->N
e^(V+1)+S->S
End
0->{4*J+I+L1}
theta++
End
End
End
End
If theta
N()
End
Return
Lbl RIGHT
0->theta
For(J,0,3)
3->N
For(K,1,3)
3-K->I+1->X
If {4*J+I+L1}->V!=0
Repeat {4*J+X+L1}->T=V or (T!=V and (T!=0)) or (X=N)
X++
End
If (T!=V and (T!=0))
X--
End
If X!=I
If {4*J+X+L1}=0
V->{4*J+X+L1}
Else
X-1->N
V+1->{4*J+X+L1}
e^(V+1)+S->S
End
0->{4*J+I+L1}
theta++
End
End
End
End
If theta
N()
End
Return
Lbl UP
0->theta
For(J,0,3)
0->N
For(I,1,3)
I-1->X
If {4*I+J+L1}->V!=0
Repeat {4*X+J+L1}->T=V or (T!=V and (T!=0)) or (X=N)
X--
End
{4*X+J+L1}->T
If T!=V and (T!=0)
X++
End
If X!=I
If {4*X+J+L1}=0
V->{4*X+J+L1}
Else
X+1->N
V+1->{4*X+J+L1}
e^(V+1)+S->S
End
0->{4*I+J+L1}
theta++
End
End
End
End
If theta
N()
End
Return
Lbl SAVE
conj(L1,Q,16)
S->{Q+16}^^r
Return
Lbl LOAD
conj(Q,L1,16)
{Q+16}^^r->S
Return
Lbl N
16->L
Repeat {L1+L}=0
rand^16->L
End
rand^6/5+1->{L1+L}
Return
Lbl R
0->S->W
Fill(L1,16,0
N()
N()
Return
Lbl GO
0->H
For(I,0,15)
If {I+L1}=0 or (I<12 and ({I+4+L1}={I+L1})) or (I^4!=3 and ({I+1+L1}={I+L1}))
1->H
End
End
!If H
Pause 300
ClrDraw^^r^^r
If S={Q+18}^^r
RECT(20,17,56,30,~1)
Text(30,20,"Game Over!")
Text(28,28,"Score:",S>Dec)
Text(23,36,"New Highscore!")
Else
RECT(24,21,47,21,~1)
Text(29,24,"Game Over!"
Text(27,32,"Score:",S>Dec)
End
DispGraph
Repeat getKey
End
R()
GUI()
End
Return
Lbl H
ClrDraw^^r^^r
For(I,0,11)
Pt-On(I/6*48+20,I^6*9+5,I+1*8+Pic0)
If I<6
Text(29,I*9+6,e^(I+1)>Dec)
End
End
Text(56,6,"128")
Text(56,15,"256")
Text(56,24,"512")
Text(52,33,"1024")
Text(52,42,"2048")
Text(52,51,"4096")
Text(58,58,"by Toctave"
DispGraph
Repeat getKey
End
GUI()
Return
Lbl RECT
HLine({r2},{r1}-{r5},{r1}+{r3}+{r5}
HLine({r2}+{r4},{r1}-{r5},{r1}+{r3}+{r5}
VLine({r1},{r2}-{r5},{r2}+{r4}+{r5}
VLine({r1}+{r3},{r2}-{r5},{r2}+{r4}+{r5}
Return
Lbl GUI
ClrDraw^^r^^r
Tangent(32,3,Pic1
For(I,0,15)
Pt-On(I^4*9+31,I/4*9+21,Pic0)^^r
End
RECT(29,19,38,38,1
RECT(70,21,24,14,~1
RECT(70,38,24,14,~1
TEXT()
Return
Lbl D
For(I,0,15)
If {L1+I}
Pt-On(I^4*9+31,I/4*9+21,{L1+I}*8+Pic0)
End
End
DispGraph^^r
Wref(31,21,35,35)
Return
Lbl TEXT
Text(72,22,"Score:"
Text(73,28,S>Dec
Text(75,39,"Best:"
Text(73,45,{Q+18}^^r>Dec
VLine(94,45,50)
VLine(94,28,33)
Return
Fix 4
What I changed :
-The GUI doesn't update every loop anymore, it now has its own subroutine GUI()
-Same for text, it only updates when needed with TEXT()
-Game Over is now supported, whenever you're stuck, the game stops and displays a window with your score and highscore if you beat it, then waits for any key and resets, it's subroutine GO()
-Every display bug is fixed, the text does not flash like an epileptic mouse anymore
-
Nice to see it done ! ;)
-
could you upload a compiled version?
i'm too lazy to download tokenIDE again :P
-
oops I totally forgot that :x
Here you go!
Don't hesitate to tell me if you see a bug/find the graphics horrible/have an idea for a new feature!
-
Oooh that looks quite nice, and I like the different tile style replacing numbers with drawings. :D
-
Thanks! I thought numbers would be either unreadable or would take the whole screen so I went for this style, allowing to have regular tile sizes. Any new feature ideas?
-
Would animated blocks be feasible? I think if you did that you should make the moving blocks monochrome while they are still moving, so the grayscale won't look weird.
-
Everything's feasible!
but erm... I have no idea how to do that.I would need to check if a block has moved and from where to where, then in a for loop make all the moves... I can't think of another way, and this one would be quite complicated to put up.
-
You can do that while you compute the tile movement.
-
I'm actually working on animations! What kind do you want? The kind where everything moves one tile at a time, or the kind of slide present in the "official" online version (where one "slide" iteration moves all tiles to their destination)?
-
Well I think the official version would be best as long as its not too slow.
-
Well nikitouzz's 2048 has original animations and it is far from being too slow ;)
-
Excuse me guys but would you care discussing this on your own thread since it's kind of unrelated to mine..
-
True, sorry about that :/
But in fact, there are (already) so many 2048 topics that I didn't even notice this was not JW's topic -.-
-
Hmmm I thought JWin was offering you some help but w/e. :P
-
Oh dang, ok. I didn't read it that way, thought he offered to add animations in his own game which I found weird. Anyway, I tried to implement animations this way :
-each time there is movement, store the evaluated cell address, the sprite index and the target cell address in a list
-make a for loop with the animation frame as an incrementing variable :
(for left-right movement here)
For(frame, 0, 7)
Check if there's something in the sprite, then
Pt-Off((target-pos)*frame+(pos^4*9+31), pos/4*9+21, sprite)
Pt-On((target-pos)*(frame+1)+(pos*9+31), pos/4*9+21, sprite)
End
Which gives with proper axe syntax :
For(J,0,7)
For(I,0,15)
If {I*3+L2}!=0
Pt-Off({I*3+2+L2}-{I*3+1+L2}*J+({I*3+1+L2}^4*9+31),{I*3+1+L2}/4*9+21,{I*3+L2}+Pic0)
Pt-On({I*3+2+L2}-{I*3+1+L2}*(J+1)+({I*3+1+L2}^4*9+31),{I*3+1+L2}/4*9+21,{I*3+L2}+Pic0)
End
End
End
But it doesn't work at all and gives weird results :(
-
Excuse me guys but would you care discussing this on your own thread since it's kind of unrelated to mine..
well excuuuse me princess :P
[EDIT]
this is a zelda reference btw
-
This thread...
SO! Can anyone tell me why the code I wrote above doesn't work? 'Cause here's an excel with exemples value that returns the Good numbers, I have no idea why it won't work on calc...
-
One thing to be wary of, which it looks like might have tripped you up in your code, is that Pt-Off() is a little bit deceptively named. It does not actually erase a sprite, but in fact draws a sprite (with overwrite logic instead of the OR logic used by Pt-On()). If you actually want to "erase" a sprite, you have to redraw what was behind it on top of it. In this case, I'd say that the easiest thing to do is to re-display the entire board at the start of rendering each frame, overwriting all tiles wherever they may have been last frame.
Also, I think you need a /8 after the multiplications by frame and frame+1.
As an optimization note, you can make division by small powers of two faster, at the cost of size, by chaining together divisions by two, like /2/2/2 for /8. If you divide by the same power of two more than once, you can often mitigate the size cost while keeping most of the speed gains by putting the division into a subroutine and calling that whenever you need to divide by it. You divide by both 8 and 4 in your code snippet, which could be pulled into subroutines that even share the same code:
Lbl Div8
/2
Lbl Div4
Return /2/2
-
You can also evaluate I*3+L2 once and save it into a variable instead of evaluating it 10 times per iteration. You can even forget about this and add 3 to a variable initialized at L2 after every iteration step and replace your For(I,0,15) with a For(16).
-
OK thanks guys this is great
Runer, I can't redraw thé whole board on top of it because I need every celle that moves to be displayed on the buffer before the unique Dispgraph (unique in the big for loop I mean)
About the /8, it's not needed because the pos and target values are not in pixels but in values from 0 to 15. If you open xls you'll sée that this calculus returns the right value
Hayleia, I will do what you said about the variable, but I don't think your second idea really brings anything to the program. However I'm the newbie here :D
Edit : Here's an xls file (That no one will read) that does every calculus using only a pos and target value.
-
Toctave, here is a little tip : If you're on a phone, try setting your keyboard language to english, the auto-correction will try to correct into english words! ;) :blah:
-
LOL I get the same issue with thé all the time because I forget to press the language switch. XD
-
Kii Keyboard on Android supports primary and secondary language, with correction on both languages without switching ;)
Maybe other keyboards do it too but I know this one does because I use it.
-
I just use the AOSP keyboard, it works pretty well. :P