943,793 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3135
  • C++ RSS
Apr 20th, 2004
0

Objects are not displaying in my program, also need to know how to work mouse clicks.

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ZSA004 is offline Offline
2 posts
since Apr 2004
Apr 20th, 2004
0

Re: Objects are not displaying in my program, also need to know how to work mouse clicks.

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.
Last edited by cscgal; Apr 30th, 2004 at 2:19 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ZSA004 is offline Offline
2 posts
since Apr 2004
Aug 9th, 2007
-1

Re: Objects are not displaying in my program, also need to know how to work mouse clicks.

Game Programming is EASY. Introducing Graphics and mouse support is also simple.
Check out <snipped> for tutorials based on this topic
Last edited by happygeek; Aug 9th, 2007 at 10:09 am. Reason: Solicitation for own site
Reputation Points: 31
Solved Threads: 3
Junior Poster
krnekhelesh is offline Offline
127 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: getline printing null characters
Next Thread in C++ Forum Timeline: compiler doesnt like my if/else statements??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC