Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Toctave on April 14, 2014, 09:39:41 am

Title: [Axe game] 2048
Post 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

Code: [Select]
.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
Title: Re: [Axe game] 2048
Post by: Streetwalrus on April 14, 2014, 09:43:38 am
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)
Title: Re: [Axe game] 2048
Post by: TheCoder1998 on April 14, 2014, 09:45:59 am
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
Title: Re: [Axe game] 2048
Post by: Streetwalrus on April 14, 2014, 09:47:54 am
Double post = D:
Title: Re: [Axe game] 2048
Post by: Sorunome on April 14, 2014, 09:55:49 am
That game is looking nice so far! So many good-quality 2048 clones out there :)
Title: Re: [Axe game] 2048
Post by: Toctave on April 14, 2014, 10:13:44 am
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"?
Title: Re: [Axe game] 2048
Post by: TheCoder1998 on April 14, 2014, 10:15:55 am
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
Title: Re: [Axe game] 2048
Post by: Streetwalrus on April 14, 2014, 10:16:24 am
No, just remove all the pointers after all the sprites but the first. Then use Pic0 instead of PicX. ;)
Title: Re: [Axe game] 2048
Post by: Toctave on April 14, 2014, 10:37:15 am
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?
Title: Re: [Axe game] 2048
Post by: TheCoder1998 on April 14, 2014, 10:37:55 am
have enough archive on your calc, which one are you using?
Title: Re: [Axe game] 2048
Post by: Toctave on April 14, 2014, 10:39:48 am
I have a TI-83+ (fr), and it says I have 86651 bytes of free archive...
Title: Re: [Axe game] 2048
Post by: TheCoder1998 on April 14, 2014, 10:40:55 am
then you shouldn't get so many garbage collect messages
it's not a big deal right?
Title: Re: [Axe game] 2048
Post by: Streetwalrus on April 14, 2014, 10:41:30 am
Try manually GCing.
Title: Re: [Axe game] 2048
Post by: TheCoder1998 on April 14, 2014, 10:41:53 am
oh yeah, that could help too
Title: Re: [Axe game] 2048
Post by: Toctave on April 14, 2014, 10:45:23 am
Try manually GCing.
Yeah sure I should try that WTF are they talking about...
Title: Re: [Axe game] 2048
Post by: TheCoder1998 on April 14, 2014, 10:45:59 am
try garbage collecting from the catalog [2nd][0] and then garbage collect
Title: Re: [Axe game] 2048
Post by: Streetwalrus on April 14, 2014, 10:46:21 am
Lol. I meant GarbageCollecting of course. :P
Title: Re: [Axe game] 2048
Post by: TheCoder1998 on April 14, 2014, 10:46:42 am
:ninja:
Title: Re: [Axe game] 2048
Post by: Toctave on April 14, 2014, 10:49:37 am
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.
Title: Re: [Axe game] 2048
Post by: TheCoder1998 on April 14, 2014, 10:50:36 am
that's what i've been trying to tell you
i had the same issue when i was programming in axe a while ago
Title: Re: [Axe game] 2048
Post by: Streetwalrus on April 14, 2014, 10:52:06 am
Yeah, only refresh (English for actualiser) the text when needed. Or get rid of it altogether if you can.
Title: Re: [Axe game] 2048
Post by: Toctave on April 14, 2014, 10:53:11 am
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?
Title: Re: [Axe game] 2048
Post by: TheCoder1998 on April 14, 2014, 10:54:52 am
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)
Title: Re: [Axe game] 2048
Post by: Toctave on April 14, 2014, 10:57:12 am
I saw one with animations and stuff, though I think the graphics weren't as schlick as mine tbh :D
Title: Re: [Axe game] 2048
Post by: TheCoder1998 on April 14, 2014, 10:58:47 am
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
Title: Re: [Axe game] 2048
Post by: Toctave on April 14, 2014, 11:06:02 am
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 :/
Title: Re: [Axe game] 2048
Post by: Streetwalrus on April 14, 2014, 11:07:41 am
Instead you could check for contiguous areas on the grid. That's easier.
Title: Re: [Axe game] 2048
Post by: TheCoder1998 on April 14, 2014, 11:09:48 am
if block next to block 1 = block 1
then: not game over

