MikeDX
|
|
Day 5 - Jumping
All the code and assets for this tutorial are on github !
On day 4, we added a little 3 frame running animation to our player. Now we're going to make him jump!
To catch up, download day 4 from github
Open up the DIV IDE. If you choose to continue at the splash screen, we should see where we were when we left off yesterday.
First thing we need to do is create our jumping sprite.
close all the open maps via the MAP menu, and make a copy of graph 1 like we did previously.
edit the new graph using the graph editor to show our character in a jump motion.
Once you're done, drag this image into your FPG and give it the ID of 5.
Now onto the jumping code!
Add these three new private variable in your player PROCESS PRIVATE
list just below animcount as follows:
Code: |
jumping = FALSE;
jump_offset = 0;
jump_power = 8;
|
The "jumping" variable we will use to know if we are jumping (or not)
The "jump_offset" variable is going to be used to keep track of how many pixels to jump every "FRAME"
The "jump_power" variable is used to store how strongly our player can jump.
Let's see how these are used:
We will use the spacebar to jump, lets add the condition to check for space being pressed in our code:
Code: |
IF ( KEY(_space) && jumping == FALSE )
jump_offset = -jump_power;
jumping = TRUE;
END
|
This code does two things. First it checks if the spacebar is pressed, and then checks to see if we are already jumping. If we are, we don't want to
jump again! We'll later change this to also check if we are standing on the ground.
now below this, add another IF statement, to do some calculations on the Y variable.
Code: |
IF ( jumping == TRUE )
y = y + jump_offset;
jump_offset = jump_offset +1;
graph = 5;
IF ( jump_offset > jump_power )
jumping = FALSE;
graph = 1;
END
END
|
This simplified jump routine changes the Y variable by a different ammount each frame and sets the graph to be 5 (which is our jump sprite), until the
offset has return to its original value. At which point it set jumping back to FALSE, and returns the graph to the walking sprite.
Run the code with F10, we should get something that resembles some reasonable jumping animation
Keywords learned in this lesson:
Code: |
TRUE
FALSE
IF()
KEY()
_space
END
graph
y
|
That's all for this step. next time - running!
|
|
humildadever
DIV Junior
Posts: 40
Registered: 27-2-2016
Member Is Offline
|
|
I like Very good
|
|
RKSoft
Game Making Machine!
Posts: 232
Registered: 1-3-2016
Location: Germany
Member Is Offline
|
|
looks good
|
|
humildadever
DIV Junior
Posts: 40
Registered: 27-2-2016
Member Is Offline
|
|
Thanks a lot. I waiting news upgrates..
|
|
pommyman
DIV Junior
Posts: 10
Registered: 19-1-2017
Member Is Offline
|
|
That's Brilliant!
I've got a little jumping man!
|
|
RKSoft
Game Making Machine!
Posts: 232
Registered: 1-3-2016
Location: Germany
Member Is Offline
|
|
What about tutorial videos? Are they welcome?
|
|
MikeDX
|
|
Absolutely! I have done some on YouTube already
|
|
RKSoft
Game Making Machine!
Posts: 232
Registered: 1-3-2016
Location: Germany
Member Is Offline
|
|
Mike, i took your tutorial prg, played with your code and this is the current result :D
But, i found some baaaaaad bugs. I report them in the bug report forum.
This is the current version. A work of 2 days (2-3 hours per day).
ESC to kill
Q or ALT+X to quit the program
Cursor keys to move, jump and duck.
[Edited on 23-1-2017 by RKSoft]
Attachment: Tutorial 1 - Jumpman.7z (14kB) This file has been downloaded 2936 times
|
|
MikeDX
|
|
wow that is really nice!
Kinda puts my tutorial to shame, you've take it to the next level and beyond!
on linux I had to rename screens.fpg to screens.FPG but apart from that it ran flawlessly
|
|
RKSoft
Game Making Machine!
Posts: 232
Registered: 1-3-2016
Location: Germany
Member Is Offline
|
|
Thanks, but you are a better programmer, you work on DIV .
So, if i finish this little 1-level programm i will prepare it to a tilebase system with an editor (sperate) for DIV users who search such a system.
|
|
MikeDX
|
|
I really like your colour scheme you have setup in the IDE. is that based on the blitz ide?
|
|
RKSoft
Game Making Machine!
Posts: 232
Registered: 1-3-2016
Location: Germany
Member Is Offline
|
|
I think it could be like Blitz but in my Blitz ide i setup white background and black font color ^^. This (in my DIV) color scheme i like because it
is good to read the syntax, numbers etcl. When you are interest i can write the definitions here.
|
|
dom cook
Div Pro
Posts: 387
Registered: 4-3-2016
Member Is Offline
|
|
Mario of Many Colours.
Here's my effort.
It's Mario pretending to be Marvin Spectrum.
Keys: _up = jump
_right = roll
_down=slide
_z = red suit
_x = green suit
_c= blue suit
combinations of _z,_x,_c make the other colours.
Attachment: smb.fpg (33kB) This file has been downloaded 2953 times
Attachment: smb.prg (7kB) This file has been downloaded 2877 times
Here's the music (courtesy of the amazing LMMS, which I've just discovered)
Attachment: forestrun.ogg (1.1MB) This file has been downloaded 3239 times
[Edited on 1-2-2017 by dom cook]
|
|
MikeDX
|
|
That's very cool Dom. I'm a huge fan of the spectrum. DIV can even output a spectrum type mode via a dll.
Roland, yes I'd like your colour config please!
|
|
dom cook
Div Pro
Posts: 387
Registered: 4-3-2016
Member Is Offline
|
|
Quote: Originally posted by MikeDX | That's very cool Dom. I'm a huge fan of the spectrum. DIV can even output a spectrum type mode via a dll.
|
Not that Spetrum, Marvin Spetrum is/was a nice mini game involving hopping through coloured light gates. (It was on Newgrounds I think)
|
|
MikeDX
|
|
Your colour scheme threw me off!
Still cool though
|
|
RKSoft
Game Making Machine!
Posts: 232
Registered: 1-3-2016
Location: Germany
Member Is Offline
|
|
@dom cook
nice little programm, continue work and make it final
|
|
dom cook
Div Pro
Posts: 387
Registered: 4-3-2016
Member Is Offline
|
|
Sure, just keep supplying the graphics. (Did you notice?)
Here's an update in which I've added music, removed a redundant key _right function, and changed the reverse scroll after collisions so that only the
player is affected (wrt screen coordinates).
[Edited on 1-2-2017 by dom cook]
Attachment: smb.prg (7kB) This file has been downloaded 2822 times
Attachment: forestrun.ogg (1.1MB) This file has been downloaded 3204 times
|
|
RKSoft
Game Making Machine!
Posts: 232
Registered: 1-3-2016
Location: Germany
Member Is Offline
|
|
It will be better when you pack all needed files into one zip
Nice run, but i'm confused with the keys. ^^
[Edited on 1-2-2017 by RKSoft]
|
|
willicab
DIV Junior
Posts: 12
Registered: 12-7-2016
Member Is Offline
|
|
Hi, can you give me permission to translate this tutorial and post it on my blog?
|
|
MikeDX
|
|
Yes you can have permission to do that
|
|
willicab
DIV Junior
Posts: 12
Registered: 12-7-2016
Member Is Offline
|
|
Oh thanks :D
|
|