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:
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.
Code:
Thanks in advance!
Oh, and here's a map editor I threw together half a sec ago
Code:
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.
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
Oh, and here's a map editor I threw together half a sec ago
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