Why is my sprite constant in mint language? - mit-scratch

He only moves a little bit and not moves forever

The (move 10 steps) block will only move your player by a tiny bit. It moves in the direction that your sprite is facing.
If you would like to have it moving for a longer period of time, (and smoother), I'd recommend using a loop of some kind.
Putting a Forever() loop around it will have it always move forward.
Repeat(number of times to repeat) will move it forward however many times you want.
Try to experiment with more of these loops and see which one best fits your project and goals.

You have multiple options. The first is to put the 'move 10 steps' block into a forever loop, so you code goes like the first one in the image and that will make your sprite move 10 blocks until the stop button is pressed.
Or alternatively, you could use a repeat (no. of times to repeat) block, like the second one:
Two Block Options
That's all!

Related

Why does the sprite costume not change?

I'm just starting to play about in Scratch...
I seem to have a sprite of a cat with two 'costumes', which I guess are like frames.
I made this sequence:
...but when I click the green flag the cat moves to the right but the costumes don't switch.
If I make a simpler sequence:
...and manually change the costume in the drop-down then the costume does change.
What is the limitation here?
This is by design. By default, loops have a built-in delay of about 1/30 second. (There are ways to eliminate that delay, but that is off-topic here.) This was done to help inexperienced programmers witness the effect of a loop; possibly also to make execution speed more consistent (regardless of client's CPU power).
In your case, that means costume2 will be visible for 1/30 second before switching back to costume1.
Costume1 on the other hand, is instantly followed up by costume2.
Consequently, you will only see costume2.
There are various ways to fix that.
Change your script to repeat 5 { move 10 steps; next costume; } This gives both costumes an implicit 1/30 second delay. If this is still too short, add a delay (wait ... seconds). Note: next costume wraps around, so assuming the sprite has 2 costumes, it will flip back and forth between costume1 and costume2.
Too jerky? Use glide ... secs to ... instead of 'move and wait'.
Or just take smaller steps; swap costume once every few steps.
Make two separate scripts running in parallel, one for the movement, the other for switching costumes. That makes it easier to specify a different delay for each.
Try using a [wait] block: the change between costumes may be so fast that it seems like it is walking without changing costumes...

Cloning Sprites in MIT-Scratch

Recently, in a project for school. I have come across an increasingly frustrating and what seems to be an unsolvable problem. Whilst attempting to create a diving game, in which the sprite of a diver (sprite x) touches clones of a fish sprite (referred to as y by me) to rack up scores as high as 25. While the mechanisms for diver movement appear to be completely fine. However, loading the game would result in no reaction from the fish and its clones. I had already programmed the clones of the fish sprites to hide and delete themselves if touching sprite x. However, the fish refused to clone itself even after many attempts at rewriting the script. I would like to know if there was anything I missed or screwed up. Thank you. And these are the images of the respective scripts of the sprites in links below. Thank you.
Here's your problem:
WHEN I RECEIVE "start game"
WAIT (2) SECS
REPEAT (25)
CREATE CLONE OF "myself"
WAIT (6) SECS
BROADCAST "game over"
You're starting the game, waiting 2 seconds, cloning the fish 25 times, and then ending the game.
There's at least one issue here, and probably another.
First of all, you're cloning all of the sprites into the exact same spot. The clones are piling on top of each other, giving the appearance of only being one fish, since they're all in the exact same space. I'd advise moving to a random x and y on the stage in between each clone.
Second, you have BROADCAST "game over" immediately there. This works if this is the way you're implementing a time limit on the game, but otherwise, you're just ending the game 6 seconds after the last fish appears.
So, correcting these two things, you end up with something like this:
WHEN I RECEIVE "start game"
WAIT (2) SECS
REPEAT (25)
GO TO X: ([RANDOM PICK (-200) TO (200)]) Y: ([RANDOM PICK (-150) TO (150)])
CREATE CLONE OF "myself"
WAIT (6) SECS
If you want each fish to disappear after 6 seconds, then add a DELETE THIS CLONE to the above script.
You can delete this script:
That's now covered by the other script, above, and is also slightly buggy. It's kinda useless now.
And, in your other script, the one starting WHEN GREEN FLAG CLICKED... to have the fish disappear when touching the diver, replace the WHEN GREEN FLAG clicked with a WHEN I START AS A CLONE.

SpriteKit & Swift: How to create level "segments" that are randomly "stitched" together to create an endless game?

The concept that I am talking about is similar to the style of game seen in many minimalistic, popular mobile games such as Color Switch, the Line Zen, Phases, or Bounce. These are endless games composed of a series of "levels" or "rooms" that are placed in a random order, and are one after another, creating the effect of an endless game. The key thing is that the challenges in each level are not random, they are drawn up before, and if that certain level is chosen randomly, it appears on the screen and the player moves through that level.
I think this concept might be called procedural generation, though I'm not positive.
How would I do this in SpriteKit using Swift? I'm not really sure where to start, maybe create a function for each level segment and, every few seconds, choose a random one to put on the screen?
Any help is appreciated!
Thanks so much!
Procedural generation is the name of the concept you are describing.
The approach will change a bit depending on the type of game you are trying to make but let's look at procedural generation in an infinite runner game. What you want to do is set up a buffer of level segments. The total size of the segments in your buffer should be at least twice the size of the screen. Every segment should be a child of the same segments node and they should be positioned so that each starts right after the previous one ends.
When a segment moves off screen (the player passed it):
remove that segment from the segments node
initialize a new segment (probably from a sks file)
add the new segment to the segments node
position it behind the last segment in the segments node.
The logic you use for choosing the next "random segment" is up to you. It can be truly random or you can fine tune it for the best user experience (avoid repeating segments, avoid segments that would ruin the flow, etc).
The key is to remove segments as they go offscreen and add a new one at the end of the buffer. This must be position based, not time based (time is less reliable even when the game scrolls at a constant speed).

Scrolling Clone Sprites

I'm attempting to make a code in which I have a sprite act as the main terrain sprite (aka a tile) and have clones of that sprite stack on to the end of it, while maintaining the scroll code, which allows the x positions of the main sprite and the clones to change as the player pushes down on the "a" and "d" Key, While maintaining their proper positions in line. The issue I am having is that for some reason the third costume in my terrain doesn't seem to appear when its clone is created to act as the last tile in line.
I think the issue is that it's already created all the clones, but the first terrain block it clones off of spawns at the same time as the new ones.
By the way, Scrollnum determines the position in the line.
When your clone starts, it goes to the next costume, but since the base spirte's costume is always the first, the clones' will always be the second. You need to set the costume according to the clone ID. That variable (scrollnum) should be "for this sprite only", by the way.
I have had a similar problem, and it's possible that you are not using the right costume number. Try going one costume number down.
I completely forgot about this question but I did manage to figure it out in the and I thought I should post the answer considering that it may be of help to others.
Let me explain this code a bit, as shown in the image this uses a block instead of the repeat loop I attempted to use mainly due to the ability to use it more often as well as condense my code. The CloneX variable is refers to the tiles X positioning as a multiple in reference to the screen size. The equation when used looks like this: (CloneX * 480) + ScrollX. The TileX variable refers to the amount in which you want cloned.
This is how I ended up calling it. I ended up setting the costume to the one I needed for the level in order to start the generation of tiles. Then I initialized for the variables in the block]2

