I have student who made the following game: [https://arcade.makecode.com/77060-13028-42082-82982](https://arcade.makecode.com/77060-13028-42082-82982).
The object is to create a game that pitches a baseball (from the sprite, "baseball_player_2") and then when it touchs the hitter sprite ("baseball_Player_1"), the player could take a swing and make a hit. Right now, the hitter just has a simple collision that randomly sends the ball into an outfield.
The student also used a camera control to show the ball moving up the field. The student wanted the game to reset to allow another pitch and bring the camera back to the pitcher. I assume a function would work easily here, that would return to the starting point after a specific amount of time.
TL;DR: **I was wondering if anyone has coded a similar project: an input to trigger a sprite to "pitch" a ball, then "hit" the ball with a trigger when it comes in contact with the another sprite.** I thought that a Pong example would work, but it seems difficult to code it to check for a collision and if the user is pressing a button to create the "hitting" action. Any suggestions are welcome, we have been really frustrated trying to think of solutions.
I think you should first create a sprite that represents the camera’s start position. Then when the ball is hit, you make the camera follow the ball and once you want the camera to go back, make the camera follow the sprite (Start position).
If it seems a bit confusing I can head into the editor and show you how to do it.
Is this what you were looking for?
I just added and changed a few things.
I hope this helps!
Nice baseball game! I’ll leave you a list of what I fixed for your student.
I set up the camera so it will be there now after the ball hits a wall.
The ball will be flung if you hit “X” on the keyboard if it is overlapped with the pitcher
This is a version I decided to do if he wants to see the code
This truly well designed, especially clever having a catcher (aka “GuyBehindBatter”)! The way you added the position of the players using the “set position” was a good call as well as deducting health for strikes. Thank you for explaining and offering your solutions.
Random thought: I am hope that someday an extension would exist to let us change the “hearts” for health into something else. It would be fun to have those as baseballs or something else to label to the strikes.
We don’t have it in an extension yet? Crazy!
It’s also not too hard to do it with the textSprite extension and the icon, as long as you keep track of lives in a separate variable.
I believe I know what you’re saying. Are you talking about changing the sprites into some kind of baseball sprite?
Wow, this was an amazing version and yes, exactly what the student was looking for. This worked tremendously well and makes so much sense as a conditional statement. The reseting of the ball once it goes off the screen was a wonderful addition too! Thank you for taking the time to work through this for us and share your solution. It was incredibly helpful!
Your idea made a lot of sense. I was in the process of exploring that when I received the second reply. I wanted to thank you though for consideration and response. It was a helpful to have your suggestion to talk it out with my student.
That’s a really good project for some of my advanced students or high school ones. Thanks for the suggestion!