Log In  

Cart #wall_jump_platformer-4 | 2019-08-31 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
3

Alright, well believe it or not this would actually be the FIRST platformer I have ever written, one where you have an actual map to navigate let alone a wall-jumping sprite.

Years ago I did make some action games that worked on grids using HIRES and LORES on the Apple computer, but as I got older I wanted more and more to make turn-based thinking games relying less on human-made maps and more on computer-generated - and that is my primary focus today.

Well - this is certainly not what is happening here.

In any case, it is complete, and hopefully others can learn from the code and make good carts from it.

The first thing it does is create a sample playfield for the player to explore.

Then you have a cursor letting you place your player sprite. Use arrow keys to navigate the 64x32 area and press O to do so.

Finally you are in Testplay. Arrow keys control the player. Press O to jump and X to return to select player position.

To Wall Jump, jump then hit a wall just as you are getting ready to fall. Your player will grip the side of the wall and then fling off in the opposite direction. You can use this to climb a narrow chimney for instance.

HOPE THIS HELPS !

P#67082 2019-08-31 19:52 ( Edited 2019-08-31 20:26)

Hello, sorry for this non related comment, but I was wandering if you could help me.
Do you know if it is possible to use variables from tables in for cycles?

P#67161 2019-09-03 00:06
1

Can you post some code please, Rik ? I'm kind of a see-what-I-can-do based on seeing code that does not work correctly.

Failing that ... I'm not really understanding the question. Would like to help.

P#67165 2019-09-03 03:53
vr["s"] = 3 //is declared previously in the code

local i = {{}, {}}
for i[1][1] = 1, vr["s"] do

end

It returns:

syntax error
for i[1][1] = 1, vr["s"] do
'=' or 'in' expected near '['
P#67182 2019-09-03 12:30

Apparently you cannot index arrays. And, that's fine. You don't need to. Understand that the index in a FOR/DO loop is always a temporary variable and always an integer or floating point value.

Try this code:

cls()
vr={}
vr["s"] = 3
local i = {{}, {}}
for ix = 1, vr["s"] do
  i[1][1]=ix
  print(i[1][1])
end

To get the results you want above.

Remember that the index is temporary. Try this:

cls()
i=5
for i=1,10 do
  print(i)
end
print(i)

Now you would think that variable I would contain 10 or 11 as most programming languages would do. But no, not PICO-8. Instead once you are out of the loop, whatever variable you defined outside it is returned. In this case, 5.

Try this:

cls()
for i=1,10 do
  print(i)
end
print(i)

Now the result is [NIL] !

You see that the index truly is forgotten once you are outside the loop. This is why if you want to have a copy of the index outside the loop or set an array with the index, you must create a new variable to it.

Arrays of any kind as the index in a FOR/DO are not permitted for the index:

a={}
a[1]=1
for a[1]=1,5 do
print(a)
end

Which of course returns an error.

HOPE THIS HELPS !

P#67187 2019-09-03 17:34 ( Edited 2019-09-03 17:36)

It confirms what I feared, thanks for your time though.
I was using a table because in my code it's actually 3 nested for cycles and I needed to make a 7 lines operation on all of their variable in order to use them.
Guess I'll make a function so it only takes up 3 lines in the final code...

P#67222 2019-09-04 09:25 ( Edited 2019-09-04 12:37)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 10:29:33 | 0.012s | Q:22