C++ :: How To Assign A Rectangle To Images

Apr 26, 2012

I am making a game Pong, and have been struggling with the collision aspect between the baal hitting off the paddle. I have created a Class, to draw a rectangle, to work with collision however I dont know how to assign the rectangle to the images of the ball and paddle.

#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <vector>
#include <cmath>
#include "gwin.h"
const int NUMBEROFBALLS = 1;

[Code] .....

View 1 Replies


ADVERTISEMENT

C++ :: Send Rectangle To A Function Which Takes A Rectangle Argument

May 13, 2014

Consider I have a rectangle like this:

Point p1(100,100);
Point p2(300,200);
Graph_lib::Rectangle r(p1,p2);

And also I have a function that takes a rectangle and returns a Point of that, say, top-left corner of that rectangle. For example:

Point N(Graph_lib::Rectangle R1);

My question is that, first, how to send that Rectangle r(p1,p2) to the Point N(Graph_lib::Rectangle R1) function? And then, how to return a Point from that function?

My IDE is visual studio 2012.

View 19 Replies View Related

C/C++ :: Put A Number In Rectangle?

Oct 4, 2014

the code draws rectangle or square it depends on you (column,row) then, put number in the center of the rectangle i don't want to extra space after putting one,two,three or four digits number in the center of the rectangle

