-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCarObjectA.h
109 lines (86 loc) · 2.16 KB
/
CarObjectA.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
100
101
102
103
104
105
106
107
108
#pragma once
#include "Sprite.h"
class CarObjectA : public Sprite
{
private:
bool animate = false;
int notIntersectoin = 500;
int vX;
int vY;
bool leftLight = false;
bool rightLight = false;
public:
CarObjectA(HINSTANCE hInst, LPCWSTR path) : Sprite(hInst,path,375,520,50,70) {
}
void setAnimate(bool val) {
this->animate = val;
}
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(bool val) {
leftLight = val;
}
void turnRight(bool val) {
rightLight = val;
}
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 {
if (y != notIntersectoin) {
x += vX;
y += vY;
}
}
void go() {
if (animate)
this->setVelocity(0, -2);
else
y = notIntersectoin;
}
};