C++ SFML Frogger Sprite Movement - animation

I am new to coding and currently making a C++ version of Frogger using SFML.
I want my frog to move like it does here: http://froggerclassic.appspot.com/
Currently I am using isKeyPressed to move my frog and it is moving in a smooth motion in any direction rather than jumping from position to position how I intend it to. How should I go about implementing this?

As often there are multiple solutions.
You can use events instead of real-time inputs. That way you can move once when a KeyPressed event happens and don't move until the KeyRelease event happens.
Alternatively, you can introduce a sort of cool down for your key. So when you detect a key press the first time you move the frog by X amount and staet the cooldown timer. As long as the timer isn't zero, you don't move the frog.
As timet you can use an sf::Clock and a sf::Time.

Related

Joint for physical gun slider?

I want to make it so when I fire my gun the slider shoots back and then comes forward like a real gun. However I don't know how I should start because I can't find any relevant information on Google and I don't know what to search. All I need is the logic behind how to do it, I can code it myself.
I would agree with zambari.
Just create an animation and play it when your guns gets fired.
Edit:
Since you are talking about 3D, you could either
move the pivot of the object to the point where the trigger would be attached. This way, all you need to do is change the objects rotation for the animation.
use joints
This is the best tool for VR guns with interactable parts. I HIGHLY recommend looking at this to ANYONE making a VR game
https://github.com/Oyshoboy/weaponReloadVR

Unreal Engine 4: Character collider goes through floor when crouching

I'm using the 3rd person blueprint template and I've added a custom sprint and custom crouch functionality to it.. when crouching I trigger the crouching animations according to the character speed and set the max walk speed to a low value, I can interrupt the crouch by sprinting and vice versa... I can stand up from the crouch by pressing the crouch key again or attempting to jump.
It all worked quite well, until I attempted to manipulate the capsule collider's half height according to the character's speed whenever crouch, jump, or sprint is pressed... I can see the collider working as expected, however when I try to crouch the character's feet sink into the ground and when I try to stand up again the character falls through the floor...
Any help would be greatly appreciated...
The problem is that just shrinking the half-height is probably not what you want when your character is crouching, because your collision capsule is shrinking from the top and the bottom.
So, the feet of your character start to sink into the ground and when you grow your capsule it will clip through your level and fall down due to gravity.
You have two possibilities to fix this:
Use two capsules on your character, one for crouching and one for standing and only activate the one you are using
Move the capsule down the same time you are shinking it.
The capsule needs to finish at the same point, so move it lower.

blender + unity rig animation at which level?

hi i am a beginner in unity and blender both.
here is my question
i created 1 player character with rig and make 1 animation of moving hand like punching in boxing game.
now if i put another character, on whom my player is going to punch, required animation to show the reaction of punch or it will be done by unity it self?
and if this is right (i have to create the animation for reaction), so is that in all the game like vice city player moving and fell down on floor etc. etc...?
If your question is: "Will Unity make animations for you by itself?" then the answer is no. You have to create your own animations using either Unity's built-in tools or 3D modeling software.
On the other hand if your question is: "Will Unity automatically trigger animations depending on circumstances?" then the answer is yes and no. Yes, you can make an animation tree which reads your script's variables and changes the animation accordingly. No, since you have to make the scripts and the animator.

Writing an efficient game-loop

I have recently asked a question here about programming a game so it will be efficient and won't lag.
I have made a game that lags like hell. I suspect that the way that I programmed it's game-loop, could be the source of the problem.
I want to describe to you in general the situation in my game, and then present my way of programming it's game loop.
It's a game for two players. Each player controls a tank. Each tank can shoot missiles. Each tank can collect 'gifts' from the field.
Each missile of tank1 can collide with tank2, and each missile of tank2 can collide with tank1.
Each missile can collide with a boundary of the screen.
Each tank can collide with the other tank.
Each tank can collide with 'gifts'.
All missiles constantly move.
Tanks move when specific buttons on the keyboard are pushed.
My game loop (Each stage is inside a method called from the game loop):
Loop through all the missiles on the screen, and update their location (move them).
Loop through all of tank1's missiles, and for every one check if collides with tank2.
Loop through all of tank2's missiles, and for every one check if collide with tank1.
Loop through all the missiles on the screen, and check if collide with screen boundaries.
Check if specific keys are pressed on the keyboard. If so, move tanks.
Check if the two tanks collide.
Loop through all of the 4 'gifts' on the screen, and check if they touch a tank.
Questions:
This game-loop is probably inefficient. How inefficient is it? A little, or a lot?
How can I improve the game loop and/or the way it's methods work? How can I achieve the same thing, more efficiently?
How likely is it for a game-loop to be the main cause for poor performance level? How common is it in games for this to be the source of the problem?
Appreciate your help.
I wouldn't necessarily say it's inefficient since you're just giving us the general idea of what might be done in several other games. It sounds like all you're doing is moving objects and checking for collisions, which I'm assuming uses AABB collision detecting. Nothing really expensive here. Of course it has room for improvement. See #2.
You're probably getting input more than once, so what you could do is get the input at the beginning of each frame and store it in some way. I don't know what form of input you're using, but if you're using a keyboard for example, you'd get and store the state of the WASD keys and check those states when handling tank input.
The most notable optimization you could make is you loop through every missile 3 times. The first time is to move them, the second to check their collisions, and the third time to check if they are outside the screen. In one loop, you can move them, check if they're outside of the screen, and then check if they collide with the opposing tank. I recommend doing it in this order, because if the bullet does happen to move outside the screen you can avoid doing an unnecessary collision check.
Finally, you only have to check if the two tanks collide when they move, and you only have to do it once. If you need it so something happens for every frame the two tanks are on top of each other, you can store the state of the collision and you only need to update it again when one tank moves.
It really depends. You're probably locking the frame rate by sleeping, so you could be sleeping for too long. Try to remove your method of frame rate limiting and seeing what happens.

Is it better to count n ticks or run two seperate timers

I'm making a snake game and on every tick the snake moves. because the snake is moving a whole unit on each tick the animation is jumpy. The game is on an invisable grid so the snake can only change directions at specific points.
Would it be considered better practice to have a timer that will move the snake a pixels at a time counting it with a variable, and on every n tick run the code to change direction. Or is it better to have two separate timers; one for move the snake a pixel at a time and another for changing the snakes direction?
Essentially, you're creating a "game-loop" to update the displayList (in Actionscript) and re-draw your view. When the game gets complex, Timers and listening for ENTER_FRAME events will be constrained to the flashplayer settings for screen refresh (i.e. it's FPS) and the CPU's rendering based on what it is tasked to process.
For frame-rate independent animation, you should probably use a combination of ENTER_FRAME to track milliseconds and GetTimer() calls to more accurately (to the millisecond) call animations and normalize the experience across a variety of platforms.
Basically, listen for the ENTER_FRAME event, check the current milliseconds since the last update and if it exceeds your refresh-rate (in terms of milli's), fire off the animation/state update: check for snake collision detection with a "direction-block" - handle if true, then update the snake's movement / position / state.
Flash updates the Display List at whatever it's settings, and CPU / machine-dependent issues are. The key, I've found, is to make sure you're normalizing the speed of updates to make the experience consistent. Timer's have their usage, but can cause memory performance issues. ENTER_FRAME is synced to the main timeline / frame-rate settings.
For a dated, but interesting discussion 3 years ago, check out this post from actionscript.org.

Resources