Created
June 30, 2015 21:15
-
-
Save scazon/60c75eccb7c1efbea977 to your computer and use it in GitHub Desktop.
Navigating IF nodes on the Game Boy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* In this version, each node in the story has a function | |
which displays text to the printer/screen, gives the | |
player options to choose from, and returns an enum of the | |
next node to go to based on that decision. */ | |
typedef enum NODE { | |
//nodes can have more descriptive names, | |
//e.g. what part in the story you're in | |
NODE1, | |
NODE2, | |
NODE3, | |
NODE4 | |
} NODE; | |
//define pointers to node functions | |
typedef NODE (*nodeFunction)(void); | |
//declare node functions | |
NODE node1(); | |
NODE node2(); | |
NODE node3(); | |
NODE node4(); | |
//create array of node functions | |
//functions have to be listed here in the | |
//same order as in the enum list | |
nodeFunction nodeTable[] = { | |
node1, | |
node2, | |
node3, | |
node4 | |
}; | |
NODE nextNode(NODE choiceNode){ | |
//choicenode is the NODE returned from previous node function | |
return nodeTable[choiceNode](); | |
} | |
//define node functions | |
NODE node1(){ | |
//print text to printer | |
//print choice options to screen | |
//wait for user to pick an option | |
if (option==1){ //return the next node based on option picked | |
return NODE2; | |
} else { | |
return NODE3; | |
} | |
} | |
NODE node2(){}; | |
NODE node3(){}; | |
NODE node4(){}; | |
void main(){ | |
NODE nextNodeEnum = node1(); //get first choice | |
while(1) { //chain together nodes based on choices | |
nextNodeEnum = nextNode(nextNodeEnum); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment