I'm making a CSE tower defense game, and it runs kinda slow. I was wondering if anyone had any ideas on how to speed it up:


Code:
:CLASSIC Answer
:SetUpEditor {L1},{L2},{L3}
:DelVar {L1}DelVar {L2}DelVar {L3}
:Lbl MP
:ClrHome
:[[2,2,2,3,1,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1][2,1,1,3,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2][2,1,1,3,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2][2,1,1,3,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2][2,1,1,3,1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,3,1,1,2][2,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,1,2][2,1,1,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,1,3,1,1,2][2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,3,1,1,2][2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,3,1,1,2][2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,1,3,2,2,2]]→[A]
:" O!-*1234                                             *→Str1
:For(A,1,10
:For(B,1,26
:Output(A,B,sub(Str1,[A](A,B),1
:End:End
:SetUpEditor {L1},{L2}
:2→A
:2→B
:DelVar K
:5→dim({L1}
:1→{L1}(1
:100→{L1}(2
:1→E
:{-}15→R
:
:
:
:Lbl T2
:While K≠102
:Output(A,B,"X
:{L1}(2)→θ
:If θ≥0 and θ<10
:26→Z
:If θ≥10 and θ<100
:25→Z
:If θ≥100 and θ<1000
:24→Z
:If θ≥1000
:23→Z
:If θ<0 and θ>{-}10
:25→Z
:If θ≤{-}10 and θ>{-}100
:24→Z
:If θ≤{-}100 and θ>{-}1000
:23→Z
:If θ≤{-}1000
:22→Z
:
:Output(1,Z,θ
:Repeat K
:getKey→K
:End
:If K=34 or K=24 or K=25 or K=26
:Output(A,B,sub(Str1,[A](A,B),1
:
:A+(K=34 and A≠9)-(K=25 and A≠2→A
:B+(K=26 and B≠25)-(K=24 and B≠2→B
:If [A](A,B)=1 and (K=92 or K=93 or K=94 or K=82 or K=15
:Then
:If K=15:Then
:Repeat K:getKey→K:End
:If K=33:Then
:Repeat K:getKey→K:End
:If K=44:Then
:Repeat K:getKey→K:End
:If K=55 and θ≥100:Then
:55→[A](A,B:θ-100→θ:End
:DelVar KEnd:End:End:End
:If K=92 and θ≥10:Then
:6→[A](A,B:θ-10→θ:End
:If K=93 and θ≥20:Then
:7→[A](A,B:θ-20→θ:End
:If K=94 and θ≥30:Then
:8→[A](A,B:θ-30→θ:End
:If K=82 and θ≥40:Then
:9→[A](A,B:θ-40→θ:End
:θ→{L1}(2
:Output(1,22,"     
:End
:End
:Output(A,B,sub(Str1,[A](A,B),1
:
:Lbl L
:E+1→E
:R+15→R
:5E→dim({L2}
:E→dim({L3}
:For(C,1,E
:40+R→{L3}(C
:End
:
:For(C,1,E
:2-C→{L2}(5C-4)
:1→{L2}(5C-1
:5→{L2}(5C
:End
:Lbl LV
:For(D,1,26+E
:
:For(C,1,E
:If [A]({L2}(5C-1),{L2}(5C))≠1:Then
:1→[A]({L2}(5C-1),{L2}(5C
:{L1}(2)-100→{L1}(2
:End
:If {L2}(5C-4)>0 and {L2}(5C-4)≤27 and {L3}(C)>0
:Then
:Output({L2}(5C-1),{L2}(5C),"0
:prgmAASHOOT
:End:End
:For(C,1,E
:If {L2}(5C-4)>0 and {L2}(5C-4)≤27
:Output({L2}(5C-1),{L2}(5C)," 
:End
:
:For(C,1,E
:If ({L2}(5C-4)>0 and {L2}(5C-4)<6) or ({L2}(5C-4)>22 and {L2}(5C-4)<27
:Then
:{L2}(5C-1)+1→{L2}(5C-1
:1→{L2}(5C-3)
:0→{L2}(5C-2)
:End
:
:If {L2}(5C-4)≥6 and {L2}(5C-4)≤22
:Then
:{L2}(5C)+1→{L2}(5C
:0→{L2}(5C-3)
:1→{L2}(5C-2)
:End
:
:If {L2}(5C-4)=40
:100→{L2}(5C-4
:End
:
:For(C,1,E
:{L2}(5C-4)+1→{L2}(5C-4
:End
:End
:DelVar K
:
:For(C,1,E
:If {L3}(C)≤0
:{L1}(2)+5→{L1}(2
:End
:Goto T2


And here is the prgmAASHOOT


Code:
:If {L3}(C)>0
:Then
:For(G,{-}2,1
:If {L2}(5C-4)>2 and {L2}(5C-4)<26
:Then
:If [A]({L2}(5C-1)+G,{L2}(5C)+2)≥6
:{L3}(C)-([A]({L2}(5C-1)+G,{L2}(5C)+2)-5)→{L3}(C
:If [A]({L2}(5C-1)-G,{L2}(5C)-2)≥6 and [A]({L2}(5C-1)-G,{L2}(5C)-2)≤9
:{L3}(C)-([A]({L2}(5C-1)-G,{L2}(5C)-2)-5)→{L3}(C
:If [A]({L2}(5C-1)+2,{L2}(5C)-G)≥6 and [A]({L2}(5C-1)+2,{L2}(5C)-G)≤9
:{L3}(C)-([A]({L2}(5C-1)+2,{L2}(5C)-G)-5)→{L3}(C
:If [A]({L2}(5C-1)-2,{L2}(5C)+G)≥6 and [A]({L2}(5C-1)-2,{L2}(5C)+G)≤9
:{L3}(C)-([A]({L2}(5C-1)-2,{L2}(5C)+G)-5)→{L3}(C
:End:End:Return
Would you mind uploading the 8Xp files? Many people are to lazy to convert them to try it out.
Sorunome wrote:
Would you mind uploading the 8Xp files? Many people are to lazy to convert them to try it out.
I think he's mostly looking for optimizations at this point. Smile Based on reading the code, it looks like it might be unfinished at this point to me. Correct me if I'm wrong, 16aroth6.

Here's a first optimization:

Code:
:{L1}(2)→θ
:If θ≥0 and θ<10
:26→Z
:If θ≥10 and θ<100
:25→Z
:If θ≥100 and θ<1000
:24→Z
:If θ≥1000
:23→Z
:If θ<0 and θ>{-}10
:25→Z
:If θ≤{-}10 and θ>{-}100
:24→Z
:If θ≤{-}100 and θ>{-}1000
:23→Z
:If θ≤{-}1000
:22→Z
to
Code:
:{L1}(2
:26-(Ans<0)-int(log(Ans+not(Ans→Z
Please try to understand that rather than just blindly using it, though.
here they are.
Tower Defense

That code looks good, but it still dosen't help the speed of the program.

The worst part is the prgmAASHOOT, I was wondering if there was a faster way to do it.
16aroth6 wrote:
That code looks good, but it still dosen't help the speed of the program.
Of course, but I want to get you to start thinking about optimizations and different ways you could write each chunk of code that you create.

Quote:
The worst part is the prgmAASHOOT, I was wondering if there was a faster way to do it.
It would be best for you to first explain what this chunk of code does (even though I have a pretty good idea) so we can think about whether your high-level approach is a good one.
prgmAASHOOT checks around the enemy for towers, so that if there are, the enemys can take damage.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement