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
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 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
I have 2 cameras and 1 Canvas, and I want to change the display for the scene to the second camera when pressing a button, and at the same time, change the target display for the Canvas to the second camera as well, and I'm using C#.
I know that I have to use GetComponent<Camera> and GetComponent<Canvas> but i don't know how to set the indexes for these two.
Any help will appreciated.
Rather than changing the index: just disable the one camera and enable the other. There's no point wasting GPU cycles rendering something that can't be seen (which is what a second active camera will do).
As for changing the Canvas target:
Change the canvas's worldCamera property, eg:
canvasGO.GetComponent<Canvas>().worldCamera = cam2.GetComponent<Camera>();
I'm trying to pass some text between pages to a textblock. It works fine with small amount of data, but with large amount of data the page won't load.
Page 1:
NavigationService.Navigate(new Uri("/Pages/DetailPage.xaml?gameGuide=" + gameGuide, UriKind.Relative));
Page 2:
if (NavigationContext.QueryString.TryGetValue("gameGuide", out gameGuide))
guideTxtBlk.Text = gameGuide;
The data source is from a XML file which I'm downloading to Page 1.
Here is the amount of data that work:
In the level "Project Nova", after you fight the British and
escape, you must set an explosive. Make sure you clear out all the
enemies before planting it. There should be a Mosin–Nagant gun after
killing the enemies in the first room. This should help you clear out
the enemies in the second room, especially the enemies on the higher
walkways. You can shoot through the metal gratings. After setting the
explosive, shoot the highlighted beam and make your way out. As you
head out, there will be an enemy outside the door on your right and
another coming on your left. Kill these two and then sprint down the
walkway. There will be a few more enemies climbing onto the ship but
you should have no issues killing them and proceeding. A last enemy
should be up high so be forewarned. If you die at any time during this
run, you may still have enough time to make it, as long as there is
2:15 left on the timer.
Here is the one that don't work:
This is easiest to do on Recruit difficulty and is done on the level
"WMD". You will be in control of the dispatcher in the SR71 plane and
a soldier on the ground, switching between them from time to time. To
zoom in you press (LT) and to zoom out you press (RT). To command your
squad on where to go, press (A) on the location. Use (LS) to move the
cursor around the area. After you find the squad on your screen, you
will be given an insertion point that is to the east of you labeled
"1602". After you hear that vehicles are coming in from the north, you
will be told to put your team into the building labeled "Safe House".
Select the Safe House with (A). You will be put into the soldier’s
scenario to kill the enemies entering the house. After the encounter
with the enemies that entered the building, you will be put back into
the hands of the dispatcher. Make sure all 4 of your teammates are
alive on the screen. After this, select the back of the Safe House
building. To the right you will see two enemies next to a barrel.
Scroll over these enemies and select them with (A) to have your team
attack them. Directly behind them is an objective point. Select the
objective point so that your team moves to this location. After that,
you will be given another insertion point just below this one. You
will see bushes halfway between your current location and the
objective point. Select the bushes with (A) to have your team move
there (you should be 500-600 away from the insertion point).
Immediately after they have moved, your dispatch will tell you that a
large group of enemies is coming around. You will be told to hold down
(RS) to make your team go into a prone position and not be seen by the
enemies. After you get the all clear, move your team to the objective
directly in front of them and you will be given an objective labeled
"Barracks". The on screen reticule should turn red, so select the
Barracks with (A) to have them move into position. Now you will be put
back into the view of the soldier. Eliminate all the enemies found
inside of the building and be sure to be in front to take as much of
the fire that is shot at you and your teammates. At the end of all
this, you should have all four of your teammates with you. You need to
clear the last room, plant and detonate the C4 and make it through the
barracks. You will be given a new insertion point once you leave the
barracks, so guide your team there. When you have reached the second
insertion point outside of the building, you have safely guided the
squad without killing them. Make sure that while you are controlling
your team, no vehicles that drive by see you as your team on the
ground will be eliminated immediately. If they are eliminated, you
will need to restart the whole mission over.
There is a maximum length for a URI. I think it is somewhere around 2000 characters. You should probably adopt a different method to pass the data between the pages. Use a global variable, put the data in the ViewModel, or save and retrieve from PhoneApplicationService/IsolatedStorage are some options.
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).