Door Open

Blitz3D Forums/Blitz3D Beginners Area/Door Open

I'm New To blitz3d but having a good time. I'm having trouble figureing out how To raise a door slowly up( Or down For that matter. the code I use works but too fast. I have looked And can't find any examples. I tryed finding the dundeon thing that Rook mentioned but isn't out there. I appreciacte any help you could give. heres what I've got ;sliding door


Graphics3D 800, 600, 0, 1 ;3D graphics at a resolution of 800x600
SetBuffer BackBuffer() ;do all drawing to the back drawing buffer
Timer# = MilliSecs(); + 10000

Const PLAYER_COL= 1
Const LEVEL_COL = 2
Const ENEMY_COL = 3
Const BULLET_COL= 4

Global level2 ;
Global previous_millisecs_time = MilliSecs()
;
Type bullettype ;set up the bullet type
Field entityhandle ;create a field to contain the handle of the bullets mesh
End Type

Type badguytype ;set up the badguy type
Field entityhandle ;will contain the handle of the badguys mesh
Field state ;will contain the state that the badguy is currently in
End Type

Type doortype
Field entityhandle
Field state
End Type

light = CreateLight() ;Create a light to see
RotateEntity light, 30, 30, 0 ;angle the light
player = CreatePivot() ;A simple pivot is all we need to represent the player
camera = CreateCamera(player) ;create the camera and attach it to the player
CameraRange camera, .01, 250 ;set the camera range to something reasonable


;CREATE SKY
sky = CreateSphere(40)
FlipMesh sky ScaleEntity sky,1000,1000,1000
PositionEntity sky,0,0,0
sky_tex = LoadTexture ("sky.jpg")
EntityTexture sky,sky_tex
EntityFX sky,1

level = LoadMesh("anewroom&door.b3d") ;load in the level mesh

level2 = LoadMesh("door.b3d")
PositionEntity level2,0,0,1
FlipMesh level2
EntityType level2,1
EntityRadius level2,1.05
;==============
; Load gun target
;==============
targ=LoadSprite("target.png",1,camera)
MoveEntity targ,0,0,50
EntityOrder targ,-2

;hand held gun Number 2
gun2 = LoadMesh("pistol.3ds")
gun2_tex = LoadTexture("pistol.jpg")
EntityShininess gun2,0.8
EntityRadius gun2, .5
EntityParent gun2,camera
ScaleEntity gun2,.2,.2,.2
PositionEntity gun2,EntityX(camera),EntityY(camera)-1.5,EntityZ(camera)+2
RotateEntity gun2 ,-5,-2,0
EntityOrder gun2,-2
;HideEntity gun2

bulletmesh = LoadMesh("bullet.b3d") ;load in a bullet mesh (this will be a template mesh)
bulletmesh = CreateCone():RotateMesh bulletmesh,90,0,0:ScaleEntity bulletmesh,.1,.1,.1
EntityType bulletmesh, BULLET_COL ;set up collision type for the bullet
EntityRadius bulletmesh, .01 ;set up collision radius for the bullet
;HideEntity bulletmesh ;hide the template meshes since they are not actual objects




EntityType player, PLAYER_COL ;set up collision type for the player
EntityRadius player, .3;, .95,.125 ;set up the players collision radius (1.9 meters tall, .6 meters wide)
EntityType level, LEVEL_COL ;set up collision type for the level
EntityType level2,LEVEL_COL
Collisions PLAYER_COL, LEVEL_COL, 2, 2 ;player to level



MoveEntity camera, 0, .9, 0 ;move camera up to height of players head (also moves weapon)
MoveEntity player, 0,1,-4 ;move the player to the starting position
MoveEntity gun2, .1,-.15,.1

Global previous_millisecs_time = MilliSecs()


While Not KeyHit(1) ;ESC key

wkey = KeyDown(17) ;collect user input
skey = KeyDown(31) ;It's a good practice to collect these inputs only once
akey = KeyDown(30) ;per loop. This will prevent odd behaviors from happening,
dkey = KeyDown(32) ;for instance if the state of a key changes between multiple
mouse1 = MouseHit(1) ;checks of that key while still in the same loop.
spacekey = KeyHit(57)
If wkey Then MoveEntity player, 0, 0, .1 ;Forward - w key
If skey Then MoveEntity player, 0, 0, -.1 ;Back - s key
If akey Then MoveEntity player, -.1, 0, 0 ;Left - a key
If dkey Then MoveEntity player, .1, 0, 0 ;Right - d key
If spacekey Then MoveEntity player, 0,2.5,0




If KeyHit(18) doorup()


TurnEntity player, 0, -MouseXSpeed()/5.0, 0 ;rotate player Pivot according to mouse X movement
TurnEntity camera, MouseYSpeed()/5.0, 0, 0 ;rotate camera up/down according to mouse Y movement
If EntityPitch(camera) < -45 ;don't allow camera to look below -45 degrees
RotateEntity camera, -45, EntityYaw(camera), EntityRoll(camera)
EndIf
If EntityPitch(camera) > 45 ;don't allow camera to look above 45 degrees
RotateEntity camera, 45, EntityYaw(camera), EntityRoll(camera)
EndIf
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2 ;reset mouse position to middle of screen

TranslateEntity player, 0, -.1, 0 ;simple gravity



UpdateWorld ;figures out collisions

If mouse1 ;check if left mouse button was pressed
bullet.bullettype = New bullettype ;create a bullet
bullet\entityhandle = CopyEntity(bulletmesh) ;create the bullet mesh
PositionEntity bullet\entityhandle, EntityX(gun2, 1), EntityY(gun2, 1), EntityZ(gun2, 1) ;place the bullet at the guns position
RotateEntity bullet\entityhandle, EntityPitch(gun2, 1), EntityYaw(gun2, 1), EntityRoll(gun2, 1);orientate the bullet with the gun
ResetEntity bullet\entityhandle ;otherwise bullet could hit enemy while moving from 0,0,0 to current position
EndIf

For thisbullet.bullettype = Each bullettype ;iterate through all of the bullets
MoveEntity thisbullet\entityhandle, 0, 0, 2 ;move the bullet forward along the bullets Z axis
If Abs(EntityX(thisbullet\entityhandle, 1)) > 10000 ;check if the bullet is way out of bounds
FreeEntity thisbullet\entityhandle ;delete the bullet mesh
Delete thisbullet ;delete the bullet
ElseIf Abs(EntityY(thisbullet\entityhandle, 1)) > 10000 ;check if the bullet is way out of bounds
FreeEntity thisbullet\entityhandle ;delete the bullet mesh
Delete thisbullet ;delete the bullet
ElseIf Abs(EntityZ(thisbullet\entityhandle, 1)) > 10000 ;check if the bullet is way out of bounds
FreeEntity thisbullet\entityhandle ;delete the bullet mesh
Delete thisbullet ;delete the bullet
EndIf
Next

UpdateWorld ;figures out collisions



RenderWorld ;draws the 3d scene
Flip ;displays the scene to the screen
Wend ;loop until the ESC key is pressed
End



Function doorup()
maxlift = 3.5
For lift# = lift + .001 To maxlift

MoveEntity level2,0,lift#,0
currtime_in_millisecs = MilliSecs()
time_passed = currtime_in_millisecs - previous_millisecs_time
If time_passed > 100 Then time_passed = 100
If time_passed = 100 Then MoveEntity level2, 0,.1,0

; EndIf
Next