http://calcg.org/newlogo2.png Not Logged in.
Login | Register

General Discussion Board \ Calculator Programming \ Sprites

Click here to log in (you must be logged in to post comments).

AuthorComment
banjo2E
Wraith
avatar
Posted: 6 Mar 2007
16:45 GMT
Total Posts: 689
The program downloadable by this URL is my attempt at making sprites.

Click Here

If you see weird stuff, ignore it. I didn't know what to put for message text in my confirmation email to myself.

Anyway, this is one of two versions. In the other version, lines seven and eight, instead of being blank, read:

:While getkey=0
:End

The first version is fast but the screen flickers so fast that the bottom is a ludicrously light gray. The second, modified version does not flicker but is slow. How may I move past this block that has been stopping me from using sprites for like a year now?

---
http://uncyclopedia.org/wiki/User:Administrator <------ WOOOOO!!!!!
haveacalc
Guardian
avatar
Posted: 6 Mar 2007
18:38 GMT
Total Posts: 1111
Since Barret listens to this forum's users more than anyone could ever hope for elsewhere, all's well. Look at Barret's post for what I originally wrote.

---
-quoted directly from most movies that don't exist (and some that do).
Barrett
Administrator
avatar
Posted: 6 Mar 2007
21:12 GMT
Total Posts: 1676
Taken from the page haveacalc linked to:



Try this example first. It works because Output continues to the next line (and the next) when the string to be displayed exceeds 16 characters. Since it replaces anything that was previously there, the ClrHome can be removed:

8->X
5->Y
Lbl 0
Output(1,1,"OOOOOOOOOOOOOOOOO OO OO OO OO OO OOOOOOOOOOOOOOOOO
Output(Y,X,"!
getKey->Z
If Z=25
Then
Y-1->Y
End
If Z=34
Then
Y+1->Y
End
If Z=24
Then
X-1->X
End
If Z=26
Then
X+1->X
End
0->Z
If X=1
Then
2->X
End
If X=16
Then
15->X
End
If Y=1
Then
2->Y
End
If Y=8
Then
7->Y
End
Goto 0

Some things:
1) When there's only one line of code to execute in the If /Then statement, you can get rid of the Then's and End's.
2) Use an endless "While " loop instead of your label. Replace "Lbl 0" with "While 1" and "Goto 0" with "End"
3) There's no reason to clear Z before storing the getKey to it again (you can get rid of "0->Z").
4) You can just display your background once. To erase the character's position, store its previous coordinates to other variables.
The program now looks like this:

