TGC Codebase Backup



Stick Figure Walking by Jedi Lord

11th Jun 2006 21:29
Summary

It a tutorial for people who want to know what is Sine/Cosine.



Description

What you will see, it will have a Stick Figure walking, also I added some note along the code to explain what it was doing and soemthing important in the code.
I just made this tutorial for the newcomer, and I don't want newcomer end up like me on something what you DON'T want to know...
I have out done another work for everyone to check it out.
I make the movement and leg walking... it all related to sine and cosine.
Remember... one most important thing in Sine/Cosine...
When you are using it... they flip rotation... usually 0 degree is up, but in that system... it flipped to down.
You will understand during the tutorial... if you don't understand, then make your own Stick Figure walking... soon you will find out about it.

THE MOST IMPORTANT THING YOU NEED TO KNOW:
X=SINE
Y=COSINE
for example:
X=normalpositionx+sin(180)*radius.
I hope I explained much.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    REM Project: Stick Figure Walking
REM Created: 6/11/2006 5:12:25 PM
REM
REM ***** Main Source File *****
REM

sync on : sync rate 60

legangle1#=25
legangle2#=335

pointAy=110

pointBx=300
pointBy=200

leg1x=pointBx+sin(legangle1#)*50
leg1y=pointBy+cos(legangle1#)*50

leg2x=pointBx+sin(legangle2#)*50
leg2y=pointBy+cos(legangle2#)*50

pointCy=150

arm1x=pointBx+sin(45)*30
arm1y=pointCy+cos(45)*30

arm2x=pointBx+sin(315)*30
arm2y=pointCy+cos(315)*30

moha=1
do
cls

if leftkey()=1
side=0
if legangle1#=315
moha=-1
endif
if legangle1#=45
moha=1
endif
legangle1#=wrapvalue(legangle1#-moha)
legangle2#=wrapvalue(legangle2#+moha)
pointBx=pointBx-1
endif

if rightkey()=1
side=1
if legangle1#=45
moha=-1
endif
if legangle1#=315
moha=1
endif
legangle1#=wrapvalue(legangle1#+moha)
legangle2#=wrapvalue(legangle2#-moha)
pointBx=pointBx+1
endif

`THIS MAYBE LOOK COMPLEX BUT SIMPLE...
`STICK FIGURE ALWAY MAKE LINE... AND HOW TO MAKE IT LOOK LIKE IT WALKING?
`IT USE LINE TO PASS EACH OTHER... SO... TAKE A LOOK AT THESE CONDITION

`WE NEED TO MAKE A BORDER... SO IT WILL NOT CAUSE ANY STRANGE EFFECT
`LIKE 315 TO 45 DEGREE
`I KNOW THIS CAN BE WEIRD... THE ROTATION IS FLIPPED DUE TO SINE AND COSINE EFFECT
`180 DEGREE IS UP AND 0 DEGREE IS DOWN... AND 45 DEGREE IS RIGHT AND 315 DEGREE IS LEFT...

if legangle1#>45
if legangle1#<315-1
legangle1#=45
endif
endif

if legangle1#<315
if legangle1#>45+1
legangle1#=315
endif
endif

if legangle2#>45
if legangle2#<315-1
legangle2#=45
endif
endif

if legangle2#<315
if legangle2#>45+1
legangle2#=315
endif
endif

leg1x=pointBx+sin(legangle1#)*50
leg1y=pointBy+cos(legangle1#)*50

leg2x=pointBx+sin(legangle2#)*50
leg2y=pointBy+cos(legangle2#)*50

arm1x=pointBx+sin(45)*30
arm1y=pointCy+cos(45)*30

arm2x=pointBx+sin(315)*30
arm2y=pointCy+cos(315)*30

if side=0
circle pointBx-7,pointAy-9,10
else
circle pointBx+7,pointAy-9,10
endif
line pointBx,pointAy,pointBx,pointBy
line pointBx,pointBy,leg1x,leg1y
line pointBx,pointBy,leg2x,leg2y
line pointBx,pointCy,arm1x,arm1y
line pointBx,pointCy,arm2x,arm2y

set cursor 0,0
print "Angle: ",legangle1#
sync
loop

`THIS MAY BE COMPLEX MATH... BUT IT IS VERY SIMPLE!!!
`SINE IS DESIGNED TO MANAGE X VALUE FOR ROTATION
`COSINE IS DESIGNED TO MANAGE Y VALUE FOR ROTATION
`REASON WHY WE MULTIPLY THE SINE AND COSINE: IS TO INCREASE IT RADIUS OR IT WILL BE A DOT...
`SINE AND COSINE IS THE ONLY THING THAT CAN FIND POSITION FOR WHERE X AND Y POSITION...
`I HOPE THAT EXPLAINED HOW TO USE IT...
legangle1#=45
legangle2#=315

pointAy=110

pointBx=100
pointBy=200

leg1x=pointBx+sin(legangle1#)*50
leg1y=pointBy+cos(legangle1#)*50

leg2x=pointBx+sin(legangle2#)*50
leg2y=pointBy+cos(legangle2#)*50

pointCx=100
pointCy=150

arm1x=pointCx+sin(45)*30
arm1y=pointCy+cos(45)*30

arm2x=pointCx+sin(315)*30
arm2y=pointCy+cos(315)*30