Author 
Message 

dxfan101010
Member
Joined: 31 Mar 2008 Posts: 194

Posted: 01 Jun 2009 11:14:53 pm Post subject: 


Ok so i am making an **Astroids game ** and its an the home screen. iv got the flight "engine" working and the laser but i cant figure out how to make 5 astroids float around until they get shot heres my code
I have read all the topics i could but i couldnt find what i needed
Code: 4/>/X
8/>/Y
"^"/>/Str1
Repeat A=100// this is just to keep the game going
getkey/>/K
If K=0
Q/>/K
X+(k34)(K=25)/>/X
Y+(K=26)(K=24)/>/Y
ClrHome
If K=24
"<"/>/Str1
If K=25
"^"/>/Str1
If K=26
">"/>/Str1
If K=34
"V"/>/Str1
If K!=21 and K!=31
K/>/Q
If X=0:8/>/X
If X=8:1/>/X
If Y=0:16/>/y
If Y=17:1/>/Y
Output(X,Y,Str1
If K=21:Then
If Q=25:Then
X/>/B
For(A,B,1,1)
Output(A,Y," ' // apstorphe
End
End
If Q=34:Then
X/>/B
For(A,B,8)
Output(A,Y," ' // apstorphe
End
End
If Q=24:Then
Y/>/B
For(A,B,1,1)
Output(X,A,"
End
End
If Q=26:Then
Y/>/B
For(A,B,16)
Output(X,A,"
End
End
End
If K=31:Then
randint(1,8/>/X
randint(1,16/>/Y
End
End
Any optimazition welcome thanks in advanced
Last edited by Guest on 01 Jun 2009 11:18:46 pm; edited 1 time in total 

Back to top 


tr1p1ea
Elite
Joined: 03 Aug 2003 Posts: 870

Posted: 02 Jun 2009 01:24:11 am Post subject: 


Have you thought about using a list to keep track of your asteroids X,Y's etc? 

Back to top 


dxfan101010
Member
Joined: 31 Mar 2008 Posts: 194

Posted: 02 Jun 2009 01:28:54 am Post subject: 


Sort of i am not all that great with list yet. i thought about using variables but that would take up 2 much room. how would you make the astroids float like they do in the game. i could use randint to start the positions and L1 for X and L2 gor Y but how would you add or subtract based on the direction they are going. 

Back to top 


Weregoose Authentic INTJ
Super Elite (Last Title)
Joined: 25 Nov 2004 Posts: 3976

Posted: 02 Jun 2009 01:32:48 am Post subject: 


Here's one you might try, since those For( loops are so similar:
If Q=24 or Q=26
Then
Y→B
For(A,B,1+15(Q=26),12(Q=24
Output(X,A,"
End
End
(But then, I'm not sure if we have to store to B on that one.)
The first line can be tempered further. Imagine that 24 and 26 are the only two numbers that'll leave a "one" after they are reduced by 25. One of those values will be negative, and the other will be positive:
If Q25=1 or Q25=1
To fix that, we can take the absolute value of both sides (on both equations):
If abs(Q25)=abs(1) or abs(Q25)=abs(1)
Simplify:
If abs(Q25)=1 or abs(Q25)=1
Since we are now basically testing something against itself with or, we can remove the redundancy:
If abs(Q25)=1
Finally, bringing the 1 to the other side of the equation allows us to drop an ending parenthesis:
If 1=abs(Q25
This is the exact same test as If Q=24 or Q=26!
Last edited by Guest on 11 Jul 2010 04:03:01 pm; edited 1 time in total 

Back to top 


dxfan101010
Member
Joined: 31 Mar 2008 Posts: 194

Posted: 02 Jun 2009 01:44:47 am Post subject: 


Omfg I had to read that like 4 times to get is
If 1=abs(Q25
Then
Y→B
For(A,B,1+15(Q=26),12(Q=24
Output(X,A,"
End
End
Replaces all this
If Q=24:Then
Y/>/B
For(A,B,1,1)
Output(X,A,"
End
End
If Q=26:Then
Y/>/B
For(A,B,16)
Output(X,A,"
End
End
so could you do
If 1=abs(Q26
Then
X→B
For(A,B,1+7(Q=34),12(Q=25
Output(Y,A,"'
End
End
ok so this is not doing what its supposed to its giving me a domain err what did i do wrong i think its right here
Last edited by Guest on 02 Jun 2009 02:02:12 am; edited 1 time in total 

Back to top 


Weregoose Authentic INTJ
Super Elite (Last Title)
Joined: 25 Nov 2004 Posts: 3976

Posted: 02 Jun 2009 09:28:01 am Post subject: 


If not post make sense of ounce, note please its drawing was in night's middle after day not short.
You swapped A and Y in the output. The combining of the loops was done brilliantly, but there's the small matter of getting the first condition to work the way it should... Starting off with If Q=25 or Q=34, we want to find a number that will produce the same result (ignoring sign, positive or negative) whether it was subtracted from 25 or from 34. The target number in any case will always turn out to be the midpoint between the two values, or the average.
Looking at 1=abs(Q25)—the one I wrote—the 1 on the lefthand side of the equation is the absolute distance between either of 24 or 26, and their average (which is 25). abs(2425) equals 1, and abs(2625) equals 1. 24 and 26 are the only two numbers where subtracting 25 and taking the absolute value is going to equal 1 – this is why 1 needs to be the number that we compare with in the optimized form!
For 25 and 34, the number will be different. Subtracting the average (29.5) from either one of these numbers will give the same answer between them, but it won't be 1 like it was last time. As both abs(2529.5) and abs(3429.5) equal 4.5, the "optimized" form should be If 4.5=abs(Q29.5). But, if we were trying to save space with this, then the decimals have ruined it already: the original form was smaller. We can manage to salvage a byte by multiplying both sides by 2 to get 9=2abs(Q29.5, but there is nothing that we can do about the 29.5 inside in the function.
Well, there is .1>fPart(Q[font="verdana"]³√(3, but that allows for the [PRGM] and [+] keys to pass. Probably not a good idea for this program.
Last edited by Guest on 11 Jul 2010 03:32:54 pm; edited 1 time in total 

Back to top 


dxfan101010
Member
Joined: 31 Mar 2008 Posts: 194

Posted: 02 Jun 2009 02:36:16 pm Post subject: 


Thank you Weregoose it was relly late but after fixing that first conditonial and changing Y and A it looks good and works great it saved about 30 byts
Her is the cod ewith the replaced loops
Code: 4/>/X
8/>/Y
"^"/>/Str1
Repeat A=100// this is just to keep the game going
getkey/>/K
If K=0
Q/>/K
X+(k34)(K=25)/>/X
Y+(K=26)(K=24)/>/Y
ClrHome
If K=24
"<"/>/Str1
If K=25
"^"/>/Str1
If K=26
">"/>/Str1
If K=34
"V"/>/Str1
If K!=21 and K!=31
K/>/Q
If X=0:8/>/X
If X=8:1/>/X
If Y=0:16/>/y
If Y=17:1/>/Y
Output(X,Y,Str1
If K=21:Then
If 1=abs(Q25
Then
Y→B
For(A,B,1+15(Q=26),12(Q=24
Output(X,A,"
End
End
If 9=2abs(Q29.5
Then
X→B
For(A,B,1+7(Q=34),12(Q=25
Output(A,Y,"'
End
End
End
If K=31:Then
randint(1,8/>/X
randint(1,16/>/Y
End
End
ok so 2 more questions how do you fill a list with random numbers. and second how do you add or subtrat from each one based on which way its going up, down, right, and left 

Back to top 


ztrumpet
Active Member
Joined: 06 May 2009 Posts: 555

Posted: 02 Jun 2009 03:10:16 pm Post subject: 


dxfan101010 wrote: ok so 2 more questions how do you fill a list with random numbers. and second how do you add or subtrat from each one based on which way its going up, down, right, and left
1) To fill List 1 (length of L) with random intigers from A to B:
For(C,1,L
randInt(A,B>L1(C
End
However, this can be faster if you don't use randInt(. For example to fill List 1 with 10 random integers from 1 to 16:
For(A,1,10
1+int(16rand>L1(A
End
2)I don't know what you mean. To add element 3 of List 1 by one simply do:
1+L1(3>L1(3
I don't think this is what you mean, but it's helpful to know. 

Back to top 


cssc
Newbie
Joined: 04 Jan 2008 Posts: 36

Posted: 02 Jun 2009 03:40:35 pm Post subject: 


A better way to fill a list with random numbers A through B. C is how many numbers you want
randInt(A,B,C >L1 

Back to top 


woodswolf
Advanced Newbie
Joined: 26 Feb 2009 Posts: 53

Posted: 02 Jun 2009 04:00:35 pm Post subject: 


Randint is slightly faster from experience
When considering randInt(A,B,C
rand can do exactly the same
A+int(Brand(C
however, after 15 seconds the randint part says MEMORY ERROR when C = 999
and rand says MEMORY ERROR after 17 seconds when C = 999 

Back to top 


ztrumpet
Active Member
Joined: 06 May 2009 Posts: 555

Posted: 02 Jun 2009 04:02:07 pm Post subject: 


@cssc
Duh!
I forgot...
@woodswolf
Wow, Let me find DarkerLine's command info for on rand.
Edit: Here they are: http://www.unitedti.org/index.php?showtopic=6883
Kinda like Weregoose said:
It's best to do 1=abs(K25 but what if you have three or more numbers?
Do this: max(K={24,25,26,34 (Numbers here are an example)
This is also better when the difference between two numbers is odd. ( max(K={21,22 is smaller than .5=abs(K21.5 )
Last edited by Guest on 02 Jun 2009 04:14:16 pm; edited 1 time in total 

Back to top 


dxfan101010
Member
Joined: 31 Mar 2008 Posts: 194

Posted: 02 Jun 2009 05:59:03 pm Post subject: 


cssc wrote: A better way to fill a list with random numbers A through B. C is how many numbers you want
randInt(A,B,C >L1
thank you this is what i was looking for i was going to use randint 5 times but i knew there was a better way i NEVER THOUGHT there was a 3rd argument for randint
ztrumpet wrote: 2)I don't know what you mean. To add element 3 of List 1 by one simply do:
1+L1(3>L1(3
I don't think this is what you mean, but it's helpful to know.
i know how this works but would i have to do that for each of the five list elemets for x and for y or is there a faster way?
Just so you know i am going to have 5 astroids 3 going up or down and 2 going left or right the astroids are going to be either O's or thetas.
Thank you guys for all the help.
Last edited by Guest on 02 Jun 2009 06:02:09 pm; edited 1 time in total 

Back to top 


ztrumpet
Active Member
Joined: 06 May 2009 Posts: 555

Posted: 02 Jun 2009 06:01:01 pm Post subject: 


You could do L1+1>L1. It adds everything in L1 by one. 

Back to top 


dxfan101010
Member
Joined: 31 Mar 2008 Posts: 194

Posted: 02 Jun 2009 06:05:53 pm Post subject: 


so could i do a for loop like
For(X,1,3)
1+L1(X/>/L1(X
End
this would add 1 to the first three elements of list one right 

Back to top 


ztrumpet
Active Member
Joined: 06 May 2009 Posts: 555

Posted: 02 Jun 2009 06:07:45 pm Post subject: 


Yes. You might want to use two lists so you could use L1+1 and L21. This would be quicker and smaller. 

Back to top 


dxfan101010
Member
Joined: 31 Mar 2008 Posts: 194

Posted: 02 Jun 2009 06:16:02 pm Post subject: 


Ok thats kinda what i was thinking ill work on the astroids part after dinner and deadliest warrior thank you for all the help again. 

Back to top 


ztrumpet
Active Member
Joined: 06 May 2009 Posts: 555

Posted: 02 Jun 2009 06:17:42 pm Post subject: 


Ur Welcome.
Are you are going to post the finished game here? (I know your not finished yet, but...) 

Back to top 


dxfan101010
Member
Joined: 31 Mar 2008 Posts: 194

Posted: 02 Jun 2009 06:19:57 pm Post subject: 


Yes when i finish or when i need more help ill post the new code up here. but my link port is broken so it will just be hand typed code. 

Back to top 


ztrumpet
Active Member
Joined: 06 May 2009 Posts: 555

Posted: 02 Jun 2009 06:21:47 pm Post subject: 


Cool. It sounds like a fun game. 

Back to top 


dxfan101010
Member
Joined: 31 Mar 2008 Posts: 194

Posted: 02 Jun 2009 06:26:07 pm Post subject: 


Yeah iv had fun making it it took me like 3 days to get the laser loop to fire in onl one direction but it will probley take me a while to finish because i have camp and then i am going to alaska but ill work on it as much as i can 

Back to top 


