Solved How to process several key events at the same time?
-
Not exactly. They have one line:
qDebug() << ...
As for second your sentence. I'm sorry I didn't quite get that. Could you please explain?
-
I wonder about the executes, too. You just print things on qdebug, so how you know you are no longer moving when firing?? You're actually never start moving
-
@Suares said in How to process several key events at the same time?:
As for second your sentence. I'm sorry I didn't quite get that. Could you please explain?
But it would be interesting how you exactly implemented the moving. Because thats essential to know when it stops doing what it's supposed to be doing ;)
I mean that the commands maybe get deleted because no object holds a reference to it anymore. But again this needs insight how the commands actually work.
-
If user stop pressing keys - NoCommand will be executed.
Please look at UserInput.cpp line 27:
return (cmd) ? cmd : std::make_shared<NoCommand>();
If there is no command from user - queue is empty that is why I return NoCommand.
Definition of this command is:
void NoCommand::Execute() noexcept { }
-
@Suares
yes, but still it's not clear how the actual moving is implemented... -
you need to have something like this:
void updateScene() { littleMan.positionX += moveX; // you remember what i told you about the moveX variable and the signal? littleMan.positionY += moveY; for(auto& it : boldList) it.update(); // while this update function will move your bold one step forward in the fire direction. }
and your slot for firing will add an bold to the boldList. An bold can be a struct like this:
struct Bold { QPoint position; QVector2D direction; int speed; }
-
Please wait. I need more time to implement real moving for my tank.
I'll show you my way as soon as possible. -
Man, how you know you stop moving, when you never implemented moving???
-
I implemented movement. If don't belieave you can build project :)
Tank moves, but I can't move and fire at the same time. I want to fix it. -
D:\workspaces\Qt_default\BattleCity-master\include\Game.h:44: Fehler: 'atomic' in namespace 'std' does not name a template type
Is it just me, or is the code a little unreadable? @raven-worx
@Suares why are you always using {} instead of ()??
KeyEventFilter* kef = new KeyEventFilter{ _userTank, this }; Game{ argc, argv }
ok this code is really ugly (in my opinion) but if i understand it right you are doing this:
get key press and generate a Commando from it,
save them in a queue,
remove the commando from the queue and execute the command, till the list is empty.So if you press the key it is on the queue once. you take it, execute and forgot about it.
Again why don't you make something like this:
class tank{ ... QPoint m_position; QVector2D m_speed = {0,0}; void addSpeed(QVector2D speed){ m_speed += speed; } update() { m_position += m_speed; } } struct Bold{ QPoint(position); QVecotr2D(direction); int speed; } MainWindow(){ private: tank* myTank = new tank; QVector<Bold> m_bolds; addbold(tank* tank) { Bold newBold = {tank.getPos, tank.getDirection, 100}; m_bolds.pushback(newBold); } mainLoop() { myTank->update(); for(auto& it : m_bolds) it.position += it.direction * speed; render(); } keyPressEvent() { if(upPress) tank->addSpeed(0,1); else if(upRelease) tank->addSpeed(0,-1); if(downPress) tank->addSpeed(0,-1); else if(downRelease) tank->addSpeed(0,1); else if(leftPress) tank->addSpeed(-1,0); else if(leftRelease) tank->addSpeed(1,0); if(rightPress) tank->addSpeed(1,0); else if(rightRelease) tank->addSpeed(-1,0); else if(spacePress) addBold(tank); } } } }
you need just your tank class, your MainWindow and a struct for the bold. Your Project has: 7(!!) Classes