Need help destroying gui entities..
Blitz3D Forums/Blitz3D Programming/Need help destroying gui entities..
| ||
| Hi all, as most of you know I have been working on a character creator. There is but 2 probs I have found while combining my character creator with rpg. I need character creator to be in a function. i need that function to return a value. and the problem is after return, even though pmodel = player1, it still says "entity does not exist". after returning the value of pmodel to player\model, i need to free all the stuff from the character creator itself. now i cant seem for some reason to free anything and clearworld() after i return the value. i can only do 1 or the other code: AppTitle "Beta RPG"
;Include "start.bb"
Dim playermesh(1)
Include "includes/Imphenzia_Audio.bb"
Global sky1
Global showbox
Global mh
Global mayturn
Global playerchosen
Global characreate
Global newid
AppTitle "characreate"
HidePointer
Global welcome = SFX_Load("media\welcome.wav", "group1", False)
SFX_Play(welcome,0.5,False)
Global origx# = 0
Global origy# = 0
Global pos_x# = 5
Global pos_y# = 10
Global HWND=SystemProperty("ApphWnd")
Global HWND_TOP = 3
Global gfxw,gfxh,gfxd,gfxmode,maxblocks
maxblocks = 0
Const FPS=60
Global period=1000/FPS
Global time=MilliSecs()-period
Global pmodel
gui_mode = 1
load_gui()
gfxw=800
gfxh=600
gfxd=0
gfxmode=2
setgfx3d(gfxw,gfxh,gfxd,gfxmode)
AmbientLight 255,255,255
Sky = CreateSphere(100)
ScaleEntity Sky,500, 500, 500
EntityOrder sky, 9
FlipMesh Sky
EntityColor Sky,68,207,252
;=================================================================================================
;=================================================================================================
Type TFlare
Field Ent% ; Sprite Flare
Field Ray% ; Cone affichant les rayons
Field RayR# ; Roll du rayon
Field Cam% ; la Camera affectée par la lumiere
Field Light% ; la lumiere generant le flare
Field Size%,Z# ; dimension du sprite
Field force# ; alpha courant pour le flare
Field ToForce# ; alpha destination .
Field texF% ; texture du flare
Field TexR% ; texture de rayons
End Type
Global LVL
Global NEXTLVL
Global EXPR
Global HP
Global MAXHP
Global MP
Global MAXMP
Global ATK
Global MAXATK
Global COOLED
Global MAXTIME#
Global CURRENT#
Global alpha#
Global fade_001
Global fademode
fademode = 002
Global alight
Global light#
Global min_alp#
Global max_alp#
Global min_lig#
Global max_lig#
If fademode = 1
alpha# = 0.0
light# = 0.0
Else If fademode = 2
alpha# = 1.0
light# = 1.0
Else If fademode = 001
alpha# = 0.0
light# = 0.0
Else If fademode = 002
alpha# = 1.0
light# = 1.0
EndIf
min_alp# = 0.0
min_lig# = 1.0
max_alp# = 1.0
max_lig# = 254.0
;n =0
;n2 = 0
;n1 = 0
Global T = CreatePlane()
EntityColor T, 68,207,0
EntityShininess T, 1
EntityAlpha T, .5
;Global T = LoadTerrain("Heightmaps/terrain256.bmp")
Ttex = LoadTexture("Colourmaps/c_terrain256.bmp")
Global Panel = LoadImage("Panel.png")
Global goldicon = LoadImage("coin.png")
Global goldtex = LoadTexture("coin.png")
Global poticon = LoadImage("ffxiipotion0wb4.jpg") ;potion
Global deathsound = LoadSound("wdeath.wav")
Global losesound = LoadSound("gameover.wav")
Global zapsound = LoadSound("zap.wav")
Global lvlupsound = LoadSound("peakwind.wav")
Global hitsound = LoadSound("wpain.wav")
Global goldsound = LoadSound("gold.wav")
Global theitem
ScaleTexture Ttex,256,256
EntityTexture T,Ttex
ScaleEntity T,32,100,32
light=CreateLight()
RotateEntity light, 45.0, 0, 0
Global test
test = sky
Global test2
Global test3
Global obj1 = test
Global obj2 = test2
Global multiple
Global health1
Global magic1
multiple = 1
;Setup Camera
Global Camera = CreateCamera()
;CameraViewport Camera,0,0,width,height
CameraRange Camera,1,1000
; Texture "flou"
FlareTex= TEX_SunFlare (256)
; la lumiere ( soleil )
Local SunRx# = -50
Local SunRy# = +30
SunPiv = CreatePivot (camera)
; lumiere directionnelle !
lit = CreateLight (1,SunPiv)
sun = CreateSphere (100.5,SunPiv) ;(8,SunPiv)
ScaleEntity (sun,4,4,4)
EntityOrder (sun,100)
EntityColor (sun,1024, 1024, 1024) ;(sun,255,240,220)
MoveEntity (sun,0,0,20)
EntityBlend (sun,3)
;EntityAlpha (sun, .5)
EntityFX (sun,12);1
halo = CreateSprite (sun)
ScaleSprite (halo,6,6)
EntityAlpha (halo,.2)
EntityOrder (halo,101)
EntityFX (halo,9)
EntityTexture (halo,FlareTex)
EntityBlend (halo,3)
RotateEntity (SunPiv,SunRx,SunRy,0,1)
; Flare => eblouissement
fsize = 256
Flare = FLR_Create (Camera,Sun,4,-100,FlareTex)
;======================================
;Setup Player
;======================================
Type Player
Field model,hp,attack,maxhp,experience,nextlvl,lvl,maxattack,cooled,Current#,maxtime#
Field mp,maxmp
End Type
player.Player = New Player
If player\lvl < 1 Then player\lvl = 1
player\lvl = LoadFile("LVL")
player\nextlvl = 100
player\experience = 0
player\model = pmodel
If player\model<>0 EntityColor player\model,255,105,0
If player\model<>0 MoveEntity player\model,50,0,50
player\hp = 15^5
player\maxhp = 15^5
player\mp = 15^5
player\maxmp = 15^5
player\attack = 1
player\maxattack = 2
player\cooled = True
player\maxtime# = 3
player\current# = 3.0
;semi-colon means comment out line.
;Global Name$ = "01"
;If Name$ = "" Then WB3D_Notify "ERROR","No name was chosen for username..",0 : End
LVL = player\lvl
NEXTLVL = player\nextlvl
EXPR = player\experience
HP = player\hp
MAXHP = player\maxhp
MP = player\mp
MAXMP = player\maxmp
ATK = player\attack
MAXATK = player\maxattack
COOLED = player\cooled
MAXTIME# = player\maxtime#
CURRENT# = player\current#
health1 = player\hp/player\maxhp
magic1 = player\mp/player\maxmp
;EntityFX sky, 1
;Global Sprite = CreateSprite()
; ScaleSprite Sprite,2,1 ;.5,.25
;Global Sprite2 = CreateQuad(.5,.25,0)
; ScaleMesh Sprite2,-4,4,4
;Global SpriteTexture = CreateNameTexture(1+16+32)
; EntityTexture Sprite,SpriteTexture
; EntityTexture Sprite2,SpriteTexture
;EntityParent Sprite,player\model
;PositionEntity Sprite,MeshWidth(player\model)/8,MeshHeight(player\model)/2+2,0
;EntityParent Sprite2,player\model
;PositionEntity Sprite2,-MeshWidth(player\model)/8,MeshHeight(player\model)/2+2,0
test2 = player\model
;======================================
;Update Hostile
;======================================
Global IDLE,CONFRONT,DEAD,FLEE
IDLE = 1
CONFRONT = 2
DEAD = 3
FLEE = 4
Type Hostile
Field model,hp,attack,attackrange,state,target.player,ox,oz,fleepivot,cooled,Current#,maxtime#
End Type
;======================================
Global RESETR = False
Global GOLD = 0
Global INVENTORYITEMS = 0
Dim inventory(9)
For A = 1 To 9
Inventory(A) = False
Next
SeedRnd MilliSecs()
.reset
CreateHostile(1,25,25)
CreateItem(1,50,25)
CreateItem(1,25,50)
For X = 1 To 25
CreateHostile(1,65+Rand(0,200),65+(Rand(0,200)))
Next
;======================================
;======================================
;======================================
;======================================
;======================================
;======================================
;======================================
While Not KeyHit(1)
Repeat
elapsed=MilliSecs()-time
Until elapsed
;how many 'frames' have elapsed
ticks=elapsed/period
;fractional remainder
tween#=Float(elapsed Mod period)/Float(period)
For k=1 To ticks
time=time+period
If k=ticks Then CaptureWorld
If MouseDown(1) Or MouseDown(2)
For p.player = Each player
TurnEntity p\model,0,-MouseXSpeed(),0
Next
; TurnEntity camera,+MouseYSpeed(),0,0
EndIf
Cls
If RESETR = True
RESETR = False
Goto reset
EndIf
UpdateCamera(Camera,player\model)
UpdateHostile()
UpdateItem()
UpdatePlayer()
Set_Keys()
final=FadeScreen(min_alp#, max_alp#, min_lig#, max_lig#, fademode, land, test, test2, multiple)
If MouseHit(1)
DebugLog MouseX() + "," + MouseY()
EndIf
Next
UpdateWorld
RenderWorld tween
UpdateText()
; Text 25, 10, "Health"
; Text 25, 35, "Magic"
; Color 0,0,0
; Rect 495,32,150,15
; Color 100,100,100
; Rect 500,35,150,13
; Color 0,0,0
; Rect 24,24,102,7
; Color 255,0,0
; Rect 25,25,player\hp*(100.0/player\maxhp),5
; Color 0,0,0
; Rect 495,22,150,15
; Color 100,100,100
; Rect 500,35,150,13
; Color 0,0,0
; Rect 24,84,102,7
; Color 0,255,0
; Rect 25,45,player\mp*(100.0/player\maxmp),5
; DrawImage Panel,ImageWidth(Panel)/8,ImageHeight(Panel)/8
; mage=Createbar(10, 40, "Magic", 0, 255, 0, 127, 127, 127, 0, 0, 0, 0, 255, 0, 10, 55, player\mp*(100.0/player\maxmp), 2, 10, 50, player\mp*(100.0/player\maxmp), 2, 10, 52, player\mp*(100.0/player\maxmp), 2)
; Populate_Bar("HP")
; Populate_Bar("MP")
UpdateInventory()
Text 807,418,GOLD
Color 0,0,0
Rect 0,100,150,500
Color 255,0,0
Text 5,100," Level " + player\lvl
Text 5,120,"HP: " + player\hp + "/" + player\maxhp
Text 5,140,"MP: " + player\mp + "/" + player\maxmp
Text 5,160,"Dmg: " + player\attack + " - " + player\maxattack
Text 5,180,"Exp: " + player\experience + "/" + player\nextlvl
Text 5,200,"alpha="+alpha#
Text 5,220,"fademode="+fademode
Text 5,240,"multiple="+multiple
LabelEntity(Camera, player\model, "AA")
Flip
Wend
End
Function load_gui()
gfxw=800
gfxh=600
gfxd=0
gfxmode=2
setgfx3d(gfxw,gfxh,gfxd,gfxmode)
temp = CreatePlane()
playermesh(0) = LoadAnimMesh("media/ninja.b3d")
playermesh(1) = LoadAnimMesh("markio/mariorun.x")
For x = 0 To 1
HideEntity playermesh(x)
Next
Local defaultsky
Local player1 = LoadAnimMesh("media/ninja.b3d")
defaultsky=loadsky()
AmbientLight 255,255,255
Local cam = CreateCamera()
CameraRange cam, 1, 1000 : PositionEntity cam, 0, 1, 0
ScaleEntity player1, .5, .5, .5
RotateEntity player1, 0, -180, 0
PositionEntity player1, 0, 0, 8
Animate player1, 2
Local im
Local background
SetBuffer BackBuffer()
im = LoadAnimImage("filmstrip2.png", 32, 32, 0, 2)
MidHandle im
background = LoadImage("bricktex.jpg")
imbg = LoadImage("filmbg.png")
mouseicon = LoadImage("sword.png")
ResizeImage mouseicon, 64, 64
HandleImage mouseicon, 0, 64
If gfxw = 1600
width = GraphicsWidth() Shr 2-ImageWidth(background)/8
height = GraphicsHeight()/1.5
imwidth = 44
imheight = 44
ResizeImage background, width, height
If gfxmode = 2 Then api_MoveWindow(HWND, 0, 0, GraphicsWidth(), GraphicsHeight(), $000A)
Else If gfxw = 1280 And gfxh = 960
imwidth = 64
imheight = 64
ResizeImage im, imwidth, imheight
Else If gfxw = 1152
imwidth = 44
imheight = 44
ResizeImage im, imwidth, imheight
Else If gfxw = 1024
width = GraphicsWidth()/4-ImageWidth(background)/8
height = GraphicsHeight()
imwidth = 44
imheight = 44
ResizeImage background, width, height
ResizeImage im, imwidth, imheight
Else If gfxw = 720
width = GraphicsWidth()/4-ImageWidth(background)/8
height = GraphicsHeight()
imwidth = 44
imheight = 44
ResizeImage background, width, height
ResizeImage im, imwidth, imheight
Else If gfxw = 400
width = GraphicsWidth()/2-ImageWidth(background)/8
height = GraphicsHeight()
imwidth = 32
imheight = 32
ResizeImage background, width, height
ResizeImage im, imwidth, imheight
Else If gfxw = 800
width = GraphicsWidth()/4-ImageWidth(background)/8
height = GraphicsHeight()
imwidth = 44
imheight = 44
ResizeImage background, width, height
ResizeImage im, imwidth, imheight
Else
imwidth = 32
imheight = 32
ResizeImage im, imwidth, imheight
EndIf
;If Not AnimSeq(player1) = 1
While Not KeyHit(1)
If sky1=1 Then PositionEntity sky1,EntityX(player1),EntityY(player1),EntityZ(player1)
If defaultsky=1 Then PositionEntity defaultsky, EntityX(player1),EntityY(player1),EntityZ(player1)
mx = MouseX()
my = MouseY()
old_mouse_x = cur_mouse_x ;this is the line where i define the old variable for mousex()
cur_mouse_x = MouseX()/2 ;this is the new mousex()
mouse_x_delta = cur_mouse_x-old_mouse_x ;this is the current mousex() ;this is what im going to use in the y value of "turnentity player1"
characreate = newchar ;this is the old characreate
newchar = 0 ;this is the new characreate
newfinal = newchar ;this is the value i will use to change characreate to 0 only if you are not mousing over a block.
oldselect = newselect
newselect = 0
newsfinal = newselect
mh = MouseHit(1)
omousedown = newmouse_down
newmouse_down = MouseDown(1)
fmousedown = newmouse_down
If player1 <> 0
If fmousedown And mayturn = 0
If mx > ImageWidth(background)
TurnEntity player1, 0, mouse_x_delta, 0
Else If mx < ImageWidth(background) Or mx > GraphicsWidth()-1
RotateEntity player1, 0, -180, 0
EndIf
EndIf
EndIf
which=y*2+x
If Not mayturn Then fmousedown = 0
If (which <> 0) And mayturn = 1 Then mayturn = 0
If mx < 0 Then mx = 0
If my < 0 Then my = 0
If mx > GraphicsWidth() Then mx = GraphicsWidth()
If my > GraphicsHeight() Then my = GraphicsHeight()
If KeyDown(29) <> KeyDown(57) Or KeyDown(57) <> KeyDown(29)
If KeyDown(29)
MoveEntity cam, 0, .1, 0
Else If KeyDown(57)
MoveEntity cam, 0, -.1, 0
EndIf
EndIf
MoveEntity cam, 0, 0, (KeyDown(200)-KeyDown(208) Or KeyDown(17) - KeyDown(31))*1
TurnEntity cam, 0, (KeyDown(203) - KeyDown(205) Or KeyDown(30) - KeyDown(32))*1, 0
UpdateWorld
RenderWorld
DrawImage background, origx#+pos_x#, origy#+pos_y#
If mh
For x = 0 To 1
For y = 0 To maxblocks
imx = (0.2 * width) + (0.57 * width * x) + (origx#) + (pos_x#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#) + (pos_x#)
If ImageRectOverlap(im, imx,imy,mx,my,1,1)
which = y * 2 + x
selected = which
If which <> oldwhich Then
HideEntity player1
ShowEntity playermesh(which)
player1 = playermesh(which)
If which = 0 PositionEntity player1,0,0,8
If which = 1 PositionEntity player1,0,0,8
If which = 0 Animate player1,1
If which = 1 Animate player1,1
If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0
If which = 1 Then ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0
oldwhich = which
Else If which = oldwhich
showbox = 1
EndIf
EndIf
Next
Next
EndIf
For x = 0 To 1
For y = 0 To maxblocks
which=y*2+x
imx = (0.2 * width) + (0.57 * width * x) + (origx#) + (pos_x#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#) + (pos_y#)
DrawImage im, imx, imy, which
DrawImage imbg, imx-ImageWidth(imbg)/2, imy-ImageHeight(imbg)/2
Next
Next
For x = 0 To 1
For y = 0 To maxblocks
imx = (0.2 * width) + (0.57 * width * x) + (origx#) + (pos_x#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#) + (pos_y#)
which=y*2+x
If (which = selected) Or ImageRectOverlap(im, imx,imy, mx,my,1,1)
characreate = 1
Color 150,150,150
Rect imx-ImageWidth(im)/2, imy-ImageHeight(im)/2, ImageWidth(im), ImageHeight(im), 0
Rect imx-ImageWidth(im)/2+1, imy-ImageHeight(im)/2+1, ImageWidth(im), ImageHeight(im), 0
If selected And which = 0
Color 0,0,0
Text imx-StringWidth("Ninja")/2-1, imy-StringHeight("Ninja")/2-1, "Ninja"
Color 102,102,255
Text imx-StringWidth("Ninja")/2, imy-StringHeight("Ninja")/2, "Ninja"
Else If selected And which = 1
Color 0,0,0
Text imx-StringWidth("Markio")/2-1, imy-StringHeight("Markio")/2-1, "Markio"
Color 68,207,255
Text imx-StringWidth("Markio")/2, imy-StringHeight("Markio")/2, "Markio"
EndIf
EndIf
Next
Next
If KeyDown(44) = 0
DrawImage mouseicon, mx, my
EndIf
Color 0,0,0
Music_Handler()
SFX_Handler()
Text GraphicsWidth()/2, GraphicsHeight()/2, "x"+EntityX(cam)
Text GraphicsWidth()/2, GraphicsHeight()/2+20, "y"+EntityY(cam)
Text GraphicsWidth()/2, GraphicsHeight()/2+30, "z"+EntityZ(cam)
Text GraphicsWidth()/2, GraphicsHeight()/2+50, "zp"+EntityZ(player1)
Text GraphicsWidth()/2, GraphicsHeight()/2+60, "mx"+mx
Flip
Wend
pmodel = player1
MessageBox(SystemProperty("ApphWnd"), pmodel, player1, 0)
Return pmodel
;FreeEntity player1
;FreeEntity temp
;FreeEntity sky1
;FreeEntity defaultsky
;FreeEntity sky1
;FreeEntity cam
;FreeImage background
;FreeImage mouseicon
;FreeImage im
;ClearWorld()
End FunctionANY help is GREATLY appreciated, ANY criticism is GREATLY ignored! :) Thanks! ~DS~ |
| ||
| I had some difficulty finding my way around your code, at what point does the error appear? |
| ||
| Well. its not an ACTUAL error. What it does is the entities from the character creator are somehow still loaded. the PROBLEM is in function "load_gui()", i need it to return a value 1ST THEN destroy the gui. the problem is, i cant do that as u cant put freeentity or freeimage or ANYTHING under a return.. which is also making player\model non-existant, because there IS no character it loaded. thats what it thinks at least. the part im having trouble with: function load_gui() ~DS~ |
| ||
| if u want, i can tab the data i gave to you. :) |
| ||
Well, you have this:Global pmodel gui_mode = 1 load_gui() but in the load_gui function, player1 = playermesh(which)which (Provided 'which' is valid, I assume you are using to select the model for Player1. However, a bit further down you are using 'which' again, still within the loop but for an image frame:
which=y*2+x
imx = (0.2 * width) + (0.57 * width * x) + (origx#) + (pos_x#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#) + (pos_y#)
DrawImage im, imx, imy, which
So, t's possible, when looping back again, 'which' is greater than the selection available for playermesh() values and that's the problem, when finally: pmodel = player1(Just before the MessageBox) 'player1' despite being given a value, is not a correct mesh handle. I would suggest checking the values of "which" at the point where player1 = playermesh(which) or using different variable labels. |
| ||
| yes. which is both player id, and icon id. i did that for easy use |
| ||
| HOWEVER. player\model returns a value in the 8 digits, like this: 32049182 kinda makes me wonder.. o.o |
| ||
| Ok. I have a screenshot for u here: ![]() also, i changed dim playermesh(1) to: dim playermesh(99999999) |
| ||
| I'm really confused about a lot of the aspects in your code. It may be best if you work on re-structuring it going through each section and making sure they work individually, otherwise, it gives me a headache trying to follow it through. |
| ||
| ok. well player\model = pmodel global maxids = 16 ;how many maximum ids are stored global maxblocks = 0 ;2 blocks for every block so 0 would = 0 AND 1 = 1 AND 2, and so on up to 8 blocks (which would definitely be 16 blocks) dim playermesh(maxid) ;maxids of playermesh again, this would definitely = 16 as theres only 16 icons which = y*2+x ;id of selected character and is = to 0..maxblocks player1 = loadmodel(which) loadmodel(which) loads the model depending on its id using player1 = playermesh(which) and pmodel is returned as pmodel=player1 in the function "loadmodel(which)" that should explain it ^^ |
| ||
| Please go to the help section of your Blitz3D, in there is a "Basic Tutorials" section, read and complete that. After you have completed then check under the Help section again for "Language Reference" in there is a section on the left called "Variables" under there you will find the answer to your question. Sorry I could not be of much more help, but this will surely help you more in the long run. |
| ||
| ok. this doesnt help. it tells me what i already know |
| ||
| global maxids = 16 ;how many maximum ids are stored global maxblocks = 0 ;2 blocks for every block so 0 would = 0 AND 1 = 1 AND 2, and so on up to 8 blocks (which would definitely be 16 blocks) dim playermesh(maxid) ;maxids of playermesh again, this would definitely = 16 as theres only 16 icons which = y*2+x ;id of selected character and is = to 0..maxblocks player1 = loadmodel(which) loadmodel(which) loads the model depending on its id using player1 = playermesh(which) if "y" can go up to maxblocks (16) Then "which" is going to increase to at least 32, maybe to 33 Despite how many icons/blocks you have, you have only two meshes, two units of data in the playermesh() array. Did you check the value of "which" just before the point I suggested? |
| ||
| yes. the value of which is equal to the number of the icon. just like i said. i did: messagebox(hwnd, which, which, 0) and it returned the id of the block of the player that i chose when i click on it anyway. i dont get why pmodel is still returning either nothing or a value too high for my array i did everything right |
| ||
| again. i tried everything. but it didnt work.. |
| ||
Did you read the help section?Local player1 = LoadAnimMesh("media/ninja.b3d") |
| ||
| what about that line? its fine.. |
| ||
| You need to learn about variable scope and how Blitz3D works. The error message details that the Entity no longer exists, this means that it has either lost scope or has been destroyed. I would suggest you sit down and re-write your code, use tabs, try to make it smaller and do some more debugging to find out where the entity looses scope or gets destroyed. I can tell you now it is within the first part of your program. Here is some much easier to read code that pretty much sums up your problem: |
| ||
| OMG! Flemmonk! i realize what i did wrong. i wrote to setgfx3d()s. and in the wrong spot! :D THANK YOU! :D Now I have but 1 problem. After returning pmodel from the function, i need to clear the entire world of the editor. yet still keep pmodel = to player1. what do i do in here? look at the bottom of the function. code: Function load_gui()
temp = CreatePlane()
playermesh(0) = LoadAnimMesh("media/ninja.b3d")
playermesh(1) = LoadAnimMesh("markio/mariorun.x")
For x = 0 To 1
HideEntity playermesh(x)
Next
Local defaultsky
Local player1 = LoadAnimMesh("media/ninja.b3d")
defaultsky=loadsky()
AmbientLight 255,255,255
Local cam = CreateCamera()
CameraRange cam, 1, 1000 : PositionEntity cam, 0, 1, 0
ScaleEntity player1, .5, .5, .5
RotateEntity player1, 0, -180, 0
PositionEntity player1, 0, 0, 8
Animate player1, 2
Local im
Local background
SetBuffer BackBuffer()
im = LoadAnimImage("filmstrip2.png", 32, 32, 0, 2)
MidHandle im
background = LoadImage("bricktex.jpg")
imbg = LoadImage("filmbg.png")
mouseicon = LoadImage("sword.png")
ResizeImage mouseicon, 64, 64
HandleImage mouseicon, 0, 64
If gfxw = 1600
width = GraphicsWidth() Shr 2-ImageWidth(background)/8
height = GraphicsHeight()/1.5
imwidth = 44
imheight = 44
ResizeImage background, width, height
If gfxmode = 2 Then api_MoveWindow(HWND, 0, 0, GraphicsWidth(), GraphicsHeight(), $000A)
Else If gfxw = 1280 And gfxh = 960
imwidth = 64
imheight = 64
ResizeImage im, imwidth, imheight
Else If gfxw = 1152
imwidth = 44
imheight = 44
ResizeImage im, imwidth, imheight
Else If gfxw = 1024
width = GraphicsWidth()/4-ImageWidth(background)/8
height = GraphicsHeight()
imwidth = 44
imheight = 44
ResizeImage background, width, height
ResizeImage im, imwidth, imheight
Else If gfxw = 720
width = GraphicsWidth()/4-ImageWidth(background)/8
height = GraphicsHeight()
imwidth = 44
imheight = 44
ResizeImage background, width, height
ResizeImage im, imwidth, imheight
Else If gfxw = 400
width = GraphicsWidth()/2-ImageWidth(background)/8
height = GraphicsHeight()
imwidth = 32
imheight = 32
ResizeImage background, width, height
ResizeImage im, imwidth, imheight
Else If gfxw = 800
width = GraphicsWidth()/4-ImageWidth(background)/8
height = GraphicsHeight()
imwidth = 44
imheight = 44
ResizeImage background, width, height
ResizeImage im, imwidth, imheight
Else
imwidth = 32
imheight = 32
ResizeImage im, imwidth, imheight
EndIf
;If Not AnimSeq(player1) = 1
While Not KeyHit(1)
If sky1=1 Then PositionEntity sky1,EntityX(player1),EntityY(player1),EntityZ(player1)
If defaultsky=1 Then PositionEntity defaultsky, EntityX(player1),EntityY(player1),EntityZ(player1)
mx = MouseX()
my = MouseY()
old_mouse_x = cur_mouse_x ;this is the line where i define the old variable for mousex()
cur_mouse_x = MouseX()/2 ;this is the new mousex()
mouse_x_delta = cur_mouse_x-old_mouse_x ;this is the current mousex() ;this is what im going to use in the y value of "turnentity player1"
characreate = newchar ;this is the old characreate
newchar = 0 ;this is the new characreate
newfinal = newchar ;this is the value i will use to change characreate to 0 only if you are not mousing over a block.
oldselect = newselect
newselect = 0
newsfinal = newselect
mh = MouseHit(1)
omousedown = newmouse_down
newmouse_down = MouseDown(1)
fmousedown = newmouse_down
If player1 <> 0
If fmousedown And mayturn = 0
If mx > ImageWidth(background)
TurnEntity player1, 0, mouse_x_delta, 0
Else If mx < ImageWidth(background) Or mx > GraphicsWidth()-1
RotateEntity player1, 0, -180, 0
EndIf
EndIf
EndIf
which=y*2+x
If Not mayturn Then fmousedown = 0
If (which <> 0) And mayturn = 1 Then mayturn = 0
If mx < 0 Then mx = 0
If my < 0 Then my = 0
If mx > GraphicsWidth() Then mx = GraphicsWidth()
If my > GraphicsHeight() Then my = GraphicsHeight()
If KeyDown(29) <> KeyDown(57) Or KeyDown(57) <> KeyDown(29)
If KeyDown(29)
MoveEntity cam, 0, .1, 0
Else If KeyDown(57)
MoveEntity cam, 0, -.1, 0
EndIf
EndIf
MoveEntity cam, 0, 0, (KeyDown(200)-KeyDown(208) Or KeyDown(17) - KeyDown(31))*1
TurnEntity cam, 0, (KeyDown(203) - KeyDown(205) Or KeyDown(30) - KeyDown(32))*1, 0
UpdateWorld
RenderWorld
DrawImage background, origx#+pos_x#, origy#+pos_y#
If mh
For x = 0 To 1
For y = 0 To maxblocks
imx = (0.2 * width) + (0.57 * width * x) + (origx#) + (pos_x#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#) + (pos_x#)
If ImageRectOverlap(im, imx,imy,mx,my,1,1)
which = y * 2 + x
selected = which
If which <> oldwhich Then
HideEntity player1
ShowEntity playermesh(which)
player1 = playermesh(which)
If which = 0 PositionEntity player1,0,0,8
If which = 1 PositionEntity player1,0,0,8
If which = 0 Animate player1,1
If which = 1 Animate player1,1
If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0
If which = 1 Then ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0
oldwhich = which
Else If which = oldwhich
showbox = 1
EndIf
EndIf
Next
Next
EndIf
For x = 0 To 1
For y = 0 To maxblocks
which=y*2+x
imx = (0.2 * width) + (0.57 * width * x) + (origx#) + (pos_x#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#) + (pos_y#)
DrawImage im, imx, imy, which
DrawImage imbg, imx-ImageWidth(imbg)/2, imy-ImageHeight(imbg)/2
Next
Next
For x = 0 To 1
For y = 0 To maxblocks
imx = (0.2 * width) + (0.57 * width * x) + (origx#) + (pos_x#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#) + (pos_y#)
which=y*2+x
If (which = selected) Or ImageRectOverlap(im, imx,imy, mx,my,1,1)
characreate = 1
Color 150,150,150
Rect imx-ImageWidth(im)/2, imy-ImageHeight(im)/2, ImageWidth(im), ImageHeight(im), 0
Rect imx-ImageWidth(im)/2+1, imy-ImageHeight(im)/2+1, ImageWidth(im), ImageHeight(im), 0
If selected And which = 0
Color 0,0,0
Text imx-StringWidth("Ninja")/2-1, imy-StringHeight("Ninja")/2-1, "Ninja"
Color 102,102,255
Text imx-StringWidth("Ninja")/2, imy-StringHeight("Ninja")/2, "Ninja"
Else If selected And which = 1
Color 0,0,0
Text imx-StringWidth("Markio")/2-1, imy-StringHeight("Markio")/2-1, "Markio"
Color 68,207,255
Text imx-StringWidth("Markio")/2, imy-StringHeight("Markio")/2, "Markio"
EndIf
EndIf
Next
Next
If KeyDown(44) = 0
DrawImage mouseicon, mx, my
EndIf
Color 0,0,0
Music_Handler()
SFX_Handler()
Text GraphicsWidth()/2, GraphicsHeight()/2, "x"+EntityX(cam)
Text GraphicsWidth()/2, GraphicsHeight()/2+20, "y"+EntityY(cam)
Text GraphicsWidth()/2, GraphicsHeight()/2+30, "z"+EntityZ(cam)
Text GraphicsWidth()/2, GraphicsHeight()/2+50, "zp"+EntityZ(player1)
Text GraphicsWidth()/2, GraphicsHeight()/2+60, "mx"+mx
Flip
Wend
pmodel = player1
MessageBox(SystemProperty("ApphWnd"), pmodel, player1, 0)
FreeEntity player1
FreeEntity temp
FreeEntity sky1
FreeEntity defaultsky
FreeEntity sky1
FreeEntity cam
FreeImage background
FreeImage mouseicon
FreeImage im
;ClearWorld()
Return pmodel
End Function~DS~ |
| ||
| i hope this helps. if not. i can rewrite it with tabs :) ~DS~ |
| ||
| Are all those variables Global? Else you can't address them from inside functions. Alternatively, you could use the Gosub command instead of using functions. That way you don't need to make anything Global. |
| ||
| well, i prefer globals, cuz gosub is a bit slow. i dont even like using gosub for .reset but idk how to change reset into a function :3 and yea. they are. |
| ||
| nvm.. problem? SOLVED! :D ~DS~ |
| ||
| Gosub slow? Ever tried that? I allways thought that internally, on a machinecode level, Gosub and Function are the same thing. You might find that Gosub is even slightly faster, since it has no parameters. |
| ||
| Gosub wouldn't be adding to the stack with params, and I doubt the label would have any internal use, so yeah it should be faster, though Functions are "neater" for reading in my opinion. |
