Skip to content

代码 #1

Description

@aryecatcher

#include <stdio.h>
#include
#include <time.h>
#include <graphics.h>
#include
#include
#include

constexpr auto PI = 3.1415926;

using namespace std;

//全局变量
ExMessage msg = { 0 };
int speed_M = 1; /角色移动速度/
int speed_C = PI / 12; /角色旋转速度/
int speed_S = 3; /子弹速度/

//角色一
class Role_1
{
public:
Role_1(double r, double a) { //极坐标 其中r表示长度,a表示角度
this->r = r;
this->a = a;
}

void getMovement()
{
	//vector<IMAGE> img_Role_1_tank
	for (int i = 0; i < 12; i++) {
		loadimage(img_Role_1_tank + i, ""); // 掩码图 缺
		loadimage(img_Role_1_tank + i + 1, "");// 原图 缺
	}

	for(int i = rand()%12; i < 12 ; i++) {

		r += speed_M * vr;
		rotateimage(img_Role_1_tank + i, img_Role_1_tank + (i + 1),speed_C * va); // 缺少图层
		
		putimage((int)rand() % 640, (int)rand() % 480, img_Role_1_tank + i, NOTSRCERASE);
		putimage((int)rand() % 640, (int)rand() % 480, img_Role_1_tank + i + 1, SRCINVERT);

		peekmessage(&msg, EX_KEY | EX_MOUSE);
		if (msg.message == WM_KEYDOWN)
		{
			switch (msg.vkcode)
			{
			case 'W':
				vr = -1;
				break;
			case 'S':
				vr = 1;
				break;
			case 'A':
				va = -1;
				break;
			case 'D':
				va = 1;
				break;
			}

		}

	}
}

void getShoot()
{
	if()
	//子弹运动路径
	x += speed_S * 1 * cos(speed_C * va); 
	y += speed_S * 1 * sin(speed_C * va);

	while (x != 640 && y != 480) {   //坐标与地形不同

		loadimage(img_Role_bullet + 0, "");//掩码图 缺
		loadimage(img_Role_bullet + 1, "");//原图 缺
		putimage(x,y, img_Role_bullet + 0,NOTSRCERASE);
		putimage(x, y, img_Role_bullet + 1, SRCINVERT);
		x++;
		y++;
	}

}

private:
IMAGE img_Role_1_tank[100];
IMAGE img_Role_bullet[2];
double r, a; //极坐标
int x = r * cos(a / 180) + getwidth() / 2 * cos(speed_C * va); //子弹射出位置的x
int y = r * sin(a / 180) - getheight() / 2 * sin(speed_C * va); //子弹射出位置的y
int vr = 0; //位移向量
int va = 0; //角速度向量
int vs = 0; //子弹向量

};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions