Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Help with getting Mario to jump. Code included. Please help :-) Thank you!

Author
Message
phillips 74
19
Years of Service
User Offline
Joined: 22nd Jun 2005
Location: Iowa
Posted: 9th Dec 2005 17:12
Hello everyone. Trying to make mario jump. Please help. Not too good with trig. Copied from an Amos Amiga programming book. Thank you!

sync rate 0
sync on
hide mouse

randomize 1000

load bitmap "C:\Documents and Settings\Owner\Desktop\DBprojects\sprites&images\sonic2.bmp",0
get image 1,0,0,32,32
set sprite 1,0,1

dim mario(4)
X=200:Y=400
mario(0)=200
mario(1)=400
mario(2)=0
mario(3)=0

speed=3

do

cls 0
` mario(2)=0:direction=0
if leftkey()=1
if mario(2)=0
mario(0)=mario(0)-speed
direction=-1
endif
endif

if rightkey()=1
if mario(2)=0
mario(0)=mario(0)+speed
direction=1
endif
endif

if spacekey()=1
if mario(2)=0
mario(2)=1
xoffset=mario(0)
yoffset=mario(1)
endif
endif



if mario(2)=1
gosub jump
endif

if mario(0)>640
mario(0)=640
endif

if mario(0)<0
mario(0)=0
endif

if mario(1)<0
mario(1)=0
endif

sprite 1,mario(0),mario(1),1

sync

loop



jump:

height=180
width=80
jumpspeed=speed

if mario(3)<481
`sleep 1000
rem jump left

if direction=-1
x=cos(mario(3))*width/2
mario(0)=xoffset+x-width/2
endif

if direction=1
x=x-cos(mario(3))*width/2
mario(0)=xoffset+x+width/2
endif

y=sin(mario(3))*height/2
mario(1)=yoffset+y
mario(3)=mario(3)+jumpspeed
else
mario(1)=yoffset
mario(2)=0
mario(3)=0
endif
return
Fneep
19
Years of Service
User Offline
Joined: 3rd Sep 2005
Location: In my house
Posted: 14th Dec 2005 01:25
Okay, now its a good idea to instead of just typing in code, use the code snippets tab.

Juts type in [ c o d e ] when you want to start, and [ / c o d e ] when you want it to end. Obviously without the spaces. Example:



JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 15th Dec 2005 06:44
[/b][[b]code]your code here[/b][[b]/code]

Appointed by Jimmy as "MR. GAME REVIEW WIZARD GUY"
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 15th Dec 2005 07:22
I'm sure he's given up on this message by now but...

If you just change "mario(1)=yoffset+y" to "mario(1)=yoffset-y" you'll start Mario in the right direction for a jump. It started the jump by going down first.


Torrey
20
Years of Service
User Offline
Joined: 20th Aug 2004
Location: New Jersey
Posted: 15th Dec 2005 11:41 Edited at: 15th Dec 2005 11:41

Attachments

Login to view attachments
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 15th Dec 2005 11:56
He probably couldn't find any Mario sprites.

@ phillips 74
I found the attached file using google image search and typing "mario sprite".


Attachments

Login to view attachments
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Dec 2005 13:03
Quote: " He probably couldn't find any Mario sprites"


I found some very quickly when I was searching for some examples to test SpriteEdit (WIP post).

TDK_Man

D Ogre
21
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 23rd Dec 2005 02:52
This is a copy of an old post I did some time ago on this very subject. It contains the source code, but no sprite images. Sorry, you will have to study the code and design the sprites yourself to work with it. It uses trig functions to make the sprite jump. The code was originally designed to work at the bottom of the screen. This is perfect for those wanting to make a 2D fighter game, but with a little work, it could be used on a Mario style game.

-----------------------------------------------------------------------

You say your having trouble with making a sprite jump. My character control subroutine I wrote handles this. It uses a little bit of trig. to calculate the arc for the jump. The code doesn't do collision with the background or use gravity, but it could employ this with a little modification. I condensed the code below.



This code works with a 192x256 sprite on a 1024x768 screen. In order to use the subroutine with different sprite and screen resolutions you will have to modify the X and Y character limits.

To calculate the limits use:

X max. = SCREEN WIDTH()-SPRITE WIDTH(SpriteNumber)
Y max. = SCREEN HEIGHT()-SPRITE HEIGHT(SpriteNumber)

As I said before, the routines uses trig. to create a jumping arc for the character. Here is the breakdown:

x=(sx+150)+150*sin(a):y=512+125*cos(a) jumping right
x=(sx-150)+150*sin(a):y=512+125*cos(a) jumping left

variables usage:

sx = current location of sprite at the start of the jump.
a = angle in degrees from center of arc.
150 = x eliptical value (radius) and offset for x.
125 = y eliptical value (radius) for y.
512 = center of arc at y and current character position at y.

This code is designed to work at the bottom of the screen. Play with the code and change some of the values to see how it works. Try to make it work all over the screen on the Y axis...
new programmer
19
Years of Service
User Offline
Joined: 20th Dec 2005
Location: right behind you.
Posted: 27th Dec 2005 04:54
lol people!! theres like 10 million on the mario website mensioned in the java game dev cooperation

Login to post a reply

Server time is: 2025-05-16 09:47:43
Your offset time is: 2025-05-16 09:47:43