19
Nov

supernatural step 7 gravity and jumping


this video is part of a series in which
I learned about programming a ritual video game on the Commodore 64 in
assembly code I’m using is from the game
supernatural written by Georg Rottensteiner you may also know the game as guns in
ghosts this is not a tutorial just meet learning game program enjoy the video
and we’re on to the next step and establish its so cool this is the point where my gaming
creation stopped if I take this one more step then I’ll be further than I’ve ever
been doing falling gravity and jumping and until now the movement of our
players rights which is basically just still the hitbox has been kind of stale
because we move one pixel per game loop iteration and what if you wanna you know
if you wanted to make that movement a little bit more lively you’re going to
have to change that up a little bit which is what we’re going to do this
time and I’ve always thought that that would be very difficult because I’ve
looked at ways of implementing physics in video games and looking at artificial
micro-gravity routines and all that kind of stuff and it was so complex and I
suppose there if you really wanted to
implemented in that way you could do you can make it very difficult that this
this is so elegant and I have to say that the code that we have is not you
know may not be very elegance but the idea behind it is and I’ve learned that
the idea behind the code that we’re looking at is really is really nice and
it’s very important to have the right idea and then to go implemented so until
now we had a bright basically we had hit box running around we could move it all
over but we’re gonna change things up before I really get stuck in the
something that I wanted to say about the the slowdown that I was getting in the
win vice emulator I was using the regular
one when you install vice there’s a number of executables and one of them is
an accurate 1 I’m reading this off the SourceForge website is that as of
version 2.3 there to emulate is one is X 60 X 64 which fast and the other one is
the X 64 S C which is accurate and the accurate one called while X 64 S II
features a cycle based on pixel accurate Vick to emulation requires a much faster
machines in the old one than the old emulator with the X 64 emulator was
their first the sc1 is newer I tried my my code on real Commodore and it worked
perfectly there was no slowdown at all and then I used the SEC one and the same
effect was there is no more slow down just using a newer version of the
emulator it worked so that’s good also the something I’d like to note
after having uploaded the last part of this video series is that sometimes code
isn’t presence code that isn’t you know and I don’t mention that and that sounds
a little bit weird but some occurrences don’t happen for instance when the
players moving left to right there are points in the code where were you you might expect there to be a check of
whether or not the value goes to zero like an exposition going to zero or why
position going across certain value but we don’t do that because there are other
ways of checking whether or not the player is trying to leave the field you
know every level is surrounded by a bunch of characters which is always
there so there’s no way the players ever going to reach that position where the x
coordinates going to be less than 0 so that means that when I don’t mention
it means the cold is it there but it doesn’t mean that nothing is in place to
prevent things from going wrong so that’s that’s kind of sort of an
unmentioned kind of thing that is there gonna try to talk about those things
right when we have a look at what we’re going to be building this time because
it it it it works and its effect as it’s so funny just like a real video game as
you can see we we have some new character designs will have a look at
that as well but this is our player oh sorry I have to set up the joystick
again that one and for some reason Save Settings safe current settings done that so here we go this is our
player but watch what happens when i when i go off the edge here before I
fall but watch what happens when I push the joystick up it just works is falling
and his jumping so if I fall off here and I can jump off the age group doesn’t
this just look like this this is look like gain this edge too high sorry I
cannot jump on here but this is this is this is what we’re going to build and I
can tell you that it is surprisingly simple let’s look at the data again I know this
new things here we have a jump table of course we’re going to use tables again
we have a jump table have a full table these and other tables but these are the
sizes of those tables and we’re going to scroll down to the data section and look
at the tables and sells there is a player jump position which is actually
just an index into the stable so it might have been called player jump index you know it’s called position and has
jumped table with a couple of values and I’m gonna I’m gonna explain a little bit
about how about what these values mean and as a fall index and a full speed
tables a player jump table in a full speed table I guess the player can only
jump or maybe other enemies are going to have their own jump tables I don’t know
if the false be table is going to be the same for everything that falls so now
what is the theory the theory is 41 that there is no longer a player down
movement rights we removed the the the the detection of the player down of the of the joystick down movement
because we are going to make sure that in every iteration of the game loop the
players going to go down unless used blocked right that is your gravity and up movement is going to be jump so
that’s going to be different we’re gonna be looking at that gravely first because
we have to realize that the player if there’s nothing under his feet so if the
if the collision detection routine and that we analyze last time doesn’t block
we go down now if we just let the player go down one
pixel per game loop it would look as stale as the other movements but you’ve
already seen now that that it that’s not the case so how do we do that we do that
by allowing the player to move more than 1 pixel in one game loop that means
simply that we have to have a little loop within the game loop that says you
know don’t move the player down just one pic so but two pixels or three pictures
were there that number is what you see here depending on the fault the players
fault position we recorded a number of iterations of that move the player down
so this move to play down 1 pixel in one game loop 1 pixel and then the next game
will be goes to pixels next code game loop to next game loop three next game
loop three and it goes on and on and on a you can sort of influence the fall
speed and of course the speed increases as you go the player stops falling as soon as the
move down routine blocks that means the fall ends and there is no real end to
the to this now I’m I’m I’m gonna give away the secret it’s it’s so elegant
it’s so nice the jump table is basically the same
thing but in the other direction as soon as the player presses up we record the
fact that the players jumping and we let the player move eight pictures up that’s
an entire character by the way that’s no coincidence then in the next game loop
over this is actually a good 10 III that’s looking at these values were not
moving the player up seven pixels and then moving them up
another five pixels so that’s that’s interesting maybe ok well im gonna have
to look at this because saying it like that I mean falling is ok you know we
can move him down one and wound up to this is obvious but this is different so
it’s not really the same time I’m kind of surprised by this I have to we have
to really take a look at this now so but the principle this is saying that inside
a game loop i I think this just sets the the position we we move up by eight
let’s just have a look but the cool thing is I was expecting the jump to be
orchestrated completely like from the position where the player is we jump up
and then we let him land down and was thinking parabolas and all that kind of
thing but that’s not the case jump just says up it pushes the player
up and then the gym protein is finished what happens then maybe that’s it anyway
what happens then is that the the routine that pulls a player down our
artificial gravity starts pulling on the player and starts moving him down again
at full speed so you get a very interesting up and down movements that
is half done by the jump routine and have done by the fall routine so and and
all the blocking of course is done by the routines as we’ve already written in
the play guitar so let’s go to play control here we are player control as you can see is called
once every game loop right the game loop still hasn’t changed a thing so we load
the player jump index maybe it is position of calling index but maybe I’m
wrong but we’re going to look at the dow movement first anyway so let’s assume
that the player wasn’t jumping to the position is zero you know this says if
it’s not share within the players jumping obviously we are not and then
he’s the old code the old code said well as the player moving the joystick down
and if so then we do play a move down now we just do play a move down always
and the result of player move down is either one you know we load the
accumulator with 10 depending on whether it is or isn’t moving down so it equals
zero then we were not falling and not falling is this routine and it says you
know the player fall position they fall in
Mexico’s 20 store that and then we just continue with the rest which was not
down pressure so we’ve done we’re done with all the noun stuff now the
interesting case of course is what happens if we were falling yes you know
we’ve moved to play down 1 pixel player fell what happens at player fell we go
to that declaration that we are which is basically just a little further down in
the code the player fell we load current position we check the the the value in
the fall speed table if that equals 0 than the fall is complete when the fall
is complete we say okay loader for position compared to the table size if
if we’re there than the fall speed is at max and we just continue with the rest otherwise we increase the player fall
position and we picked that up on the next iteration of the game loop now if
we go back to this case and we load the fall speed value and it’s not see wrote
something else we store that imprimatur five we decrease it if it’s come to zero
the Falls complete if not moved to play down jack for blocking by the way and
jump back to follow up so this is the loop inside the game loop that says okay
take the value from the table and decrease you know moved to play down as
many times as it says they’re so there’s one pixel to Pixel three pictures
whatever number of pixels there this may mean that the player is blocked at some
point so I wonder what happens if we tried to move the player down but were
blocked immediately it tries to keep on doing that a couple of times so that may
mean that we’re motionless or can we can try think we can still control the
player while we are moving so I will falling so we jump to the follow-up and
when we’re done the fall is complete and we just go back to this and everything
so that you know everything goes as plan so that is it basically that is it for
falling we just have a little table and we make sure that we iterate the number
of times that you know it says in that table and we moved to play down of
course the player down function here is quite elaborate and allows us to check
whether or not we are hitting stuff there’s one thing that I forgot to show
I we can do that now we’ve done the following that is the falling so we’re
doing this at every game will let’s have a look at their character set editor and
gonna have to load from file character set project we have some characters this
is a kid this is the background character were filling the background
with this these I don’t know this is our character set these are our letters are
you well designed by Trevor I think and then this at character position 96 character 96 we have some this is the
the ground stuff you know this is the stuff that we walk on and this stuff
from 128 is our borders stuff looks like Rick rock basically this looks like
ground now as you can remember maybe is that routine that check for blocking
actually checked characters that were larger or equal to 1 28 but that routine
has changed its gone to 9600 any character that is defined from this
points blocks is nice to see you know this is i mean Trevor he understands a
design these are multicolor characters so you have to realize it any you know this is all gonna show the
grid show the grid in multicolor this is your grid which is extremely course she
disease are two pixels to pixels to pixels and still he manages to design
something that really looks you know he looks good and it connects you know you
can put these together and they just connect and and they make something that
looks like around very well done ok done that let’s look at what happens
to the jumping ok same thing as we come into our play control you know from from
the last game loop iteration these values these dumb position values of
course tell us what we were doing in the last in the last iteration so we sort of
have you know a transfer of information we just have a memory position somewhere
that says hey we were in the in the jump table so let’s just say we were denied
doing anything last time as a player is jumping ok so nothing is
happening yet but what if not less fresh not right breasts I have to check where we did
that not down pressed not oppressed ok ok ok not down pressed and then we were
checking for up right so we players jumping function is the same as this one players jumping so either we check by
checking the joystick you know who pressed up a player’s jumping or we were
already jumping insist they were jumping and we go to players jumping so what
happens at players jumping players jumping we increase the composition that
is funny because I don’t know what it was when we started how was it
initialized player Jim position let’s let’s look let’s look at where
this is look at where this this is used because if we weren’t doing
anything yet increase it there we load it right
that’s funny because we weren’t there yet jump on been there yet Jim blocked oh
it’s initialized 10 Cedis this actually initiative initialize it was zero so
plagued control go back down sorry for all the jumping around in the code but
players jumping let’s go to the declaration and the first if nothing’s
happened before then we increased the position so the first we increase if it
was zero and we increase it we’re skipping the first value basically
because it’s zero and then it goes to one which was that value is 7 and anyway
we recently loaded we compared to the table if it’s not the table sized yet
then we jump on otherwise if it is that table-size we said about 20 in the
jumpers complete jumped complete I think it just goes into normal operation jump
complete so what if we r me in the middle of the table we load the
composition index we get the value at that point which is seven if it’s 0 I think the values at the end with 0
red 0 then the gym pass complete to that’s at the end what’s your let’s 269
remember that line number jumped able right at the end there as heroes right
jews 269 come back right so we we have the jump position as the index we load
the value Fitzgerald Jim complete if not restored in forever 25 we move up if
that returns zero then the jumpers blocks away you know we can if we bumped
her head into something basically if we bump the lower character of our hitbox
into something we decrease of five if it’s not then we
go to gym it does it moves it moves to the player up by seven pixels that’s
funny I don’t I don’t really see how that works jump blocks ok if jumped as blocks then
we put it put it back to Sharon jump stops jump stops is probably just right
just there so how does this work I would say I would say that if if I you know my
first conclusion is that since the first thing we starts doing what are we where
we were we not falling down crests players jumping the first thing if it
starts at zero and the first thing is we increase it we go to one so we skipped
the first value that is I think that is intended so that I mean you can call it
a bug but you know it it’s just that the first value is ignored in that table
actually we get there we check if we’re at the end which is illogical for not at
the end we jump on we load the value that is there we load no we we load the
oh ok yes well it was zero it is now one we get that we used the one is the index
into the table we get the values seven because that’s the value at that point
if equal 0 notes doesn’t equal 0 so we store that in forever five we moved the
player up and we decrease perimeter five until
it’s zero so we moved the player up by seven pixels then in the next iteration
of the O of the game loop jump complete I think
what happens I think what happens that doesn’t happen does it know because we
do it next time we shape layers jumping because you know where we’re at position
1 in the jump table players jumping we increase the table again how large is
that job let’s let’s look let’s look at the jump in the gym but in how high is
it actually it is quite high here oh look it’s it’s easily look at how high
the jump is so it does I thought it was I thought it was silly to think that it
would look at look at how high jumps that’s at least 2 characters so that’s
at least 16 pictures that were jumping so it it’s not that strange actually and
during the jump we can move by the way I noticed ok so it does work the way I
thought it it worked just the jump is much bigger than I thought so in the
first loop we move it up the intention is afraid go down to the jump table you see if the index is 0 this is what
we mean to do but the first step it takes is to increase the the the gym
position so it goes today there what would actually be better and and and I
don’t know if it’s going to crash but since the first thing we do is to
increase it gonna do that the effect is the same match ok ok ok probably perhaps
I’m missing something but on the first iteration let’s just go down to the date
again because I want to look at the table on the first iteration we move the
player up we never do this so we moved the player up by seven bits 7 pixels
then by five then by three den bye to them by one so that’s seven and five was
12 15 17 18 19 so that’s actually 20 pixels something like that we move him
up 20 pixels and then the jump ends let’s look at that that that would mean
once again players jumping lets players jumping
there we go we increase the gym position it was zero so he goes to one we loaded
check what it is is it the table size if it’s the table sized in we’re done we
return it back to zero and the next time we coming here the first thing we do is
to increase its so actually I should do that and that it should really I think it should
increase or jump even further or jump distance even for in there as she that
something’s happened makes it makes a very weird extra jump really doesn’t it
looks as if the the 8th I think I might be able to jump back on this thing now
yes it appears to be doing two jumps actually like him like an automatic
double gym but it’s sort of lifts us up to the to do to do is actually enjoyable
already have money in scoring points shit I’m feeling that it’s a game so
this is weird and perhaps I haven’t really sad and the depths of the gods
lost my way players jumping back 20 so we increase that thing we loaded
check it to the table size if it’s not equal then we jump on jump on you know
you jump continues we load it into the position in two acts we get the value
and we just moved the player up by that amount of pixels that we find there
let’s see Jim continue to you jump elite jump complete ok table table size of the gym complete
complete complete by the way if we simply go she and then we check the left
and right so this makes that we can still move the same is for player move
down player fell not falling player fell I’m pretty sure
the player fell players jumping fall complete full complete just takes us
back to their full complete right comes into here as well so that means it when
we fall we can go left and right as well so and that is an important game
mechanic don’t forget you know if it to be able to move left and right inside of
a jump is is very important you know we can all remember the games it says jump
and you know it it it finishes like a complete jump I played Chuckie egg i i’d
never played check yet until like two days ago and I played it and that’s one
of those games lets you jump and it goes it makes the final you know it’s it’s
it’s like an entire orchestrated jump but the trick is to not do that just
push the player up and then let gravity take over its perfect it’s perfect so
that is it for falling just the one question why does it why does that that
first value get skipped I’m gonna look into that and I’m I’m pretty sure when I
think about it all know by tomorrow or later today and I’ll come back to it in
the next video so thank you for watching again I hope you’ve enjoyed it questions go ahead remember this code is
available on my get her page I’ll put a link to my
if you go to my webpage the Highlander donnell you’ll find links to my get her
page and this project so you can download the code you can get the IDE
and you get get voice in start you know doing this yourself and if you wanna
watch your welcome of course well thanks for watching and I will see you next
time

Tags: , , , , , , , , , , , , , , , , , , , , , , ,

3 Comments

  • NVIDIA G says:

    You are correct it's the player Jump Index Offset.A better way to name your variables is _PlayerJumpIndexOffset  I use this a lot in z80 coding.You can always change the table around and instead of inc Player_Jump_Pos,lda Player_Jump_Pos…you change to lda Player_Jump_Pos,inc Player_Jump_Pos.Also all this velocity tables are not needed and shows the coder really didn't know how to code a proper jump physics function,use 8.8 fixed point as it's more realistic and easy to implement.Let me know if you want to learn to code a proper jump physics function in 6502.

  • bwack says:

    Fun seeing it jump like that and the tables in the code. The block has come to life 🙂

  • Tyrosaurus says:

    I agree, being able to move left and right during a jump or fall enhanced gameplay!For a jump with height h and width w the parabola is:
     
    y = 4*h*x*(w – x)/w^2 
     
    So if h=40 pixels and w=80 pixels, it is reduced to:
     
    y = x*(80 – x)/40
     
    where x would go from 0 to 80.
     
    So x is the x-coordinate in pixels and y is the height at x.

Leave a Reply

Your email address will not be published. Required fields are marked *