| | |
Objects are not displaying in my program, also need to know how to work mouse clicks.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2004
Posts: 2
Reputation:
Solved Threads: 0
Objects are not displaying in my program, also need to know how to work mouse clicks.
0
#1 Apr 20th, 2004
I am trying to finish a fishing program. Basically the user inputs how many fish spawn and how fast they move, then the user tries clicking as many fish as possible before they go off the screen. Also, the fish need to turn into a fish skeleton (which was drawn as a .GIF) when clicked on. I have much of the code written, just need a bit of help. If you feel you can help me please contact me and I can upload some code. WILLING TO PAY WELL FOR TIME!
Thanks. (I think this is a very simple program but I haven't been able to learn much in class as there is no text we use....I'm quite desperate to learn how to fix this, thanks again!)
MSN: Zachary.Adams@Colorado.EDU
AIM: ZSA004
Thanks. (I think this is a very simple program but I haven't been able to learn much in class as there is no text we use....I'm quite desperate to learn how to fix this, thanks again!)
MSN: Zachary.Adams@Colorado.EDU
AIM: ZSA004
•
•
Join Date: Apr 2004
Posts: 2
Reputation:
Solved Threads: 0
Re: Objects are not displaying in my program, also need to know how to work mouse clicks.
0
#2 Apr 20th, 2004
Here is my source code. I am really new at programming so ANY help that could assist would be awesome.
//Zach Adams
//CSCI 1300
//Project 4
//Several "fish" sprites move once across the screen and user must "catch" them with the net, which is the mouse clicking on them.
//COMMENTS
//I have not been able to figure out how to include the catching of the fish and the keeping track of total points, which is what I am going to have in the final program. I also plan to make the fish look more fish-like, perhaps with .GIF's if making a complicated fish exclusively with C++ coding is too complicated.
#include <winbgim.h>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "Fish.h"
#include <cstdlib>
using namespace std;
const int WINDOW_SIZE = 700;
//Program
int main ()
{
int N;
cout << "How many fish do you want to release?" << endl;
cin >> N;
int S;
cout << "How fast do you want them to move? 1=Fast 100=Slow" << endl;
cin >> S;
initwindow (WINDOW_SIZE, WINDOW_SIZE, "Fish Tank");
setbkcolor (BLUE);
setcolor (BLACK);
cleardevice ();
vector<fish> fishies
while (I < N)
{
fishies.push_back(fish());
}
while (S > 100)
{
cout << "That's just not possible. Re-enter.";
cin >>S;
}
while (S < 1)
{
cout << "That's ludicrous speed. Don't go to plaid. Re-enter.";
cin >>S;
}
cout << "CATCH FISH!" << endl;
srand (time (NULL));
Fish b();
b.move();
b.draw();
fishies[0].draw();
//The delay multiplied by the user-defined variable S cause the game to go slower for higher numbers entered.
delay (10*S);
return EXIT_SUCCESS;
}
// vector<fish> fishies
///////////////////////////////////////////////////////////////////
Header file for fish object
class Fish
{
public:
// constructors
Fish (); //"default" constructor, no arguments
Fish (int r, int g, int b);
// "accessor" functions, not used in this example
int getx ();
int gety ();
int getdx ();
int getdy ();
// "mutator" functions, not used in this example
void setx (int _x);
void sety (int _y);
void setdx (int _dx);
void setdy (int _dy);
// other member functions
void move ();
void draw ();
private:
int x;
int y;
int dx;
int dy;
int red;
int green;
int blue;
};
/////////////////////////////////////////////////////////////////////////
fish class
#include <winbgim.h>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include "fish.h"
using namespace std;
Fish::Fish ()
{
x = 200 + rand () % 10;
y = 10 - rand () % 10;
dx = 4 + rand () % 20;
dy = 16 - rand () % 16;
red = rand () % 256;
green = rand () % 256;
blue = rand () % 256;
}
//Fish::Fish (int r, int g, int b)
// x = 10 + rand () % 10;
// y = WINDOW_SIZE - 10 - rand () % 10;
// red = r;
// green = g;
// blue = b;
int Fish::getx ()
{
return x;
}
int Fish::gety ()
{
return y;
}
int Fish::getdx ()
{
return dx;
}
int Fish::getdy ()
{
return dy;
}
void Fish::setx (int _x)
{
x = _x;
}
void Fish::sety (int _y)
{
y = _y;
}
void Fish::setdx (int _dx)
{
dx = _dx;
}
void Fish::setdy (int _dy)
{
dy = _dy;
}
void Fish::move ()
{
x += dx;
y += dy;
dy++;
}
void Fish::draw ()
{
setfillstyle (SOLID_FILL, COLOR (red, green, blue));
fillellipse (x, y, 16, 8);
//These lines are meant to color in the eye for the fish.
setcolor (BLACK);
setfillstyle (SOLID_FILL, BLACK);
fillellipse (x+6, y-2, 4, 4);
}
The window opens but the fish do not appear. I am trying to solve that problem before I focus on making it so when a fish is clicked it changes into a skelleton. If anyone feels like helping I would be indebt for eternity.
//Zach Adams
//CSCI 1300
//Project 4
//Several "fish" sprites move once across the screen and user must "catch" them with the net, which is the mouse clicking on them.
//COMMENTS
//I have not been able to figure out how to include the catching of the fish and the keeping track of total points, which is what I am going to have in the final program. I also plan to make the fish look more fish-like, perhaps with .GIF's if making a complicated fish exclusively with C++ coding is too complicated.
#include <winbgim.h>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "Fish.h"
#include <cstdlib>
using namespace std;
const int WINDOW_SIZE = 700;
//Program
int main ()
{
int N;
cout << "How many fish do you want to release?" << endl;
cin >> N;
int S;
cout << "How fast do you want them to move? 1=Fast 100=Slow" << endl;
cin >> S;
initwindow (WINDOW_SIZE, WINDOW_SIZE, "Fish Tank");
setbkcolor (BLUE);
setcolor (BLACK);
cleardevice ();
vector<fish> fishies
while (I < N)
{
fishies.push_back(fish());
}
while (S > 100)
{
cout << "That's just not possible. Re-enter.";
cin >>S;
}
while (S < 1)
{
cout << "That's ludicrous speed. Don't go to plaid. Re-enter.";
cin >>S;
}
cout << "CATCH FISH!" << endl;
srand (time (NULL));
Fish b();
b.move();
b.draw();
fishies[0].draw();
//The delay multiplied by the user-defined variable S cause the game to go slower for higher numbers entered.
delay (10*S);
return EXIT_SUCCESS;
}
// vector<fish> fishies
///////////////////////////////////////////////////////////////////
Header file for fish object
class Fish
{
public:
// constructors
Fish (); //"default" constructor, no arguments
Fish (int r, int g, int b);
// "accessor" functions, not used in this example
int getx ();
int gety ();
int getdx ();
int getdy ();
// "mutator" functions, not used in this example
void setx (int _x);
void sety (int _y);
void setdx (int _dx);
void setdy (int _dy);
// other member functions
void move ();
void draw ();
private:
int x;
int y;
int dx;
int dy;
int red;
int green;
int blue;
};
/////////////////////////////////////////////////////////////////////////
fish class
#include <winbgim.h>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include "fish.h"
using namespace std;
Fish::Fish ()
{
x = 200 + rand () % 10;
y = 10 - rand () % 10;
dx = 4 + rand () % 20;
dy = 16 - rand () % 16;
red = rand () % 256;
green = rand () % 256;
blue = rand () % 256;
}
//Fish::Fish (int r, int g, int b)
// x = 10 + rand () % 10;
// y = WINDOW_SIZE - 10 - rand () % 10;
// red = r;
// green = g;
// blue = b;
int Fish::getx ()
{
return x;
}
int Fish::gety ()
{
return y;
}
int Fish::getdx ()
{
return dx;
}
int Fish::getdy ()
{
return dy;
}
void Fish::setx (int _x)
{
x = _x;
}
void Fish::sety (int _y)
{
y = _y;
}
void Fish::setdx (int _dx)
{
dx = _dx;
}
void Fish::setdy (int _dy)
{
dy = _dy;
}
void Fish::move ()
{
x += dx;
y += dy;
dy++;
}
void Fish::draw ()
{
setfillstyle (SOLID_FILL, COLOR (red, green, blue));
fillellipse (x, y, 16, 8);
//These lines are meant to color in the eye for the fish.
setcolor (BLACK);
setfillstyle (SOLID_FILL, BLACK);
fillellipse (x+6, y-2, 4, 4);
}
The window opens but the fish do not appear. I am trying to solve that problem before I focus on making it so when a fish is clicked it changes into a skelleton. If anyone feels like helping I would be indebt for eternity.
Last edited by cscgal; Apr 30th, 2004 at 2:19 pm.
Re: Objects are not displaying in my program, also need to know how to work mouse clicks.
-1
#3 Aug 9th, 2007
![]() |
Similar Threads
- How do i make my program work for 5 times and then Expire (VB.NET)
- Simulate Key strokes, and mouse clicks (C#)
- the program don't seem to work (VB.NET)
- need help to make this program work (C++)
- hOW DOES THIS PROGRAM WORK? processor (C)
Other Threads in the C++ Forum
- Previous Thread: getline printing null characters
- Next Thread: compiler doesnt like my if/else statements??
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





