Omnimaga

Calculator Community => TI Calculators => General Calculator Help => Topic started by: saintrunner on February 21, 2012, 09:41:10 pm

Title: Saint's Casio BASIC n00b movement engine
Post by: saintrunner on February 21, 2012, 09:41:10 pm
As Casio calcs are becoming more and more popular here at Omni, I took it upon myself to figure out a very simple movement code so all us new Casio users can begin our long but enjoyable journey on more Casio games! If you are accustom to TI-BASIC you could probably figure all this out as only a few things are different. Also I would like to state that if you plan to use tiles with this code (I'll probably make a tutorial on that later) you might need to tweak a few things like the location of cleartext's.

28=up, 27=right, 38=left, 37=down

Now to the nitty gritty :) The best way for me to do this is to comment the code and explain areas of importance:

Code: [Select]
ClrGraph:ClrText     ->this will just make sure there is nothing on the screen
1->X:2->Y      -> sets your variables for your beginning location
While 1    ->begins loop
Getkey->G     ->sets all keypresses to G in a sense
Locate X,Y,"@"            -> commonly 'output(' in TI-Basic this will draw your symbol as point X,Y, or 1,1
If (G=27 And X=/21)         ->checks if getkey 27 (or right) is pressed and X does not 21 (the far right side of the screen)
Then X+1->X     ->add one to X, or in other words move to the right
Clrtext           ->gets rid of previously drawn character so you don't end up with a line of characters :P
IfEnd                 -> ends the If statement
If (G=38 And X=/1)           ->if left key is pressed and not all the way to the left
Then X-1->X
Clrtext
IfEnd
If (G=37 And Y=/7)      ->the next lines of code will be basically the same thing, but in accordance to up and down or Y
Then Y+1->Y
ClrText
IfEnd
If (G=28 And Y=/1)
Then Y-1->Y
ClrText
IfEnd
If G=47     ->if exit is pressed
Stop       -> .....well STOP! lol
IfEnd
WhileEnd    -> end the whole while loop


that's about it :) post comments and questions, but most of this should make sense!

Enjoy!
Title: Re: Saint's Casio BASIC n00b movement engine
Post by: Yeong on February 21, 2012, 09:44:37 pm
can't you pull down ClrText to the bottom instead of putting a lot of them?
Title: Re: Saint's Casio BASIC n00b movement engine
Post by: DJ Omnimaga on February 22, 2012, 02:54:41 am
Interesting, I haven't checked the whole code yet, but I shall try to copy it on my  calculator to see how it looks like and hopefully take a few pictures.

You should post the program file on the forums as well, so people can load it on their calc faster.
Title: Re: Saint's Casio BASIC n00b movement engine
Post by: turiqwalrus on February 22, 2012, 05:31:59 am
Code: [Select]
If (G=27 And X=/21)         ->checks if getkey 27 (or right) is pressed and X does not 21 (the far right side of the screen)
Then X+1->X     ->add one to X, or in other words move to the right
Clrtext           ->gets rid of previously drawn character so you don't end up with a line of characters :P
IfEnd                 -> ends the If statement
If (G=38 And X=/1)           ->if left key is pressed and not all the way to the left
Then X-1->X
Clrtext
IfEnd
If (G=37 And Y=/7)      ->the next lines of code will be basically the same thing, but in accordance to up and down or Y
Then Y+1->Y
ClrText
IfEnd
If (G=28 And Y=/1)
Then Y-1->Y
ClrText
IfEnd
If G=47     ->if exit is pressed
Stop       -> .....well STOP! lol
IfEnd

could be optimized into:
Code: [Select]
If G                                                                                ->make sure to delete G at the beginning of the loop, though :P
Then Clrtext
IfEnd
X+(G=27 And X=/21)-(G=38 And X=/1)->X                   ->if right is pressed, X is incremented by 1, if left is pressed, X is decremented by one
Y+(G=37 And Y=/7)-(G=28 And Y=/1)->Y                      ->same deal here, except with Y
If G=47                                                                         ->this stays the same as in saintrunner's code...
Then Stop                                                                     ->methinks that you forgot a Then...
IfEnd
This might be a bit harder to understand for noobs, but it should be smaller(and maybe faster)

EDIT: this would also save some space:
delete this:
Code: [Select]
If G=47
Then Stop
IfEnd
and replace the while loop with this:
Code: [Select]
While G=/47This eliminates another If loop :D

EDIT2: We should probably add a casio-basic section to our tutorials...
Title: Re: Saint's Casio BASIC n00b movement engine
Post by: saintrunner on February 22, 2012, 02:48:56 pm
Yeah, I was planning on optimizing it today, I just wanted to get something out so people can get a feel for stuff :) also there shouldn't be any clrtexts in there if you want to display other 'tiles' otherwise you end up deleting them all....instead a locate x,y, " " would be better

and I'll add the file above, but I recommend just typing it in to the calc so you get used to the Casio feel
Title: Re: Saint's Casio BASIC n00b movement engine
Post by: saintrunner on February 22, 2012, 06:03:06 pm
Double post ...sorta tutorial update:

This version supports menu's and optimized code. A bit more complicated, but still WAYYY smaller....232 bytes including menus. Enjoy :)


Title: Re: Saint's Casio BASIC n00b movement engine
Post by: Yeong on February 22, 2012, 06:33:14 pm
Code: [Select]
If G=47
Then Stop
IfEnd

This can be optimized to

Code: [Select]
G=47=>Stop

;)
=> can be found in JUMP menu.
Title: Re: Saint's Casio BASIC n00b movement engine
Post by: DJ Omnimaga on February 22, 2012, 06:36:30 pm
Double post ...sorta tutorial update:

This version supports menu's and optimized code. A bit more complicated, but still WAYYY smaller....232 bytes including menus. Enjoy :)



How did you add menus and movement in 232 bytes?? O.O
Title: Re: Saint's Casio BASIC n00b movement engine
Post by: Darl181 on February 22, 2012, 06:39:31 pm
It'll be interesting to see how crazy-optimized Prizm Basic can get 0.o
Maybe there might be some built-in semi-hidden things eventually found, like how you could Text(-1..) in Ti-Basic...
Title: Re: Saint's Casio BASIC n00b movement engine
Post by: saintrunner on February 22, 2012, 06:46:15 pm
Double post ...sorta tutorial update:

This version supports menu's and optimized code. A bit more complicated, but still WAYYY smaller....232 bytes including menus. Enjoy :)



How did you add menus and movement in 232 bytes?? O.O

with the Menu command

Menu "name","option1",#variable,"option2",#variable

just like in TI BASIC

example:

Menu "Menu","start game",S,"quit",Q

lbl s
blah blah blah

lbl Q
Stop