Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

0HAPTER 11 0Nl.

FR0N hlhJA T0 PlRATE


2b2
LIIeruI TrunsIuIIon
Now Iook buck uI IIgure 111 und compure Ihe GML on Ihe IeII wIIh Ihe ucIIons on Ihe rIghI. II
IoIIows exucIIy Ihe sume sIrucIure us Ihe orIgInuI sequence oI ucIIons Ior IhIs evenI. We`ve even
udded commenIs (In green) Io show you Ihe equIvuIenI ucIIon Ior euch IIne oI GML code. In IhIs
cuse, Ihere were 13 ucIIons IhuI huve converIed InIo 13 IInes oI GML, buI IhIs wIII noI uIwuys be
Ihe cuse. In zooIdtag.gmk, we huve dIrecIIy mupped euch ucIIon sequence InIo Ihe equIvuIenI
GML wIIhouI IukIng uny shorIcuIs Io muke II eusIer Ior you Io reIuIe Ihe GML buck Io your
prevIous experIence wIIh ucIIons.
So Ior every ucIIon you cun use In D&D progrummIng, Ihere Is un equIvuIenI pIece oI GML
IhuI does Ihe sume |ob. We`ve compIIed u IIsI oI Ihe mosI common ucIIons Irom ZooI und how
Ihey IrunsIuIe InIo sequences oI GML InsIrucIIons IhuI huve sImIIur, or IdenIIcuI, resuIIs. Tuke
some IIme now Io Iook Ihrough Ihe new GML versIon oI ZooI und see how Ihe orIgInuI ucIIons
huve been repIuced wIIh code IhuI creuIes u compurubIe ouIcome.
Actions and Their GML Equivalents
1. IncIude u Set VuriuhIe ucIIon IhuI seIs Ihe VuriuhIe x Io Ihe VuIue }.
x = } (sIundurd)

x = x+} (ReIutive opIIon checked)
2. IncIude u Test VuriuhIe ucIIon IhuI checks II Ihe VuriuhIe x Is equuI to Ihe VuIue }.
iT{ x == } ) (equuI to)

iT{ x : } ) (greuter thun)
iT{ x : } ) (Iess thun)
3.
IncIude u Sturt BIock ucIIon.

{ (Sturt BIock)

} (End BIock)
eIse (EIse)
4.
IncIude u Chunge Instunce ucIIon Io chunge InIo ob_dtagon wIIh Perform events seI
Io yes.

instance_change{ ob_dtagon, true ) (Perform events seI Io yes)

instance_change{ ob_dtagon, 1aIse ) (Perform events seI Io not)
5.
IncIude u Speed HorizontuI ucIIon wIIh Hor. Speed seI Io }.

hseed = }

hseed = hspeed+} (ReIutive opIIon checked)
.
IncIude u Speed VerticuI ucIIon wIIh Vert. Speed seI Io -|.

vseed = -| (sIundurd)

vseed = hspeed-| (ReIutive opIIon checked)
0HAPTER 11 0Nl. FR0N hlhJA T0 PlRATE
2b3
7.
IncIude u PIuy Sound ucIIon Io pIuy snd_boom wIIh Loop seI Io fuIse.

sound_Iay{ snd_boom ) (Loop seI Io fuIse)

sound_Ioop{ snd_boom ) (Loop seI Io true)
8.
IncIude u Set AIurm ucIIon Io seI AIurm 0 Io }0 Steps.

aIatm]0] = }0

9.
IncIude u Destroy Instunce ucIIon.

instance_desttoy{) ( Ior SeIf)

with( other )
instance_desttoy{) ( Ior Other)
10.
IncIude u Set Friction ucIIon IhuI seIs Friction Io 0.5.

Ttiction = 0.5

11.
IncIude u Set Gruvity ucIIon IhuI seIs Gruvity Io i und Direction Io 210.

gtavity = i
gtavity_ditection = 210

12.
IncIude u Set HeuIth ucIIon IhuI seIs VuIue Io i00.

heaIth = i00

13.
IncIude u Test HeuIth ucIIon IhuI IesIs II Ihe heuIIh Is Iess thun Ihe VuIue 0.

iT{ heaIth 0 )

14.
IncIude u Set Lives ucIIon IhuI seIs VuIue Io }.

Iives = }

15.
IncIude u Test Lives ucIIon IhuI IesIs II Ihe number oI IIves Is equuI to Ihe VuIue }.

iT{ Iives == } )

1.
IncIude u Move Free ucIIon IhuI seIs Direction Io i80 und Speed Io i0.

ditection = i80
seed = i0

17.
IncIude u Reverse VerticuI ucIIon.

vseed = -vseed (Reverse VerticuI)

hspeed = -hspeed (Reverse HorizontuI)
18.
IncIude u Repeut ucIIon wIIh Times seI Io 10.

teeat{ i0 )

19.
IncIude un Exit Event ucIIon.

exit

20.
IncIude u Check Ohect ucIIon IhuI checks wheIher Ihe currenI InsIunce wouId coIIIde
wIIh Ohect ob_dtagon uI u ReIutive posIIIon oI X6, Y5.

iT{ Iace_meeting{ x6, y5, ob_dtagon ) == ttue ) (sIundurd)

0HAPTER 11 0Nl. FR0N hlhJA T0 PlRATE
2b4
iT{ Iace_meeting{ x6, y5, ob_dtagon ) != ttue ) (NOT opIIon checked)
21.
IncIude u Test Chunce ucIIon wIIh Sides oI i50.

iT{ itandom_tange{ i, i50 ) == i )

22.
IncIude u Wrup Screen ucIIon IhuI seIs Direction Io horizontuI.

move_wta{ ttue, TaIse, stite_width/2 ) (Direction Io horizontuI)

move_wta{ 1aIse, true, sprite_height/2 ) (Direction Io verticuI)
move_wta{ true, true, stite_width/2 ) (Direction Io hoth)
hote The move_wta fuuctiou does uot provide ideutical results to the wrap Screeo actiou iu all
situatious, out the code precediug will provide comparaole results providiug the origius of ]our sprites are
ceutered.
23.
IncIude u Druw Sprite ucIIon IhuI druws Ihe Sprite st_dtagon uI X66, Y55, wIIh u
Suhimuge oI }.

dtaw_stite{ st_dtagon, }, 66, 55 ) (sIundurd)

dtaw_stite{ st_dtagon, }, x+66, y+55 ) (ReIutive opIIon checked)
24.
IncIude u Creute Instunce ucIIon IhuI creuIes un InsIunce oI Ihe Ohect ob_dtagon uI
X66, Y55.

instance_cteate{ 66, 55, ob_dtagon ) (sIundurd)

instance_cteate{ x+66, y+55, ob_dtagon ) (ReIutive opIIon checked)
25.
IncIude u Creute Moving ucIIon IhuI creuIes un InsIunce oI Ihe Ohect ob_dtagon uI
X66, Y55, wIIh u Speed oI } und Direction oI 210.

vat instance
instance = instance_cteate{ 66, 55, ob_dtagon )
instance.seed = }
instance.ditection = 210

You might also like