From Scratch Snake Game

0 favourites
  • 9 posts
From the Asset Store
Snake
$9.99 USD
Template for snake, fully documented in comments and video
  • Hello, all! I've been exploring tutorials and using the in-program examples to help me start my very first game. So far, using the chain-rope example, I managed to pin the parts of the snake together! Woohoo!

    Some questions:

    How do I stop the head from moving backwards? I have a 4-way, 90 degree behavior. I only want it to move left, right, or forward.

    How do I fix the space between the body parts?

    Thank you!

  • For your controls, add an extra condition checking the angle of the head. Only allow the event to run if the angle of the new direction is +/-100 degrees of the head's angle

  • I understand the logic but how do I do that in the program? I have a little knowledge in PHP. When I asked for help in those forums, they would post code snippets. Is that possible here?

  • Snake movement covered in following thread:

  • Thank you, Alextro.

    I usually type in "construct 2 how do i...." and come up with a lot of answers, but I'm finding a theme amongst the help on the forum. it seems that no one gives directions on what to use on the event sheet, they just give logic.

    I understand the logic behind my game, such as finding the angle of the head and such and such, but I really have no idea how to actually 'find the angle'. At this moment, I decided to take a step back and focus on head movement. I want to disable the opposing direction so the snake can not go back into the body. So if it's going up, it can't go down. Left, it can't go right. I can't figure out how to disable any keys.

    My logic would tell me "when key is down", disable another key, but I see no such 'disabling' of anything. This program is a lot trickier than I expected. Suggestions?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You don't need to disable any keys. All conditions need to be true for an event to run, so you add conditions to your movement events to check if they can be run. Here are a few ways to do this, I've given two examples.

    The first says if sprite is within 100 degrees of 0 (facing right) and right arrow is pressed, then move right. If the sprite is facing left (180 degrees), this event will not run.

    The second is inverted, which you can access by right clicking a condition. The condition is that this event can run if the sprite angle is NOT facing 270 degrees (up).

    To answer the question of how to find the angle specifically, you're going to use "Expressions". In this case, Sprite.Angle will give you the angle of the sprite. Here is more about expressions - https://www.scirra.com/manual/78/expressions

    Regarding why people give advice logic first instead of straight code, there are many reasons.

    One is that there are usually many ways to go about achieving something, and without seeing what you have done or what approach you have tried, a certain method/example provided may or may not work for you. This is why it is recommended to post your own capx when asking for help - tips-for-posting-in-the-quot-how-do-i-quot-forum_t62843

    People generally want you to figure it out on your own first so that you can really learn it instead of just copy pasting code. We hope that a logical hint can get you moving in the right direction, as many problems stem from a logical misunderstanding - like when you were trying to disable keys (which is a possible solution by the way, just more complicated).

    Also we literally can't just copy and past code from Construct, we need to make it, take a screenshot or save a capx and then upload it. I myself don't always work on a device with Construct on it, so I can give logical advice but not provide an example right away. Another reason to provide your capx, so we people don't have to recreate your problem from scratch.

    Another reason may be because your questions were too general. Again, there can be many solutions to a given problem. If you ask a general question, you'll get general advice. This usually leads to more specific questions which will get answered. Again, yet another reason to post your capx or what you have worked on yourself first.

    EDIT: tl;dr version: You have the highest likelihood of someone responding with a specific capx example if you provide your own capx first.

    From your first post, you asked how to fix the space between body parts. What space between body parts? We have no way of knowing what your snake looks like, or why there is space to begin with.

  • Thank you, again, oosyrag. What you said makes complete sense so now any questions I ask will have much more information. I'll work on that head movement. Thank you!

  • An alternative method - this one uses a variable flag for your direction, in case your system doesn't use a held down key for controlling the snake, also does not rely on the angle of the sprite.

  • Thank you, oosyrag!! I tinkered with the two you posted and neither of them worked well for me (because I must have forgotten a few steps somewhere) so I sat back and considered all the information you gave me. What I did was removed the directional behavior completely. Then on the event sheet, i looked for the angle of head using the "between" option and for each angle, there are two sub conditions. The angle of the head would be 0, so it can only go up or down so those were the two conditions. It worked like a charm. Thank you so much. Sometimes my biggest flaw (in life in general!) is over thinking things so I really sat down and KISSed it. Thank you so much again.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)