## Jumping/Throwing with slices extra data

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

lennyhome
Slime Knight
Posts: 109
Joined: Fri Feb 14, 2020 6:07 am

### Jumping/Throwing with slices extra data

I've put it together very quickly. It was meant to be a test case for my python compiler project but I thought it came out hilarious and I wanted to share it.

EDIT: Now it's in 3D and it throws at random in one of 16 directions.

It's about setting up a minimal physics system using slices extra data. For those who remember I did something physics based two years ago, except back then I had to use a bunch of global variables and I was curious to know if I could do the same with the new slices extra data space.

I can get into detail if anybody's interested but for the most part I've made it so:

extra data 0 = generic state
extra data 1 = fixed point x position
extra data 2 = fixed point y position
extra data 3 = fixed point x velocity
extra data 4 = fixed point y velocity

Then for every frame:

Code: Select all

``````# update velocity with some gravity
set slice extra(sl3, 3, get slice extra(sl3, 3) + fix24:from(0))
set slice extra(sl3, 4, get slice extra(sl3, 4) + fix24:from(1))
# update position
set slice extra(sl3, 1, get slice extra(sl3, 1) + get slice extra(sl3, 3))
set slice extra(sl3, 2, get slice extra(sl3, 2) + get slice extra(sl3, 4))
# tell the engine
set slice x(sl3, fix24:floor(get slice extra(sl3, 1)))
set slice y(sl3, fix24:floor(get slice extra(sl3, 2)))
``````
To initiate a thow/jump, force an initial velocity:

Code: Select all

``````set slice extra(sl3, 3, fix24:from(0))
set slice extra(sl3, 4, fix24:from(-10))
``````