# Omnimaga

## Calculator Community => TI Calculators => General Calculator Help => Topic started by: sjasogun1 on January 20, 2011, 08:10:53 am

Title: fx-9860GII; inefficient coding?
Post by: sjasogun1 on January 20, 2011, 08:10:53 am
I'm creating a simple maze-like game on my fx-9860GII, but there's one thing taking a huge amount of data and time. The goal of the game is to move a dot (.) between the crosses (X) towards the exit (O). There are also fake exits (looks exactly the same as a real exit). Touching a cross or fake exit adds 1 to the death counter (which decreases your score after completing all of the levels by 2500 per death) and resets the level. Every step you take also decreases 100 from your final score.

The problem is not the positioning of the crosses, (fake) exits and the dot, but the death system is. Level 1 and 2 are respectively 3220 and 5344 in size. They just contain this bit of code, repeated over and over again:

(Everything between {} is either a command I can't type or a number that differs throughout the code and [] are comments)

Spoiler For Spoiler:
If X={x-coordinate of cross/fake exit}          [Determines the x-coordinate of the cross/fake exit]
Then If Y={y-coordinate of cross/fake exit}            [Determines the y-coordinate of the cross/fake exit]
Then ClrText                                                      [Clears the screen]
Locate 7,2,"YOU DIED"{disp_command}                  [Displays "YOU DIED" text]
D+1-->D                                                           [Adds 1 to the death variable]
Prog "LEVEL1"                                                    [Restarts the level]
IfEnd                                                                [Ends the x-coordinate If-statement]
IfEnd                                                                [Ends the y-coordinate If-statement]

I was wondering whether there is a more efficient way to do this instead of repeating this (with variations for completing the level and hitting a fake exit). I'm asking because I also recently learned how to get rid of the tracks the dot leaves behind without being required to draw all of the crosses and (fake) exits again per step.

Title: Re: fx-9860GII; inefficient coding?
Post by: AngelFish on January 20, 2011, 12:06:19 pm
Well, you could just do

Code: [Select]
`If (x={})(y={}Then ClrTextLocate 7,2,"YOU DIED"IS>(DProg "Level"IfEnd`
Title: Re: fx-9860GII; inefficient coding?
Post by: sjasogun1 on January 21, 2011, 04:16:05 am
It helps a bit, but I meant: is there any way to get all of the combinations of x and y coordinates in a single command?
Title: Re: fx-9860GII; inefficient coding?
Post by: sjasogun1 on January 26, 2011, 04:08:38 am
Never mind, I found out already. The easiest way is to use (X={} AND Y={}) OR (X={} AND Y={}) multiple times, so you can get all of the possible death locations in one if-statement.

Problem solved, topic locked.