Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: Gale on March 25, 2010, 07:09:57 pm

Title: Lightning!
Post by: Gale on March 25, 2010, 07:09:57 pm
Hey! I'm currently working on my first RPG in pure BASIC.

For the main menu, i want to have lightning strikes on the horizon in the picture on the backdrop. So far, this is my code:

Code: [Select]
:Lbl M1
:RecallPic Pic3
:While 1
:rand(25
:RecallPic Pic5
:rand(25
:ClrDraw
:RecallPic Pic3
:End

Pic3 is the normal picture, and Pic5 is the normal picture, but with lightning bolts in the picture. My problem is this: the ClrDraw causes the whole picture to flicker, and i don't know how to avoid it. And yes, I know the flickering can be interpreted as lightning strikes, but i still don't like it.
Title: Re: Lightning!
Post by: SirCmpwn on March 25, 2010, 07:11:08 pm
Have you considered using assembly libraries?
Title: Re: Lightning!
Post by: DJ Omnimaga on March 25, 2010, 07:14:03 pm
unfortunately it is impossible to prevent the flicker without the help of ASM (specifically Zpic, since it overwrites the entire screen instead of just turning on pixels needed and leave the rest intact). The only way to really prevent it without the help of ASM is to not use pics to draw the bolts, but simply draw them manually with lines(). For example, if your background is black you'll use Line(x1,y1,x2,y2,0 to draw parts of them, and Line(x1,y1,x2,y2 when erasing the bolts. This may be slower, though. (altough it will take much less memory)
Title: Re: Lightning!
Post by: SirCmpwn on March 25, 2010, 07:26:43 pm
If the scene takes place at night, I would suggest storing a picture of a black screen.  Then, you can clear the screen with black and get rid of the lightning fairly easily.
Title: Re: Lightning!
Post by: Gale on March 25, 2010, 07:29:54 pm
yeahh, but i wanted the bolts to look really jagged, and it would call for pt-on() commands and other annoying things. i guess i'll just have to trick my friends and say the flicker is intentional P:
Title: Re: Lightning!
Post by: SirCmpwn on March 25, 2010, 07:33:07 pm
Lol, good idea.
I would strongly reccomend using xLib or Celtic III, though.
Title: Re: Lightning!
Post by: DJ Omnimaga on March 25, 2010, 07:40:57 pm
if you use xlib/celtic, make sure to add a few Rand commands between each frames, though, else it will run way too fast and you won't see anything.

For example, if you loop through 3 pics 5 times, do:

Code: [Select]
For(A,1,5
For(B,1,3
real(3,B,0,1
RandRandRandRand
End
End
Title: Re: Lightning!
Post by: Eeems on March 25, 2010, 07:52:10 pm
instead of rand's you could use a randInt(0,9,2 to slow it down and just play around with the numbers to find the right setting.
Title: Re: Lightning!
Post by: Builderboy on March 25, 2010, 08:11:29 pm
I use rand(# to do all of my delays, you just change the number higher to make a longer delay.  Rand(#) generates a list of length # filled with random elements, so it can be quite slow :)
Title: Re: Lightning!
Post by: jsj795 on March 25, 2010, 11:01:13 pm
For example, if your background is black you'll use Line(x1,y1,x2,y2,0 to draw parts of them, and Line(x1,y1,x2,y2 when erasing the bolts.

Isn't it backwards? Line(x1,y1,x2,y2 is to draw and Line(x1,y1,x2,y2,0 to erase.
And I tend to switch back and forth with   rand(X  and   For(X,0,99:End for delay effect. I found out that if x is really big in rand(x, it might cause memory error (such as insufficient ram if you are running big program) since you are storing the list with the dimension of x into Ans

Edit: If there are too many PtOn( then you can use the compression, which can be found here:
http://tibasicdev.wikidot.com/compression (http://tibasicdev.wikidot.com/compression)
Although it might be slower than hard-coding (which means coding each PtOn( Codes) because this method is going through the For( loop.
Title: Re: Lightning!
Post by: {AP} on March 25, 2010, 11:04:42 pm
Isn't it backwards? Line(x1,y1,x2,y2 is to draw and Line(x1,y1,x2,y2,0 to erase.

Normally, yes, but he said that he's on a black background. ;P
Title: Re: Lightning!
Post by: DJ Omnimaga on March 25, 2010, 11:06:18 pm
^
Title: Re: Lightning!
Post by: jsj795 on March 25, 2010, 11:06:41 pm
oh okay nvm then^^
Title: Re: Lightning!
Post by: Builderboy on March 25, 2010, 11:26:47 pm
Mmmm if you wanted to stick to pure Basic you could also draw the lightning with Line(#,#,#,#,0) and then erase it with a recallPic, since recallPic does not overwrite, it just overlays.  You could even generate the pic yourself in startup if you wanted to be file independent.
Title: Re: Lightning!
Post by: DJ Omnimaga on March 25, 2010, 11:30:18 pm
keep in mind with this method, some bolts will appear later, though. If you use this, you might want to display the top of each lightnings first, then the middle part, then the bottom, etc.
Title: Re: Lightning!
Post by: Builderboy on March 25, 2010, 11:34:20 pm
Yeah, and that could also give a nice effect too!
Title: Re: Lightning!
Post by: Gale on March 26, 2010, 04:55:43 pm
what real(# would i use from xLIB or Celtic? and i would use lines, but i'm trying to keep program size to an absolute minimum, as the game itself will take a lot of mem (it's gonna be a moving sprite rpg with one or two detailed towns)
Title: Re: Lightning!
Post by: {AP} on March 26, 2010, 05:05:20 pm
You'd use real(3 most likely. It works exactly like RecallPic but with some other features.

real(3,pic_num,logic,update_LCD

pic_num = Number of the pic. (0-255)
logic = How the pic is displayed.
 0 =  Overwrite
 1 = AND
 2 = OR
 3 = XOR

update_LCD =
 0. Doesn't update
 1. Updates screen
 
For what you want, you'd just need "real(3,3,0,1" and "real(3,5,0,1".

Also, note that a Pic takes up a LOT of memory so it would probably be smaller to use several line commands over a 2nd picture.
Of course, if you plan on using xLIB or CIII anyway, the pics can be archived so it will take less RAM to use pics.

Up to you.
Title: Re: Lightning!
Post by: Gale on March 26, 2010, 05:13:52 pm
hmm. well i have everything archived all the time anyway (i use CalcUtil). but yeah, i mostly cared about RAM because my friend has a normal TI-84, and almost all of his arc and ram are in use, and since he's doing the storyline, he should be able to use it P:
Title: Re: Lightning!
Post by: SirCmpwn on March 26, 2010, 05:34:42 pm
^CalcUtil++
Title: Re: Lightning!
Post by: Gale on March 26, 2010, 05:36:31 pm
^CalcUtil++
haha best app i've ever found besides omnicalc ^^
Title: Re: Lightning!
Post by: DJ Omnimaga on March 26, 2010, 06:20:49 pm
We are a bit offtopic, but I am curious about something: Do you mean calcutil runs every single archived program on your calc in any way? I mean for example, if I have

EXEC EDIT NEW
*LOL
*PRGMLOL
*ZLOL
ZSPRITE
*ZZZ

prgmLOL contains:

Code: [Select]
:A+1->A
:prgmZZZ
:prgmZLOL

Will prgmZZZ/ZLOL commands return a ERR:ARCHIVED?

Back on topic, I personally would prefer using lines for drawing lightning, simply because pics are a waste of space (unless the bolts are really complex and stuff).
Title: Re: Lightning!
Post by: Gale on March 26, 2010, 06:22:42 pm
nope, i'm pretty sure it wont. pictures cant be archived though. to run archived pics you can just use xLIB anyway

so yeahh, now i can clear my ram pretty haphazardly and have around 19-20k RAM at all times P:
Title: Re: Lightning!
Post by: DJ Omnimaga on March 26, 2010, 06:37:17 pm
aaah ok I see now. I was wondering cuz I was unsure to which extent CalcUtil worked with archived stuff. But yeah my point is that even if archived the pics still took a lot of memory x.x. I mean, in ROL3, if I decided to draw the lightning bolt inside a pic instead of an archived subroutine, I would have ran out of pic, first, (ones that can be sent fine ungrouped, that is), and secondly I would have wasted about 500 bytes of archive

I guess it's up to you, though, but remember you can't just use pics for every single thing in the programming world. Sometimes it's best to either draw stuff manually to save space, abuse programs to run archived subprograms like XCOPY or xLIB (if you use it alerady) or use smaller sprites. It depends of opinions, though. I just had bad memories of downloading games abusing pictures before, only to realise the abuse of pics made them so huge that the author could only add maybe 4 or 5 map in the game
Title: Re: Lightning!
Post by: Geekboy1011 on March 26, 2010, 06:39:56 pm
one word about calcutil its very glitchy with omnicalc and a few other asm programs :/
 i had to reset my os cause if it X.x so be sure to backup often X,x
Title: Re: Lightning!
Post by: DJ Omnimaga on March 26, 2010, 07:22:51 pm
wasn't the code also stolen from NoShell, but with more functions added? I wonder if it works on OS 2.5xMP too
Title: Re: Lightning!
Post by: Gale on March 26, 2010, 08:03:44 pm
i wouldn't doubt that it was stolen from NoShell, it's almost identical haha
Title: Re: Lightning!
Post by: DJ Omnimaga on March 26, 2010, 08:40:52 pm
BrandonW said it was. Idk if the author of calcutil asked permission, but BrandonW said he didn't mind since Noshell isn't really updated anymore and buggy
Title: Re: Lightning!
Post by: mapar007 on March 27, 2010, 06:41:50 am
The calcUtil credits refer to NoShell and Brandon iirc.
Title: Re: Lightning!
Post by: DJ Omnimaga on March 28, 2010, 12:52:09 pm
aaah ok, that's good at least :P
Title: Re: Lightning!
Post by: cooliojazz on March 28, 2010, 11:43:36 pm
^^ Works w/2.53mp
@Geekboy1011 it really screwed up your OS?
Title: Re: Lightning!
Post by: ztrumpet on April 02, 2010, 12:53:41 pm
Gale, I'm glad you're working on an RPG!  This will be pretty cool!

How's progress? ;D