Half scenes with static elements, other with spawn

I have 2D game, where half scene with spawn enemies and (for example) other half scene, where I want use static enemies and other elements.
I thought to create sript that after some time (for example 10 seconds), will stop spawn scripts , and run the movement of other elements.
So. Maybe there is a reasonable solution to this problem.
[UPDATE]
I need the most sensible solution of such a problem, I do not mean to do this, but how to make it better.
1) Can make static elements, which will be a certain time, just stand behind the camera, and then move ... or programmatically create static elements, over time, in advance of known locations...Or download the entire stack of elements over time.
2) Or can completely abandon this idea. A striking example is the Subway Surf, there static scenes (layout) are created in random order.
P.s. I hope I have explained my problem
Just learn to use "Invoke", it's extremely simple.
Invoke( "YourOtherRoutine", 10f );
So after ten seconds it will run the other routine. That routine could easily stop one script running, start another script running, or, whatever it is you want to do. There are tens of thousands of examples of Invoke() and InvokeRepeating() on the usual Unity forums, etc.
From your reference to Subway Surf, I assume that you want to generate static elements like the path and static trains in subway surf and non-Static elements like some moving trains. If so then I have a possible solution.
You can create pre-defined sets of elements (let say 20 or 30 set with different combination of elements) and then spawn them randomly one after another. e.g. have a look at the two reference images below.
Now, note that you might see these scenes exactly as in the images multiple times while playing the game, this is because they are pre-created, The developers behind Subway surf have created these paths and saved them as prefabs and then spawn them at different locations during game play.
You might have noticed that sometime the path is the same but the position of trains is different. This can be achieved by further creating spawn points on your path and then at runtime randomly select points on which you want to spawn your static elements.
In many cases when there are more than one gates you can pass through (I am referring to the gate in the second image). the moving trains spawns on the path of the gate you cross. Spawning the moving train can be achieved as mentioned in step two with a movement script attached to it. Regarding the question of how to know on what path to spawn there are two possible ways (that I can think of right know).
You can keep track of your players current lane and then spawn the train on that lane.
You can place separate triggers on each lane and then detect which lane trigger was triggered and then spawn the train on that lane.
For other moving trains just use the method in step 2 to spawn them but with a movement script attached.