I have to make a Windows Form Application which has to be a cat chasing a mouse. And you move the mouse with the arrow keys while that cat is going towards the mouse. It should detect when they both get in contact and show the time it took.
Both the cat and mouse should be placed randomly in the window each new game. And in higher difficulty, it should have two holes and when the mouse goes in one of them it shows on the other. Can someone help because I have no idea where to start the main part?
I've already placed pictures if a cat and a mouse in separate picture boxes and made the part with choosing difficulty.
You'd basically be combining these steps:
Implement an OnKeyDown handler to respond to key presses. Reposition the mouse image when this occurs.
Create a timer for the cat animation. At each step move the cat towards the mouse's position.
Whenever the position of one of the objects changes, check if there's a collision and handle it appropriately.
It's pretty simple to do this with a game engine as well. That would handle the animation for you. Here's how you'd get started with Unity for example:
https://msdn.microsoft.com/en-us/magazine/dn759441.aspx
Related
I have a procedurally generated tilemap that the player can interact with through mouse clicks. Each time the player clicks I get its screen position convert it to world cords and find the correct tile. This is fine but only works with single clicks and has no idea about a continuous hold of the mouse.
I am trying to figure out how to have a timed system like click and hold, both Minecraft and Terraira have ideas of break progress for each block / tile which is what I really want.
Anyone have an Idea how to track this and reset it when the player releases the mouse.
Instead of doing your own raycasting when the pointer goes down and then calling your interaction method, add a monobehaviour to each of your tiles that implements the IPointerDownHandler, IPointerExitHandler, and IPointerUp handler. Make sure you have an eventhandler in the scene, and a physcisRaycaster on your active camera!
OnPointerDown -> set a time stamp to time.unscaledTime
OnPointerExit -> reset timestamp to -1 or what ever (some religious coders would prefere a nullable float, so then set it to null), to cancel the interaction
OnPointerUp -> if your timer is > -1 (or NOT null), check if time.unscaledTime - your time stamp > your time threshold, if so -> call your interaction method. Reset the timer
More logic can be added of course.
EDIT:
from your comment, since you don’t want to have the logic per-tile, instead, when you click, save the tile that is “in world position of the screen position click”, and WHILE the mouse is down, check (in some frequency, per frame or every few ms), if the pointer is STILL on the same tile. if so, keep your timer running, otherwise reset it. if the timer expires, your interaction may start. if the pointer goes up, reset
I have a cat and mouse game and I have the mouse randomly moving about with timers and direction change etc. When the mouse moves left, the picture box changes to another completely separate file so it looks like it has turned.
I'm now trying to check if the cat has collided with the mouse so that I can end the game.
Does anyone know how I could check the current bounds of the mouse so I can detect when its been hit? I can provide any code needed but as it is long I'll copy and paste on request.
that the question linked below was how i was planning on doing it,
public void Collsions()
{
if (Cat.Bounds.IntersectsWith(Mouse.bounds))
}
but i then realized that the MouseBounds cant fine a bound as the image changes all the time depending on its direction
MouseImage.Image = MouseImages.Images[(int)currentDirection];
so there is a list of images that change depending on the direction of the mouse,and i don't know how to check the bounds after the image is changed.
this is all the mouse code:
https://pastebin.com/aEUWBdru
this is all the cat code (so far);
https://pastebin.com/ndAbDv5c
i'm creating a game where a slider will have a countdown. If the time is finished, the player lost a life. If he hit the button in a specific point of the slider, he receive a bonus point. I manage to create the slider, the timer, and the hotspot being showed in a random.rage(), but how i can keep track if the user is sucessfull in the atempt?
I tried follow the hotspot position in y and comparing with the slider value in the time of the click, but the max value of the slide will keep changing, so i don't think this is the best solution.
The idea is: if the user press the button when the red part is right in the white part (gui will be added later) he gain a bonus.
Here a video of the game: https://youtu.be/sttWSFXBrj8
Is there a way to smooth out the mouse movements? I want to remove all the small jitter in normal mouse moving with the hand, like you can never draw a clean line in paint because of you hand doing small jittering movements.
This might be hard to understand what I mean, but if you know zbrush they have a feature that is called lazy mouse http://www.pixologic.com/docs/index.php/Lazy_Mouse im looking for a way to recreate this inside my app. I can read the mouse position with Cursor.Position but I don't find a way to average out these numbers before they get sent to the pointer on the screen.
This is only possible if you can delay the effect of the mouse movement slightly. You record the points of the mouse movement at a certain frequency and then average them out to a line. Then use that line to draw whatever you need. You wont be able to directly set the mouse cursor to the averaged position as that would then feedback into your program as a new mouse movement.
Make sure you build it so you can tweak how long you delay the mouse movement, and how aggressive the averaging is (say by restricting the number of points it includes), and the frequency at which you record mouse movements (this is could affect cpu usage if its too frequent).
You will of course have to create some sort of abstraction for the mouse in your application and create a way for the application to get hold of it. (I would be trying to keep this as similar as possible to normal winforms/wpf so I could revert the change and just use mouse movement directly if needed).
I need to freeze the windows mouse cursor on the screen, so it stays hovered over a specific UI element. While the mouse is in this frozen state, I would still like to be able to interact with the UI using a "fake" mouse pointer.
Currently, I've got a low level mouse hook that prevents WM_MOUSEMOVE messages from being passed along, effectively stopping all real mouse movement. However, when I don't pass along the updated coordinates, windows actually sends me the old coordinates in a separate WM_MOUSEMOVE message, as if to correct for the fact that the mouse didn't move.
Any idea on either how to prevent Windows from sending me these corrected coordinates, or another approach of how I can freeze the actual mouse curosr and still allow the physical mouse to control a "Fake" cursor?
You can suppress mouse cursor movement by using DirectInput exclusive mode.
You should acquire mouse input device when cursor movement must be suppressed. This will block windows cursor movement but you can get messages for your fake cursor using DirectInput API.
If you move the mouse cursor position in response to a WM_MOUSEMOVE message, to put the mouse back to where you want it, you will get another mouse move message because the mouse has been moved again (because you moved it). To stop this, don't set the mouse position if it is already in the right place.
You may also want to clip the mouse position to your window and get exclusive access to it.
Why don't you just draw an image of the cursor at the place you want it frozen, then set the real mouse cursor to be hidden (Cursor.Hide IIRC).
It's not clear to me what you are trying to do, perhaps making a tutorial for your app and you want to show mouse movements, etc. Perhaps this library will be useful:
http://www.codeproject.com/KB/system/globalmousekeyboardlib.aspx