You code has a couple major flaws in it. The first flaw is that you don't initialize all of the variables that you are using. This causes domain errors because the variables may be large or smaller than the screen size before the program even begins. The second flaw that you have is that you use a for( loop to loop. The way that your program is coded, if 99 turns come along and you have still not gotten your guy, the program ends. I don't think this is the intended behavior of the program. Instead, what you should have used is a while( or a repeat( loop. Besides these two flaws, there is just general optimizations that your program lacks. This is the code that resulted from taking all of these things into account.
1->A:1->B
8->C:8->D
Repeat A=C and B=D
ClrHome
getKey->K
A+(Ans=34 and A<8)-(Ans=25 and A>1->A
B+(K=26 and B<16)-(K=24 and B>1->B
Output(A,B,9
Output(C,D,6
randInt(-1,1
C+(Ans=1 and C<8)-(Ans=-1 and C>1->C
randInt(-1,1
D+(Ans=1 and D<16)-(Ans=-1 and D>1->D
End
Anonymous wrote:You code has a couple major flaws in it. The first flaw is that you don't initialize all of the variables that you are using. This causes domain errors because the variables may be large or smaller than the screen size before the program even begins. This is where the user sets it, saves code space. The second flaw that you have is that you use a for( loop to loop. The way that your program is coded, if 99 turns come along and you have still not gotten your guy, the program ends. I don't think this is the intended behavior of the program. Actually, this is intended. Also a form of keeping score, thought about using For(99,1,-1, but that uses more space ;] Instead, what you should have used is a while( or a repeat( loop. Besides these two flaws, there is just general optimizations that your program lacks. This is the code that resulted from taking all of these things into account.
1->A:1->B
8->C:8->D
Repeat A=C and B=D
ClrHome ;Flashing effect, don't want this
getKey->K
A+(Ans=34 and A<8)-(Ans=25 and A>1->A
B+(K=26 and B<16)-(K=24 and B>1->B
Output(A,B,9
Output(C,D,6
randInt(-1,1
C+(Ans=1 and C<8)-(Ans=-1 and C>1->C
randInt(-1,1
D+(Ans=1 and D<16)-(Ans=-1 and D>1->D
End
Have you two Guests even considered registering to this board? I'm finding myself having to backtrack to distinguish between you two. In the long run, registering will save us a lot of headache.
"If SOURCE is outlawed, only outlaws will have SOURCE."
This depends on how you want the AI player to move. Do you want to have the AI player sporadically jumping or do you want it moving by one?
are you quoting yourself or is this a different 'Guest'. Please register as it will save me headaches too. Afaik the two 'Guest's could be the same person having a convo with himself
Just a lil something off-topic, but in the other topic CoBB told me to use boolean logic so yesterday I looked at my walking engine code and I figured out a new way to handle animated walking sprite, a method that can be used for many thing, like switching back and forth a variable. Assuming that you store 0 in H. Instead of
I need help optimizing the code in Aura's overworld engine. Keep in mind, in many places where the code is clunky I would be unable t do it any other way, because of the ridiculous abilities required of this engine.
//Main walking loop
35->X
Asm(prgmZPIC //each screen-sized section of map is represented by a pic; this map is 2x6, therefore pic 31 is the top left corner and pic 36 is the bottom right
19:Asm(prgmCODEX
24->A //chrcter x coord
32->B //character y coord
2->S
prgmZUP //displays character facing upwards
While 1
getKey->K
If K=24
Then
If A>=8 //if character is not about to step off the left edge of the screen
Then
prgmZHITLEFT //runs collision detection
Else
If X/=31 and X/=33 and X/=35 //if moving the character will not move him off the left edge of the map
Then
X-1->X
Asm(prgmZPIC
72->A
prgmZLEFT //displays character facing left
End
End
End
If K=25
Then
If B>=4
Then
prgmZHITUP //collision detection
Else
If X>32
Then
X-2->X
Asm(prgmZPIC
32->B
prgmZUP
End
End
End
If K=26
Then
If A<=68
Then
prgmZHITRIGH
Else
If X/=32 and X/=34 and X/=36
Then
X+1->X
Asm(prgmZPIC
0->A
prgmZRIGHT
End
End
End
If K=34
Then
If B÷28
Then
prgmZHITDOWN
Else
If X<35
Then
X+2->X
Asm(prgmZPIC
0->B
prgmZDOWN
End
End
End
End
Also need help optimizing my collision detection (this is realy ugly code):
//downwards collision detection
If X=31 //if pic=31
Then
For(L,1,dim(LX131 //scans the list containing the x value of the top right corner of each collideable object in pic31
If LX131(L)<=A+24 and LX231(L)>=A and LY131(L)<=B+40 and LY231(L)>=B+36 //if moving the character will move him over an object
Then
LX131(L)->T
LY131(L)->U
If LT31(L)=1
Then
B+8->B
1->M
prgmZDOWN //draws the chcracter facing downwards
prgmZTILE1 //masks the tile over the character
Return
End
prgmZDOWN
Return
End
End
End
// this is repeated for each pic, and that whole program is repeated for the other three directions
"You're very clever, young man, but it's turtles all the way down!"
//up = 1, down = 2, left = 3, right = 4
If X=31 //if pic=31
Then
For(L,1,dim(LX131
If //this code will probably need to be changed depending on D
Then
LX131(L)->T
LY131(L)->U
If LT31(L)=1
Then
B+8(D=2) - 8(D=1 -> B
A+8(D=4) - 8(D=3 -> A
1->M
prgmZDIR //draws the character
prgmZTILE1 //masks the tile over the character
Return
End
prgmZDIR
Return
End
End
End
prgmZDIR:
If D= 2 : prgmZDOWN
If D= 1 : prgmZUP
If D= 3 : prgmZLEFT
If D= 4 : prgmZRIGHT