If you're never heard of a tower defense game, it's basically a roadmap-like path through which enemies travel. You can place towers along this path to attack the enemies. Some towers are fast, slow, strong, weak, etc. A couple examples are
Vector TD and Vector TD 2. Anyway, today I tried to make a tower defense game and failed miserably. I set up the cursor and moving enemies, grid, map, and everything. But horror! It moves slower than molasses in January!

As soon as my laptop gets fixed I'll be able to upload the program as it is now, but is this even fixable in TI-BASIC? Or do I have to do it in Asm?
I'm sure a simple tower defense game could be sufficiently optimized to work in BASIC. The only extremely CPU-intensive sections are when the ships are moving through the maze, and your big processing power hogs there would be aiming and pathfinding. Not the end of the world.
KermMartian wrote:
I'm sure a simple tower defense game could be sufficiently optimized to work in BASIC. The only extremely CPU-intensive sections are when the ships are moving through the maze, and your big processing power hogs there would be aiming and pathfinding. Not the end of the world.


I seem to remember making one for a contest Razz

but it was greatly simplified just 1 path so I would not have to deal with path finding), but still incredibly slow if I remember correctly >.>

I cannot find the link >.>


This is what it looks like now. To scale and whatnot. I have the program check what the X and Y values for all the enemies are (they're
stored in L1 as { X, Y, health, full health, ...} ), then change either the X value or Y value depending on where they are. Is this massively inefficient, or can someone write me some optimized code for determining direction?
That's quite inefficient. You should work out the path they'll be following before they begin to go through, so they can just follow the path and no pathfinding is necessary during the run.
KermMartian wrote:
That's quite inefficient. You should work out the path they'll be following before they begin to go through, so they can just follow the path and no pathfinding is necessary during the run.


Huh?

Oh, do you mean like I'd set a fifth value so that it would be incremented every turn, and determine the paths that way?
No, I mean before they go through, run some math to do a simulated run before there's aiming and ammunition to deal with, figure out the path that they will be following, then you can apply it and not have to calculate the path in the midst of dealing with health, aiming, etc etc.
KermMartian wrote:
No, I mean before they go through, run some math to do a simulated run before there's aiming and ammunition to deal with, figure out the path that they will be following, then you can apply it and not have to calculate the path in the midst of dealing with health, aiming, etc etc.


Well, I haven't implemented anything yet besides the cursor and the enemies' movement. I don't understand. I'm going to try incrementing a single value and see if that speeds it up any.

Edit: Okay, I give up. Keeps giving me some retarded dimension error with the enemies list.

If you want to have a crack at it or tell me what I'm doing wrong, the file is on United-TI.

Edit by Kerm: Please edit, don't doublepost.
Please edit instead of doublepost.

A dimension error means you're trying to store to an element of the list that doesn't exist. There are three possibilities for the cause of this:

1: The index you're trying to access is < 1
2: The index you're trying to access is > dim(LIST)+1
3: The index you're trying to access is not an integer
KermMartian wrote:
Please edit instead of doublepost.

A dimension error means you're trying to store to an element of the list that doesn't exist. There are three possibilities for the cause of this:

1: The index you're trying to access is < 1
2: The index you're trying to access is > dim(LIST)+1
3: The index you're trying to access is not an integer



Oh. Wait a second, I just realized what the problem was.
Now the enemies are moving across the screen very slowly.
Care to share some code? http://sc.cemetech.net to get it in a nicely-presentable form.
...Wow, that sounds awesome. Need any help?
Yeah. I want someone to help me make it not run slow Razz

Here's the whole damn thing:


