馬里奧吃金幣、消失
阿新 • • 發佈:2019-01-29
#include <yzkgame.h>
#pragma comment( linker, "/subsystem:\"console\" /entry:\"mainCRTStartup\"" )
#pragma comment(lib, "YZKGame.lib")
int beginGameText = 0;
void gameMain1(void)
{ int distance_1 = 1000;
int distance = 100000;
int mario=0;
int bgImg=0;
int ch;
int x;
int y;
int i;
int coinNum[10] = { 1,2,3,4,5,6,7,8,9,10 };
int coinXs[10] = { 100,222,310,402,515,604,708,786,590,600 };
int coinYs[10] = { 100,222,300,412,505,164,578,586,480,590 };
int coinX, coinY;
setGameTitle("少年");
setGameSize(800, 600);
createImage(bgImg,"大片草地.png");
createSprite(mario, "mario");
playSpriteAnimate(mario, "walk");
hideText(beginGameText);
for (i = 0;i < 10;i++) {
createSprite(coinNum[i],"coin");
playSpriteAnimate(coinNum[i],"rotate");
setSpritePosition(coinNum[i],coinXs[i],coinYs[i]);
}
while (TRUE) {
ch=getPressedKeyCode();
x=getSpriteX(mario);
y=getSpriteY(mario);
if(ch==RP_KEY_LEFT) {
x=x - 1;
setSpritePosition(mario, x, y);
setSpriteFlipX(mario, FALSE);
for ( i = 0; i < 10; i++){
coinX = getSpriteX(coinNum[i]);
coinY = getSpriteY(coinNum[i]);
distance = (x - coinX)*(x - coinX) + (y - coinY)*(y - coinY);
if (distance < distance_1){
hideSprite(coinNum[i]);
}
}
pauseGame(10);
}
else if (ch==RP_KEY_RIGHT) {
x++;
setSpritePosition(mario, x, y);
setSpriteFlipX(mario, TRUE);
for ( i = 0; i < 10; i++){
coinX = getSpriteX(coinNum[i]);
coinY = getSpriteY(coinNum[i]);
distance = (x - coinX)*(x - coinX) + (y - coinY)*(y - coinY);
if (distance < distance_1){
hideSprite(coinNum[i]);
}
}
pauseGame(10);
}
else if (ch==RP_KEY_UP)
{
y++;
setSpritePosition(mario, x, y);
setSpriteFlipX(mario, FALSE);
for (i = 0; i < 10; i++){
coinX = getSpriteX(coinNum[i]);
coinY = getSpriteY(coinNum[i]);
distance = (x - coinX)*(x - coinX) + (y - coinY)*(y - coinY);
if (distance < distance_1){
hideSprite(coinNum[i]);
}
}
pauseGame(10);
}
else if (ch==RP_KEY_DOWN) {
y--;
setSpritePosition(mario, x, y);
setSpriteFlipX(mario, TRUE);
for (i = 0; i < 10; i++){
coinX = getSpriteX(coinNum[i]);
coinY = getSpriteY(coinNum[i]);
distance = (x - coinX)*(x - coinX) + (y - coinY)*(y - coinY);
if (distance < distance_1){
hideSprite(coinNum[i]);
}
}
pauseGame(10);
}
}
pauseGame(10000);
}
void gameMain(void){
setGameTitle("狂吃");
setGameSize(300, 300);
createText(beginGameText,"奔跑吧兄弟");
setTextPosition(beginGameText,110,160);
while(TRUE){
int mouseX = getMousePositionX();
int mouseY = getMousePositionY();
if (mouseX > 110 && mouseX < 190 && mouseY > 160 && mouseY < 180 && isMouseLeftButtonDown()){
gameMain1();
}
pauseGame(10);
}
}
int main(void)
{
rpInit(gameMain);
return 0;
}
#pragma comment( linker, "/subsystem:\"console\" /entry:\"mainCRTStartup\"" )
#pragma comment(lib, "YZKGame.lib")
int beginGameText = 0;
void gameMain1(void)
{ int distance_1 = 1000;
int distance = 100000;
int mario=0;
int bgImg=0;
int ch;
int x;
int y;
int i;
int coinNum[10] = { 1,2,3,4,5,6,7,8,9,10 };
int coinXs[10] = { 100,222,310,402,515,604,708,786,590,600 };
int coinYs[10] = { 100,222,300,412,505,164,578,586,480,590 };
int coinX, coinY;
setGameTitle("少年");
setGameSize(800, 600);
createImage(bgImg,"大片草地.png");
createSprite(mario, "mario");
playSpriteAnimate(mario, "walk");
hideText(beginGameText);
for (i = 0;i < 10;i++) {
createSprite(coinNum[i],"coin");
playSpriteAnimate(coinNum[i],"rotate");
setSpritePosition(coinNum[i],coinXs[i],coinYs[i]);
}
while (TRUE) {
ch=getPressedKeyCode();
x=getSpriteX(mario);
y=getSpriteY(mario);
if(ch==RP_KEY_LEFT) {
x=x - 1;
setSpritePosition(mario, x, y);
setSpriteFlipX(mario, FALSE);
for ( i = 0; i < 10; i++){
coinX = getSpriteX(coinNum[i]);
coinY = getSpriteY(coinNum[i]);
distance = (x - coinX)*(x - coinX) + (y - coinY)*(y - coinY);
if (distance < distance_1){
hideSprite(coinNum[i]);
}
}
pauseGame(10);
}
else if (ch==RP_KEY_RIGHT) {
x++;
setSpritePosition(mario, x, y);
setSpriteFlipX(mario, TRUE);
for ( i = 0; i < 10; i++){
coinX = getSpriteX(coinNum[i]);
coinY = getSpriteY(coinNum[i]);
distance = (x - coinX)*(x - coinX) + (y - coinY)*(y - coinY);
if (distance < distance_1){
hideSprite(coinNum[i]);
}
}
pauseGame(10);
}
else if (ch==RP_KEY_UP)
{
y++;
setSpritePosition(mario, x, y);
setSpriteFlipX(mario, FALSE);
for (i = 0; i < 10; i++){
coinX = getSpriteX(coinNum[i]);
coinY = getSpriteY(coinNum[i]);
distance = (x - coinX)*(x - coinX) + (y - coinY)*(y - coinY);
if (distance < distance_1){
hideSprite(coinNum[i]);
}
}
pauseGame(10);
}
else if (ch==RP_KEY_DOWN) {
y--;
setSpritePosition(mario, x, y);
setSpriteFlipX(mario, TRUE);
for (i = 0; i < 10; i++){
coinX = getSpriteX(coinNum[i]);
coinY = getSpriteY(coinNum[i]);
distance = (x - coinX)*(x - coinX) + (y - coinY)*(y - coinY);
if (distance < distance_1){
hideSprite(coinNum[i]);
}
}
pauseGame(10);
}
}
pauseGame(10000);
}
void gameMain(void){
setGameTitle("狂吃");
setGameSize(300, 300);
createText(beginGameText,"奔跑吧兄弟");
setTextPosition(beginGameText,110,160);
while(TRUE){
int mouseX = getMousePositionX();
int mouseY = getMousePositionY();
if (mouseX > 110 && mouseX < 190 && mouseY > 160 && mouseY < 180 && isMouseLeftButtonDown()){
gameMain1();
}
pauseGame(10);
}
}
int main(void)
{
rpInit(gameMain);
return 0;
}