8->X
5->Y
8->A
5->B
Output(1,1,"OOOOOOOOOOOOOOOOO OO OO OO OO OO OOOOOOOOOOOOOOOOO
While 1
Output(A,B,"
Output(Y,X,"!
X->A
Y->B
getKey->Z
If Z=25
Y-1->Y
If Z=34
Y+1->Y
If Z=24
X-1->X
If Z=26
X+1->X
If X=1
2->X
If X=16
15->X
If Y=1
2->Y
If Y=8
7->Y
End

Now, remember that a true condition equals one and that a false condition's zero. Take this line of code, for example:
X-(Z=24 and X!=2)+(Z=26 and X!=15->X
If you pressed the left arrow key and the character isn't already as far left as it can go, subtract one. If the right arrow key was pressed and you haven't yet reached the rightward bound, add one. So, you can change the program to this:


8->X
5->Y
8->A
5->B
Output(1,1,"OOOOOOOOOOOOOOOOO OO OO OO OO OO OOOOOOOOOOOOOOOOO
While 1
Output(A,B,"
Output(Y,X,"!
X->A
Y->B
getKey->Z
X-(Z=24 and X!=2)+(Z=26 and X!=15->X
Y-(Z=25 and Y!=2)+(Z=34 and Y!=7->Y
End

I wasn't able to test any of this code, so I may have messed up somewhere. Nevertheless, you should be able to get the gist of it all.


---
-Barrett A
haveacalc
Guardian
avatar
Posted: 6 Mar 2007
22:37 GMT
Total Posts: 1111
It's true!

Optimizing it even further:
8→X
5→Y
5→A
"OOOOOOOOOOOOOOOO
Disp Ans
For(B,2,7
Disp "O O
End
Output(8,1,Ans
While 1
Output(A,B,"
Output(Y,X,"!
Y→A
X→B
getKey→Z
X-(Ans=24 and X≠2)+(Ans=26 and X≠15→X
Y-(Z=25 and Y≠2)+(Z=34 and Y≠7→Y
End
As you look at this code, remember that Ans contains the most recently executed mathmatical or string operation, excluding For( loops' incrementing. Also, when a For( loop finishes looping, the increment (1 as default) is added to the used variable. That's why it works to use "B" for the For( loop without ever giving it a value later (but still before the While loop): the For( loop aleady sets it.

Note: Throughout all those first examples, I accidentally typed
X→A
Y→B
when it should actually be
Y→A
X→B
So, you'd need to change that to get each example working properly.

Does all of that help, banjo?

---
-quoted directly from most movies that don't exist (and some that do).
banjo2E
Wraith
avatar
Posted: 8 Mar 2007
05:49 GMT
Total Posts: 689
Possibly, thank you.

Edit: Oh, but that one statement:
"When there's only one line of code to execute in the If /Then statement, you can get rid of the Then's and End's."

Sadly, that does not work for me. I don't know why. It just bugs up for me quite frequently.

---
http://uncyclopedia.org/wiki/User:Administrator <------ WOOOOO!!!!!
banjo2E
Wraith
avatar
Posted: 8 Mar 2007
13:23 GMT
Total Posts: 689
Wait, what's with all the factorials?

(I double-posted so you'd look at this.)

---
http://uncyclopedia.org/wiki/User:Administrator <------ WOOOOO!!!!!
haveacalc
Guardian
avatar
Posted: 8 Mar 2007
15:18 GMT
Total Posts: 1111
Since I was unable to display the unequal-to character in my post, I used its almost universal equivalent (!=). Just find n' replace...

---
-quoted directly from most movies that don't exist (and some that do).
banjo2E
Wraith
avatar
Posted: 9 Mar 2007
05:51 GMT
Total Posts: 689
Ahhh... That makes sense. Although, if you have Word, you can use the symbol directory to get it, then copy-and-paste it into wherever you're posting it. It may also be on Character Map, though that is more limited than Word's Symbols.

---
http://uncyclopedia.org/wiki/User:Administrator <------ WOOOOO!!!!!
haveacalc
Guardian
avatar
Posted: 9 Mar 2007
10:31 GMT
Total Posts: 1111
That's not the problem. Have you tried putting a character like that in one of your posts? If not, do.

---
-quoted directly from most movies that don't exist (and some that do).
TheOnlyJon
Dragoon
avatar
Posted: 9 Mar 2007
20:26 GMT
Total Posts: 96
ŢÖŤÂĹĻŸ ŨŃŖĒÃĎĀΒĿĚ

---
<--! I have no comment at this time -->
Barrett
Administrator
avatar
Posted: 9 Mar 2007
23:02 GMT
Total Posts: 1676
☼♫♪♀♂▓▒░♠♣♥♦ ﻻﻦﺹﻈДЁώЊ≠

Ok those things should work now... any of those & # digits ; combinations should work...

---
-Barrett A
haveacalc
Guardian
avatar
Posted: 10 Mar 2007
12:02 GMT
Total Posts: 1111
Ok, thanks. I'll edit my post...

---
-quoted directly from most movies that don't exist (and some that do).
banjo2E
Wraith
avatar
Posted: 10 Mar 2007
13:50 GMT
Total Posts: 689
Man, it's kinda weird how discussions can go from programming help to site updating.

---
http://uncyclopedia.org/wiki/User:Administrator <------ WOOOOO!!!!!
haveacalc
Guardian
avatar
Posted: 10 Mar 2007
14:02 GMT
Total Posts: 1111
No, seriously: How comes your comprehension on the discussed concepts? Do you have any questions?

---
-quoted directly from most movies that don't exist (and some that do).
banjo2E
Wraith
avatar
Posted: 11 Mar 2007
12:23 GMT
Total Posts: 689
Nope. No questions at this time.

---
http://uncyclopedia.org/wiki/User:Administrator <------ WOOOOO!!!!!





Portal | My Account | Register | Lost Password or Username | TOS | Disclaimer | Help | Site Search | File Archives Copyright © 2002-2019 CalcG.org