Everyone,
I'm trying to make it so when you cast a spell but are farther than 200 pixels away from the monster(or the mousex,mousey when you click the monster)
To make it say "target out of range" above the players head.
I'v tried it alot but for some reason cant get the range to work on BOTH sides.
This is my code and media:
gosub Setup : `Setup screen options
gosub SetupVariables : `Create and modify game variables
gosub LoadMedia : `Load game media from media file
`|*******************************************************************|
`|**************************MAIN LOOP START**************************|
`|*******************************************************************|
do
CLS
gosub Updatevariables
gosub Magic
gosub PlayerMovement
gosub PlayerJumping
gosub MonsterWaypoints
gosub Showmedia
gosub PlayerMouseOverMonsters
gosub StatBars
gosub PlayerAnimations
gosub PlayerCollision
gosub Debuginfo
sync
loop
`|*******************************************************************|
`|***************************MAIN LOOP END***************************|
`|*******************************************************************|
`|*******************************************************************|
`|*******************************************************************|
`|**************************SUB-ROUTINES*****************************|
`|*******************************************************************|
`|*******************************************************************|
Setup:
sync on
sync rate 60
hide mouse
set image colorkey 0,106,106
backdrop on
color backdrop rgb(0,0,0)
`Create Arrays
dim MonsterLocationX(50,50)
dim MonsterLocationY(50,50)
dim MonsterHealth(10,10)
`Set Arrays
MonsterLocationX(0,0)=300 : MonsterLocationY(0,0)=515
Monsterhealth(0,0)=100
return
SetupVariables:
`Player Variables
playerflip=0
playerx#=20
playery#=200
oldPlayerx#=playerx#
oldPlayery#=playery#
playerHealth=100
playerMana=100
player_walk_left = 0
player_walk_right = 0
grav#=0
totalmana=100
playercollision=0
Targetoutofrange=0
`Timers
manaregen=timer()
outofrangetext=timer()
`Other Variables
CurrentSpell = 1
`Spells
FireballButtonX#=511 : FireballButtonY#=9 : FireballButtonPressed=0
monsterclicked=0
fireball_spell=1 : attack_fireball=0
firehit=10
`Monster Variables
slimeblue=100 : slimebluesprite=100 : slimeblueleft=0 : slimeblueright=1
`Enviornment
brokenledge=1001
stoneground=1002
`Images
player_idle=1
cursor=1000
outline=2000
return
LoadMedia:
`Load Player images
load image "media/sprites/characters/player_idle.bmp",player_idle,1
load image "media/sprites/characters/player_walking1.bmp",2,1 : create animated sprite 2,"media/sprites/characters/player_walking1.bmp",3,1,2 : hide sprite 2
load image "media/sprites/characters/player_walking2.bmp",3,1 : create animated sprite 3,"media/sprites/characters/player_walking2.bmp",3,1,3 : hide sprite 3
load image "media/sprites/characters/player_fireball.bmp",4,1 : create animated sprite 4,"media/sprites/characters/player_fireball.bmp",3,1,4 : hide sprite 4
`Load monster images
load image "media/sprites/monsters/slimeblue.bmp",slimeblue : create animated sprite slimebluesprite,"media/sprites/monsters/slimeblue.bmp",2,1,slimeblue
`Load spell things
load image "media/sprites/spells/fireball.bmp",999 : load image "media/sprites/spells/fireball2.bmp",998
load image "media/sprites/cursors/arrowgolden.bmp",cursor,1
load image "media/sprites/cursors/outline.bmp",outline,1 : sprite outline,0,0,outline : hide sprite outline
load image "media/sprites/spells/firehit.bmp",firehit,1 : sprite firehit,monsterLocationX(0,0),monsterLocationY(0,0),firehit : hide sprite firehit
`Load enviornment
load image "media/sprites/scenery/ground2.bmp",stoneground,1
load image "media/sprites/scenery/brokenledge.bmp",brokenledge,1
return
UpdateVariables:
oldplayerx# = playerx#
oldplayery# = playery#
mx#=mousex()
my#=mousey()
if mana<99
if timer()>manaregen+900 then inc playermana,2 : manaregen=timer()
endif
if playermana >= totalmana then playermana=totalmana
return
Statbars:
`Health Bar
ink rgb(255,0,0),0 : box 298,5,502,19
ink rgb(0,0,0),0 : box 299,6,501,18
ink rgb(175,0,0),0 : box 300,7,300+playerhealth*2,17
ink rgb(255,255,255),0 : set cursor 391,6.5 : set text font "arial" : print "";playerhealth;"%"
`Mana Bar
ink rgb(0,75,255),0 : box 297,23,502,37
ink rgb(0,0,0),0 : box 298,24,501,36
ink rgb(0,0,195),0 : box 299,25,300+playermana*2,35
ink rgb(255,255,255),0 : set cursor 391,24.5 : set text font "arial" : print "";playermana;"%"
`Spell Book
ink rgb(111,76,27),0 : box 507,5,795,37
ink rgb(0,0,0),0 : box 508,6,794,36
ink rgb(145,130,85),0 : box 509,7,793,35
ink rgb(255,255,255),0 : set cursor 391,24.5 : set text font "arial" : print "";playermana;"%"
`Spell Buttons
if mousex()>FireballButtonX# and mousex()<FireballButtonX#+25
if mousey()>FireballButtonY# and mousey()<FireballButtonY#+25
FireballButtonPressed=1
endif
endif
if FireballButtonPressed=1 then paste image 998,FireballButtonX#,FireballButtonY# else paste image 999,FireballButtonX#,FireballButtonY#
if FireballButtonPressed=1
FireballButtonPressed=mouseclick()
if mouseclick()=1
end
FireballButtonPressed=0
endif
else
FireballButtonPressed=0
endif
return
ShowMedia:
`Show player,animations
sprite 1,playerx#,playery#,player_idle
sprite 2,playerx#,playery#,2
sprite 3,playerx#,playery#,3
sprite 4,playerx#,playery#,4
sprite firehit,monsterLocationX(0,0),monsterLocationY(0,0),firehit
`Show UI
sprite cursor,mousex(),mousey(),cursor : set sprite priority cursor,1
paste image 999,FireballButtonX#, FireballButtonY#
`Show Environment
sprite stoneground,0,screen height()-32,stoneground
sprite brokenledge,0,350,brokenledge
`Show monsters
if monsterhealth(0,0) <= 0 then monsterLocationX(0,0)=1000
sprite slimebluesprite,monsterLocationX(0,0),monsterLocationY(0,0),slimeblue
return
Magic:
if monsterclicked=1 and playermana =>25
`Bounderies should be put here for player
attack_fireball=1
endif
return
PlayerMovement:
if keystate(30)=1
playerx#=playerx#-2 : `move player 2 units back
player_walk_left=1
if keystate(30)=1 and playerflip=1
mirror sprite player_idle
playerflip=0
endif
endif
if keystate(32)=1
playerx#=playerx#+2 : `move player 2 units forward
player_walk_right=1
if keystate(32)=1 and playerflip=0
mirror sprite player_idle
playerflip=1
endif
endif
if keystate(30)=1 and keystate(32)=1 : `If both buttons are pressed make character go idle
player_walk_right=0 : player_walk_left=0 : hide sprite 2 : hide sprite 3 : show sprite player_idle
endif
return
PlayerJumping:
if spacekey()=1 and grav#=0 then grav#=grav#+13.5 : `Increase player gravity
dec grav#,1.1 : `Decrease player gravity back to the ground
playery#=playery#-grav# : `Move the player with the gravity
return
PlayerAnimations:
if player_walk_left = 1
hide sprite player_idle
show sprite 2
play sprite 2,1,5,100
if sprite frame(2) = 3
player_walk_left=0
set sprite frame 2,0
hide sprite 2
show sprite player_idle
endif
endif
if player_walk_right = 1
hide sprite player_idle
show sprite 3
play sprite 3,1,5,100
if sprite frame(3) = 3
player_walk_right = 0
set sprite frame 3,0
hide sprite 3
show sprite player_idle
endif
endif
if attack_fireball = 1 and playermana => 25
hide sprite player_idle
show sprite 4
show sprite firehit
play sprite 4,1,3,100
if sprite frame(4)=3
attack_fireball=0
monsterclicked=0
set sprite frame 4,0
playermana=playermana-25
monsterhealth(0,0)=monsterhealth(0,0)-54
hide sprite 4
hide sprite firehit
show sprite player_idle
endif
endif
return
PlayerCollision:
if sprite collision(1,brokenledge) then playercollision=1
if sprite collision(1,stoneground) then playercollision=1
`If the player is collided then stop them
if playercollision=1 then playery#=oldplayery# : grav#=0 : playercollision=0
return
PlayerMouseOverMonsters:
if sprite collision(cursor,slimeblue)
ink rgb(255,0,0),0
set cursor monsterLocationX(0,0)+15,monsterLocationY(0,0)-22
print "";monsterhealth(0,0);"%"
sprite outline,monsterlocationX(0,0),monsterlocationy(0,0),outline
show sprite outline
if mouseclick()=1 and playermana => 25
monsterclicked=1
endif
else
hide sprite outline
endif
return
MonsterWaypoints:
return
debuginfo:
ink rgb(255,255,255),0
set cursor 0,0
print "FPS : ";screen fps()
print "Player x : ";playerx#
print "Player y : ";playery#
print "Player grav : ";grav#
return
-Inverted
PS: The boundery code would go at line 178.
Thanks in advanced,
-Inverted
Opposites are different, not wrong