[Moved] Duck hunt game



  • Hello. I am trying to create a duck hunt game via QT creator. So i need some help. I have user interface (background some picture) and now i need to create object ( animated GIF duck flying) <- i dunno how to do this , then to make it show on user interface ( background ) <- also this | and the most important thing i have to make that object move via X axis. ( from 0 to 700 ) and the most important part is that, that i have to make the movement visible -> i want to see moving object via X axis. Also the duck must appear somewhere in Y axis ( from 0 to 100 ) it has to be random appearing and hard thing that the more time pass, the more ducks have to appear in different places on Y axis ant move via X axis. Any help is appreciated . Very many thanks. I have tried with this. This means to create duck object.
    @void CFrameWnd::SukurtiAnti() {
    // QMovie *movie = new QMovie(”:/Antis/paveiksl/duck.gif”);
    // QLabel *processLabel = new QLabel(this);
    // processLabel->setMovie(movie);
    // movie->start(); QWidget *antis = new QWidget(this);
    // antis->setStyleSheet(“background-image: url(:/Antis/paveiksl/duck.gif)”);
    ui->gridLayout->addWidget(antis);
    QPushButton *button = new QPushButton(“one”);
    ui->gridLayout->addWidget(button);
    button->setGeometry(20,20,20,20);
    button->setStyleSheet(“background-image: url(:/Antis/paveiksl/duck.gif)”);
    antis->show();
    }@
    First of all i try to create new widget antis then new layout is created to make duck visible on background ( but there isn’t and i don’t know why) . i tried to make animated gif with movie, but the picture is not shown … i also tried to create pushbutton but there is no results at all.. In advance, thanks for any replies ........



  • 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..



  • Maybe changing the title, removing the screaming caps and the asap, might help!?
    I only replied because I got big time annoyed by the title and didn't bother reading your post.



  • 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.



  • So if i "tab" to the button i can kill the duck with my eyes closed?
    Mayby u can use a mouseclick or touch event on the coordinates of the duck widget?



  • 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.


  • Moderators

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.