HELLO! I make game!
In my game I want to be able to draw stuff and that stuff becomes a dynamic body. But it becomes a soft body instead. I use "Fixed Joint" to merge the different objects from the drawing of stuff.
I thought that would make the body stiff, but instead it becomes kind of like a ragdoll except the "limbs" aren't rotating (which they shouldn't).
I cleaned my code a bit so it's ready for this post.
REMSTART
**********************************************************
Title: {no name}
Version: v 1.0.1
Author: Lukas W
About: Draw stuff to get the red ball into the thing.
A Tablet is recommended for accurate drawing (once game is complete).
To Do: Neatly Colored AND colorfull 2D GRAPHIX! (Hollowed shapes, like the game.. I forgot name)
Orthographic camera?
Use toilet later
A Thanks To:
Bergice - some tips
Acelepage - some tips
BillR - some code modifications
**********************************************************
Also:
This code is for debugging only, you are not permitted to use
the code in your own projects, unless I personally allow you to.
(I don't want to see people go ahead and make the game I want to
make before I make it) :-( PS: This is not an open source game.
PPS: Code was written at 1680x1050 resolution, so if you use lower than this, you may experience problems like this.
REMEND
` ANYWAY,
` ***********************************************************************
` SETUP - Variables
` ***********************************************************************
Global mx,my,_draw,oldmx,oldmy As Integer
Global timerFinish,timeSpent As Integer
Global timerStart As Integer
Global _hasDrawn,_drewSomething As Boolean
Global ScrW As Integer : ScrW = 1024
Global ScrH As Integer : ScrH = 768
` ***********************************************************************
` ***********************************************************************
` SETUP - Application
` ***********************************************************************
Sync On : Sync Rate 60 : Set Display Mode ScrW, ScrH, 32
Color Backdrop 0 : Autocam off : Position Camera 0, 0, -50
Create Bitmap 1, ScrW, ScrH : Set Current Bitmap 0
Phy Enable Debug : Phy Start
` ***********************************************************************
` ***********************************************************************
` SETUP - Arrays
` ***********************************************************************
` Setup Object History Array
Type tObjectData
xp,yp,zp As Float
ax,ay,az As Float
le As Float
id As Integer
EndType
Dim ObjectData(0) As tObjectData
` Setup Drawing History Array
Type tDrawing
ox,oy As integer
nx,ny As Integer
EndType
Dim Drawing(0) As tDrawing
` ***********************************************************************
` ***********************************************************************
` ACTION - Load Level
` ***********************************************************************
` TEMP TEMP TEMP TEMP TEMP TEMP TMEP TEMP TEMP TEMP
`Make Object Box 9999, 1000, 5, 100 : Position OBject 9999, 0, -50, 0 : Rotate Object 9999, 0, 0, 315 : Phy Make Rigid Body Static Box 9999
Make Object Box 9998, 1000, 5, 100 : Position Object 9998, 0, -50, 0 : Phy Make Rigid Body Static Box 9998
`Make Object Box 9997, 50, 100, 100 : Position Object 9997, -50, -50, 0 : Phy Make Rigid Body Static Box 9997
`Make Object Box 9996, 1000, 1000, 5 : Position Object 9996, 0, 0, 99 : Phy Make Rigid Body Static Box 9996 : hide object 9996
`Make Object Box 9995, 1000, 1000, 5 : Position Object 9995, 0, 0, 98 : Phy Make Rigid Body Static Box 9995 : hide object 9995
`make object sphere 10000, 10 : position object 10000, 0, -20, 50 : phy make rigid body dynamic sphere 10000
` TEMP TEMP TEMP TEMP TEMP TEMP TMEP TEMP TEMP TEMP
` ***********************************************************************
Do
` ***********************************************************************
` ACTION - Display HUD
` ***********************************************************************
Set Cursor 0, 0
Print "FPS: ", Screen FPS()
Print "POL: ",Statistic(1)
Print
Print "Time spent: ", timespent, " ms"
` ***********************************************************************
` ***********************************************************************
` ACTION - Draw Objects Using Mouse
` ***********************************************************************
drawVectorLines()
drawConvert_2d_to_3d()
` ***********************************************************************
` ***********************************************************************
` ACTION - Update Application
` ***********************************************************************
Phy Update
Sync
` ***********************************************************************
Loop
` ***********************************************************************
` FUNCTION - Use Mouse to draw lines on screen
` ***********************************************************************
Function drawVectorLines()
If mx >0 And mx <ScrW And my >0 And my <ScrH
If MouseClick() =1 And _draw =0 Then _draw =1 : Set Current Bitmap 1
If MouseClick() =0 And _draw =1 Then _draw =2
If _draw =0 And _hasDrawn =1 Then Empty Array Drawing(0) : Set Current Bitmap 0 : _hasDrawn =0 : _drewSomething = 0
EndIf
mx = MouseX() : my = MouseY()
If _draw =1
If mx<>oldmx Or my<>oldmy
Array Insert At Bottom Drawing(0)
pos = Array Count(Drawing(0))
Drawing(pos).ox = oldmx
Drawing(pos).oy = oldmy
Drawing(pos).nx = mx
Drawing(pos).ny = my
_drewSomething = 1
EndIf
For x= 1 To Array Count(Drawing(0))
Ink RGB( 255, 255, 255 ), 0
Line Drawing(x).ox, Drawing(x).oy, Drawing(x).nx, Drawing(x).ny
Next x
Copy Bitmap 1, 0
EndIf
oldmx=mx : oldmy=my
EndFunction
` ***********************************************************************
` ***********************************************************************
` FUNCTION - Convert the 2D lines into 3D objects
` ***********************************************************************
Function drawConvert_2d_to_3d()
If _draw =2
timerStart = Timer()
If _drewSomething = 1
` create 3d object from vector drawing
For x= 1 To Array Count(Drawing(0))
Pick Screen Drawing(x).ox, Drawing(x).oy, 100
xp1# = Get Pick Vector X() : yp1# = Get Pick Vector Y() : zp1# = Get Pick Vector Z()
Pick Screen Drawing(x).nx, Drawing(x).ny, 100
xp2# = Get Pick Vector X() : yp2# = Get Pick Vector Y() : zp2# = Get Pick Vector Z()
length# = 1 + Sqrt( (xp1#-xp2#)^2 + (yp1#-yp2#)^2 )
middlex# = Sqrt( (xp1#-xp2#)^2 ) /2
middley# = Sqrt( (yp1#-yp2#)^2 ) /2
xp# = Camera Position X() + (xp1#+middlex#)
yp# = Camera Position Y() + (yp1#-middley#)
zp# = Camera Position Z() + zp1#
angle# = Atanfull( Drawing(x).ox-Drawing(x).nx, Drawing(x).oy-Drawing(x).ny ) +90
Obj = FreeObj()
Make Object Box Obj, length#, 1, 1
Position Object Obj, xp#, yp#, zp#
Rotate Object Obj, 0, 180, angle# `: Fix Object Pivot Obj
anglex# = Object Angle X( Obj )
angley# = Object Angle Y( Obj )
anglez# = Object Angle Z( Obj )
Array Insert At Bottom ObjectData(0)
pos = Array Count(ObjectData(0))
ObjectData(pos).xp = xp#
ObjectData(pos).yp = yp#
ObjectData(pos).zp = zp#
ObjectData(pos).ax = anglex#
ObjectData(pos).ay = angley#
ObjectData(pos).az = anglez#
ObjectData(pos).le = length#
ObjectData(pos).id = Obj
Next x
` joint everything together
For x = 1 To Array Count(ObjectData(0))
obj = ObjectData(x).id
ax# = ObjectData(x).ax
ay# = ObjectData(x).ay
az# = ObjectData(x).az
Phy Make Rigid Body Dynamic Box obj
Phy Set Rigid Body Mass obj, 100.0
Phy Set Rigid Body Rotation Obj, ax#, ay#, az#
If x > 1
JointID = FreeJoint()
If x = Array Count(ObjectData(0))
Phy Make Fixed Joint JointID, Obj, ObjectData(1).id
Else
Phy Make Fixed Joint JointID, Obj, ObjectData(x-1).id
EndIf
`Phy Set Joint Break Limits JointID, 7000.0, 2000.0
EndIf
Next x
EndIf
` done
_draw =0
_hasDrawn =1
Empty Array ObjectData(0)
timerFinish = Timer()
timespent = (timerFinish - timerStart)
EndIf
EndFunction
` ***********************************************************************
` ***********************************************************************
` FUNCTION - Collection of 'Find Free X' functions
` ***********************************************************************
Function FreeObj() : Repeat : Inc returnVal, 1 : Until Object Exist( returnVal ) =0
EndFunction returnVal
Function FreeMesh() : Repeat : Inc returnVal, 1 : Until Mesh Exist( returnVal ) =0
EndFunction returnVal
Function FreeJoint() : Repeat : Inc returnVal, 1 : Until Phy Get Joint Exist( returnVal )=0
EndFunction returnVal
` ***********************************************************************
REMSTART
+-----------------------+
| Credits (LIST SUX) |
+-----------------------+---------------------------+
| Coding - Lukas W |
+---------------------------------------------------+
REMEND
REMSTART
Version History:
v 1.0.0 - 05/26/2008
----------------------
ADDED: Draw in a 3D View
ADDED: Convert drawing into dynamic 3d object
ADDED: Reset application and change screen resolution
FIXED: Vector image instead of rasterized image
FIXED: Tried to create object from drawing if you clicked outside the window
V 1.0.1 - 00/00/0000
----------------------
FIXED: Instead of creating object with limbs, it now creates boxes jointed together
FIXED: Objects have rotation applied
FIX: Turn off "soft body" (but how?)
Design Doc:
Draw shapes that will interact with the level and hopefully lead the ball to the swirl
solid dynamic shapes
rope (joint a shape with a different shape OR joint a shape with a static entity)
static entities appear as gray spheres
dynamic entities are white
ropes are yellow
Right click on a shape to delete it (and all of its grouped objects)
50 levels OR MORE :-O
Achievements
Level Editor as well
REMEND
I hope you know how to solve this issue because I've struggled with it for a day now.
You may want to have a look at the code and run it, to better understand what I am trying to explain but fail so miserably!
kthx.
PS:
Note that the drawing and converting is not PERFECT! I am sorry I suck at taht part.
I allways afraided from a clowns. aww..