-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackGroundObject.h
100 lines (78 loc) · 2.03 KB
/
BackGroundObject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#pragma once
#include "Sprite.h"
class BackGroundObject : public Sprite
{
private:
int vX;
int vY;
bool leftLight = false;
bool rightLight = false;
public:
BackGroundObject(HINSTANCE hInst, LPCWSTR path,int x, int y, int width,int height) : Sprite(hInst, path, x, y, width, height) {
}
void virtual render(HWND hwnd, PAINTSTRUCT ps, HDC hdc) {
BITMAP bitmap;
HDC hdcMem;
HGDIOBJ oldBitmap;
hdcMem = CreateCompatibleDC(hdc);
oldBitmap = SelectObject(hdcMem, hBitmap);
GetObject(hBitmap, sizeof(bitmap), &bitmap);
BitBlt(hdc, x - width / 2, y - height / 2, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);
if (leftLight)
LeftLight(hdc);
if (rightLight)
RightLight(hdc);
SelectObject(hdcMem, oldBitmap);
DeleteDC(hdcMem);
}
void turnLeft() {
rightLight = false;
leftLight = true;
}
void turnRight() {
rightLight = true;
leftLight = false;
}
void switchOffLights() {
leftLight = rightLight = false;
}
void LeftLight(HDC hdc) {
SelectObject(hdc, CreateSolidBrush(RGB(255, 165, 0)));
int size = 5;
int left = x - width / 2 + size;
int top = y - width / 2 - size;
int right = x - height / 2 + size;
int bottom = y - height / 2 - size;
Ellipse(hdc, left, top, right, bottom);
left = x - width / 2 + size;
top = y + width / 2 + size;
right = x - height / 2 + size;
bottom = y + height / 2 + size;
Ellipse(hdc, left, top, right, bottom);
}
void RightLight(HDC hdc) {
SelectObject(hdc, CreateSolidBrush(RGB(255, 165, 0)));
int size = 5;
int left = x + width / 2 - size;
int top = y + width / 2 + size;
int right = x + height / 2 - size;
int bottom = y + height / 2 + size;
Ellipse(hdc, left, top, right, bottom);
left = x + width / 2 - size;
top = y - width / 2 - size;
right = x + height / 2 - size;
bottom = y - height / 2 - size;
Ellipse(hdc, left, top, right, bottom);
}
void setVelocity(int x, int y) {
this->vX = x;
this->vY = y;
}
virtual void update() override {
x += vX;
y += vY;
}
void go() {
this->setVelocity(0, -2);
}
};