[Moved] Duck hunt game
-
bq. "Claiming urgency is very likely to be counter-productive...":http://www.catb.org/~esr/faqs/smart-questions.html#urgent
-
This post is not really readable.
Mayby you can change the question in a normal question instead of screaming and demanding?
After that, please wrap your code in "@" tags so people can read it.
This way you dont have to expect a lot of help.@secretNinja:
when i wrote my post, i didnt saw yours yet. :) -
I updated my post.. Sorry for my demands and screamings, this project just getting me to death... I must to do it, but teacher doesn't explain how to.... All the stuff i have to do myself.. So forums is my last hope..
-
is it ok now
-
Actually, it's almost perfect :)
-
[quote author="audrensitas" date="1303734384"]is it ok now[/quote]Aaah that's much better...
Maybe having a look at "DoodleDrive":https://projects.forum.nokia.com/doodledrive might give you some inspiration.
-
Reads much better now!
Is there a special reason that you use a QPushButton for the display of a picture? Mayby you can use a "pixmap":http://doc.qt.nokia.com/4.7/qpixmap.html ?
As for the "moving" , i suggest that u use a "timer":http://doc.qt.nokia.com/4.7/qtimer.html or even a "timeline":http://doc.qt.nokia.com/4.7/qtimeline.html combined with the setgeometrie() function of the widget u use. -
I use QPushButton in order that when there will be on game, when duck will be flying on X axis, when clicked on it, it should go down in a state - dead. That is why I use QPushButton.
-
Hi all,
I am trying to create Duck Hunt game in qt creator.
There is my code to create duck in constructor:
@ QMovie *movie = new QMovie(":/Antis/paveiksl/duck1111.gif");
l = new QLabel(this);
l->setMovie(movie);
movie->start();
l->setGeometry(-5,0,55,39);
l->show();
xas = 1;
yas = rand()$0; // DUCK IS RANDOM POSITION GENERATED ON Y AXIS.
@- First of all, is there a possibility to set duck start position in X axis in -5 coordinate, so that when the game start the duck would fly from the corner or from the left part of my background, it wouldn't be seen when the game just starts. Is there a possibility to set this with setGeometry or do i need to use some other function?
- Secondly, can someone advice how to create dynamic array or dynamic slot to create ducks. I don't need one duck, i need many ducks that would be flying in the screen after more time have passed.
- Moreover is it also a possibility to set delay after random duck creation that one duck is flying, then after few seconds more ducks start flying?
I am using QTimer for movement of the duck
@ QTimer *t = new QTimer(this);
connect(t,SIGNAL(timeout()),this,SLOT(Metodas()));
t->setInterval(1/30);
t->start(50); @@void CFrameWnd::Metodas()
{
xas +=1;
l->move(xas,yas);
}@However, what is the best idea to do when the duck reaches X axis end or end of the screen? To stop qtimer or to quit application with results or ?...
And finally, can someone advice for the duck killing? Do i have to create a pushbutton, that will be connected with the duck object and when clicked the duck would change to 'dead' position and will be moving to a certain coordinate down Y axis and then disappear .Any advices are appreciated.
Thanks in advance. -
Merged yet another duck hunt thread with one of the existing.
-
/me feels sorry for those poor ducks...
[quote author="audrensitas" date="1304401454"]
- First of all, is there a possibility to set duck start position in X axis in -5 coordinate, so that when the game start the duck would fly from the corner or from the left part of my background, it wouldn't be seen when the game just starts. Is there a possibility to set this with setGeometry or do i need to use some other function?[/quote]
Sure. Doesn't your current method work properly?
[quote]- Secondly, can someone advice how to create dynamic array or dynamic slot to create ducks. I don't need one duck, i need many ducks that would be flying in the screen after more time have passed.
[/quote]
You are asking two very different things. Look into Qt's container classes to store your duck objects. Don't even think of trying to create "dynamic slots" or something like that. Re-think your design instead. Just create an class that manages a single duck (you might want to call that class Duck), and create multiple Duck objects. You can give this Duck class slots and signals if you need, and those would only be related to that single Duck object. I would also make this object responsible for animating itself from left to right.
[quote]
- Moreover is it also a possibility to set delay after random duck creation that one duck is flying, then after few seconds more ducks start flying?
[/quote]
Sure. You are already using random in your code. Why not apply the same idea to a QTimer object who's interval you change at every trigger and that you have create your new Duck objects?
[quote]
However, what is the best idea to do when the duck reaches X axis end or end of the screen? To stop qtimer or to quit application with results or ?...
[/quote]
What do your requirements say you need to do? How should we know? The fact that you need to be able to show multiple ducks, tells me that you probably should not quit the application. After your duck moves off-screen, you probably can destroy the Duck object and increase some counter for the number of missed ducks, or something like that.
[quote]
And finally, can someone advice for the duck killing? Do i have to create a pushbutton, that will be connected with the duck object and when clicked the duck would change to 'dead' position and will be moving to a certain coordinate down Y axis and then disappear .
[/quote]
That would depend on how you plan to actually make the hunting work. You did not tell us about that.
-
QGraphicsView is something I would use for creating such game.
You can reimplement QGraphicsItem, so you get a DuckItem, where you can implement all the logic for moving a duck. You will get QMouseEvents directly to your item, so killing a duck is just a proper handling of events sent to your class.