While playing Monopoly in IRC (and winning
), I threw this together
1) This goes just before the main game begins (the big do loop), setting up the variables that will be used in spellcasting.
Not that you asked, but I have included two spells (red and blue, or fire and ice). Red deals 75 damage and costs 5, Blue deals 25 and costs 2. I'm sure it's easy enough to remove if you wish.
The textures used were just plain red and blue, nuffin fancy
DIM spell_cost(1)
mp=50
max_mp=50
cur_spell=0
spell_cost(0)=5
spell_cost(1)=2
spell_cast=0
load image "red.jpg",1,1
load image "blue.jpg",2,1
2) Casting magic. All within the main loop...
` code for changing current spell (control key). Cannot change if a spell is currently being cast
if controlkey()=1 and spell_cast=0
cur_spell=cur_spell+1
if cur_spell>1 then cur_spell=0
endif
` if shift key is pressed and no spell is already being cast AND have enough MP, then we create the particles and stuff
if shiftkey()=1 and spell_cast=0 and mp>=spell_cost(cur_spell)
mp=mp-spell_cost(cur_spell)
make particles 1,cur_spell+1,40,20: rotate particles 1,0,object angle y(1),90
particleangle#=object angle y(1)
particlex#=object position x(1): particley#=object position y(1): particlez#=object position z(1)
position particles 1,particlex#,particley#,particlez#
make object sphere 4,1: hide object 4
position object 4,particlex#,particley#,particlez#
spell_cast=1
endif
` if a spell is in play, it must move and check for collision with enemies
if spell_cast=1
particlex#=newxvalue(particlex#,particleangle#,1.3)
particlez#=newzvalue(particlez#,particleangle#,1.3)
position particles 1,particlex#,particley#,particlez#
position object 4,particlex#,particley#,particlez#
for a=10 to 100
if object exist(a)=1 and spell_cast=1
if object collision(4,a)=1
if cur_spell=0 then enemy(a).health=enemy(a).health-75
if cur_spell=1 then enemy(a).health=enemy(a).health-25
delete object 4
delete particles 1
spell_cast=0
endif
if enemy(a).health<10 then delete object a
endif
next a
endif
if particlex#<object position x(1)-100 or particlex#>object position x(1)+100 or particlez#<object position z(1)-100 or particlez#>object position z(1)+100
if spell_cast=1
delete object 4
delete particles 1
spell_cast=0
endif
endif
And that seems to be it... i'm sure you can work out how to do an energy bar yourself now that you've seen a couple?
Oh, one thing... I was taking the code to build this from from page 3... so it won't have XP adding in yet. You'd have to put the same code that occurse when an enemy dies by the sword, up there where it checks for death by magic... if that makes sense...
Any confusion, ask and i'll try to explain