current position:Home>C + + game programming -- Game Name: Flash Christmas tree 2.0
C + + game programming -- Game Name: Flash Christmas tree 2.0
2022-01-27 02:41:50 【Code Knight】
Compile environment :Mictosoft Visual Studio 2022, EasyX_2021
do person : Code Knight <[email protected]>
Last modified :2021-12-16
demonstration :
( Take a look at it. , The picture will move )
Ideas :
More beautiful .
Code :
#include<graphics.h>
#include<time.h>
#include<conio.h>
#include<iostream>
#include"EasyXPng.h"
using namespace std;
#pragma comment(lib,"Winmm.lib")
const int width = 600;
const int length = 600;
const int MAXSNOW = 200;
const int MAXLIGHT = 20;
const int BOUNDS = 20;
//const int SZ = 10;
int key = 0;// Function selection key :2 snow ,3 Lighting
IMAGE gift, snows, star1, star2, voids, voidss, ren, ling, li, wa, llala;
struct SNOW
{
int x;
double y;// Along the y The shaft falls
double step;// Falling speed
int color;
};
SNOW snow[MAXSNOW];// Array of structs (200 A snowflake )
int TREE[BOUNDS][BOUNDS] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//15-x
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//15-x
{0,0,0,0,0,0,0,7,0,0,0,0,0,0,0},
{0,0,0,0,0,0,1,1,1,0,0,0,0,0,0},
{0,0,0,0,0,7,7,7,7,7,0,0,0,0,0},
{0,0,0,0,1,1,1,1,1,1,1,0,0,0,0},
{0,0,0,0,0,7,7,7,7,7,0,0,0,0,0},
{0,0,0,0,1,1,1,1,1,1,1,0,0,0,0},
{0,0,0,7,7,7,7,7,7,7,7,7,0,0,0},
{0,0,0,0,1,1,1,1,1,1,1,0,0,0,0},
{0,0,0,7,7,7,7,7,7,7,7,7,0,0,0},
{0,0,1,1,1,1,1,1,1,1,1,1,1,0,0},
{0,0,0,0,0,0,0,2,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,2,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,2,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,2,0,0,0,0,0,0,0}//15-y
};
class christmasTree
{
public:
void Initialize();// Night
//
void drawTree();// christmas tree
void drawTree2();//2tree
void drawTree3();//3tree
//
void initSnow(int i);// Snowflake initialization
void moveSnow(int i);// snow
void Snow(christmasTree CT);// Flying snow
//
void yellowLight(int i, int j, int SZ);
void redLight(int i, int j, int SZ);
void Light(int i, int j, int SZ);// flash light
//
void Surprise();// Pleasantly surprised
};
void christmasTree::Initialize()
{
initgraph(width, length);
//setbkcolor(WHITE);
//cleardevice();
loadimage(&gift, "gift.jpg", 300, 300);
loadimage(&snows, "snows.png", 30, 30);
loadimage(&voids, "voids.png", 20, 20);
loadimage(&voidss, "voidss.png", 20, 20);
loadimage(&star1, "star.png", 600, 600);
loadimage(&star2, "star.png", 300, 300);
loadimage(&ren, "ren.png", 500, 500);
loadimage(&ling, "ling.png", 300, 300);
loadimage(&li, "li.png", 300, 300);
loadimage(&wa, "wa.png", 300, 300);
loadimage(&llala, "llala.png", 300, 100);
putimage(150, 150, &gift);
_getch();
closegraph();
//BeginBatchDraw();
}
void christmasTree::yellowLight(int i, int j, int SZ)
{
if (TREE[i][j] == 7)
{
int x = ((j + 0) * SZ + (j + 1) * SZ) / 2;
int y = ((i + 0) * SZ + (i + 1) * SZ) / 2;
int r = SZ / 4;
setlinecolor(YELLOW);
setfillcolor(YELLOW);
fillcircle(x, y, r);// Center formula (x1+x2)/2
//Sleep(20);
setlinecolor(RGB(9, 163, 67));
setfillcolor(RGB(9, 163, 67));
fillrectangle(j * SZ, i * SZ, (j + 1) * SZ, (i + 1) * SZ);
}
}
void christmasTree::redLight(int i, int j, int SZ)
{
if (TREE[i][j] == 1)
{
int x = ((j + 0) * SZ + (j + 1) * SZ) / 2;
int y = ((i + 0) * SZ + (i + 1) * SZ) / 2;
int r = SZ / 4;
setlinecolor(RED);
setfillcolor(RED);
fillcircle(x, y, r);// Center formula (x1+x2)/2
//Sleep(20);
setlinecolor(GREEN);
setfillcolor(GREEN);
fillrectangle(j * SZ, i * SZ, (j + 1) * SZ, (i + 1) * SZ);
}
}
int color = 10;
void christmasTree::Light(int i, int j, int SZ)
{
//yellowLight(i, j, SZ);
//redLight(i, j, SZ);
int x = 20;
putimagePng(100 + x, 50, &star2);
putimagePng(50 + x, 100, &star2);
putimagePng(20 + x, 150, &star2);
putimagePng(-10 + x, 200, &star2);
putimagePng(-30 + x, 250, &star2);
putimagePng(-50 + x, 300, &star2);
putimagePng(-80 + x, 350, &star2);
putimagePng(100 + x, 50, &star2);
putimagePng(150 + x, 100, &star2);
putimagePng(180 + x, 150, &star2);
putimagePng(210 + x, 200, &star2);
putimagePng(230 + x, 250, &star2);
putimagePng(250 + x, 300, &star2);
putimagePng(280 + x, 350, &star2);
putimagePng(150 + x, 180, &ren);
putimagePng(50 + x, 200, &ling);
setbkmode(TRANSPARENT);// Display transparent text
settextcolor(RGB(255-color, 0+color,color++));// Set font color
settextstyle(50, 0, _T(" Song style "));// Set font size , typeface
outtextxy(240, 130, _T(" St. "));// Output font
settextstyle(50, 0, _T(" Song style "));// Set font size , typeface
outtextxy(240, 190, _T(" Birthday "));// Output font
settextstyle(50, 0, _T(" Song style "));// Set font size , typeface
outtextxy(240, 250, _T(" fast "));// Output font
settextstyle(50, 0, _T(" Song style "));// Set font size , typeface
outtextxy(240, 310, _T(" Happy "));// Output font
}
void christmasTree::drawTree()
{
int i, j;
setlinestyle(PS_SOLID, 36);
int SZ = width / BOUNDS*1.25;
for (int i = 0; i < BOUNDS; i++)
{
for (int j = 0; j < BOUNDS; j++)
{
if (TREE[i][j] == 1)
{
setlinecolor(GREEN);
setfillcolor(GREEN);
fillrectangle(j * SZ, i * SZ, (j + 1) * SZ, (i + 1) * SZ);
Sleep(1);
}
if (TREE[i][j] == 2)
{
setlinecolor(RGB(95, 41, 31));
setfillcolor(RGB(95,41,31));
fillrectangle(j * SZ, i * SZ, (j + 1) * SZ, (i + 1) * SZ);
Sleep(1);
}
if (TREE[i][j] == 7)
{
setlinecolor(RGB(9, 163, 67));
setfillcolor(RGB(9, 163, 67));
fillrectangle(j * SZ, i * SZ, (j + 1) * SZ, (i + 1) * SZ);
Sleep(1);
}
if (key == 3)
{
//BeginBatchDraw();
//drawTree();
Light(i, j, SZ);// flash light
//FlushBatchDraw();
}
}
}
putimagePng(-25, -40, &star1);
}
void christmasTree::drawTree2()
{
int i, j;
int SZ = width / BOUNDS * 1.25;
for (int i = 0; i < BOUNDS; i++)
{
for (int j = 0; j < BOUNDS; j++)
{
if (TREE[i][j] == 1)
{
setlinecolor(GREEN);
setfillcolor(GREEN);
fillrectangle(j * SZ, i * SZ, (j + 1) * SZ, (i + 1) * SZ);
}
if (TREE[i][j] == 2)
{
setlinecolor(RGB(95, 41, 31));
setfillcolor(RGB(95, 41, 31));
fillrectangle(j * SZ, i * SZ, (j + 1) * SZ, (i + 1) * SZ);
}
if (TREE[i][j] == 7)
{
setlinecolor(RGB(9, 163, 67));
setfillcolor(RGB(9, 163, 67));
fillrectangle(j * SZ, i * SZ, (j + 1) * SZ, (i + 1) * SZ);
}
if (key == 3)
{
//BeginBatchDraw();
drawTree();
putimagePng(-25, -40, &star1);
Light(i, j, SZ);// flash light
//FlushBatchDraw();
}
}
}
putimagePng(-25, -40, &star1);
//FlushBatchDraw();
}
void christmasTree::initSnow(int i)
{
snow[i].y = 0;
snow[i].x = rand() % width;
snow[i].step = (rand() % 5000) / 10000.0 + 1;
//snow[i].color = (int)(snow[i].step * 255 / 6.0 + 0.5);// Gradual
//snow[i].color = RGB(snow[i].color, snow[i].color, snow[i].color);
cleardevice();
drawTree2();// Painting trees
}
void christmasTree::moveSnow(int i)// snow
{
//BeginBatchDraw();
setlinestyle(PS_SOLID, 36);
//putpixel((int)snow[i].x, snow[i].y, 0);// Painting snow
//cleardevice();
putimagePng(-25, -40, &star1);
putimagePng((int)snow[i].x, snow[i].y, &voids);
snow[i].y += snow[i].step;
if (snow[i].y > length) initSnow(i);// Generate new snowflakes
//putpixel((int)snow[i].x, snow[i].y, snow[i].color);// Draw snow again
putimagePng((int)snow[i].x, snow[i].y, &snows);
//cleardevice();
//FlushBatchDraw();
}
void christmasTree::Snow(christmasTree CT)
{
srand((unsigned)time(NULL));
for (int i = 0; i < MAXSNOW; i++)
{
CT.initSnow(i);
snow[i].y = rand() % length;
}
while (!_kbhit())
{
drawTree2();// Painting trees
for (int i = 0; i < MAXSNOW; i++)
CT.moveSnow(i);
Sleep(20);
}
//FlushBatchDraw();
}
int main()
{
christmasTree CT;
CT.Initialize();
initgraph(width, length);
mciSendString(_T("open 123.mp3 alias bkmusic"), NULL, 0, NULL);// Play music
mciSendString(_T("play bkmusic repeat"), NULL, 0, NULL);// Loop Playback
CT.drawTree();
while (cin>>key)
{
switch (key)
{
case 2:
CT.Snow(CT);
break;
case 3:
CT.Snow(CT);
break;
case 4:
return 0;
}
}
return 0;
}
copyright notice
author[Code Knight],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270241486624.html
The sidebar is recommended
- Spring IOC container loading process
- [thinking] the difference between singleton mode and static method - object-oriented programming
- Hadoop environment setup (MySQL environment configuration)
- 10 minutes, using node JS creates a real-time early warning system for bad weather!
- Git tool
- Force deduction algorithm - 92 Reverse linked list II
- What is the sub problem of dynamic programming?
- C / C + +: static keyword summary
- Idea does not have the artifacts option when configuring Tomcat
- Anaconda can't open it
guess what you like
-
I don't know how to start this
-
Matlab simulation of transportation optimization algorithm based on PSO
-
MySQL slow log optimization
-
[Vue] as the window is stretched (larger, smaller, wider and higher), the text will not be displayed
-
Popular Linux distributions for embedded computing
-
Suzhou computer research
-
After installing SSL Certificate in Windows + tomcat, the domain name request is not successful. Please answer!!
-
Implementation time output and greetings of jQuery instance
-
The 72 year old uncle became popular. Wu Jing and Guo fan made his story into a film, which made countless dreamers blush
-
How to save computer research
Random recommended
- Springboot implements excel import and export, which is easy to use, and poi can be thrown away
- The final examination subjects of a class are mathematical programming, and the scores are sorted and output from high to low
- Two pronged approach, Tsinghua Professor Pro code JDK and hotspot source code notes, one-time learning to understand
- C + + recursive knapsack problem
- The use of GIT and GitHub and the latest git tutorial are easy to understand -- Video notes of crazy God speaking
- PostgreSQL statement query
- Ignition database test
- Context didn't understand why he got a high salary?, Nginxfair principle
- Bootstrap switch switch control user's guide, springcloud actual combat video
- A list that contains only strings. What other search methods can be used except sequential search
- [matlab path planning] multi ant colony algorithm grid map path planning [including GUI source code 650]
- [matlab path planning] improved genetic algorithm grid map path planning [including source code phase 525]
- Iinternet network path management system
- Appium settings app is not running after 5000ms
- Reactnative foundation - 07 (background image, status bar, statusbar)
- Reactnative foundation - 04 (custom rpx)
- If you want an embedded database (H2, hsql or Derby), please put it on the classpath
- When using stm32g070 Hal library, if you want to write to flash, you must perform an erase. If you don't let it, you can't write continuously.
- Linux checks where the software is installed and what files are installed
- SQL statement fuzzy query and time interval filtering
- 69. Sqrt (x) (c + + problem solving version with vs runnable source program)
- Fresh students are about to graduate. Do you choose Java development or big data?
- Java project: OA management system (java + SSM + bootstrap + MySQL + JSP)
- Titanic passenger survival prediction
- Vectorization of deep learning formula
- Configuration and use of private image warehouse of microservice architect docker
- Relearn JavaScript events
- For someone, delete return 1 and return 0
- How does Java dynamically obtain what type of data is passed? It is used to judge whether the data is the same, dynamic data type
- How does the database cow optimize SQL?
- [data structure] chain structure of binary tree (pre order traversal) (middle order traversal) (post order traversal) (sequence traversal)
- Webpack packaging optimization solution
- 5. Operation element
- Detailed explanation of red and black trees
- redhat7. 9 install database 19C
- Blue Bridge Cup notes: (the given elements are not repeated) complete arrangement (arrangement cannot be repeated, arrangement can be repeated)
- Detailed explanation of springboot default package scanning mechanism and @ componentscan specified scanning path
- How to solve the run-time exception of test times
- Detailed explanation of k8s management tool kubectl
- Android system view memory command