This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. TI-Basic => TI-BASIC
Author Message
TI-newb


Member


Joined: 24 Dec 2008
Posts: 158

Posted: 20 Mar 2009 09:35:07 pm    Post subject:

im currently making a game where you move side to side, and you shoot at these alien invaders xDD sound familiar? anyways im going to use XLib for the sprites and movement(just wanted to let u guys know)

what i am having troubles with is the bullets, does anyone know how i can make the bullets move up from where my turret is... like i could make 1 bullet move but using only 1 variable, but if i need more then 1 bullet i would need several variables.. anyone have a solution?
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 21 Mar 2009 03:32:29 am    Post subject:

[quote name='TI-newb' post='132060' date='Mar 21 2009, 02:35 AM']im currently making a game where you move side to side, and you shoot at these alien invaders xDD sound familiar? anyways im going to use XLib for the sprites and movement(just wanted to let u guys know)

what i am having troubles with is the bullets, does anyone know how i can make the bullets move up from where my turret is... like i could make 1 bullet move but using only 1 variable, but if i need more then 1 bullet i would need several variables.. anyone have a solution?[/quote]
Use the fraction part. Like 4.1 can be x=4 and y=1...
Use the commands like fpart( and int( to retrieve the right part of the variable.

You can even store 4 small numbers in a variable with complex numbers. But that is too slow. And in case you ask: fraction part is faster than using complex numbers approach.
Back to top
WikiGuru
ADOS (Attention deficit... Oh! Shiny!)


Elite


Joined: 15 Sep 2005
Posts: 923

Posted: 21 Mar 2009 06:01:08 pm    Post subject:

What Galandros said and lists. They can grow almost indefinitely (until 999 elements, or no more RAM).
Back to top
elfprince13
Retired


Super Elite (Last Title)


Joined: 11 Apr 2005
Posts: 3500

Posted: 21 Mar 2009 07:14:54 pm    Post subject:

uh, better yet is complex lists, since since x+yi very nicely represents coordinates on a plane. Well, I guess it depends. It'll take more memory, but it'll be easier to work with and easier to read. Take your pick. For speed you'd probably have to do a side by side comparison.

Last edited by Guest on 21 Mar 2009 07:15:50 pm; edited 1 time in total
Back to top
luby
I want to go back to Philmont!!


Calc Guru


Joined: 23 Apr 2006
Posts: 1477

Posted: 22 Mar 2009 07:24:31 pm    Post subject:

And to seperate the real and the imag parts, use
imag(L1(1->Y //generates Y
L1(1)-Ans->X //generates X


Last edited by Guest on 11 Jul 2010 05:59:14 pm; edited 1 time in total
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 23 Mar 2009 02:54:50 pm    Post subject:

luby wrote:
L1(1)-Ans->X

Shouldn't that be L1(1)-iAns->X?

And I assume you're not using real( because xLib messes with it?


Last edited by Guest on 11 Jul 2010 05:59:38 pm; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 23 Mar 2009 09:49:10 pm    Post subject:

I can't see how accessing real(L1(I and imag(L1(I can possibly be faster than accessing L1(I and L2(I. Since real( and imag( can't possibly add negative time to a calculation.

The other problem is that, as mentioned above, using real( is tricky when Xlib is involved. And X-iimag(X isn't an ideal solution either: instead of a real number like 5 it will return 5+0i, which is almost but not quite the same: for one thing, 5+0i=5 not only isn't true, it gives a data type error.

There is a way to get the real real part of a number without using real(, but it's not pretty: abs(X)cos(angle(X (or, alternatively, P►Rx(abs(X),angle(X). Since both abs() and angle() return real numbers, the result is a real number as well. Another possibility is abs(X-iimag(X, but that doesn't work for potentially negative numbers.

The only situation in which I would recommend using complex numbers for coordinates is if you were planning on doing complicated things to all the bullets at the same time (moving them all down is a simple thing: with both techniques, just add/subtract from the x-coordinate list). It's marginally simpler and faster to shift all the bullets diagonally if you're using the complex-number approach. It's much easier to rotate all the bullets around a point with complex numbers. But I don't really see why you'd be doing this.


Last edited by Guest on 11 Jul 2010 05:59:58 pm; edited 1 time in total
Back to top
simplethinker
snjwffl


Active Member


Joined: 25 Jul 2006
Posts: 700

Posted: 23 Mar 2009 10:18:12 pm    Post subject:

To get the real part of a number using only imag(, can't you just use imag(iX?

Last edited by Guest on 11 Jul 2010 05:58:59 pm; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 24 Mar 2009 09:50:47 am    Post subject:

Yeah... I realized that shortly after my original post. Then the internet died.
Back to top
elfprince13
Retired


Super Elite (Last Title)


Joined: 11 Apr 2005
Posts: 3500

Posted: 25 Mar 2009 06:39:33 pm    Post subject:

DarkerLine wrote:
The only situation in which I would recommend using complex numbers for coordinates is if you were planning on doing complicated things to all the bullets at the same time (moving them all down is a simple thing: with both techniques, just add/subtract from the x-coordinate list). It's marginally simpler and faster to shift all the bullets diagonally if you're using the complex-number approach. It's much easier to rotate all the bullets around a point with complex numbers. But I don't really see why you'd be doing this.

In case they get sucked in to a tornado (obviously Wink )
Back to top
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 26 Mar 2009 02:00:55 am    Post subject:

Okay, I don't understand anything of the above posts, but you can use lists to keep track of all the bullets. My method only moves bullets upward at 90 degrees but can be easily modified.

You'll have some list of x and y coordinates of each bullet that's created. When you create a bullet, you pretty much increment (twice cuz x and y are 2 elements) a counter to a "free" element of some list of like what, like 20 elements * 2 for x and y.. so about 40 i'd say. When you create a new bullet, you'd assign the coordinates of the new bullet to the next free element.. as bullets move off the screen you can pretty much just go through the list then restart at the beginning of the list (by the time 20 bullets are shot, the first will have already went off the edge). You will have some for loop that will move each bullet up and a check to see if it hit the top screen or something else.. Then you can null bullets that have been removed off the screen already so you know they aren't there (0,0 is good cuz 0,0 isn't to common) and you're done.

The above posts seem like sick optimizations, but this is the concept I think they're saying. Hope this helped.


Last edited by Guest on 26 Mar 2009 02:06:58 am; edited 1 time in total
Back to top
TI-newb


Member


Joined: 24 Dec 2008
Posts: 158

Posted: 07 Apr 2009 07:59:47 pm    Post subject:

thank-you, the last post i actually understood lol... im not really good with this programming yet and i was debating about using a list to store all the x and y variables.

the first post interested me too, and surely i will try to combine that into the list. thanks!
Back to top
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 09 Apr 2009 02:23:10 pm    Post subject:

Unfortunately, Ti-basic is pretty slow, so the list method needs to be higly optimized, hence everyone elses posts.


Generally, without optimizations this is the pseudocode using 2 lists one for x and one for y to make it slightly easier to undertstand. It's very ineffecient, but the concept is much more important.

This uses output to display things
\\ <-comment
Quote:
Lx
\\ list x, it'll have say 20 elements
Ly
\\ list y will have 20 (equal for bith as these are pairs. So x(1) and y(1) are coordinates for bullet 1.
1->A \\counter
8->Y
16-X \\ coordinates for the ship lets say
While 1 \\never ending loop
Getkey->Z
if Z=2nd_Button \\ forgot the keycode
then
(Y-1) ->Ly(A)
X-> Lx(A)
A+1->A
\\ The counter is incremented the next bullet, so if the person clicks 2nd again it will assign the new bullet coordinates to the next element

if A > length_of_listx
//loop around the list when the counter goes to an element that doesn't exist. And length of listx = length of listy so it doesn't matter the comparison
then
1->A
end
\\ When you make a bullet, the bullet is created right above the ship right? So The x-cor is the same, but the y cor is one less (above it)


\\ Okay if you look at how bullets work, you'll see that they move upward until they either hit something or go off the edge. If
\\ the bullets move up every loop lets say, it'll take like 8 loops in this code until the bullet leaves the screen.. so the bullet is gone and free
\\to be nulled and used again. You can cycle thru the elements because there's no possible way that you can overwrite another bullet's
\\coordinates when looping. It'll be long gone off the screen.


For C,1,20,1 \\ code to move bullets up
if Ly( C ) != 0
\\if 0 =nulled bullet, then if its not 0 we want to move the bullet. doesn't matter if either x or y, you can null either. Output doesn't display 0,X or Y,0 or 0,0
then
Ly( C ) - 1 -> Ly( C ) \\ when Ly( C ) hits 0, it automatically nulls itself
end
end
end \\ ^end to the while 1


I did not display anything because the order of drawing would make me have to swap the code order into something that doesn't make as much sense. Oh and this code doesn't take into consideration of other collisions like enemy collisions..

[edit] failz dang thats hard to read, okay, i'm using a quote box instead.


Last edited by Guest on 09 Apr 2009 02:35:18 pm; edited 1 time in total
Back to top
Mapar007


Advanced Member


Joined: 04 Oct 2008
Posts: 365

Posted: 10 Apr 2009 05:24:05 am    Post subject:

I think you should limit the number of bullets. Seeing the game slow down as you fire more of them isn't very realistic eh.
Back to top
Display posts from previous:   
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
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement