• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

2d perspective Getting Started with it all

Zizka

Member
Hello guys,

So I've tried reading the manual and checking tutorials on youtube but I'm still perplexed.

The thing is, I don't know where to start. Everything feels daunting and difficult to approach.

I'd like to have my character move on a 2D perspective sort of like this:


I'd like to start with this challenge: integrating a character and then having it move around a 2D environment with collision detection.

Could you guys point out a good tutorial which could help me with this is n00b friendly?

Thank you for reading.

E.
 

Rob

Member
Search for platformers tutorials on YouTube and add movement/collision to the search terms. There are many existing tutorials that will show you how to do it ;)

I think most people would recommend Shaun Spaldings videos so you could add his name in there too.
 
R

robproctor83

Guest
If you visit the market you will find some 2d platform starter kits. You can download one of those and start playing with it, the variables, etc. There are also a lot of good tutorials online, just search Google or YouTube it's as simple as that. Best luck.
 

Zizka

Member
Thank you for the replies.

I think most people would recommend Shaun Spaldings videos so you could add his name in there too.
I've started following his tutorial and can now move my green square around which is cool and encouraging.

I had a question:

At some point in the code, in order to make sure the player doesn't move if both left and right keys are pressed at the same time, the author provides the following bit of code:

Code:
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
var move = key_right - key_left;
Could there have been another way to handle this? I think there are probably many ways to do so but I just found that way non-intuitive (for someone who has no experience with programming).
 
R

robproctor83

Guest
Sure, there are a handful of ways you could do this, but the way you mentioned is probably one of the fastest, if not the fastest. You could, instead, do something simple to understand like

if((key_left == 1 and key_right != 1) or (key_left != 1 and key_right == 1)) move = 1;

But, that is much slower... Depending on what your doing you could also just do

var move = (keyboard_check(vk_left) || keyboard_check(vk_right)) ? 1 : 0;
 

FrostyCat

Redemption Seeker
I had a question:

At some point in the code, in order to make sure the player doesn't move if both left and right keys are pressed at the same time, the author provides the following bit of code:

Code:
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
var move = key_right - key_left;
Could there have been another way to handle this? I think there are probably many ways to do so but I just found that way non-intuitive (for someone who has no experience with programming).
That particular piece of code is trivial to understand in tabular form. Didn't the author of that tutorial explain to you how it works?

Draw a 2x2 table. Label the columns 0 and 1 for the value of key_right, and the rows 0 and 1 for the value of key_left. Now calculate the value of move at each cell intersection. Compare the computed results to what you would expect under the given keyboard states.

The subtraction method is the most straight-forward method for handling mutually-cancelling input. Using multiple conditions for this purpose is error-prone and verbose.

And if you don't already have one, go to the nearest stationery store and buy a handheld whiteboard. Whenever you find code you don't understand, draw a table of variable values, manually trace through the code, and record the outcomes. Having a concrete model of code execution, be it on a whiteboard or in your head, is the best predictor of whether you have a future in code.

Sure, there are a handful of ways you could do this, but the way you mentioned is probably one of the fastest, if not the fastest. You could, instead, do something simple to understand like

if((key_left == 1 and key_right != 1) or (key_left != 1 and key_right == 1)) move = 1;

But, that is much slower... Depending on what your doing you could also just do

var move = (keyboard_check(vk_left) || keyboard_check(vk_right)) ? 1 : 0;
Not only is this long-winded, it is also functionally different compared to the original. move is supposed to be -1 when only the left key is pressed.
 

Zizka

Member
Whenever you find code you don't understand, draw a table of variable values, manually trace through the code, and record the outcomes. Having a concrete model of code execution, be it on a whiteboard or in your head, is the best predictor of whether you have a future in code.
I don't really understand what you mean by that if I'm being honest. What do you mean by "trace through the code"?

Didn't the author of that tutorial explain to you how it works?
Nope, that he didn't.
 

TheouAegis

Member
I don't really understand what you mean by that if I'm being honest. What do you mean by "trace through the code"?
In math teacher terms: show your work. LOL

Write the code in question out as-is. Then write it out again replacing each variable with a possible value - in this case, either 0 or 1. Do this for all possible outcomes and you'll see how logical the code is.

Is it intuitive for a newbie? No, but it was also not originally used around these forums initially. There is a reason the right-left method is so popular around herec because it is logically sound.

You could dump all the directions into one variable as with gamepads and then check the bits, then clear the matching bits if they are both set. Old games didn't even zero out the directions because it was a moot point with gamepads/joysticks. Zeroing out directions is only a keyboard input issue, the resolution of which has never been beginner-friendly.
 

Zizka

Member
Zeroing out directions is only a keyboard input issue, the resolution of which has never been beginner-friendly.
Well, as long as you're saying it's not beginner-friendly, I think it's reassuring that I don't understand the whole thing right away.

In the video, we copy/paste a wall tile in order to make the floor and walls for collisions. Will it be possible to determine collisions areas instead? I guess I'll find out as I keep going but I'd like to know. I'd like to have chunks of sprite to be passable/impassable as opposed to using tiles if that makes any sense.

For example here: (art by Fool)


I'd like to be able to zone the walls as being impassable instead of pasting tiles all over the place. Is it possible?
 

NightFrost

Member
Will it be possible to determine collisions areas instead?
One pretty popular method to create freely placeable (as opposed to grid-aligned) movement blockers is to use invisible collision object. Player simply checks for it as one of the objects that blocks movement (which in turn is usually done by parenting all movement blockers to a single master object). The blocker object would use a semi-transparent sprite (like 1x1 pixel red square) to make placement easier. You create a separate layer for these, place and scale instances of the blocker object wherever you want, and when you're happy with them you turn the layer invisible. Or have code turn the layer invisible at game start.
 
R

robproctor83

Guest
Sure it's possible. You would just have to do it. You could make a single transparent square that you use for collissions and then just scale it much larger when you need it to take up more space... simple as that.
 
Top