9/13/2023 0 Comments On screen snake![]() From the Operators drawer, drag a "_ = 50" block into the if block. Add an "if then" block inside the "forever" block. Replace it with a "forever" block from the Control drawer. "When down arrow key is pressed", "set direction to down", etc.).ĭelete the "move 10 steps" block from the code space. Connect the block to the "When up arrow key is pressed" block.ĭo the same for the other arrow keys (i.e. Take a "set direction to 0" block from the Variables drawer and type "up" in the place of "0". ![]() Drag a "When space key is pressed" block from the Events Drawer onto your code space. When a box pops up asking for a new variable name, type in "direction", and then hit OK. Go to the Variables drawer and click the "Make a Variable" button. Tip: Remember to repeatedly save your code by clicking the "Save Now" button on the top right of the screen that appears when you've added new code to the code space. The red stop sign next to it stops your program. The green flag above the viewing area, when clicked, runs your program. We'll be talking about sprites more in the next step. The bottom half is your sprite pane, where all the sprites you've created are displayed. The area most right of the screen is divided in half-the top half is your viewing area, where you'll see your code output. The most left side with all the code blocks is divided into sections based on functionality, and I'll be calling these sections "drawers." The section right next to the drawers is what I call the "code space." This is where we'll be dragging and connecting the code blocks together. When you're on the Code tab, there are three main sections that we'll have to worry about. The next tab over is the Sounds tab, where we'll be adding sound effects to our game. On the tab to the right, the Costumes tab, is where we will be drawing our game characters (the apple and snake). This will take you to a brand new project page.Īutomatically, the project page is on the Code tab, where we'll be dragging code blocks to actually make our snake game. ![]() Once you're logged in, click the Create tab at the top of the page, next to the Scratch logo. Sign in if you already have an account, or click Join Scratch at the top right to create a new account. To create a new project on Scratch, go to. If you're interested in learning more, I'd recommend going to Scratch's Ideas page. : This isn't going to be a full out crash course on how Scratch works. Var snake = new Snake(1, 15, 'testnaam') This is the main code (Snake code): var game I really hope that someone can help me out so I can proceed with our game. The function that I'm referring about is inside the Snake script under one that has the snake code in it and the other has the food code in it. I will put the entire code down below so you can see it through. My knowledge of javascript is very basic so what I'm doing here is all new for me. As far as I know I have the function as it should be, but for some reason it does not work. Now I'm stuck because I want to create a function that allows the snake to eat the food and then grow longer. Nothing really extreme just the basic snake game but then with more players.Ĭurrently I've created a code that can move the snake and also will place food randomly on the canvas (I'm using the HTML5 Canvas element in which the game is played). We are making a snake game by using node.js so we can create a multiplayer snake game. Currently I'm making a snake game with a school friend of mine. This is my first post so I hope that I put everything correctly down below here! :-P
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |