diff --git a/C++ProjectTemplate b/C++ProjectTemplate index c1aa29d..7c06d62 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/input b/input new file mode 100644 index 0000000..6641009 --- /dev/null +++ b/input @@ -0,0 +1,141 @@ +noop +noop +addx 5 +noop +noop +addx 1 +addx 3 +addx 2 +addx 4 +addx 3 +noop +addx 2 +addx 1 +noop +noop +addx 4 +noop +addx 1 +addx 2 +addx 5 +addx 3 +noop +addx -1 +addx -37 +addx 37 +addx -34 +addx 7 +noop +addx -2 +addx 2 +noop +noop +noop +addx 5 +addx 2 +noop +addx 3 +addx 15 +addx -8 +addx -9 +addx 21 +addx -9 +addx 5 +addx 2 +addx 3 +addx -2 +addx -38 +noop +addx 3 +addx 37 +addx -33 +addx 5 +noop +noop +addx 5 +noop +noop +addx 5 +noop +addx -1 +addx 1 +addx 5 +noop +noop +addx 5 +noop +noop +noop +addx 1 +addx 2 +noop +addx 3 +addx -36 +noop +noop +noop +addx 6 +addx 21 +addx -17 +addx 18 +addx -8 +addx -7 +addx 2 +addx 5 +addx -8 +addx 13 +addx -2 +addx 7 +noop +addx -2 +addx 5 +addx 2 +addx 1 +noop +addx -38 +addx 4 +addx 3 +noop +addx 34 +addx -29 +addx -2 +addx 10 +addx -3 +addx 2 +addx 3 +noop +addx -22 +addx 2 +addx 23 +addx 7 +noop +noop +addx 3 +noop +addx 2 +addx -18 +addx 19 +addx -38 +addx 5 +addx 2 +noop +addx 1 +addx 4 +addx 1 +noop +noop +addx 2 +addx 5 +addx 2 +noop +addx 1 +noop +addx 2 +addx 8 +addx -1 +addx -30 +addx 31 +addx 2 +addx 5 +addx -35 +noop diff --git a/main.cpp b/main.cpp index 8ab7e53..d53bdc6 100644 --- a/main.cpp +++ b/main.cpp @@ -4,86 +4,54 @@ using namespace olc; -class Example : public olc::PixelGameEngine -{ -public: - Example() - { - sAppName = "Example"; - } - -public: - bool RayVsRect(const vf2d ray_origin, const vf2d ray_dir, const olc::utils::geom2d::rect target, vf2d&contact_point, vf2d&contact_normal, float&t_hit_near){ - - contact_normal = { 0, 0 }; - contact_point = { 0, 0 }; - - vf2d t_near = {(target.pos.x - ray_origin.x) / ray_dir.x, (target.pos.y - ray_origin.y) / ray_dir.y}; - vf2d t_far = {(target.pos.x + target.size.x - ray_origin.x) / ray_dir.x, (target.pos.y + target.size.y - ray_origin.y) / ray_dir.y}; - - if (t_near.x > t_far.x) {float b; b = t_near.x; t_near.x = t_far.x; t_far.x = b;}; - if (t_near.y > t_far.y) {float b; b = t_near.y; t_near.y = t_far.y; t_far.y = b;}; - - if (t_near.x > t_far.y || t_near.y > t_far.x) return false; - - t_hit_near = fmax(t_near.x, t_near.y); - float t_hit_far = fmin(t_far.x, t_far.y); - - if (t_hit_far < 0) return false; - - contact_point.x = ray_origin.x + t_hit_near * ray_dir.x; - contact_point.y = ray_origin.y + t_hit_near * ray_dir.y; - - if (t_near.x > t_near.y) - if ( 1.0f / ray_dir.x < 0) - contact_normal = { 1, 0 }; - else - contact_normal = { -1, 0}; - else - if ( t_near.x < t_near.y) - if ( 1.0f / ray_dir.y < 0) - contact_normal = { 0, 1 }; - else - contact_normal = { 0, -1 }; - - return true; - - +void incrementClock(int&clockCycle,int®,int&sum){ + if (clockCycle%40>=reg-1&&clockCycle%40<=reg+1){ + std::cout<<'#'; + } else { + std::cout<<'.'; + } + clockCycle++; + if (clockCycle%40==0){ + std::cout<{originPoint+velocity,5},olc::utils::geom2d::rect{{32,32},{64,32}})) { - originPoint+=velocity; - DrawCircle(originPoint,5); - } else { - DrawCircle(originPoint,5,RED); - } - DrawLine(originPoint,GetMousePos()); - - DrawRect({32,32},{64,32},RayVsRect(originPoint, GetMousePos()-originPoint, olc::utils::geom2d::rect{{32,32},{64,32}},contact_point,contact_normal,t_hit_near)&&t_hit_near<1?YELLOW:WHITE); - return true; - } -}; +} int main() { - Example demo; - if (demo.Construct(128, 120, 8, 8)) - demo.Start(); + std::ifstream file("input"); + int clockCycle=0; + bool noop=true; + int reg=1; + int amtToAdd=0; + int sum=0; + int crt=0; + while (file.good()){ + std::string line; + std::getline(file,line); + if (line.length()>0){ + std::string command=line.substr(0,line.find(' ')); + if (command=="noop"){ + noop=true; + //std::cout<<"noop"<0){ + std::string command=line.substr(0,line.find(' ')); + if (command=="noop"){ + noop=true; + //std::cout<<"noop"<