目前制作4关,
cpp.
#include "c++.h"
#include "Level1.h"
using namespace std;
int main() {
srand(time(0)); initgraph(600, 600); BeginBatchDraw();
IMAGE a; loadimage(&a, _T("1.jpg")); putimage(0, 0, &a);
setbkmode(TRANSPARENT);
settextstyle(40,0,_T("隶书"));
TCHAR s[] = _T("最后一关");outtextxy(220,280, s);
settextstyle(20, 0, _T("隶书"));
TCHAR s1[] = _T("开始游戏"); outtextxy(260, 530, s1);
FlushBatchDraw();
while (!Button_commands());
closegraph();
initgraph(1200, 600); BeginBatchDraw();
loadimage(&a, _T("1.jpg")); putimage(0, 0, &a);
FlushBatchDraw();
MessageBox(NULL, _T("红色是你,碰到绿色胜利,awd控制,黄色障碍物,跳上他"), _T(""), MB_OK);
start1();
Sleep(10000);
return 0;
}
le1.h
#pragma once
#include "c++.h"
#include "Level2.h"
using namespace std;
class ME {
private:
int x = 25; int y = 550; bool a;
public:
void loop() {
setfillcolor(RED);
IMAGE a1; loadimage(&a1, _T("1.jpg")); putimage(0, 0, &a1);
solidcircle(me.x, me.y, 15);
setfillcolor(GREEN);
solidcircle(587, 100, 15);
setfillcolor(YELLOW);
solidrectangle(400, 300, 800, 320);
FlushBatchDraw();}
void gomover2(char r) {
if (r == 'a')me.x -= 15; if (r == 'd')me.x += 15;
loop();
}
int gomover(char r) {
if (me.x > 580 && me.x < 600 && me.y < 120) win();
//跳
if (r == 'w') {
me.a = true;
//升起
for (int iy = 0; iy < 250; iy++) {
if (me.x > 580 && me.x < 600 && me.y < 120) win();
if (a == false)return 0;
me.y > 50 ? me.y-=1 : iy = 150;
if (_kbhit())me.gomover2(_getch());
loop();
}
//降落
for (int iy = 250; iy > 0; iy--) {
if (me.x > 580 && me.x < 600 && me.y < 120) win();
//检测
if (a == false)return 0;
if (occlusion_1())return 0;
me.y < 550 ? me.y+=1 : iy = 0;
if (_kbhit())me.gomover2(_getch());
loop();
}
me.a = false;
}
//
if (r == 'a')me.x -= 15; if (r == 'd')me.x += 15;
if (!occlusion_1()&& me.y < 550) {
me.y += 1;
}
loop();
}
bool occlusion_1() {
if (me.y > 300 && me.y < 400 && me.x > 400 && me.x < 800) { return true; }
else return false;
}
void win() {
setbkmode(TRANSPARENT);
settextstyle(100, 0, _T("隶书"));
cleardevice();
TCHAR s[] = _T("你通关了,难度升级!!!"); outtextxy(100, 400, s);
FlushBatchDraw();
Sleep(3000);
start2();
}
}me;
void start1() {
while (1) {
if (_kbhit())me.gomover(_getch());else me.gomover('N');
FlushBatchDraw();}
}
le2.h
#pragma once
#include "c++.h"
#include "Level3.h"
using namespace std;
class ME1 {
private:
int x = 25; int y = 550; bool a; bool b = true; int c = 1; bool d=false;
float ax = 430; int axr = 1;
public:
void loop() {
setfillcolor(RED);
IMAGE a1; loadimage(&a1, _T("1.jpg")); putimage(0, 0, &a1);
solidcircle(me1.x, me1.y, 15);
setfillcolor(GREEN);
solidcircle(20, 100, 15);
setfillcolor(RED);
solidrectangle(250,550,1200,600);
setbkmode(TRANSPARENT);
settextstyle(40, 0, _T("隶书"));
TCHAR s[] = _T("我是岩浆"); outtextxy(650,560, s);
TCHAR s1[] = _T("提示:到绿色平台上"); outtextxy(20, 20, s1);
setfillcolor(YELLOW);
solidrectangle(150,500,250,520);
solidrectangle(300,450,400,470);
solidrectangle(450,400,550,420);
solidrectangle(600, 400,700, 420);
if (me1.d) {
if (me1.ax < 20)me1.axr = 2;
if (me1.ax > 430)me1.axr = 1;
if (me1.axr == 1)me1.ax -= 0.5;
if (me1.axr == 2)me1.ax += 0.5;
solidrectangle(600, 300, 700, 320);
solidrectangle(me1.ax, 250, (me1.ax+100), 270);
}
setfillcolor(GREEN);
if(c==1)solidrectangle(800, 400, 900,420);
if(c==2)solidrectangle(1100, 400, 1200, 420);
FlushBatchDraw();}
void gomover2(char r) {
if (r == 'a') { me1.x -= 15; me1.c = 1; } if (r == 'd') { me1.x += 15; me1.c = 2; }
loop();
}
int gomover1(char r) {
if (me1.x > 0 && me1.x < 100 && me1.y < 150) win();
//跳
if (r == 'w') {
me1.a = true;
//升起
for (int iy = 0; iy < 200; iy++) {
if (kill_()) {
cleardevice();
settextstyle(100, 0, _T("隶书"));
TCHAR s[] = _T("你死了--重新开始"); outtextxy(100, 400, s);
FlushBatchDraw(); Sleep(2000);
me1.x = 25; me1.y = 550; b = false;
}
if (me1.x > 0 && me1.x < 100 && me1.y < 150) win();
if (a == false)return 0;
me1.y > 50 ? me1.y-=1 : iy = 150;
if (_kbhit())me1.gomover2(_getch());
loop();
}
//降落
for (int iy = 200; iy > 0; iy--) {
if (kill_()) {
cleardevice();
settextstyle(100, 0, _T("隶书"));
TCHAR s[] = _T("你死了--重新开始"); outtextxy(100, 400, s);
FlushBatchDraw(); Sleep(2000);
me1.x = 25; me1.y = 550; b = false;
}
if (me1.x > 0 && me1.x < 100 && me1.y < 150) win();
//检测
if (me1.a == false)return 0;
if (occlusion_1())return 0;
me1.y < 550 ? me1.y+=1 : iy = 0;
if (_kbhit())me1.gomover2(_getch());
loop();
}
me1.a = false;
}
//
if (kill_()) {
cleardevice();
settextstyle(100, 0, _T("隶书"));
TCHAR s[] = _T("你死了--重新开始"); outtextxy(100, 400, s);
FlushBatchDraw(); Sleep(2000);
me1.x = 25; me1.y = 550; b = false; }
if (r == 'a') { me1.x -= 15; me1.c = 1; } if (r == 'd') { me1.x += 15; me1.c = 2; }
if (!occlusion_1()&& me1.y < 550) {
me1.y += 1;
}
loop();
}
bool kill_() {
if (me1.y > 530 && me1.y < 600 && me1.x > 250 && me1.x < 1200) { return true; }
else return false;
}
bool occlusion_1() {
if (me1.y > 500 && me1.y < 520 && me1.x > 150 && me1.x < 250) { return true; }
else if (me1.y > 450 && me1.y < 470 && me1.x > 300 && me1.x < 400&&b) { return true; }
else if (me1.y > 400 && me1.y < 420 && me1.x > 450 && me1.x < 550) { return true; }
else if (c == 1 && me1.y > 400 && me1.y < 420 && me1.x > 800 && me1.x < 900) { me1.d = true; return true; }
else if (me1.y > 250 && me1.y < 270 && me1.x > me1.ax && me1.x <( me1.ax+100)&&me1.d) { return true; }
else if (me1.y > 300 && me1.y < 320 && me1.x > 600&& me1.x < 700 && me1.d) { return true; }
else return false;
}
void win() {
setbkmode(TRANSPARENT);
settextstyle(100, 0, _T("隶书"));
cleardevice();
TCHAR s[] = _T("你通关了,难度升级!!!"); outtextxy(100, 400, s);
FlushBatchDraw();
Sleep(3000);
start3();
}
}me1;
void start2() {
while (1) {
if (_kbhit())me1.gomover1(_getch()); else me1.gomover1('N');
FlushBatchDraw();
}
}
le3.h
#pragma once
#include "c++.h"
#include "Level4.h"
using namespace std;
int c = 1;
class ME2 {
private:
int x = 25; int y = 550; bool a; bool b = false;
int x1 = 550; int y1 = 550;
public:
void loop() {
setfillcolor(RED);
IMAGE a1; loadimage(&a1, _T("1.jpg")); putimage(0, 0, &a1);
solidcircle(me2.x, me2.y, 15);
solidcircle(me2.x1, me2.y1, 15);
setfillcolor(GREEN);
solidcircle(1200, 550, 15);
setfillcolor(YELLOW);
if (!b)
solidrectangle(0, 570, 1200, 600);
else {
solidrectangle(0, 570, 300, 600);
solidrectangle(400, 570, 1200,600);
solidrectangle(450, 500, 550, 520);
solidrectangle(550, 400, 650, 420);
solidrectangle(650, 300, 750, 320);
setfillcolor(GREEN);
solidrectangle(750, 200, 850, 220);
setfillcolor(RED);
solidrectangle(300,0, 400, 600);
settextstyle(100, 0, _T("隶书")); setbkmode(TRANSPARENT);
TCHAR s[] = _T("我"); outtextxy(300, 200, s);
TCHAR s1[] = _T("是"); outtextxy(300, 300, s1);
TCHAR s12[] = _T("岩"); outtextxy(300, 400, s12);
TCHAR s13[] = _T("浆"); outtextxy(300, 500, s13);
settextstyle(20, 0, _T("隶书"));
TCHAR s14[] = _T("提示:按下k键试试"); outtextxy(20, 20, s14);
settextstyle(100, 0, _T("隶书"));
}
FlushBatchDraw();
}
void gomover2(char r) {
if (r == 'a') { if (c == 1)me2.x -= 15; else me2.x1 -= 15; } if (r == 'd') { if (c == 1)me2.x += 15; else me2.x1 += 15; }
if (r == 'k') { if (c == 1)c = 2; else c = 1; cleardevice();
TCHAR s[] = _T("身份已切换"); outtextxy(100, 400, s);
FlushBatchDraw(); Sleep(1000);
}
loop();
}
int gomover(char r) {
if (me2.x > 1150 && me2.x < 1250 && me2.y >530) win();
//跳
if (r == 'w') {
me2.a = true;
//升起
for (int iy = 0; iy < 250; iy++) {
if (kill_()) {
cleardevice();
settextstyle(100, 0, _T("隶书"));
TCHAR s[] = _T("你死了--重新开始"); outtextxy(100, 400, s);
FlushBatchDraw(); Sleep(2000);
me2.x = 25; me2.y = 550; me2.x1 = 550; me2.y1 = 550;
}
if (me2.x > 1150 && me2.x < 1250 && me2.y >530) win();
if (a == false)return 0;
if (c == 1) {
me2.y > 50 ? me2.y -= 1 : iy = 150;
}
else {
me2.y1 > 50 ? me2.y1 -= 1 : iy = 150;
}
if (_kbhit())me2.gomover2(_getch());
loop();
}
//降落
for (int iy = 250; iy > 0; iy--) {
if (kill_()) {
cleardevice();
settextstyle(100, 0, _T("隶书"));
TCHAR s[] = _T("你死了--重新开始"); outtextxy(100, 400, s);
FlushBatchDraw(); Sleep(2000);
me2.x = 25; me2.y = 550; me2.x1 = 550; me2.y1 = 550;
}
if (me2.x > 1150 && me2.x < 1250 && me2.y >530) win();
//检测
if (a == false)return 0;
if (occlusion_1())return 0;
if (c == 1) {
me2.y < 550 ? me2.y += 1 : iy = 0;
}
else {
me2.y1 < 550 ? me2.y1 += 1 : iy = 0;
}
if (_kbhit())me2.gomover2(_getch());
loop();
}
me2.a = false;
}
//
if (kill_()) {
cleardevice();
settextstyle(100, 0, _T("隶书"));
TCHAR s[] = _T("你死了--重新开始"); outtextxy(100, 400, s);
FlushBatchDraw(); Sleep(2000);
me2.x = 25; me2.y = 550; me2.x1 = 550; me2.y1 = 550;
}
if (r == 'a') { if(c==1)me2.x -= 15; else me2.x1 -= 15;} if (r == 'd') { if (c == 1)me2.x += 15; else me2.x1 += 15; }
if (r == 'k') {
if (c == 1)c = 2; else c = 1; cleardevice();
TCHAR s[] = _T("身份已切换"); outtextxy(100, 400, s);
FlushBatchDraw(); Sleep(1000);
}
if (!occlusion_1() && me2.y < 550) {
me2.y += 1;
}
loop();
}
bool kill_() {
if ((me2.x > 300 && me2.x < 400)|| (me2.x1 > 300 && me2.x1 < 400) ) { me2.b = true; return true; }
else return false;
}
bool occlusion_1() {
if (me2.y1 > 500 && me2.y1 <520 && me2.x1 > 450 && me2.x1 < 550) { return true; }
if (me2.y1 >400 && me2.y1 < 420 && me2.x1 > 550 && me2.x1 < 650) { return true; }
if (me2.y1 > 300 && me2.y1 < 320 && me2.x1 > 650 && me2.x1 < 750) { return true; }
if (me2.y1 > 200 && me2.y1 < 220 && me2.x1 > 750 && me2.x1 < 850) { for (int i = 0; i < 500; i++) { me2.x++; loop(); }me2.y1 = 550; return true; }
else return false;
}
void win() {
setbkmode(TRANSPARENT);
settextstyle(100, 0, _T("隶书"));
cleardevice();
TCHAR s[] = _T("你通关了,难度升级!!!"); outtextxy(100, 400, s);
FlushBatchDraw();
Sleep(3000);
start4();
}
}me2;
void start3() {
while (1) {
if(_kbhit())me2.gomover(_getch()); else me2.gomover('N');
FlushBatchDraw();
}
}
le4.h
#pragma once
#include "c++.h"
#include "Level5.h"
using namespace std;
class ME3 {
private:
int x = 290; int y = 290; bool a;
public:
void loop() {
setfillcolor(RED);
IMAGE a1; loadimage(&a1, _T("1.jpg")); putimage(0, 0, &a1);
solidcircle(me3.x, me3.y, 15);
setbkmode(TRANSPARENT);
settextstyle(20, 0, _T("隶书"));
TCHAR s1[] = _T("提示:用w,a,s,d躲避攻击"); outtextxy(20, 20, s1);
FlushBatchDraw();
}
void gomover2(char r) {
if (r == 'w'&&me3.y>190)me3.y -=100; if (r == 's' && me3.y < 390)me3.y += 100;
if (r == 'a' && me3.x > 190)me3.x -= 100; if (r == 'd' && me3.x < 390)me3.x += 100;loop();
}
int gomover() {
for (int i = 0; i < 600; i+=2) {
setfillcolor(RED);
IMAGE a1; loadimage(&a1, _T("1.jpg")); putimage(0, 0, &a1);
solidcircle(me3.x, me3.y, 15);
setbkmode(TRANSPARENT);
settextstyle(20, 0, _T("隶书"));
TCHAR s1[] = _T("提示:用w,a,s,d躲避攻击"); outtextxy(20, 20, s1);
solidrectangle(i,275,i+80, 275+20);
FlushBatchDraw();
if(_kbhit())gomover2(_getch());
if (kill(i+40, 280)) {
cleardevice();
settextstyle(100, 0, _T("隶书"));
TCHAR s[] = _T("你死了--重新开始"); outtextxy(100, 400, s);
FlushBatchDraw(); Sleep(2000); return 0; }
}
for (int i = 0; i < 600; i+=2) {
setfillcolor(RED);
IMAGE a1; loadimage(&a1, _T("1.jpg")); putimage(0, 0, &a1);
solidcircle(me3.x, me3.y, 15);
setbkmode(TRANSPARENT);
settextstyle(20, 0, _T("隶书"));
TCHAR s1[] = _T("提示:用w,a,s,d躲避攻击"); outtextxy(20, 20, s1);
solidrectangle(i,i, i + 80, i + 20);
solidrectangle(600-i, 600-i,600- i + 80, 600-i + 20);
FlushBatchDraw();
if (_kbhit())gomover2(_getch());
if (kill(i, i)|| kill(600-i+40, 600-i+10)) {
cleardevice();
settextstyle(100, 0, _T("隶书"));
TCHAR s[] = _T("你死了--重新开始"); outtextxy(100, 400, s);
FlushBatchDraw(); Sleep(2000); return 0;
}
}
for (int i = 0; i < 600; i+=2) {
setfillcolor(RED);
IMAGE a1; loadimage(&a1, _T("1.jpg")); putimage(0, 0, &a1);
solidcircle(me3.x, me3.y, 15);
setbkmode(TRANSPARENT);
settextstyle(20, 0, _T("隶书"));
TCHAR s1[] = _T("提示:用w,a,s,d躲避攻击"); outtextxy(20, 20, s1);
solidrectangle(i, 275, i + 80, 275 + 20);
solidrectangle(275,i,275+20,i+80);
FlushBatchDraw();
if (_kbhit())gomover2(_getch());
if (kill(280, i+40)|| kill(i+40, 280)) {
cleardevice();
settextstyle(100, 0, _T("隶书"));
TCHAR s[] = _T("你死了--重新开始"); outtextxy(100, 400, s);
FlushBatchDraw(); Sleep(2000); return 0;
}
}
for (int i = 0; i < 800; i += 2) {
setfillcolor(RED);
IMAGE a1; loadimage(&a1, _T("1.jpg")); putimage(0, 0, &a1);
solidcircle(me3.x, me3.y, 15);
setbkmode(TRANSPARENT);
settextstyle(20, 0, _T("隶书"));
TCHAR s1[] = _T("提示:用w,a,s,d躲避攻击"); outtextxy(20, 20, s1);
solidrectangle(190,i,190+20,i+80);
solidrectangle(290,i-200,290+20,i-200+80);
solidrectangle(390,i,390+20,i+80);
FlushBatchDraw();
if (_kbhit())gomover2(_getch());
if (kill(200,i+40) || kill(300, i-200+40) || kill(400, i+40)) {
cleardevice();
settextstyle(100, 0, _T("隶书"));
TCHAR s[] = _T("你死了--重新开始"); outtextxy(100, 400, s);
FlushBatchDraw(); Sleep(2000); return 0;
}
}
for (int i = 0; i < 800; i += 2) {
setfillcolor(RED);
IMAGE a1; loadimage(&a1, _T("1.jpg")); putimage(0, 0, &a1);
solidcircle(me3.x, me3.y, 15);
setbkmode(TRANSPARENT);
settextstyle(20, 0, _T("隶书"));
TCHAR s1[] = _T("提示:用w,a,s,d躲避攻击"); outtextxy(20, 20, s1);
solidrectangle(i, 190,i + 80, 190+20);
solidrectangle(600-i, 290, 600-i + 80, 290 + 20);
solidrectangle(i, 390, i + 80, 390 + 20);
FlushBatchDraw();
if (_kbhit())gomover2(_getch());
if (kill(i+40, 200) || kill(600-i+40,300) || kill(i+40,400)) {
cleardevice();
settextstyle(100, 0, _T("隶书"));
TCHAR s[] = _T("你死了--重新开始"); outtextxy(100, 400, s);
FlushBatchDraw(); Sleep(2000); return 0;
}
}
me3.y = 290;
for (int y = 290; y < 600; y++) {
me3.y++;
loop();
}
win();
}
bool kill(int x,int y) {
if (me3.x<x + 25 && me3.x>x - 25 && me3.y<y + 25 && me3.y>y - 25)return true;
else return false;
}
void win() {
setbkmode(TRANSPARENT);
settextstyle(100, 0, _T("隶书"));
cleardevice();
TCHAR s[] = _T("你通关了,难度升级!!!"); outtextxy(100, 400, s);
FlushBatchDraw();
Sleep(3000);
//start5();
}
}me3;
void start4() {
MessageBox(NULL, _T("红色是你,碰到绿色胜利,awds控制,躲避红色攻击"), _T(""), MB_OK);
while (1) {
me3.gomover();
FlushBatchDraw();
}
}
图片(一张背景,可以不用)
需要easyx