Code:
:Lbl AA
:50→dim(L1
:50→dim(L2
:50→dim(L3
:50→dim(L4
:50→dim(L5
:10→dim(L6
:Fill 0,L1
:Fill 0,L2
:Fill 0,L3
:Fill 0,L4
:Fill 0,L5
:Fill 0,L6
:0→Xmin
:0→Ymin
:95→Xmax
:62→YMax
:ClrDraw
:ClrHome
:0→S
:0→T
:0→U
:0→V
:0→W
:0→X
:0→Y
:0→Z
:Menu("TI.TD V0.25","NEW GAME",BA,"RESUME",AC,"ERASE SAVE",AD,"CREDITS",AB
:Lbl AC
:Lbl AD
:Lbl AB
:ClrDraw
:Text(0,0,"TI-TOWER DEFENSE BETA V0.1"
:Text(6,0,"BY AEROMAX/FLAMEVIPER
:Text(12,0,"AUGUST 1, 2008. UPLOADED TO"
:Text(18,0,"UNITED-TI.ORG FORUMS AS"
:Text(24,0,"INCOMPLETE WORK. EXPECT"
:Text(30,0,"COMPLETION BY SEPTEMBER."
:Text(36,0,"ALL RIGHTS RESERVED.
:0→θ
:Repeat θ≠0
:getKey→θ
:End
:ClrHome
:ClrDraw
:Goto AA
:Lbl BA
:0→T
:Text(0,0,"-----"
:Line(20,55,20,62
:For(θ,0,55,5
:Line(0,θ,80,θ
:Line(85,θ,95,θ
:End
:For(θ,0,95,5
:Line(θ,0,θ,25
:Line(θ,30,θ,40
:Line(θ,45,θ,55
:End
:For(θ,70,80,5
:Line(θ,6,θ,9,0
:End
:For(θ,10,25,5
:Line(69,θ,66,θ,0
:End
:For(θ,70,90,5
:Line(θ,29,θ,26
:End
:For(θ,0,5,5
:Line(81,θ,84,θ
:End
:For(θ,45,55,5
:Line(81,θ,84,θ
:End
:Line(85,41,85,44
:Line(90,41,90,44
:For(θ,1,54,1
:Line(θ,1,θ,14,0
:End
:For(θ,1,4,1
:For(W,51,54,1
:Pxl-Change((62-W),θ
:End
:End
:0→X
:55→Y
:Goto BB
:Lbl BZ
:L6(1)+.33→L6(1)
:Text(0,0,(iPart(L6(1)))
:getKey→Z
:If Z=0
:Goto BC
:X→U
:Y→V
:If Z=24 and X>0
:X-5→X
:If Z=25 and Y<55
:Y+5→Y
:If Z=26 and X<90
:X+5→X
:If Z=34 and Y>0
:Y-5→Y
:For(θ,(X+1),(X+4),1)
:For(W,(63-Y),(66-Y),1)
:Pxl-Change(W,θ
:End
:End
:For(θ,(U+1),(U+2),1
:For(W,(V-2),(V-1),1
:Pxl-Change((62-W),θ
:End
:End
:Goto BC
:Lbl BB
:For(θ,5,50,5)
:(θ*2)→Z
:(0-Z)→L1(θ-4)
:44→L1(θ-3)
:L1(41)→L1(θ-2)
:L1(41)→L1(θ-1)
:0→L1(θ)
:End
:Lbl BC
:L1→L2
:For(θ,5,50,5)
:Line(L2(θ+1),(L2(θ+2)-2),(L2(θ+1)+3),(L2(θ+2)-2),0
:If L1(θ+5)<81
:L1(θ+1)+1→L1(θ+1):L1(θ+5)+1→L1(θ+5)
:If L1(θ+5)≥81 and L1(θ+5)<116
:L1(θ+2)-1→L1(θ+2):L1(θ+5)+1→L1(θ+5)
:If L1(θ+5)≥116 and L1(θ+5)<131
:L1(θ+1)-1→L1(θ+1):L1(θ+5)+1→L1(θ+5)
:If L1(θ+5)≥131 and L1(θ+5)<151
:L1(θ+2)+1→L1(θ+2):L1(θ+5)+1→L1(θ+5)
:If L1(θ+5)≥151
:L1(θ+1)-1→L1(θ+1)
:Line(L1(θ+1),(L1(θ+2)-2),(L1(θ+1)+3),(L1(θ+2)-2)
:End
:Goto BZ
You can save a few bytes by using DelVar instead of 0->variable.
Let's take this chunk of code as an example:


Code:
:For(θ,5,50,5)
:(θ*2)→Z
:(0-Z)→L1(θ-4)
:44→L1(θ-3)
:L1(41)→L1(θ-2)
:L1(41)→L1(θ-1)
:0→L1(θ)


This can be easily optimized to:


Code:
:For(θ,5,50,5
:2θ→Z
:(-)Z→L1(θ-4
:44→L1(θ-3
:L1(41→L1(θ-2
:Ans→L1(θ-1)
:0→L1(θ


Note the extraneous parenthesis removals, the use of Ans, (θ*2) to 2θ, (0-Z) to (-)Z (that's negative Z), etc.

And at the beginning:


Code:
:Lbl AA
:50→dim(L1
:50→dim(L2
:50→dim(L3
:50→dim(L4
:50→dim(L5
:10→dim(L6
:Fill 0,L1
:Fill 0,L2
:Fill 0,L3
:Fill 0,L4
:Fill 0,L5
:Fill 0,L6
:0→Xmin
:0→Ymin
:95→Xmax
:62→YMax
:ClrDraw
:ClrHome
:0→S
:0→T
:0→U
:0→V
:0→W
:0→X
:0→Y
:0→Z


You can do a ton of optimizations to end up with something like:

Code:
:Lbl AA
:50→dim(L1
:Ans→dim(L2
:Ans→dim(L3
:Ans→dim(L4
:Ans→dim(L5
:Ans→dim(L6
:Fill 0,L1
:Fill 0,L2
:Fill 0,L3
:Fill 0,L4
:Fill 0,L5
:Fill 0,L6
:0→Xmin
:0→Ymin
:1→deltaX
:1→deltaY
:ClrDraw
:ClrHome
:Delvar SDelvar TDelvar UDelvar VDelvar WDelvar XDelvarY Delvar Z
If I remember correctly that is basically how I did it (I either used an incrementor and changed the direction when at certain points or just changed direction by checking the coordinates )
  
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