​01

Coding process

* Set star properties , Initialize stars , Draw stars , Move the stars
* Set the properties of meteor , Initialization meteor
* Initialize load data , Drawing meteors by mapping , Make a meteor move
* Set up the statement text
* Main function setting array , Loading interface
02

Effect display

03

Code sharing

#include

#include// GUI Library

#include

#include

#include

#pragma comment(lib,"winmm")

#define MAXSTAR 1000

#define MAXMETEOR 100

IMAGE img1, img2, img3;

// Properties of stars

struct Star

{

int x, y;

int step;

int color;

}star[MAXSTAR];

// Attributes of meteors

struct Meteor

{

int x, y;

int step;

int style;

}meteor[MAXMETEOR];

// Initialize stars

void initStar(int i)

{

star[i].x = rand() % 1000; //[0,999]

star[i].y = rand() % 600;

star[i].step = rand() % 6+3; //[0,5]

star[i].color = RGB(rand() % 255, rand() % 255, rand() % 255);

}

// Draw and move stars

void moveStar(int i)

{

// Pixel dots

putpixel(star[i].x, star[i].y, star[i].color);

// Mobile processing

star[i].x += star[i].step;

// If you move outside the window

if (star[i].x > 1000)

{

putpixel(star[i].x, star[i].y, star[i].color);

initStar(i);

}

}

// Initialization meteor

void initMeteor(int i)

{

meteor[i].x = rand() % 2000-1000;//[-1000,999]

meteor[i].y = -600;//[0,599]-600-->[-600,-1]

meteor[i].step = rand() % 30 + 2;

meteor[i].style = rand() % 3; //[0,2]-->0,1,2

}

// Initialization data

void initDate(int i)

{

// Load picture

loadimage(&img1, "1.jpg", 30, 30);

loadimage(&img2, "2.jpg",40, 40);

loadimage(&img3, "3.jpg", 50, 50);

for (i = 0; i < MAXSTAR; i++)

{

initStar(i);

}

for (i = 0; i < MAXMETEOR; i++)

{

initMeteor(i);

}

}

// Painting meteors : Mapping

void drawMeteor(int i)

{

for (i = 0; i < MAXMETEOR; i++)

{

switch (meteor[i].style)

{

case 0:

putimage(meteor[i].x, meteor[i].y, &img1,SRCPAINT);

break;

case 1:

putimage(meteor[i].x, meteor[i].y, &img2, SRCPAINT);

break;

case 2:

putimage(meteor[i].x, meteor[i].y, &img3, SRCPAINT);

break;

}

}

}

// Moving meteor

void moveMeteor(int i)

{

for (i = 0; i < MAXMETEOR; i++)

{

meteor[i].x += meteor[i].step;

meteor[i].y += meteor[i].step;

// If the meteor runs out of the window

if (meteor[i].x>1000 || meteor[i].y > 600)

{

initMeteor(i);

}

}

}

// Word output

void text()

{

settextcolor(RGB(rand() % 255, rand() % 255, rand() % 255));

settextstyle(30, 0, " Regular script ");

char* text[50] = { "X", "X", "X", " I ", " happiness ", " Joy ", " you ", " do ", " I ", " female ", " Friends ", " friend ",
" bar ", "!", };

int x = 450, y = 100;

for (int i = 0; i < 14; i++)

{

if (i<7)

outtextxy(x, y + i * 50, text[i]);

else

outtextxy(x+100, y + (i-7) * 50, text[i]);

}

}

int main()

{

initgraph(1000, 600);

mciSendString("open 2.mp3", 0, 0, 0);

mciSendString("play 2.mp3 repeat", 0, 0, 0);

srand((unsigned int)time(NULL));// Seed of random function

setbkmode(TRANSPARENT);

int i = 0;

initDate(i);

while (1)

{

cleardevice();

for (i = 0; i < MAXSTAR; i++)

{

moveStar(i);

}

drawMeteor(i);

moveMeteor(i);

text();

Sleep(100);

}

_getch();

closegraph();

//system("pause");

return 0;

}

Technology
©2019-2020 Toolsou All rights reserved,
Huawei 2021 session Hardware Engineer Logical post (FPGA) Super detailed surface !!!Vue-element-admin upgrade ui edition virtual machine VMware Download and install the most detailed tutorial !C++ Move constructor and copy constructor sound of dripping water java Backstage interview pygame Realize full screen mode and adjustable window size mysql Database setting character set configuration modification my.ini file (windows)30 What's the experience of being a junior programmer at the age of 20 C++ Multithreading programming ( Summary of common functions and parameters )python_ cherry tree