Ed-2D
Junior Member
Posts: 59
|
Post by Ed-2D on Mar 22, 2005 20:12:04 GMT
- Fake Pivot - It's a hidden rectangle shape with its collision shape. This can be usefull to make some tests.
Function HUD_CreatePivot%(LayerID,x,y,size%=3,visible=False) Local pivot% = HUD_CreateShape (LayerID,"RECTANGLE",1,0,x,y,size,size) HUD_SetObjectVisibility pivot,visible
HUD_AddCollisionPoint pivot,0,0 HUD_AddCollisionPoint pivot,0,size HUD_AddCollisionPoint pivot,size,size HUD_AddCollisionPoint pivot,size,0 Return pivot End Function
To show pivot :
HUD_SetObjectVisibility pivot,true
|
|
|
Post by Jake on Mar 25, 2005 13:34:06 GMT
I made some functions for doing selection-boxes of different shape. These selectionboxes are "layer-aware", so you could use them with a rotated/scaled layer. You can download it from my site (see the misc. stuff-section). There's currently an issue with Z-Order (can't place shapes in front of images on the same layer) that hopefully got fixed in a few days. Jake
|
|
Ed-2D
Junior Member
Posts: 59
|
Post by Ed-2D on Mar 26, 2005 20:15:41 GMT
This function is very usefull if you make shoot'em up That's why relative & snapAngle is set to True - ObjectID (Image,Shape,Layer...)
- TargetID (Image,Shape,Layer...)
- offx horizontal offset
- offy vertical offset
- relative relative postion
- TRUE (default) - FALSE
- snapAngle
- TRUE (default) - FALSE
; ------------------------------------------------------------------------ ; OBJECT SNAP TO ANOTHER ONE : POSITION & ANGLE ; ------------------------------------------------------------------------ Function HUD_SnapObject(ObjectID%, TargetID%, offx%=0, offy%=0, relative%=True, snapAngle%=True) Local Obj1.SC_Object = Object.SC_Object(ObjectID) : If Obj1 = Null Then RuntimeError SC_BreakText("HUD_SnapObject||The first object does not exist.",50) Local Obj2.SC_Object = Object.SC_Object(TargetID) : If Obj2 = Null Then RuntimeError SC_BreakText("HUD_SnapObject||The second object does not exist.",50) Local a#=Obj2\rotation Local x%=Obj2\x Local y%=Obj2\y Local dx%,dy% ;OFFSET CALCULATION If relative dx=-offy*SC_Sin(a)+offx*SC_Cos(a) dy=offy*SC_Cos(a)-offx*SC_Sin(a) Else dx=offx dy=offy EndIf ;UPDATE POSITION Obj1\x=x+dx Obj1\y=y+dy ;UPDATE ANGLE If snapAngle Obj1\rotation=a EndIf
; UPDATE LAYER Local Layer.SC_Layer = Object.SC_Layer (Obj1\LayerID) Layer\update = 1 : Obj1\update = 1 End Function
|
|
|
Post by Jake on Mar 27, 2005 7:52:40 GMT
You should use the precalculated Sin/Cos-Values provided by SpriteCandy. It'll speed up your function.
|
|
|
Post by Jake on Mar 27, 2005 15:00:26 GMT
This function returns the layer used by an object:
Function HUD_GetObjectLayer% (ObjectID%) Local Obj.SC_Object = Object.SC_Object(ObjectID) : If Obj = Null Then RuntimeError SC_BreakText("HUD_GetObjectLayer||The specified object does not exist.",50) Return Obj\LayerID End Function
|
|
Ed-2D
Junior Member
Posts: 59
|
Post by Ed-2D on Mar 28, 2005 5:31:25 GMT
You should use the precalculated Sin/Cos-Values provided by SpriteCandy. It'll speed up your function. True... HUD_SnapObject optimized
|
|
Ed-2D
Junior Member
Posts: 59
|
Post by Ed-2D on Mar 28, 2005 5:53:57 GMT
This is a new effect control. It could simulate bounce. It could be used with FX_MoveTo or FX_SteadyMove - EffectID ( FX_MoveTo | FX_SteadyMove )
- frontierType$ kind of wall
- "X" vertical wall - "Y" horizontal wall
- frontier position of wall
Function HUD_BounceEffect(EffectID,frontierType$,frontier) Local FX.SC_FX = Object.SC_FX(EffectID) If FX<>Null Select FX\typ Case FX_STEADYMOVE Select Upper(frontierType$) Case "X" If FX\flag dx#=FX\b*SC_Sin(Obj\rotation)-FX\a*SC_Cos(Obj\rotation) dy#=FX\b*SC_Cos(Obj\rotation)-FX\a*SC_Sin(Obj\rotation) FX\a=dx FX\b=dy FX\flag=0 Else FX\a=-FX\a EndIf Obj\x=frontier Case "Y" If FX\flag dx#=-FX\b*SC_Sin(Obj\rotation)+FX\a*SC_Cos(Obj\rotation) dy#=-FX\b*SC_Cos(Obj\rotation)+FX\a*SC_Sin(Obj\rotation) FX\a=dx FX\b=dy FX\flag=0 Else FX\b=-FX\b EndIf Obj\y=frontier End Select Case FX_MOVETO Select Upper(frontierType$) Case "X" FX\h=2*frontier-FX\h FX\a=2*frontier-FX\a FX\c=FX\h-FX\a Case "Y" FX\i=2*frontier-FX\i FX\b=2*frontier-FX\b FX\d=FX\i-FX\b End Select End Select EndIf End Function
How to use : playerMoveToFX=HUD_FX_MoveTo( player, -100, 100, 1500, 0,0 ) If playerX<0 HUD_BounceEffect(playerMoveToFX,"X",0) Else HUD_BounceEffect(playerMoveToFX,"X",GraphicsWidth ()) EndIf
|
|
|
Post by Xpressive on Mar 29, 2005 7:40:16 GMT
Here's a function to let any image dissolve / explode in various styles. You can specify an image handle of the image you want to blow up. The function does not modify the original image, it creates a copy on top of your original one. So you should hide the original image while the effect is running. Use it like this: ; CALL EXPLODE FUNCTION ImageExplode MyImage, ImageLayer, 14, 2000
; HIDE ORIGINAL IMAGE HUD_SetObjectAlpha MyImage, 0
Here's the function. Include it into your own code and call it like explained above. The parameters: Image: handle of a HUD image (you can use images of any size) Layer: handle of the image's layer chunkSize: as smaller, as more fragments will be used (may be slow, if too much). duration: The duration of the explosion. Try 2000 (2 seconds) ; ------------------------------------------------------------------------ ; FUNCTION: IMAGE EXPLODE ; ------------------------------------------------------------------------ Function ImageExplode (Image%, Layer%, chunkSize%, duration%=2000)
Local i%, j%, xx%, yy%, triggerTime%, easex%, easey%, Tmp% Local chunkDelay% = 5 Local w% = HUD_GetObjectWidth (Image) Local h% = HUD_GetObjectHeight (Image) Local x% = HUD_GetObjectCoords (Image, "CornerX", 1) Local y% = HUD_GetObjectCoords (Image, "CornerY", 1) Local sw% = GraphicsWidth() Local sh% = GraphicsHeight() Local angle% = Rand(0,6) * 45 Local mode% = Rand(0,1)
j = h-chunkSize : While j >= 0 i = 0
While i <= w-chunkSize xx = (x+i)+chunkSize/2 + Sin(angle) * sw yy = (y+j)+chunkSize/2 + Cos(angle) * sh If mode = 1 Then triggerTime = j * chunkDelay : easex = Rand(1,14) : easey = 13 If mode <>1 Then triggerTime = Rand(10,2000) : easex = 4 : easey = 13
Tmp = HUD_CreateImage (Layer, (x+i)+chunkSize/2,(y+j)+chunkSize/2, i,j, chunkSize, chunkSize) HUD_FX_Rotate Tmp, Rand(0,360), False, duration, 1, triggerTime HUD_FX_MoveTo Tmp, xx,yy, duration, easex,easey, triggerTime HUD_FX_Scale Tmp, 0.001, 0.001, duration, 1,1, triggerTime HUD_FX_AutoRemove Tmp, duration + triggerTime i = i + chunkSize Wend
j = j - chunkSize
Wend
End Function
Download sample code
|
|
|
Post by Xpressive on Mar 30, 2005 14:17:21 GMT
This code generates a fading trail that can be used for comets, spaceships etc. There are no textures required, just copy & paste.
Graphics3D 640, 480, 0, 2 : SetBuffer BackBuffer()
; INCLUDE SPRITE CANDY Include "../../sprite candy.bb"
; ------------------------------------------------------------------------ ; LET'S CREATE THE HUD: ; ------------------------------------------------------------------------
; CREATE CAMERA, LIGHT, HUD & LAYER Cam% = CreateCamera() Light% = CreateLight() HUD% = HUD_Create (Cam) Layer% = HUD_CreateLayer(HUD)
lineSize% = 2 fadeOut% = 500
; ------------------------------------------------------------------------ ; MAIN LOOP ; ------------------------------------------------------------------------ While Not KeyDown(1)
x% = MouseX() y% = MouseY() If x <> lastx Or y <> lasty Temp% = HUD_CreateShape (Layer,"LINE",lineSize,0, lastx,lasty, x,y) HUD_SetObjectColor Temp, 255,255,0 HUD_FX_ColorFade Temp, 255,0,0, fadeOut HUD_FX_AlphaFade Temp,0,fadeOut HUD_FX_AutoRemove Temp,fadeOut lastx = x lasty = y End If
HUD_Update : RenderWorld : Flip 0 Wend
HUD_RemoveAll True : End
|
|
Ed-2D
Junior Member
Posts: 59
|
Post by Ed-2D on Mar 30, 2005 16:47:14 GMT
nice
|
|
Ed-2D
Junior Member
Posts: 59
|
Post by Ed-2D on Apr 10, 2005 23:35:51 GMT
Get angle and relative angle between two objects
; ------------------------------------------------------------------------ ; PUBLIC FUNCTION: GET ANGLE BETWEEN TWO OBJECTS ; ------------------------------------------------------------------------ Function HUD_GetObjectAngle# (ObjectID%, TargetID%, relativeAngle%=False )
Local Obj.SC_Object = Object.SC_Object( ObjectID ) : If Obj = Null Then RuntimeError SC_BreakText("HUD_FaceObject||The specified object does not exist.",50) Local Tgt.SC_Object = Object.SC_Object( TargetID ) : If Tgt = Null Then RuntimeError SC_BreakText("HUD_FaceObject||The specified target object does not exist.",50) Local r#,a#
; FIND ANGLE r=Obj\rotation HUD_FaceObject(ObjectID,TargetID) a=Tgt\rotation Obj\rotation=r ; FIND RELATIVE ANGLE BETWEEN -180 AND + 180 ( TURN ANGLE ) If relativeAngle a=(a-r) If Abs(r)>180 Then r=r-Sgn(r)*360 EndIf Return a End Function
|
|
Ed-2D
Junior Member
Posts: 59
|
Post by Ed-2D on Apr 11, 2005 7:39:41 GMT
snapObject fixed : i forgot to update layer.
|
|
Ed-2D
Junior Member
Posts: 59
|
Post by Ed-2D on May 4, 2005 14:28:16 GMT
It works like Input$() command. - Input text - question prefix - cursor display - Press RETURN to exit - DEL / BACKSPACE / LEFT / RIGHT repeat result$ = HUD_TextInput (MyText, MyCursor) HUD_Update : RenderWorld : Flip until result$<>"" Function HUD_TextInput$(ObjectID,textCusorID=0,question$="",ExitScancode=28) Local Obj.SC_Object = Object.SC_Object (ObjectID) : If Obj = Null Then RuntimeError SC_BreakText("HUD_TextInput||The specified text object does not exist.",50) Local TextObj.SC_Text = Object.SC_Text (Obj\TextID) : If TextObj = Null Then RuntimeError SC_BreakText("HUD_TextInput||The specified object does not seem to be a text object.",50) Local Font.SC_Font = Object.SC_Font (TextObj\FontID) : If Font = Null Then RuntimeError SC_BreakText("HUD_TextInput||The text object's font could not be found.",50) Local Cur.SC_Object = Object.SC_Object (textCusorID) If textCusorID And Cur = Null Then RuntimeError SC_BreakText("HUD_TextInput||The specified cursor object does not exist.",50)
Local txt$=HUD_GetText(ObjectID) Local txtMarker$=Chr(11) Local txtMarkerPos=Instr(txt$,txtMarker$,1) Local txtFlow$=HUD_GetTextFlow(ObjectID) Local txtWrapped$=TextObj\txt_wrapped$ ;UPDATE CURSOR ---------------------------------------------- If txtMarkerPos=0 HUD_SetText ObjectID,question$+txt$+txtMarker$ txtMarkerPos=Len(txt$)+1 If textCusorID Then HUD_SetObjectVisibility textCusorID,1 Else txtMarkerPos=txtMarkerPos-Len(question$) txt$=Mid(txt$,Len(question$)+1,Len(txt$)) EndIf If textCusorID Local lines%, length%, c$, a% Local x,y,x0,y0 lines = 1 : length = Len(txtWrapped$) If txtFlow$ = "CENTER" Then x = -(TextObj\line_widths[1] / 2) If txtFlow$ = "RIGHT" Then x = -TextObj\line_widths[1] If txtFlow$ = "LEFT" Then x = 0
; CALCULATION : CURSOR POSITION For i = 1 To length c$ = Mid(txtWrapped$,i,1) a% = Asc(c$)
; FIND TEXT MARKER? If c$=txtMarker$ Exit ; NEXT LINE? ElseIf c$ = Chr(13) lines = lines + 1 If txtFlow$ = "CENTER" Then x = -(TextObj\line_widths[lines] / 2) If txtFlow$ = "RIGHT" Then x = -TextObj\line_widths[lines] If txtFlow$ = "LEFT" Then x = 0 ; NEXT CHAR Else x = x + Font\char_widths[a] + TextObj\kerning End If Next
; SET CURSOR POSITION x0=HUD_GetObjectCoords(ObjectID,"CornerX",1) y0=HUD_GetObjectCoords(ObjectID,"CornerY",1) HUD_SetObjectRotation textCusorID,HUD_GetObjectRotation(ObjectID) HUD_PositionObject textCusorID,x0,y0 x=x*Obj\scalex y=(lines-1)*Font\line_height*Obj\scaley HUD_MoveObject textCusorID,x,y,1 EndIf
;EXIT ------------------------------------------------- If KeyHit(ExitScancode) FlushKeys txt$=Replace(txt$,txtMarker$,"") If txt$<>"" If textCusorID Then HUD_SetObjectVisibility textCusorID,0 EndIf Return txt$ EndIf ;UPDATE TEXT ------------------------------------------------- Local ascii=GetKey() If ascii txt$=Replace(txt$,txtMarker$,"") txtBefore$=Left(txt$,txtMarkerPos-1) txtafter$=Mid(txt$,txtMarkerPos,Len(txt$)) char$=Chr(ascii)
;SPECIAL CHAR? Select ascii Case 4 ;DELETE txtAfter$=Mid(txtAfter$,2,Len(txtAfter$)-1) char$="" Case 8 ;BACKSPACE txtMarkerPos=txtMarkerPos-1*(txtMarkerPos>1) txtBefore$=Left(txt$,txtMarkerPos-1) char$="" Case 31 ;LEFT txtMarkerPos=txtMarkerPos-1*(txtMarkerPos>1) txtBefore$=Left(txt$,txtMarkerPos-1) txtafter$=Mid(txt$,txtMarkerPos,Len(txt$)) char$="" Case 30 ;RIGHT txtMarkerPos=txtMarkerPos+1 txtBefore$=Left(txt$,txtMarkerPos-1) txtafter$=Mid(txt$,txtMarkerPos,Len(txt$)) char$="" Case 28 ;TOP ;txtMarkerPos=txtMarkerPos-1*(txtMarkerPos>1) ;txtBefore$=Left(txt$,txtMarkerPos-1) ;txtafter$=Mid(txt$,txtMarkerPos,Len(txt$)) char$="" Case 29 ;BOTTOM ;txtMarkerPos=txtMarkerPos+1 ;txtBefore$=Left(txt$,txtMarkerPos-1) ;txtafter$=Mid(txt$,txtMarkerPos,Len(txt$)) char$="" Case 13 ;RETURN Default If Font\char_widths[ascii]=0 Then char$="" End Select txt$=question$+txtBefore$+char$+txtMarker$+txtAfter$ HUD_SetText ObjectID,txt$ EndIf End Function
|
|
Ed-2D
Junior Member
Posts: 59
|
Post by Ed-2D on May 5, 2005 0:04:49 GMT
[UPDATED] HUD_TextInput
- bug fixed - you could add question before the input text
[UPDATED] HUD_GetObjectAngle
- relative angle fixed
|
|
|
Post by aaa11 on Aug 11, 2008 3:37:00 GMT
|
|