-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticle.cpp
71 lines (55 loc) · 1.72 KB
/
Particle.cpp
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
#include "Particle.h"
#include "SDL.h"
#include <iostream>
Particle::Particle(int x_, int y_, int w_, int h_, float x_vel_, float y_vel_, int R_, int G_, int B_)
{
std::cout << "Constructor running, chainging values" << std::endl;
x = x_; y = y_; w= w_; h = h_;
x_vel = x_vel_; y_vel = y_vel_;
R = R_; G = G_; B = B_;
}
void Particle::Draw(SDL_Renderer *renderer)
{
SDL_Rect rect;
rect.x = x;
rect.y = y;
rect.w = 4;
rect.h = 4;
SDL_SetRenderDrawColor(renderer, this->R, this->G, this->B, 255);
SDL_RenderFillRect(renderer, &rect);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
}
void Particle::DrawCircle(SDL_Renderer* renderer, int32_t radius)
{
const int32_t diameter = (radius * 2);
int32_t x = (radius - 1);
int32_t y = 0;
int32_t tx = 1;
int32_t ty = 1;
int32_t error = (tx - diameter);
while (x >= y)
{
SDL_SetRenderDrawColor(renderer, R, G, B, 255);
SDL_RenderDrawPoint(renderer, this->x + x, this->y - y);
SDL_RenderDrawPoint(renderer, this->x + x, this->y + y);
SDL_RenderDrawPoint(renderer, this->x - x, this->y - y);
SDL_RenderDrawPoint(renderer, this->x - x, this->y + y);
SDL_RenderDrawPoint(renderer, this->x + y, this->y - x);
SDL_RenderDrawPoint(renderer, this->x + y, this->y + x);
SDL_RenderDrawPoint(renderer, this->x - y, this->y - x);
SDL_RenderDrawPoint(renderer, this->x - y, this->y + x);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
if (error <= 0)
{
++y;
error += ty;
ty += 2;
}
if (error > 0)
{
--x;
tx += 2;
error += (tx - diameter);
}
}
}