Not Level

Blitz3D Forums/Blitz3D Beginners Area/Not Level

grimx(Posted 2006) [#1]
when i move the ball (p) left, it won't stay level
p\y seems to go in the minus
help

Main form:
Include "World.bb"
Include "Player.bb"
Include "Bullet.bb"

Type World
 Field image
 Field x
 Field y
End Type
Type Hole
 Field image
 Field x
 Field y
End Type

Type Player
 Field image
 Field x#
 Field y#
 Field dir
 Field speed
 Field jump
 Field alive
End Type
Type Bullet
 Field image
 Field x#
 Field y#
 Field dir
 Field speed
End Type


Global Window_W=600
Global Window_H=400

SeedRnd MilliSecs()
Graphics Window_W,Window_H,16,0
SetBuffer BackBuffer()

Global offx=1

Global Gravity#=4
Global BulletTimer
Global Running=True

Create_World()
Create_Hole()
Create_Player()

While(Running=True)
  If KeyHit(1) Then Running=False
  UpDate_World()
  UpDate_Hole()
  UpDate_Player()
  UpDate_Bullet()
  Collision()

Flip
Cls
Wend
End

Function Collision()
                            
For p.Player=Each Player
  For w.World=Each World ;|if p does not collide with w drop   .. p\y wont stay level when moving left--------|
   If ImagesCollide(w\image,w\x,w\y,0,p\image,p\x,p\y,0)=0 And p\jump=False Then p\y=p\y+1
   If ImagesCollide(w\image,w\x,w\y,0,p\image,p\x,p\y,0)=True And p\jump=False Then p\y=w\y-20
  ;|----------------------------------------------------------------------------------|
Next
 Next


End Function


world form:
Function Create_World()
  For i=1 To 6
     w.World=New World
     w\x = offx
     w\y=380
     w\image=LoadImage("floor.bmp")
     offx=offx+78
  Next
 
End Function

Function UpDate_World()
For w.World=Each World
    MaskImage w\image,0,0,0
    DrawImage w\image,w\x,w\y    
Next
End Function

Function Create_Hole()
 h.Hole=New Hole
 h\x=offx+3
 h\y=390
 h\image=LoadImage("hole.bmp")
End Function

Function Update_Hole()
 For h.Hole=Each Hole
    MaskImage h\image,0,0,0
    DrawImage h\image,h\x,h\y
Next
End Function


Player form:

Function Create_Player()
  p.Player=New Player
  p\image=LoadImage("ball1.bmp")
  p\x=30
  p\y=300
  p\speed=3
  p\dir=2
  p\jump=False
  p\alive=True
End Function

Function UpDate_Player()
 For p.Player=Each Player
  MaskImage p\image,0,0,0
  DrawImage(p\image,p\x,p\y)
  If KeyDown(203) And p\x>0 Then p\x=p\x-p\speed :p\dir=1
  If KeyDown(205) And p\x+ImageWidth(p\image)<Window_W Then p\x=p\x+p\speed :p\dir=2
  If KeyDown(57) p\jump=True 
  If p\jump=True Player_Jump()
  If KeyHit(184)  Shoot(p\x,p\y,p\dir)
 Next
End Function

Function Player_Jump()
 For p.Player=Each Player
   If p\jump=True
     p\y=p\y-Gravity#
     Gravity#=Gravity#-.08
     End If
     If p\y > 359
      p\jump=False
      Gravity#=4
     End If
   
 Next
End Function



Bullet form:

Function Shoot(x,y,dir)
 b.Bullet=New Bullet
 b\dir=dir
 If b\dir=1 b\image=LoadImage("sbullet2.bmp")
 If b\dir=2 b\image=LoadImage("sbullet.bmp")
 b\x=x
 b\y=y
 b\speed=4
 BulletTimer=MilliSecs()
End Function

Function UpDate_Bullet()
 For b.Bullet=Each Bullet
  If b\dir=1 Then b\x=b\x-b\speed 
  If b\dir=2 Then b\x=b\x+b\speed
  b\y=b\y
  DrawImage(b\image,b\x,b\y)
  If b\x+ImageWidth(b\image)>600 Or b\x<1 Then  Delete b 
 Next
End Function

 



b32(Posted 2006) [#2]
do you have the images ?


grimx(Posted 2006) [#3]
No
the floor.bmp is 80,20
the ball.bmp is 20,20


Ross C(Posted 2006) [#4]
Could you post a slightly more thorough description of your problem. People here will take the time to help you, so you got to take the time to ask the question correctly :o)


b32(Posted 2006) [#5]
post the images on some free imagehost, or use a function like this: