Quote: | Originally Posted by YottaFlop Alright. I think I've got it. But as I add more (I also have an exit key, a currently static enemy that triggers Game Overs, etc.), it starts to slow down just a small bit.
Code:
ClrHome
5->A
5->B
While 1
ClrHome
#### OUTPUT OBSTACLES ####
Output(B,A,"+")
getKey->K
While K=0
getKey->K
End
A->C
B->D
C+(K=26)-(K=24)->C
D+(K=34)-(K=25)->D
If [A](D,C)!=1
Then
A+(K=26)-(K=24)->A
B+(K=34)-(K=25)->B
End
End
|
Here's a quick little code I made:
(Note: underscores represent space in text)
Code:
ClrHome
{8,16->dim([A]
For(A,1,8
For(B,1,16
(A=1) or (A=8) or (B=1) or (B=16->[A](A,B
End
End
2->[A](2,2
3->[A](4,8
4->[A](7,15
For(A,1,8
For(B,1,16
"_
If 1=[A](A,B
"*
If 2=[A](A,B
"+
If 3=[A](A,B
"O
If 4=[A](A,B
"E
Output(A,B,Ans
If Ans="+
Then
A->C
B->D
End
End
End
C->A
D->B
Repeat A=7 and B=15
Output(C,D,"_
Output(A,B,"+
Repeat Ans
getKey->K
End
If sum(K={24,25,26,34
Then
A->C
B->D
A+(K=34)-(K=25->A
B+(K=26)-(K=24->B
If A=7 and B=15 or not([A](A,B
Then
0->[A](C,D
2->[A](A,B
Else
If 1=[A](A,B
Then
C->A
D->B
Else
C+2(A-C->E
D+2(B-D
If E>0 and E<9 and Ans>0 and Ans<17 and not([A](E,Ans
Then
Output(E,Ans,"O
[A](A,B->[A](E,Ans
0->[A](C,D
2->[A](A,B
Else
C->A
D->B
End
End
End
End
End
Works like a charm.
Quick and to the point.
What it does is it first checks to see if you pressed an arrow key, then if so, stores it's current position into C and D. Then it finds out where it will be according to which arrow you pressed. After that, it checks first and foremost to see if it's empty or if it's the exit (E) tile. If so, it puts 2 into that point on the matrix, and then clears it's old position (on both matrix and graphically). If there is something there (other than the E tile), then it first checks to see if it's a wall. If you want to customize it to your needs, you can have it check to see if it's a tile/object that you don't want your character to move. If it's a immobile object (or wall in this case) then it reverts to it's original position. If it's a mobile object (in this case the "O" or what's supposed to be a rock or something like that), then it finds out where THAT would move, and stores that into E and Ans. If that's empty, it moves both it and your character. If it isn't empty, then again, you revert to your original position. Unlike your character, when it checks to see if the rock's new position, it checks only if it's empty, if there' anything in the new position, it unconditionally, will not move. You can change this so that if you want it to go on a panel to open a door or something like that, but try and make sure that you don't program too many different types of panels, as it will get slightly slower each time you program a new one in.
What do you think?
Last edited by MufinMcFlufin : October 16th, 2009 at 12:17 PM.
|