Here's a simple game I threw together quickly a few minutes ago that uses the [A] MATRIX sort of like a map file.

The matrix has a dim of {8,16}
Probably easier just to use the map editor I threw in, if you're testing it on calc.

Code:
1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1

1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1

1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1

1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1

1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   1

1   1   1   0   0   0   0   0   0   0   0   0   0   1   1   1

1   1   1   1   0   0   0   0   1   0   0   0   1   1   1   1

1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1


You can pretty much throw in any code if you like.
1 = a block, 0 = open space

And here's the code for the game. What are some methods of optimizing this code? I did my best to optimize it as much as possible already. Though, I'm sure to get some criticism for the way I store X and Y onkeypress. Laughing

Code:
:0→X:0→Y
:"Display the map
:ClrHome
:For(θ,1,8
:For(Z,1,16
:If 1=[A](θ,Z
:Output(θ,Z,"=
:If X+Y<2 and 1=[A](θ,Z
:Then
:θ→Y:Z→X
:End
:End
:End
:"Check for valid spawn point
:If X+Y<2
:Goto OH
:"Prepare the game
:Output(Y,X,"{i}
:While 1
:Repeat K
:getKey→K
:End
:Output(Y,X,"
:X-(K=24 and X-1 and not([A](Y,X-1)))+(K=26 and X-16 and not([A](Y,X+1→X
:Y-(K=25 and Y-1 and not([A](Y-1,X)))+(K=34 and Y-16 and not([A](Y+1,X→Y
:Output(Y,X,"{i}
:DelVar K
:End
:Lbl OH
:"This happens when the map is fully saturated with blocks
:Output(1,1,"Oh no!
:Output(2,1,"Theres no place
:Output(3,1,"for the player!
:Output(8,1,"Press any key...
:Repeat getKey:End
:ClrHome
Thanks in advance! Smile

Oh, and here's a map editor I threw together half a sec ago Very Happy

Code:
:Menu("Is [A] defined?","Yes",A,"No",B
:Lbl A
:If 2=sum({8,16})=dim([A]
:Goto C
:Lbl B
:{8,16}=dim([A]
:Lbl C
:1→X:1→Y
:ClrHome
:"Display the map
:For(θ,1,8
:For(Z,1,16
:If 1=[A](θ,Z
:Output(θ,Z,"=
:End
:End
:"Prepare the editor
:Output(Y,X,"O
:If 1=[A](Y,X,"≠
:While 1
:Repeat K
:getKey→K
:End
:Output(Y,X,"
:If K=21 and K≠34 and 2<abs(K-25
:Then
:abs(1-[A](Y,X→[A](Y,X
:Else
:If 1=[A](Y,X
:Output(Y,X,"=
:X-(K=24 and X-1)+(K=26 and X-16→X
:Y-(K=25 and Y-1)+(K=34 and Y-8→Y
:Output(Y,X,"O
:If 1=[A](Y,X
:Output(Y,X,"≠
:DelVar K
:End
Swivelgames, the only thing that jumps out at me is combining
Code:
:Delvar K
:End
into
Code:
:Delvar KEnd


Can you explain this to me:

Code:
If 2=sum({8,16})=dim([A]
I don't believe combining those two commands will work, as for some reason I think it causes the parser to skip the End.
tifreak8x wrote:
I don't believe combining those two commands will work, as for some reason I think it causes the parser to skip the End.
Fascinating, although based on BrandonW's and my recent discussions of the parser and its inner workings, I'd definitely believe that.
Also:

Code:
:If K=21 and K≠34 and 2<abs(K-25

If K=21, then "K≠34" and "2<abs(K-25 " must already be true.
rthprog, Yeah, I changed that up today when I went through the code. I was pretty tired when I wrote that, haha.

KermMartian wrote:
Can you explain this to me:

Code:
If 2=sum({8,16})=dim([A]
That's actually supposed to be:
Code:
If {8,16}=dim([A]
But, again, I was tired, haha.

What other optimizations can you all find? Or tips on how to construct the program?

EDIT!
Haha, actually, I'm kind of tired right now, and the statement was actually correct. Basically I want to check if the dim of [A] is {8,16}. The statement "{8,16}=dim([A]", however, returns either {1,1} or {0,0}, so I have to check the sum of the return value it it's equal to either 2 or 0. If the dim of [A] is {8,16} the answer is 2, if not the answer is 0. Now that I look at it, though, I could probably remove the 2= and get away with it Smile



Also, I wrote a graph-screen version, and wasn't sure if you all would take a look at that as well. I greatly appreciate you all helping to optimize these Very Happy

GMAP

Code:
:ClrHome
:0→X:0→Y
:Horizontal 10
:Horizontal -10
:Vertical 10
:Vertical -10
:For(θ,0,9
:For(Z,0,22
:If X+Y<2 and not([B](θ+1,Z+1
:Then
:θ→Y:Z→X
:End
:If [B](θ+1,Z+1
:Text(1+6θ,2+4Z,"=
:End
:End
:While 1
:Text(1+6Y,2+4X,"O
:Repeat K
:getKey→K
:End
:Text(1+6Y,2+4X,"   
:X-(K=24 and X-1 and not([B](1+Y,X)))+(K=26 and X-22 and not([B](1+Y,2+X→X
:Y-(K=25 and Y-1 and not([B](Y,X+1)))+(K=34 and Y-9 and not([B](2+Y,1+X→Y
:DelVar K
:End


GMAPEDIT

Code:
:Menu("Prepare [B]?","No",A,"Yes",B
:Lbl A
:If {10,23}=dim([B]
:Goto C
:Lbl B
:{10,23}=dim([B]
:Fill(0,[B]
:Lbl C
:ClrHome
:Horizontal 10
:Horizontal -10
:Vertical 10
:Vertical -10
:For(θ,0,9
:For(Z,0,22
:If [B](θ+1,Z+1
:Text(1+6θ,2+4Z,"=
:End
:End
:1→X:1→Y
:While 1
:Text(1+6Y,2+4X,"O
:If [B](Y+1,X+1
:Text(1+6Y,2+4X,"θ
:Repeat K
:getKey→K
:End
:Text(1+6Y,2+4X,"   
:If [B](1+Y,1+X
:Text(1+6Y,2+4X,"=
:If K=34 or 2>abs(K-25
:Then
:X-(K=24 and X-1)+(K=26 and X-22→X
:Y-(K=25 and Y-1)+(K=34 and Y-9→Y
:End
:If K=21
:abs(1-[B](Y+1,X+1→[B](Y+1,X+1
:DelVar K
:End

EDIT .....6 Question removed, resolved. Very Happy
Give xLib a try. For graphscreen-oriented programs, it's pretty much magic. http://www.ticalc.org/archives/files/fileinfo/359/35907.html
KermMartian wrote:
tifreak8x wrote:
I don't believe combining those two commands will work, as for some reason I think it causes the parser to skip the End.
Fascinating, although based on BrandonW's and my recent discussions of the parser and its inner workings, I'd definitely believe that.
Since the no-newline feature of Delvar is pretty much an easter egg, I wouldn't expect differently. Would you rather the parser parse every line for Delvar when searching for an End, or simply a newline/colon preceding an End?
rthprog wrote:
Give xLib a try. For graphscreen-oriented programs, it's pretty much magic. http://www.ticalc.org/archives/files/fileinfo/359/35907.html
I truly enjoy writing pure BASIC programs, but then again I've never given any BASIC libraries a try, and it couldn't hurt. Although, I would like to know the best techniques for writing in BASIC, as that's what I'm aiming for mostly. I'd love to write an awesome pure BASIC game (or game engine) Very Happy lol (even though I'm sure it's been done plenty of times before Laughing )


EDIT I'm working on a fix for the last variation of the program (the graph screen version) I posted up, since you technically can't even attempt to overstep the boundaries cause it tries to check for non-existent elements of [B]. If anyone has any good ideas, please post them Smile (I'm sure they'll be better then mine Very Happy ). Anyway, I'm tired, so I'ma head to bed. haha. Look forward to seeing some replies. Thanks! and Thanks in advance Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement