[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/pcg/ Pro/g/ramming Challenge General
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 13
Thread images: 2
File: 1467756898246-1-inverted2.png (550 KB, 1450x1080) Image search: [Google]
1467756898246-1-inverted2.png
550 KB, 1450x1080
"Programming? What's that?" edition


RULES:

Pick a challenge between 0-99, do it as quickly as possible and make your code as small and efficient as you can in the language of your choosing. Post code when you're done!

And don't forget, Have fun!
===========================
Other links:
V3.0 (many more challenges, but not color-coordinated)
http://www.mediafire.com/view/0z6dx30ss35eexn/Programming_3.0.png

V1.4(Pretty much 2.0, but without difficulty-colors and a few different challenges)
http://www.mediafire.com/view/qaduzz1a83zu4j1/Programming_1.4.png
>>
Still kind of buggy and haven't really implemented the scoring system, but here's my "pong game" in Processing

class pongBall
{
float xPos, yPos, ballRadius;
float vx, vy;
boolean collision = true;
pongBall(float xPos, float yPos, float ballRadius, float vx, float vy)
{
this.xPos = xPos;
this.yPos = yPos;
this.ballRadius = ballRadius;

this.vx = vx;
this.vy = vy;
}

void displayBall()
{
ellipse(xPos, yPos, ballRadius, ballRadius);
}

boolean checkXCollision(float rectWidth, float y1, float y2)
{
boolean isAtPaddleHeight = (yPos >= y1 && yPos <= y2);
println("y1 = " + y1 + "\t y2:" + y2 + "booleanCheck" + isAtPaddleHeight);

if (((int)(this.xPos - this.ballRadius/2) <= (int)(rectWidth) || //Left-hand check
(int)(this.xPos + this.ballRadius/2) >= (int)(width-rectWidth)) && isAtPaddleHeight)
{
println("yPos = " +this.yPos+"\ty1: "+y1+"\ty2: "+y2);
this.vx *= -1;

line(rectWidth, 0, rectWidth, height);
line(width-rectWidth, 0, width-rectWidth, height);
println(width);
}
return collision;
}
void checkBorderCollisions()
{
if (this.xPos >= width || this.xPos <= 0)
{
this.vx *= -1;
}

if (this.yPos <= 0 || this.yPos >= height)
{
this.vy *= -1;
//println("CHANGE VY");
}
}
void moveBall()
{
this.xPos += vx;
this.yPos += vy;
}

}
>>
File: 1468048789254.jpg (484 KB, 992x1022) Image search: [Google]
1468048789254.jpg
484 KB, 992x1022
>>55526866
muh roll
>>
>>55527482
Part 2:

void settings()
{
size(500, 500);
}

pongBall practiceBall = new pongBall(125, 175, 38, 5, 0);
float paddleHeight=50, player1Height = height/2, player2Height = height/2;
void draw()
{
rectMode(CORNERS);

noFill();

background(150, 175, 200);

practiceBall.displayBall();


fill(0);
if (keyPressed)
{
if (key == 'w')
{
player1Height -= 5;
}
if (key == 's')
{
player1Height += 5;
}
if (key == CODED)
{
if (keyCode == UP)
{
player2Height -= 5;
}
if (keyCode == DOWN)
{
player2Height += 5;
}
}
}
practiceBall.moveBall();
rect(15, player1Height, 20, player1Height-paddleHeight);

rect(width-20, player2Height, width-15, player2Height-paddleHeight);

practiceBall.checkBorderCollisions();

practiceBall.checkXCollision(20, player1Height, player1Height-paddleHeight);
practiceBall.checkXCollision(20, player2Height-paddleHeight, player2Height);
}
>>
>>55527601
Rerolling
>>
>>55526866
I am roll
>>
I have some free time. Let's roll.
>>
OP Here... Apparently, someone started a similar thread like ten minutes after this one, and it got a lot more replies... To not clutter up the board, should we move to that thread (>>55527011)?
>>
I have a small proprietary program for which I need to find the a file format for. The program is quite small, and the files are small too. Would it be feasible to step through the program in a debugger from the moments where the file is read from, if at all possible, to find how this program reads and this file and stores it in memory? Linux
>>
>>55530311
I'm having trouble understanding your problem... Do you have a program that finds file formats or a program you need to find the format for the files?
>>
Giving whatever breath of fresh air I can to this dying thread:
#include <iostream>
#include <vector>
typedef double Rectangle[2][2];
//Rectangle alias is structured as follows:
/*
Minimum information for a rectangle is two points: bottom-left and top-right (opposite pairs)
First row is the coordinate for the top left point, x1, y1
Second row is coordinate for bottom-right point, x2, y2
*/

bool doRectsOverlap(Rectangle rect1, Rectangle rect2);
bool compareNums(double comparingNum, double lower, double higher);
double calculateArea(Rectangle rect1, Rectangle rect2);


int main(int argc, const char * argv[]) {

// Rectangle overlappingRect;
Rectangle rect1 =
{ {1, 0},
{6, 7} };

Rectangle rect2 =
{ {3, 4},
{9, 8} };


if(doRectsOverlap(rect1, rect2))
{
std::cout << "CONGRATULATIONS! THE RECTANGLES OVERLAPPED... Calculating area..." << std::endl;
std::cout << calculateArea(rect1, rect2);
}

return 0;
}
(Part 1)
>>
>>55532009
Part 2

bool doRectsOverlap(Rectangle rect1, Rectangle rect2)
{
//Checks to see if the two rectangles overlap by seeing if one of the x||y-coordinates in the rectangle
//Is between the two x||y coordinates of the other rectangle

int counter= 0; //Keeps track of how many "points" we have. 4 Points make a rectangle, so
//Once counter reaches 4, we know for certain the rectangles overlap
bool doesOverlap = false;

for(int i = 0; i < 2; i++)
{
if(compareNums(rect1[i][0], rect2[0][0], rect2[1][0]))//Checks rect2's X-Coordinates
counter++;

if(compareNums(rect1[i][1], rect2[0][1], rect2[1][1])) //Checks rect1's Y-Coordinates
counter++;

if(compareNums(rect2[i][0], rect1[0][0], rect1[1][0])) //Checks rect2's X-Coordinates
counter++;
if(compareNums(rect2[i][1], rect1[0][1], rect1[1][1]))//Checks rect2's Y-Coordinates
counter++;
}

if(counter >= 4)
doesOverlap = true;

return doesOverlap;
}

bool compareNums(double comparingNum, double lower, double higher)
{ //Give three numbers, it sees if comparingNum is between lower and higher.
//Useful for determining if
bool isBetween = false;
if(comparingNum >= lower && comparingNum <= higher)
{
isBetween = true;
// std::cout <<lower << " <= "<< comparingNum << " <= " << higher <<std::endl;
}
return isBetween;
}

double calculateArea(Rectangle rect1, Rectangle rect2)
{
std::vector <double> xCoordVector = { rect1[0][0], rect1[1][0], rect2[0][0], rect2[1][0]};
std::vector <double> yCoordVector = { rect1[0][1], rect1[1][1], rect2[0][1], rect2[1][1]};

std::sort(xCoordVector.begin(), xCoordVector.end());
std::sort(yCoordVector.begin(), yCoordVector.end());

double xLen = xCoordVector[2]-xCoordVector[1];
double yLen = yCoordVector[2]-yCoordVector[1];

return xLen*yLen;
}
>>
>>55526866
Roland
Thread replies: 13
Thread images: 2

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.