I made a simple 2D sandbox game here. Right now, there is terrain generation, movement, and gravity. I have one question: How can I make the player being able to move and jump at the same time (so I can jump over a block)? Note that I am adding collision. Also, any ideas/optimizations are welcome.
why not simply a command like:
j_{ump}, l_{eftM}
I don’t have time to really examine your code, but to do move and jump, I think a good way is to make sure that you don’t have jump as a separate loop from gravity, where a jump has to resolve before something else can happen. Then, the jump and the move left will be operating independently, so there is no extra step needed to be able to combine them.
Essentially, you have one game loop (the ticker action), and a bunch of state checks that it cycles through. Here is a Snap example of how I would do a game loop. I think you could translate this to desmos pretty well.
I believe that is what I have, but thanks!
For Guzman: Haha you’re right. I didn’t think of that. Thanks!
Oh, got it, sorry. Whenever that specific question comes up, it’s usually because the jump has been coded to complete as a sub-loop.
Yeah.. I thought about that already and made it so that falling and jump→fall where all under executeFall
, which is one function.
No need to be sorry. the mario game was pretty cool!
I used to teach intro to CS and the basic Mario was the final semester 1 project. And every time, the jump and move issue was the one that was always the struggle point. So that’s immediately where my mind went
Haha… I actually DID make that mistake (putting jump and gravity in different loops), but then quickly fixed it. I did update it again! you should check it out.
im over here,understanding none what you guys just said,wondering why @NTMDev decided to make so many good underground generation that we cant get to
Haha. I am adding a way to dig, but that is pretty advanced because I need to find the current index of the i_x
and i_y
the player is at, then remove it using a function. I am keeping that till last.
@Guzman_Tierno anyone have any idea on how to break a block around the player? I have DirBreak
for the direction the player is breaking in, but how can I remove an element from i_y
, then for my other “blocks” d_y
, then d_y - 1
and so on?
I’m not sure I understand what you’re looking for … if you need to remove an element from a list given its position:
https://www.desmos.com/calculator/b4qg5xq9w1
Okay thanks. That’s one part. Another problem is I have different lists for the different layers, how can I efficiently check what layer the player is on, then remove from that list?
Maybe you can just keep track of the index of the layer with a variable …
[I’m in a hurry … I’ll try to give a look at the code later]
Yes, I guess we could do that.