I have two separate levels for my maze game for the ti-84 calculator, which both have identical code. Although, one of the levels does not complete when the character reaches the end, and treats the final spot as a wall.
ClrHome
1→A
1→B
For(y,1,8
For(x,1,16
Output(y,x,sub(" XD", 1+[F](y,x),1
End:End
Repeat K=21 or [F](A,B)=2
getkey→K
If Ans
Output(A,B," ")
sum(△List(Ans={25,34}))
A+Ans([F](A+Ans,B)≠1)→A
sum(△List(K={24,26}))
B+Ansnot([F](A,B+Ans)→B
Output(A,Ans,"Θ")
End
ClrHome
Display "You Win"
Pause
Goto 99
The problem is in your logic for horizontal movement, and I would be willing to bet that in the maze that works, you move either up or down onto the goal, while in the maze that doesn't work, you move right or left onto the goal.
Your vertical movement coefficient of Ans, ([F](A+Ans,B)≠1), evaluates to true whenever the current cell is not 1, a wall. On the other hand, your horizontal movement coefficient of Ans, not([F](A,B+Ans), evaluates to true whenever the current cell is not 1 or 2, a wall or the goal. Change it to be similar to the vertical logic, ([F](A,B+Ans)≠1),and your game should be fixed.
Edit:
Also, for the sake of performance, I would recommend enclosing most of the logic in an if then statement, because it doesn't need to run if a key is not pressed.
If K
Then
[Game Logic]
End
Related
I am improving a video game of mine where I currently have the problem that NPCs can shoot through walls. In order to fix this issue, I have decided to completely re-do my work regarding ground combat.
I use a tight grid for finding paths from any point A to B. I store my grid as an image-like structure and use Jump Point Search for the pathfinding itself. My goal is to find a location that is as far away from the enemy as possible (limited by the firearms's range) that also has a direct line of sight to the enemy.
In my latest approach, I determined all nodes in my grid that are within weapon range and that are connected to the enemy's location (colored in green in the image below). The final missing part is filtering these points so that only the points with a valid line of sight remain.
I can also detect the border lines (colored in blue) very fast. I could check for every node, if a line from this node to the enemy would intersect any border line. If that is not the case, I have clear line of sight. However, I assume this to be neither fast nor the optimal solution.
Do you have any ideas or suggestions? I am glad for any hint!
I visualized the grid in the following image to give you an idea of what I am talking about. If a character would stand in the lower right green area, he could not shoot the enemy in the upper left area because of missing line of sight.
I've been looking for awhile now for someone who had created a good example of making good physics in JavaFX, or even just a 'basic jumping mechanic' as the title says. I can't really find any information on it and I'm not really sure how to implement the idea.
All I want is a basic example, or just an explanation, or even just a point in the direction of what element of JFX I'm going to use.
Any help is appreciated.
Thanks
I'm assuming you already have some sort of game loop that ticks 60 times a second such as the AnimationTimer. If you want the jump height to be something like 200 pixels, you need to set and objects y-velocity (velocity is added to the objects location every tick) to a large negative number (as the object is moving upwards) and add a smaller amount every tick to this velocity until it hits zero, (this will be the top of the jump) and then keep adding this value to the y-velocity until it reaches the ground or collides with something. (This value will be your gravity constant)
In essence, you need to set the y-velocity to a high value then take away small increments every tick to slow the jump until the y-velocity hits 0, then begin adding the gravity constant again until the object hits the ground, hope this helps :)
I am doing a project about the simulation of an elevator and ran into this problem. I have a listbox for users to choose the floor that they want to go to but I don't know how to make the door of the elevator opens in the proper order.
For example, the first person want to go to the 1st floor and the second person wants to go to the 3rd floor. They would select 1 first and then 3, but when I do this Matlab always opens the 3rd floor first and then the 1st floor.
I am thinking about storing the value of the listbox in a matrix and then use for loop to open the elevator's door according to its floor in a correct order.
This is the GUI of my project.
GUI
Under the listbox1_Callback . I tried to do this but my array only has one element.
A = [];
listValue = get(handles.listbox1,'Value');
A = [A,listValue];
I want A to holds a sequence of values so that I could apply foor loop to A and execute element by element.
Thanks for your help.
Say, for example, that you have a function called open that takes one argument, the floor number, and opens that floor's elevator door. To loop over each selected floor, do:
handles.listbox1 = uicontrol('Style', 'listbox', ...
'String', [1 2 3 4], ...
'Position', [10 10 40 100], ...
'Max', 2);
selectedFloor = get(handles.listbox1, 'Value');
for ii = 1:length(selectedFloor)
open(selectedFloor(ii));
end
Your project is probably over, but I will nevertheless contribute something. Not about programming code per se, but about elevator principles, which may help you and others conceive the system correctly the next time.
Elevator doors only open at a specific floor when the cab is at or very near (< 8 cm typically) that floor. The reason is simple: the motor and mechanism to open the doors is on the cab. The landing door is actually moved by the cab door, using a clutch with skates and pick-up rollers. Therefore, what you have to be concerned about in you program is the position of the cab, which is a simple object that moves sequentially from floor to floor.
So, when calls are registered, you have to compare them to the position of the cab. Then you decide which way to go, up or down (or just open the door if the position is already right). You keep a preferred direction until you've reached the farthest call, then you change direction or wait for new calls. Simply add or subtract 1 from the actual position (let a few seconds elapse between each operation, to make look real), compare the position with the corresponding index of the call array, and then decide to stop and open the door (if a call exists) or continue (if none exists). Don't forget to stop at the extremities, even if for some reason no call exists.
If you want to introduce landing calls in the mix, you have to take into account if they are up or down calls. You stop only for up calls while going up, and only for down calls while going down.
I'm using the first person controller for my characters movement. On a left arrow keypress, I'd like the character to instantly rotate 90 degrees and keep moving forward. Currently, when I hit the arrow key, the character makes the sharp 90 degree turn, but the forward momentum the character previously had takes a second to wear off so the character ends up sliding in the direction he was previously moving a short bit.
The closest example I can think of to visually explain what I'm trying to do is how the character turns sharp in Temple Run. How my game is currently working, if I had the character on a ledge make a sharp left turn, he'd likely keep the original momentum and slide off the edge right after he turns.
Since my character is running on the x/z axis, I'm wondering if there would just be some way to maybe swap the directional velocity/momentum? The speed the character had on the x axis would instantly be switched to the z when it turns and the other would be set to zero. I'm obviously open to any solution that accomplishes what I'm looking for.
I dug into the CharacterMotor class in the first person controller, but have yet to find what part I can tweak to accomplish this.
I'd greatly appreciate any help.
Thank you.
You can try to stop the velocity of the Rigidbody before turning.
this.rigidbody.velocity = Vector3.zero;
this.rigidbody.angularVelocity = Vector3.zero;
If you want the object to continue like it did, you can try playing around with it by saving the current velocity in a variable, setting it to 0, rotate it and then putting back the old velocity (still forward).
If it works with global vectors (so from the point of view of the world, not the object), then you can try negativing the velocity, actually causing it to go 'backwards'. I can't test it for now but either way I think you need to set the velocity to zero first before turning the character.
Im making an iPhone app where the user draws a line with their finger (the line will be straight line between where the touch began and ended). I also have a ball which will fall and hit the line. What is the best / easiest way of handling the i) drawing, and ii) collisions?
I am completely new to this and open to any ideas or source code.
I have decided to use CoreGraphics to draw the line, and to store the points in cgpoint arrays. Then, I use the parallel distance formula to calculate when the distance of the ball to the line nears zero (funny, it has never equaled zero, even though the timer repeats every 0.01). Then a collision has taken place, and I use simple applied maths vectors to calculate the resultant is the coefficient of restitution is 1