Hey everybody, I want to make a port of the game daleks, where you run away from the little dudes and make them crash into each other. Suggestions of any kind wanted.
good idea, except I would use the + mark so that It would be less complicated to check if guys had moved to the same space with pxl-test.
Why would you be using pxl-Test( to check that? It's much easier to deal with the lists directly.
true. I did have it check the lists directly in my game. I'll post the code soon, I have to finish typing it on the computer.
By the way, the Scatter Plot didn't work. It screwed the entire program up for some reason, so I just used a for loop.
I read the topic line and my mind clicked to Doctor Who.
I played this game before. Sounds good.
Here is what I think the final version of the code should be. As far as I know, this is the best it can get, without bugs.
edit: program updated. now 487 bytes on calc. Also I fixed a smallish bug where you could start out on top of a dalek/robot thingy.
::GridOff
:AxesOff
:FnOff
:PlotsOff
:0→Xmin
:1→ΔX
:0→Ymin
:1→ΔY
:4→C
:Repeat 0
:DelVar ADelVar BClrDraw
:C+1→C
:randInt(0,30,C
:3Ans+1→L₁
:randInt(0,20,C
:3Ans+1→L₂
:C→dim(L₃
:Fill(1,L₃
:Repeat not(sum((A=L₁)(B=L₂
:1+3int(31rand →A
:1+3int(21rand →B
:End
:End
:While sum(L₃
:Repeat G
:getKey→G
:End
:Pt-Off(A,B,3
:If G=91
:Then
:1+3int(31rand →A
:1+3int(21rand →B
:End
:A+3max(G={74,84,94})(A<91)-(A>1)3max(G={72,82,92→A
:B+3max(G={72,73,74})(B<61)-(B>1)3max(G={92,93,94→B
:Pt-On(A,B,3
:For(D,1,C
:L₃(D→N
:L₂(D→Z
:L₁(D
:If N
:Pt-Off(Ans,Z,2
:Ans +3N((Ans<A)-(Ans>A→L₁(D
:Ans→Z
:Z+3N((Z<B)-(Z>B→L₂(D
:Pt-On(Z,Ans,2
:If A=Z and B=Ans
:Then
:ClrDraw
:Text(28,32,"YOU DIED!
:Pause
:Stop
:End
:End
:For(D,1,C
:L₁=L₁(D) and L₂=L₂(D
:If 1<sum(Ans
:Then
:Pt-On(L₁(D),L₂(D
:L₃not(Ans→L₃
:End
:End
:End
:End
:End
:End
I think there are still several speed optimizations to be made.
:For(D,2,C)
:For(E,1,C)
:If D≠E and L₁(D)=L₁(E) and L₂(D)=L₂(E
:Then
:0→L₃(D
:0→L₃(E
:Pt-On(L₁(D),L₂(D
:End
:End
:End
This loop takes nearly twice the time it should to run, because you check every pair of collisions twice. The standard way to go through every pair is the following:
:For(D,1,C
:For(E,1,D
...
However, in this case, there's more you can do by performing operations on the entirety of the list at once:
:For(D,1,C)
:L₁=L₁(D) and L₂=L₂(D
:If 1<sum(Ans
:Then
:Pt-On(L₁(D),L₂(D
:L₃not(Ans→L₃
:End
:End
The same thing applies to these operations:
:L₁(D
:Ans+3(Ans<A and N)-3(Ans>A and N→L₁(D
:L₂(D
:Ans+3(Ans<B and N)-3(Ans>B and N→L₂(D
Try this instead:
:L₁+3L₃((L₁<A)-(L₁>A→L₁
:L₂+3L₃((L₂<B)-(L₂<B→L2
The one problem with this improvement is that you'd have to redraw all the points at the same time. Since you decided not to use scatter plots, you could do this by adding temporary lists: store the updated L₁ and L₂ to L₄ and L₅, then make a loop in which you erase the point at L₁,L₂ coordinates, and draw it at L₄,L₅ coordinates, then store L₄ and L₅ back to L₁ and L₂.
Thanks, the first improvement worked well, but in all practicality it would be MUCH less efficient to do the second improvement, because of all the complications it would have with erasing and redrawing and how the original equation fits in with the larger loop. If I made a second smaller loop with the same parameters, it would be a waste. However, I was able to improve it a little to this.
L₁(D
:Ans +3N((Ans<A)-(Ans>A→L₁(D
L₂(D
:Ans +3N((Ans<B)-(Ans>B→L₂(D
added a score and made many optimizations. Try making this one better!
I am going to update the code to use the new one variable display that darkstone knight suggested. It should be smaller and faster then. It will though take a while to figure out how it will work.
edit: nvm. The opcode for 1 var displaying was actually larger and kindof slow. I did however find TONS of things that I could optimize other than that.