Added auto-completion to snake for debugging purposes.

This commit is contained in:
Jonas 'Sortie' Termansen 2011-12-06 14:18:15 +01:00
parent fefeb92e89
commit 8be3624ca3
1 changed files with 19 additions and 0 deletions

View File

@ -44,6 +44,8 @@ const int speedincrease = -5;
const int maxspeed = 40;
volatile int speed;
bool tabhack = false;
void Clear()
{
// Reset the game data.
@ -89,6 +91,8 @@ int Init()
return 0;
}
bool tabhacking = false;
void Update()
{
int newvelx = velx;
@ -99,6 +103,8 @@ void Update()
uint32_t codepoint;
while ( (codepoint = System::Keyboard::ReceiveKeystroke(method) ) != 0 )
{
if ( tabhack && codepoint == '\t' ) { tabhacking = true; }
if ( tabhack && codepoint == ('\t' | DEPRESSED ) ) { tabhacking = false; }
bool keyup = codepoint & DEPRESSED;
if ( keyup ) { continue; }
codepoint &= ~DEPRESSED;
@ -110,6 +116,14 @@ void Update()
if ( codepoint == 'd' || codepoint == 'D' ) { newvelx = 1; newvely = 0; }
}
if ( tabhack && tabhacking )
{
if ( animalx == posx && posy < animaly ) { newvelx = 0; newvely = 1; }
if ( animalx == posx && posy > animaly ) { newvelx = 0; newvely = -1; }
if ( animaly == posy && posx < animalx ) { newvelx = 1; newvely = 0; }
if ( animaly == posy && posx > animalx ) { newvelx = -1; newvely = 0; }
}
// Make sure we don't do a 180.
if ( !(velx == -1 && newvelx == 1) &&
!(velx == 1 && newvelx == -1) &&
@ -171,6 +185,11 @@ void Update()
int main(int argc, char* argv[])
{
for ( int i = 1; i < argc; i++ )
{
if ( strcmp("--tabhack", argv[i]) == 0 ) { tabhack = true; }
}
int result = Init();
if ( result != 0 ) { return result; }