Well now that I got my feet wet posting on this forum, I'll ask another question.
I've been working my way through the programming book (very nice book by the way), and I am trying to do my own take on the mouse and cheese game. I'm using sprites on the graphscreen, with the xLib commands DRAWSPRITE, DRAWTILEMAP, etc.
Anyway, I am having trouble getting the mouse to die when it collides with the enemy. The mouse will only die if sitting still and the enemy lands on it. If I press the arrow keys with decent timing, I can go right through the enemy without being harmed.
Here is a gif slowed down to 50%
My code is outrageously huge I think, but I am still a newb at this and havent discovered all the tricks of the trade as far as simplifying things.
The code (requires doors to run):
Code:
Some things, (A,B) are the coordinates of the mouse, (C,D), (E,F) and (M,N) are the coordinates of the enemy poison.
The value of |LSET(3) will determine the number of poisons that appear on screen.
I can explain further segments of the code if needed. I would really appreciate any advice you can give.
I've been working my way through the programming book (very nice book by the way), and I am trying to do my own take on the mouse and cheese game. I'm using sprites on the graphscreen, with the xLib commands DRAWSPRITE, DRAWTILEMAP, etc.
Anyway, I am having trouble getting the mouse to die when it collides with the enemy. The mouse will only die if sitting still and the enemy lands on it. If I press the arrow keys with decent timing, I can go right through the enemy without being harmed.
Here is a gif slowed down to 50%
My code is outrageously huge I think, but I am still a newb at this and havent discovered all the tricks of the trade as far as simplifying things.
The code (requires doors to run):
Code:
ClrDraw
FnOff
AxesOff
PutSprite("00BB00DD00EE0077",8,0,1,8,0,0,0
PutSprite("182442BEC2829CE0",16,0,1,8,0,0,0
PutSprite("7E81A54224997E81",24,0,1,8,0,0,0
PutSprite("007F41495D49417F",32,0,1,8,0,0,0
PutSprite("E03C2222121D0300",40,0,1,8,0,0,0
PutSprite("0000001824241800",48,0,1,8,0,0,0
StorePic 1
ClrDraw
{7,11->dim([C]
Fill(0,[C]
For(X,1,11
1->[C](1,X
1->[C](7,X
End
For(Y,1,7
1->[C](Y,1
1->[C](Y,11
End
For(X,5,8
1->[C](4,X
End
1->[C](2,3
1->[C](3,3
1->[C](6,7
If M=1
4->[C](6,3
If M=2
0->[C](6,3
2->[C](6,10
6->[C](6,2
6->[C](2,4
6->[C](5,4
6->[C](2,7
6->[C](5,10
ClrDraw
0->K
3->L
8->A
8->B
95->T
16->D
40->C
40->F
40->E
32->N
64->M
99->H
8->R
8->S
8->Q
Repeat K=45
DrawTileMap(2,0,0,11,7,0,11,0,7,1,0,0,1
DrawText(20,0,56," H: 99 S: 2785 LV: 3 x2
For(I,0,48,6
DrawText(16,89,I," ...
End
DrawSprite(A,B,1,8,1,5,0,3,0,1
DrawSprite(C,D,1,8,1,3,0,3,0,1
If |LSET(3)=2
DrawSprite(E,F,1,8,1,3,0,3,0,1
If |LSET(3)=3
Then
DrawSprite(E,F,1,8,1,3,0,3,0,1
DrawSprite(M,N,1,8,1,3,0,3,0,1
End
Repeat K=45 or (|LSET(3)=3 and A=M and B=N) or (1=max(|LSET(3)={2,3} and A=E and B=F) or (A=C and B=D) or (2=[C](B/8+1,A/8+1) or H<=0 or T=35
getKey->K
RunIndicator(0
If K=34
Then
DrawSprite(A,B,1,8,1,5,0,3,0,1
B+8(1!=[C]((B+8)/8+1,A/8+1->B
DrawSprite(A,B,1,8,1,5,0,3,0,1
End
If K=25
Then
DrawSprite(A,B,1,8,1,5,0,3,0,1
B-8(1!=[C]((B-8)/8+1,A/8+1->B
DrawSprite(A,B,1,8,1,5,0,3,0,1
End
If K=24
Then
DrawSprite(A,B,1,8,1,5,0,3,0,1
A-8(1!=[C](B/8+1,(A-8)/8+1->A
DrawSprite(A,B,1,8,1,5,0,3,0,1
End
If K=26
Then
DrawSprite(A,B,1,8,1,5,0,3,0,1
A+8(1!=[C](B/8+1,(A+8)/8+1->A
DrawSprite(A,B,1,8,1,5,0,3,0,1
End
If 3=[C](A/8+1,B/8+1)
Stop
If max(|LSET(3)={1,2,3}
Then
DrawSprite(C,D,1,8,1,3,0,3,0,1
C+R->C
If 1=[C](D/8+1,(C+R)/8+1
~R->R
DrawSprite(C,D,1,8,1,3,0,3,0,1
End
If max(|LSET(3)={2,3}
Then
DrawSprite(E,F,1,8,1,3,0,3,0,1
E-S->E
If 1=[C](F/8+1,(E-S)/8+1
~S->S
DrawSprite(E,F,1,8,1,3,0,3,0,1
End
If max(|LSET(3)={3}
Then
DrawSprite(M,N,1,8,1,3,0,3,0,1
N+Q->N
If 1=[C]((N+Q)/8+1,M/8+1)
~Q->Q
DrawSprite(M,N,1,8,1,3,0,3,0,1
End
End
If (|LSET(3)=3 and ((A=M and B=N) or (A=E and B=F) or (A=C and B=D))) or (|LSET(3)=2 and ((A=C and B=D) or (A=E and B=F))) or (|LSET(3)=1 and A=C and B=D)
Then
Disp "POISON KILLS
Disp "LOSE 1 LIFE
L-1->L
Disp L
Pause "LIVES REMAIN
End
End
Some things, (A,B) are the coordinates of the mouse, (C,D), (E,F) and (M,N) are the coordinates of the enemy poison.
The value of |LSET(3) will determine the number of poisons that appear on screen.
I can explain further segments of the code if needed. I would really appreciate any advice you can give.