Home > Back-end >  [C] [the war] urgent! To modify the speed code
[C] [the war] urgent! To modify the speed code

Time:11-08

The source code below
For enemy aircraft speed increase over time
Trouble bosses help!!!!
 
#include
#include
#include
#include
Int position_x position_y;//the plane position
Int wide, high;//area
Int enemy_x enemy_y;//the enemy position
Int victor.
Void HideCusor ()//hide the cursor
{
CONSOLE_CURSOR_INFO cursor_info={1, 0};//value is 0, the second said to hide the cursor
SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), & amp; Cursor_info);
}
Void gotoxy (int x, int y)//the cursor
{
HANDLE HANDLE=GetStdHandle (STD_OUTPUT_HANDLE);
COORD pos.
Pos. X=X;
Pos. Y=Y;
SetConsoleCursorPosition (handle, pos);
}
Void startup initialization ()//
{
Wide=30;
High=20;
Position_x=wide/2;
Position_y=high - 3;
Enemy_x=5;
Enemy_y=0;
Victor=1;
HideCusor ();
}
Void the show ()
//functions: display the game interface
{
Gotoxy (0, 0);//the cursor to the origin
Int I, j;//row count and column count
For (I=0; I & lt; High; I++)
{
For (j=0; J & lt; Wide; J++)
{
If ((I==position_y) & amp; & (j==position_x))//plane
Printf (" * ");
Else if ((I==enemy_y) & amp; & (j)==enemy_x)//enemy planes
Printf (" $");
The else
Printf (" ");
If ((enemy_x==position_x) & amp; & (enemy_y==position_y))//judge the outcome
{
Enemy_y=1;
Victor=0;
}

}
printf("\n");
}

}
Void UpdateWithoutInput ()
{
//function: control the enemy move

Static int speed=0;//slow the progress of the $down
If (speed & lt; 20)
Speed++;
If (speed==20)
{
If (enemy_y & gt; High)
{
Enemy_x=rand () % of 31;
Enemy_y=0;
}
The else
{
Enemy_y + +;
Speed=0;
}
}
}
Void UpdateWithInput ()
//function: through the button control their movements
{
Char input;
If (_kbhit ())
{
Input=_getch ();//enter
If (input=='w')
Position_y -;
If (input=='s')
Position_y + +;
If (input=='a')
Position_x -;
If (input=='d')
Position_x + +;

}
}
Int main ()
{
Startup ();
While (victor)
{
show();
UpdateWithoutInput ();
UpdateWithInput ();
}
Printf (" GAME OVER! \ nhaha \ n ");
return 0;
}

CodePudding user response:

Write a timer function, timing UpdateWithoutInput function called

CodePudding user response:

 void UpdateWithoutInput () 
{
//function: control the enemy move

Static int speed=1;//slow the progress of the $down
If (speed & lt; 20) {
Speed++;
}
If (speed==20)
{
If (enemy_y & gt; High)
{
Enemy_x=rand () % of 31;
Enemy_y=0;
MySpeed++;//mySpeed is a global variable, the initial value is 1, the faster the mySpeed value is
If (mySpeed & gt;
=5){
MySpeed=1;
}
}
The else
{
Enemy_y +=mySpeed;//- changing aircraft speed -- -- -- -- --
Speed=0;
}
}
}


 if ((enemy_x==position_x) & amp; & (enemy_y & gt;=position_y))//determine the outcome, changed the==to & gt;=
{
Enemy_y=1;
Victor=0;
}
  • Related