something like this?
Title: Re: [Axe game] 2048
Post by: Streetwalrus on April 14, 2014, 11:11:43 am
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.
Title: Re: [Axe game] 2048
Post by: TheCoder1998 on April 14, 2014, 11:12:44 am
if block next to block 1 = block 1
or block next to block 1 = NaB (not a block :P)
then: not game over
Title: Re: [Axe game] 2048
Post by: Toctave on April 14, 2014, 11:14:17 am
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
Title: Re: [Axe game] 2048
Post by: TheCoder1998 on April 14, 2014, 11:15:24 am
yeah basically :)
but the blocks on the side only need to check those sides which actually contain spaces for blocks
Title: Re: [Axe game] 2048
Post by: Toctave on April 14, 2014, 11:17:09 am
Well if every block checks his bottom and left every bound will be checked
Title: Re: [Axe game] 2048
Post by: Streetwalrus on April 14, 2014, 11:18:25 am
Yup pretty much.
While you need at most two checks per tile, you need to check 15 of them. Not the last one.
Title: Re: [Axe game] 2048
Post by: Toctave on April 14, 2014, 11:20:43 am
Except ones from the bottom row and right column shouldn't check their right/bottom. Gotta write program that down.

Title: Re: [Axe game] 2048
Post by: Toctave on April 14, 2014, 03:07:46 pm
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 :




Code: [Select]
.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
Title: Re: [Axe game] 2048
Post by: Streetwalrus on April 14, 2014, 07:50:58 pm
Nice to see it done ! ;)
Title: Re: [Axe game] 2048
Post by: TheCoder1998 on April 15, 2014, 09:56:42 am
could you upload a compiled version?
i'm too lazy to download tokenIDE again :P
Title: Re: [Axe game] 2048
Post by: Toctave on April 15, 2014, 12:52:39 pm
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!
Title: Re: [Axe game] 2048
Post by: DJ Omnimaga on April 15, 2014, 01:17:54 pm
Oooh that looks quite nice, and I like the different tile style replacing numbers with drawings. :D
Title: Re: [Axe game] 2048
Post by: Toctave on April 15, 2014, 01:41:04 pm
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?
Title: Re: [Axe game] 2048
Post by: DJ Omnimaga on April 15, 2014, 01:45:20 pm
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.
Title: Re: [Axe game] 2048
Post by: Toctave on April 15, 2014, 01:50:43 pm
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.
Title: Re: [Axe game] 2048
Post by: Streetwalrus on April 15, 2014, 04:13:02 pm
You can do that while you compute the tile movement.
Title: Re: [Axe game] 2048
Post by: JWinslow23 on April 19, 2014, 02:59:04 pm
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)?
Title: Re: [Axe game] 2048
Post by: ClrDraw on April 20, 2014, 12:01:46 am
Well I think the official version would be best as long as its not too slow.
Title: Re: [Axe game] 2048
Post by: Hayleia on April 20, 2014, 02:32:23 am
Well nikitouzz's 2048 has original animations and it is far from being too slow ;)
Title: Re: [Axe game] 2048
Post by: Toctave on April 20, 2014, 02:35:23 am
Excuse me guys but would you care discussing this on your own thread since it's kind of unrelated to mine..
Title: Re: [Axe game] 2048
Post by: Hayleia on April 20, 2014, 02:37:29 am
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 -.-
Title: Re: [Axe game] 2048
Post by: Streetwalrus on April 20, 2014, 04:30:21 am
Hmmm I thought JWin was offering you some help but w/e. :P
Title: Re: [Axe game] 2048
Post by: Toctave on April 20, 2014, 06:48:54 am
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 :


Code: [Select]
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 :(
Title: Re: [Axe game] 2048
Post by: TheCoder1998 on April 20, 2014, 09:57:32 am
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
Title: Re: [Axe game] 2048
Post by: Toctave on April 20, 2014, 12:00:07 pm
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...
Title: Re: [Axe game] 2048
Post by: Runer112 on April 20, 2014, 12:31:55 pm
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:

Code: [Select]
Lbl Div8
/2
Lbl Div4
Return /2/2
Title: Re: [Axe game] 2048
Post by: Hayleia on April 20, 2014, 01:05:31 pm
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).
Title: Re: [Axe game] 2048
Post by: Toctave on April 20, 2014, 03:24:07 pm
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.
Title: Re: [Axe game] 2048
Post by: Eiyeron on April 24, 2014, 09:50:05 am
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:
Title: Re: [Axe game] 2048
Post by: Streetwalrus on April 24, 2014, 01:21:27 pm
LOL I get the same issue with thé all the time because I forget to press the language switch. XD
Title: Re: [Axe game] 2048
Post by: Hayleia on April 24, 2014, 01:23:00 pm
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.
Title: Re: [Axe game] 2048
Post by: Streetwalrus on April 24, 2014, 07:06:58 pm
I just use the AOSP keyboard, it works pretty well. :P