#include <stdio.h>
int main(){
int i,j;

[Code]....

View 3 Replies View Related

C++ :: Algorithm To Roll A Rectangle

Sep 17, 2014

I'm trying to draw and pivot a rectangle. How to get the new coordinates if I turn it 90 degree for example?

From this:

To this:

This is not good because it will reduce it in size.

Code:
int size = 50;
if(b) // draw rectangle
{
POINT points[4] =
{{xCoord, yCoord},

[Code] ....

View 7 Replies View Related

C :: Printing A Rectangle Using For Loops?

Jan 27, 2015

I'm trying to make a program that prints a rectangle using "*" asterisks. I am only allowed to use "for loops" and I simply cannot get this to work properly. Here is my code so far...

Code:
int main(void)
{
//RectangleSize represents the area of the rectangle(width*length)
int length, width, RectangleSize;

[Code].....

View 5 Replies View Related

C++ :: How To Create A Rectangle With 3X5 Dimension

Nov 2, 2013

I am trying to create a rectangle with 3*5 dimension which would look like:

#####
#####
#####

I wanted to use for, and do while loop for that programming. I couldn't been able to create my desired dimension of 3*5.

//complier directives
#include<iostream>
#include<cstdlib>
using namespace std;
//main body
int main () {
//local identifiers
//complier directives

[Code] .....

View 5 Replies View Related

C++ :: Representing A Rectangle With Only 3 Variables Instead Of 4

Apr 6, 2013

how to use 3 variables to represent a rectangle in a grid instead of using 4. The traditional way is to use (x,y) (x2,y2). I propose using (x,l,h).In the traditional way as you probably know, (x,y) is the left op most corner, and (x2,y2) is the bottom right most corner. In the way I am proposing X is the left side, l is the length of the top side, and also the length of the bottom. 'h' is the height of the left and right. I think it's obvious how these three can define a rectangle same as the four.

View 2 Replies View Related

C# :: Indexing Through Rectangle List?

Mar 11, 2014

I have having trouble looping through the list in the update section to update each object in the rectangleList. I am not sure how to format it because it is only drawing one and it does not move across the screen. I thought this section of code would work and loop through each object and make each one move but it does not.

for (int i = 0; i < rectangleList.Count; i++) {
enemyPosition = new Rectangle(rectangleList[i].X + 2, rectangleList[i].Y ,enemyPosition.Width,enemyPosition.Height);
} List<Rectangle> rectangleList;
protected override void Initialize() {
rectangleList = new List<Rectangle>();

[code].....

View 5 Replies View Related

C :: Produce A Rectangle Out Of Asterisks Using While Loops

Jan 30, 2015

I am new to C and am unfortunately racking my brain against this simple assignment. I believe the task is to produce a rectangle out of asterisks using while loops, yet I can only produce an "L" shape. We were given a code, with syntax errors included.We are to correct the errors and test.

Code:

#include <stdio.h>
/*Houghton, Micah*/
/*ET2560 - Cordova*/
/*Unit 5 Lab - Programming Loops*/
int main(void) {
int length, width;
int lcount, wcount;

[code]....

View 3 Replies View Related

C++ :: Calculate Area Using Rectangle / Trapezoid Or Both

Feb 17, 2014

#include <iostream>
#include <cmath>
using namespace std;

//prototypes for all separate functions
int chooseFunc(int);
int chooseMethod(int);
int numRect(int);

[Code] .....

It seems that my program will ask the user for the number of rectangles and trapezoids but will fail to compute the area under the curve from the user input. Therefore, I believe I have a logical error somewhere or I'm forgetting to call something somewhere.

View 1 Replies View Related

C++ :: Detect Colors In The Black Rectangle?

Oct 5, 2013

I want to detect colors that in the black rectangle. [URL] How can I do? What library should I use?

View 7 Replies View Related

C++ :: Drawing A Rectangle And Diamond Using Recursion?

Oct 23, 2013

write a code that draw a block and diamond each in a single run by using '*' in recursion.

Below are one 10X10 rectangle and 6X4 diamond.

**********
**********
**********
**********
**********
**********
**********
**********
**********
**********

**
* *
* *
* *
* *
* *
* *
* *
**

Note: I couldn't write the diamond here appropriately somehow.

View 1 Replies View Related

C/C++ :: Subtracting Area Of Two Circles From A Rectangle

Mar 31, 2015

[URL] .... This is what I have so far, and it isn't incorrect, but how to improve this or make it more accurate?

// subtracting the area of two circles from a rectangle
#include <iostream>
using namespace std;
int main() {
cout << "This program is designed to calculate the area of a rectangle, to exclude the area of 2 circles that have been placed inside of the rectangle." << endl << endl;

[Code] .....

View 12 Replies View Related

C/C++ :: How To Use Rectangle Height And Width In Functions

May 13, 2014

The problem says:

Define functions n(), s(), e(), w(), center(), ne(), se(), sw() and nw(). Each takes a Rectangle argument and returns a Point. These functions define connection points on and in the rectangle. For example, nw® is the northwest (top-left corner) of a rectangle called r.

I wrote below code for that:

#include <Simple_window.h>
Point n(const Graph_lib::Rectangle& r);
Point s(const Graph_lib::Rectangle& r);
Point e(const Graph_lib::Rectangle& r);
Point w(const Graph_lib::Rectangle& r);
Point ne(const Graph_lib::Rectangle& r);
Point se(const Graph_lib::Rectangle& r);

[Code]...

As you see, this just mark the top-left corner of the rectangle r. In other functions I need the specifications of that rectangle, for example its height and width. How to use these specs in those functions?

View 2 Replies View Related

C# :: Drawing Rectangle On Bitmap (Mandelbrot)

Nov 3, 2014

I've been given the task of converting a java application to a c# windows form application. The program displays a Mandelbrot which then allows the user to zoom into. I've managed to display the Mandelbrot and even zoom. However when dragging a box to zoom, the box its self doesn't show, meaning the user cannot see what area they will be zooming into.

I believe I need to call the update function which draws the rectangle as I drag however no matter what I try, I get errors from a red cross instead of the Mandelbrot to compile errors. Here is the code that I believe is relevant.

public void update(Graphics g) {
Color color = Color.White;
Pen myPen = new Pen(color);
g.DrawImage(myBitmap, 0, 0);
if (rectangle) {

[Code]....

View 3 Replies View Related

C/C++ :: How To Draw Rectangle Inside A Circle

Jul 5, 2013

Write a program using turbo c to draw a rectangle inside a circle..........

View 2 Replies View Related

C Sharp :: How To Move Rectangle In TabPage

Apr 10, 2014

How to move a rectangle in TabPage ?

View 2 Replies View Related

C++ :: Calculate Area And Perimeter Of A Rectangle

Jan 28, 2013

Write a program that prompts the user to input the length of a rectangle and the width of a rectangle and then displays the rectangle's area and perimeter. The program should be broken down in 3 parts:

1. Input the length and the width (two input statements)

2. Calculate the area & perimeter (results should be saved in variables

3. print results.

Format the output so the user can easily read the results. Use the tab escape so its easy to read.
---------------------------------------------------------------
So here's what I have so far. I have been stuck for two days

#include iostream
using namespace std;
int main () {
int double length;
int width;
int area;
int perimeter;

[Code] ....

I dont want to get a zero for not turning this in...

View 14 Replies View Related

C++ :: Images Don't Display?

Oct 6, 2013

My code is:

#include <iostream>
#include <string>
#include <cstdlib>

[Code]....

The problem is that the images don't display and the window doesn't respond.

View 5 Replies View Related

C :: Calculate Area Of Rectangle - Variable R Is Being Used Without Being Initialized

Mar 15, 2014

I am writing a program to calculate a rectangle's area.

Eg.
Enter top left point: 1 1 (User input)
Enter bottom right point: 2 -1 (User input)
Top Left x = 1.000000 y: 1.000000
Bottom Right x = 2.000000 y: -1.000000
Area = 2.000000 (Program output)

It keeps on prompting me my variable r is being used without being initialized, when I think I already did so.

Code:
typedef struct {
double x;
double y;
} Point;

[Code] ....

View 8 Replies View Related

C :: Writing Number In The Middle Of Hollow Rectangle

Oct 3, 2014

I want to put number in the center of the rectngle. Nonetheless, one space is residual.

Code:
#include <stdio.h>
nt main(){
int i,j;
int column,row;
int n;

printf("Enter column: ");
scanf("%d",&column);

[Code] .....

View 14 Replies View Related

C :: Creating PPM Image - Black Rectangle With A Circle

Mar 12, 2013

I'm trying to create a PPM image for a class assignment. A black rectangle with a circle at the point 225, 175 with a radius of 75. I have to use certain specific methods, so I can't use like Bresenham's really famous method for creating a circle.

The problem is that it compiles fine, and transfers to an image fine, but always says that I have a negative or zero image size.

Code:

#include "shapes.h"
int main () {
int i, j, x, y;

fprintf(stdout,"P6 width height 255
");

[Code] ....

And my header is:

Code:
#include <stdio.h>#include <math.h>
#define height 480
#define width 640
#define cy 175
#define cx 225
#define radius 75

The circle has to be filled in. I made it white. Also, i and j are unsused so far, so just ignore them.

View 1 Replies View Related

C/C++ :: Rectangle Not Resizing Properly - Odd Multiplication Result

May 28, 2014

I'm having some issues understanding why the "rectangle" in the following code isn't resizing properly. Here's the code:

#include <iostream>
using namespace std;
class Rectangle {
public:
Rectangle(double w, double h, double f)
: width(w), height(h), factor(f)

[Code] .....

I tested the code with a simple multiplication factor of "2", which should result in a new width and height of 4, but instead I get an odd value that seems be close to 4.

Output:

Numerically enter the width of the rectangle: 1
Numerically enter the height of the rectangle: 1

The width of the rectangle is: 1
The height of the rectangle is: 1
The area of the rectangle is: 1
The perimeter of the rectangle is: 4

Numerically enter a number to resize the rectangle: 2

The width of the rectangle after resizing is: 2.07408e-317
The height of the rectangle after resizing is: 2.07408e-317

View 2 Replies View Related

C/C++ :: Drawing A Rectangle Using ASCII Code And For Loops?

Apr 24, 2015

For a Texas holdem' project I need to be able to draw out rectangles using ASCII codes and for loops. I started the code

#include <iostream>
#include <string>
#include <Windows.h>

[Code].....

View 6 Replies View Related

C++ :: Processing Speed Of Rectangle Intersect Function?

Feb 20, 2014

I'm trying to find the fastest method to find whether or not two rectangles intersect in an effort to streamline my code. I've built this function into a rectangle class I created below.

struct rectangle{
rectangle() :X1(0), Y1(0), X2(0), Y2(0) {};
rectangle(int X1, int Y1, int X2, int Y2)
:X1(X1), Y1(Y1), X2(X2), Y2(Y2) {};

[Code].....

View 3 Replies View Related

C Sharp :: Implement Drag And Drop For Rectangle

Oct 12, 2012

I would like to know the simplest way to implement a drag and drop feature for my rectangles I draw up.

I can select the rectangles and I know I have to get the old position to equal the new position but wouldn't know how to actually do this.

I would think that I would have to put it into MouseMove but again, not sure.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved