http://calcg.org/newlogo2.png Not Logged in.
Login | Register

General Discussion Board \ Calculator Programming \ Need help with my game!

Click here to log in (you must be logged in to post comments).

AuthorComment
CarbonFire
Probe
Posted: 19 Feb 2009
21:47 GMT
Total Posts: 6
I have a Mouse Trap game where you move boxes to trap the M that randomly moves on screen. I have 2 problems.

The ü is the Store arrow and á is the litle L for List

1. The M Move Logic shuts the script down if it tries to move in the same direction twice and fails both times. Heres the code:

Lbl J

WüU
ZüV
randInt(1,4)üI
If I=1
W+1üW
If I=2
W-1üW
If I=3
Z+1üZ
If I=4
Z-1üZ

If ((W=áB(1) and Z=áB(2)) or (W=áB(3) and Z=áB(4)) or (W=áB(5) and Z=áB(6))) or W<1 or W>16 or Z<1 or Z>8
Then
UüW
VüZ
Goto J
End

If you dont get whats going on, Pretty much it saves W and Z (The M's X and Y Coordinates respectively) in case the move doesnt work out, and moves on to generate a random number 1-4. Then, it moves using the random number, and checks if its on top of any of the Boxes (the List parts) or if its off screen. If it is one of those, it sets the location to the previous spot, and tries to move again. If it doesnt hit anything, the game goes on to move the main character and the boxes.


2. The game randomly freezes occasionally

Code:
0üH
Lbl F
ClrHome
Menu("Trap V1.00","Start",C,"Instructions",D,"Exit",E)
Lbl E
ClrHome
Disp "Final Score"
Disp "The Lower = Better"
Pause H
ClrHome
Stop

Lbl D
ClrHome
Disp "To Move:"
Disp "Arrow Keys"
Disp "To Win:"
Disp "Trap the M"
Disp "Game Tip:"
Disp "M Cant Go In Box"
Disp "0 Key To Leave"
Repeat Ans
getKey
End
Goto F

Lbl C
SetUpEditorB
0üF
1üI
1üQ

1üX
1üY
1üM
1üN

10üW
4üZ
10üU
4üV

2üáB(1)
2üáB(2)
2üáB(3)
4üáB(4)
2üáB(5)
6üáB(6)

While 1
ClrHome
Output(Y,X,"X
Output(Z,W,"M
Output(áB(2),áB(1),"Ð
Output(áB(4),áB(3),"Ð
Output(áB(6),áB(5),"Ð

Repeat O
getKeyüO
End
OüK

Lbl J

WüU
ZüV
randInt(1,4)üI
If I=1
W+1üW
If I=2
W-1üW
If I=3
Z+1üZ
If I=4
Z-1üZ

If ((W=áB(1) and Z=áB(2)) or (W=áB(3) and Z=áB(4)) or (W=áB(5) and Z=áB(6))) or W<1 or W>16 or Z<1 or Z>8
Then
UüW
VüZ
Goto J
End

XüM
YüN

If K=102
Goto E

If K=24 and X>1
X-1üX

If K=26 and X<16
X+1üX

If K=25 and Y>1
Y-1üY

If K=34 and Y<8
Y+1üY

1üÁ
For(Á,1,5,2)
If X=áB(Á) and Y=áB(Á+1)
Then
ÁüL
1üA
End
End

If A=1
Then
If M>áB(L)
Then
áB(L)-1üáB(L)
End
If M<áB(L)
Then
áB(L)+1üáB(L)
End
If N>áB(L+1)
Then
áB(L+1)-1üáB(L+1)
End
If N<áB(L+1)
Then
áB(L+1)+1üáB(L+1)
End
0üA

If áB(L)<1 or áB(L)>16
Then
XüáB(L)
MüX
End
If áB(L+1)<1 or áB(L+1)>8
Then
YüáB(L+1)
NüY
End
End

H+1üH
End
tifreak8x
Administrator
avatar
Posted: 20 Feb 2009
10:29 GMT
Total Posts: 419
Hmm.. Gonna need some time to go through this and see what I can figure out..

Also, use of Lbl and Goto commands are frowned upon in BASIC, as it can, and will in 95% of anything you do, slow down your program.

----------------------------------------------------------------------

Edit bleh.. Decided to just clean up the code, fix things I see, optimize what I can..

Code:

Delvar H
Lbl F
ClrHome
Menu("Trap V1.00","Start",C,"Instructions",D,"Exit",E
Lbl E
ClrHome
Disp "Final Score","The Lower = Better"
Pause H
ClrHome
Return

Lbl D
ClrHome
Disp "To Move:","Arrow Keys","To Win:","Trap the M","Game Tip:","M Cant Go In Box","0 Key To Leave
Repeat getKey
End
Goto F


Lbl C
SetUpEditor B
Delvar F
1->I
1->Q
1->X
1->Y
1->M
1->N
10->W
4->Z
W->U
4->V
{2,2,2,4,2,6->L_B

While 1
ClrHome
Output(Y,X,"X
Output(Z,W,"M
Output(L_B(2),L_B(1),"Ð
Output(L_B(4),L_B(3),"Ð
Output(L_B(6),L_B(5),"Ð

Repeat O
getKey->O
End
O->K

Lbl J

W->U
Z->V
randInt(1,4
If Ans
W+1->W
If Ans=2
W-1->W
If Ans=3
Z+1->Z
If Ans=4
Z-1->Z

If ((W=L_B(1) and Z=L_B(2)) or (W=L_B(3) and Z=L_B(4)) or (W=L_B(5) and Z=L_B(6))) or W<1 or W>16 or Z<1 or Z>8
Then
U->W
V->Z
Goto J
End

X->M
Y->N

If K=102
Goto E

If K=24 and X>1
X-1->X

If K=26 and X<16
X+1->X

If K=25 and Y>1
Y-1->Y

If K=34 and Y<8
Y+1->Y

1->Á
For(/theta/,1,5,2)
If X=L_B(/theta/) and Y=L_B(/theta/+1)
Then
/theta/->L
1->A
End
End

If A=1
Then
If M>L_B(L:L_B(L)-1->L_B(L
If M<L_B(L:L_B(L)+1->L_B(L
If N>L_B(L+1:L_B(L+1)-1->L_B(L+1
If N<L_B(L+1:L_B(L+1)+1->L_B(L+1
Delvar A

If L_B(L)<1 or 16<L_B(L
Then
X->L_B(L
M->X
End
If L_B(L+1)<1 or 8<L_B(L+1
Then
Y->L_B(L+1
N->Y
End
End

H+1->H
End

---
Bringing you Pokemon, for your calculator.
CarbonFire
Probe
Posted: 20 Feb 2009
15:10 GMT
Total Posts: 6
ok, if fixed those 2 problems but im still working on stuff
CarbonFire
Probe
Posted: 20 Feb 2009
17:16 GMT
Total Posts: 6
k heres revised code:

if you have any questions post here ill get back to ya soon.

0üR
0üáB(8)
Lbl F
ClrHome
Menu("Trap V1.00","Start",C,"Instructions",D,"LOWSCORE",P,"Exit",E)
Lbl E
ClrHome
Disp "Final Score"
Disp "The Lower = Better"
If H<áB(7) and R=1
HüáB(7)
Disp H
Repeat Ans
getKey
End
ClrHome
Stop

Lbl P
ClrHome
Disp "LOWSCORE"
Disp áB(7)
Repeat Ans
getKey
End
Goto F

Lbl D
ClrHome
Disp "TO MOVE: ARROWS"
Disp "To Win:"
Disp "Trap the M"
Disp "Game Tip:"
Disp "M Cant Go In Box"
Disp "0 Key To Leave"
Disp "1 KEY TO RESTART"
Repeat Ans
getKey
End
Goto F

Lbl C
0üáB(8)
0üH
SetUpEditorB
0üF
1üI
1üQ

1üX
1üY
1üM
1üN

10üW
4üZ
10üU
4üV

2üáB(1)
2üáB(2)
2üáB(3)
4üáB(4)
2üáB(5)
6üáB(6)

While 1
ClrHome
Output(Y,X,"X
Output(Z,W,"M
Output(áB(2),áB(1),"Ð
Output(áB(4),áB(3),"Ð
Output(áB(6),áB(5),"Ð

Repeat O
getKeyüO
End
OüK

For(Á,1,4)
For(T,1,5,2)
If Á=1
Then
If (áB(T)=W and áB(T+1)=Z-1) or Z-1<1
áB(8)+1üáB(8)
End
If Á=2
Then
If (áB(T)=W+1 and áB(T+1)=Z) or W+1>16
áB(8)+1üáB(8)
End
If Á=3
The
If (áB(T)=W and áB(T+1)=Z+1) or Z+1>8
áB(8)+1üáB(8)
End
If Á=4
Then
If (áB(T)=W-1 and áB(T+1)=Z) or W-1<1
áB(8)+1üáB(8)
End
End
End
If áB(8)ù4
Goto E
0üáB(8)

WüU
ZüV
randInt(1,4)üI
If I=1
W+1üW
If I=2
W-1üW
If I=3
Z+1üZ
If I=4
Z-1üZ

If ((W=áB(1) and Z=áB(2)) or (W=áB(3) and Z=áB(4)) or (W=áB(5) and Z=áB(6))) or W<1 or W>16 or Z<1 or Z>8
Then
UüW
VüZ
End

XüM
YüN

If K=92
Goto F

If K=102
Goto E

If K=24 and X>1
X-1üX

If K=26 and X<16
X+1üX

If K=25 and Y>1
Y-1üY

If K=34 and Y<8
Y+1üY

1üÁ
For(Á,1,5,2)
If X=áB(Á) and Y=áB(Á+1)
Then
ÁüL
1üA
End
End

If A=1
Then
If M>áB(L)
Then
áB(L)-1üáB(L)
End
If M<áB(L)
Then
áB(L)+1üáB(L)
End
If N>áB(L+1)
Then
áB(L+1)-1üáB(L+1)
End
If N<áB(L+1)
Then
áB(L+1)+1üáB(L+1)
End
0üA

If áB(L)<1 or áB(L)>16
Then
XüáB(L)
MüX
End
If áB(L+1)<1 or áB(L+1)>8
Then
YüáB(L+1)
NüY
End
End

H+1üH
End
tifreak8x
Administrator
avatar
Posted: 20 Feb 2009
17:56 GMT
Total Posts: 419
Just curious, but did you apply -any- of the changes in code I did to your game?

Granted, I didn't get around to fixing some aspects of the movement engine that needs to be..

---
Bringing you Pokemon, for your calculator.
CarbonFire
Probe
Posted: 20 Feb 2009
18:20 GMT
Total Posts: 6
no i didnt, i didnt see your changes, and i did all the rest at school.
tifreak8x
Administrator
avatar
Posted: 20 Feb 2009
18:35 GMT
Total Posts: 419
Well, you should look into adding my changes to the code, will save you some space and speed things up a bit.

---
Bringing you Pokemon, for your calculator.
CarbonFire
Probe
Posted: 20 Feb 2009
20:53 GMT
Total Posts: 6
it would be easier for me if you changed the final code because I dont really know what you did and I dont want to mess it up
Vectris
Ultralisk
avatar
Posted: 21 Feb 2009
08:14 GMT
Total Posts: 375
If your going to use symbols at least use the right ones! I'd like to help but it's so confusing with Us for stores and As for Ls.

There's no reason to waste time using symbols when you can just use -> for store (much better than A) and use something like a | or \ for L. Or get a symbol like └ that at least kind of make sense instead of an 'a'.

If you can replace your code with -> and └ I can try to help.
CarbonFire
Probe
Posted: 21 Feb 2009
10:30 GMT
Total Posts: 6
it did that automatically cause I copied code from TI program editor. just do search and replace yourself





Portal | My Account | Register | Lost Password or Username | TOS | Disclaimer | Help | Site Search | File Archives Copyright © 2002-2019 CalcG.org