News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

collision help!

Started by RaverDave, January 01, 2006, 04:29:09 AM

Previous topic - Next topic

kevin

#15
Quoteis a label before each data block, so you could restore <label> rather than having to deal with numbers!

 yes, you can use labels.  But I wouldn't,  instead i'd use embedded strings and then use the Restores built in searching abilities.  Which will make this so much easier.

In other words rather than hard code labels into your program then having to hard coding restore points in order to load the various levels from the data..


like this



  Select CurrentLevel
      case 1
           Restore Level1

      case 2
           Restore Level2

      case 3
           Restore Level3

      case 4
           Restore Level4

; This would get pretty annoying if you had a lot of levels !

   End Select


Level1:
 Data 1,2,34

Level2:
 Data 5,6,7,8
 
Level3:
  Data 9,10,11,12

; Level Id
Level4:
  Data 13,14,15,16







 You could just do this..   :)









; set PB auto counter to 1
AcSet=1

; Level Id
Data "Level"+str$(ac(1))
 Data 1,2,3,4

 
; Level Id
Data "Level"+str$(ac(1))
 Data 5,6,7,8
 
; Level Id
Data "Level"+str$(ac(1))
  Data 9,10,11,12

; Level Id
Data "Level"+str$(ac(1))
  Data 13,14,15,16



Constant Max_number_of_levels = ac(1)




do

Cls 0

Level=rndRange(1,Max_number_of_levels-1)
; Random Pick the Level you wish to read from
  Restore "Level"+str$(level)

 
  Print "Reading data from"+ReadData$()
For lp=1 to 4
   Print ReadData()
  next
  print ""


sync
waitkey

loop




RaverDave

AAARRRGHHHHH,I was getting somewhere and the bloody editor crashed!

kevin

:(  - If you saved previously, there'll be an auto backup file saved with your project. The extesion is something like  ".~ba"  that's only if the last save was damaged in some way.  

Also, turn Case Correction OFF..

RaverDave

Bah,its getting messy,I dont know whats going on,yeh i have 2 balls bouncing using types,but no collision,when i change something it errors..its messy.might have to scrap it and start again

kevin

Whats the error ?..  and give us a look at what you've got..

RaverDave


; PROJECT : Project1
; AUTHOR  : raverdave
; CREATED : 02/01/2006
; EDITED  : 02/01/2006


;

OpenScreen 640,480,32,2
;SetFPS 0
Mouse Off
ScreenVsync On

Global PlayerX=50
Global PlayerY=430
Global PlayerWidth =10
Global PlayerHeight =10
Global Speed=4
Global currlev=1
Global maxlev=99
Global tilenum=0
Global MyMap = GetFreeMap()
CreateMap MyMap,99
Global mapx=0
Global mapy=0
Global TileWidth=32
Global TileHeight=16
Global Number_of_tiles = 9
Global XVelo#=-4
Global Yvelo#=-4
Global yspeed#=-4
Global xspeed#=-4
Global b
 Type tBall
       Status
       Xpos,Ypos
       SpeedX,SpeedY
       newx
       newy
 Image
 LifeTimer
 FlashToggle
 EndType

; create an array to house our list of balls
Dim Balls(1) As tBall



maketiles()


Repeat
testpos()
createnewlev()
Repeat
SetCursor 0,0
Cls 0
DrawMap MyMap,currlev,mapx,mapy

For b=0 To 1
Handle_player(balls(b).xpos,balls(b).ypos,PLayerWIdth,PlayerHeight,balls(b).speedx,MyMap,1)
Circle balls(b).xpos,balls(b).ypos,5,1
balls(b).ypos=balls(b).ypos+balls(b).speedy
If balls(b).ypos<=0
 balls(b).speedy=4
EndIf

If balls(b).ypos>=480
 balls(b).speedy=-4
EndIf
Next



X2=playerX+PlayerWidth
Y2=playerY+PlayerHeight
Ink RGB(0,0,0)
Ink RGB(255,255,255)

v=ScanCode()
If v=16
 quit=1
EndIf

SetCursor 40,0
Print tilenum

Sync
Until quit=1 Or tilenum<=0
Inc currlev
Until currlev>maxlev



Function Handle_player(playerx,playery,WIdth,Height,mSpeedx,ThisMap,ThisLevel)
; ==========================
; Handle Collision
; ===========================
If CheckMapImpact(thisMap,currlev,balls(b).xpos,balls(b).ypos,balls(b).NewX,balls(b).NewY,Width,Height)  

; If there was impact with the map, then read our
; new position back.
 balls(b).xpos=GetMapImpactX()
 balls(b).ypos=GetMapImpactY()

TileWidth=GetMapBlockWidth(ThisMap)
TileHeight=GetMapBlockHeight(ThisMap)

TileX=balls(b).xpos/TileWidth  
TileY=balls(b).ypos/Tileheight
If GetMapImpactLeft()
    Print "Impact occured on the LEFT side"  
hit=1
If (TileX-1)>-1
  For  lp=TileY To (balls(b).ypos+HEight-1)/TileHeight
  If PeekLevelTile(ThisMap,currlev,TileX-1,lp)<>0
   PokeLevelTile ThisMap,currlev,TileX-1,lp,0
    Dec tilenum
   EndIf
  Next

EndIf

 EndIf


     
 If GetMapImpactRight()
      Print "Impact occured on the RIGHT side"  
hit=1
; Kill Tile to the left of our position
If (TileX+1)=<GetLevelWidth(ThisMap,ThisLevel)

; Loop down the right edge of the players ball
  For  lp=TileY To (balls(b).ypos+HEight-1)/TileHeight
    If PeekLevelTile(ThisMap,currlev,TileX+1,lp)<>0
   PokeLevelTile ThisMap,currlev,TileX+1,lp,0
    Dec tilenum
  EndIf
  Next
EndIf

 EndIf

If GetMapImpactTop()
   Print "Impact occured on the TOP side"  
hit=1
; Kill Tile to the left of our position
If (TileY-1)>-1
Print "ahahhaa"
 For  Xlp=TileX To (balls(b).xpos+Width-1)/TileWidth
  If PeekLevelTile(ThisMap,currlev,xlp,TileY-1)<>0
    PokeLevelTile ThisMap,currlev,xlp,TileY-1,0
    Dec tilenum
    Print "ahahhaa"
    balls(b).speedy=4
   EndIf
 Next
EndIf

EndIf

If GetMapImpactBot()
   Print "Impact occured on the Bottom side"
    hit=1
If (TileY+1)=<GetLevelHeight(ThisMap,ThisLevel)

 For  Xlp=TileX To (balls(b).xpos+Width-1)/TileWidth
  If PeekLevelTile(ThisMap,currlev,Xlp,TileY+1)<>0
   PokeLevelTile ThisMap,currlev,Xlp,TileY+1,0
  Dec tilenum
  balls(b).speedy=-4
  EndIf
 Next
EndIf

EndIf
Else
; No Collision, Then set the current players
; position to it's new position
;balls(b).xpos=balls(b).NewX
;balls(b).ypos=balls(b).Newy
   
EndIf

EndFunction

Function maketiles()


; Loop through and draw a series of randomly coloured Boxes to the screen
For lp=1 To Number_of_tiles
 xpos=lp*tileWidth
 r=Rnd(255)
 g=Rnd(255)
 b=Rnd(255)  
 BoxC Xpos,0,Xpos+TileWidth,TileHeight,1,RGB(r,g,b)
 col=RGB(r,g,b)
 c1=RGBFade(Col,100.0)
 ShadeBox xpos+1,ypos+1,Xpos+Tilewidth-1,Ypos+Tileheight-2,c1,c1,c2,c2  
Next
; Grab the box graphics that we've just drawn as image.
TempImage=GetFreeImage()
GetImage TempImage,0,0,xpos+TIleWidth,Tileheight
MakeMapGFX MyMAP,TempImage,TileWidth,TileHeight,Number_Of_Tiles,RGB(0,0,0)


EndFunction

Function createnewlev()
tilenum=0
If currlev>1
reset()
Restore 0
currlev=1
PlayerX=50
 PlayerY=430
EndIf

CreateLevel MyMap,currlev, 100,100
For Ylp=0 To 14
 For Xlp=0 To 12
  t=ReadData()
   If t>0
   tilenum=tilenum+1
  PokeLevelTile MyMap,currlev,Xlp,ylp,t
EndIf
 Next xlp
Next ylp
EndFunction

Function reset()
XVelo#=-4
Yvelo#=-4
yspeed#=-4
xspeed#=-4
PlayerX=50
 PlayerY=430
EndFunction



Function testpos()
balls(0).xpos=Rnd(320)
balls(0).ypos=400
balls(0).speedy=-4

balls(1).xpos=Rnd(320)
balls(1).ypos=400
balls(1).speedy=-4

EndFunction

Function dump()

EndFunction




Rem levels data

Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,1,2,0,0,0,0,0,0,0,0,0,0
Data 0,1,2,3,0,0,0,0,0,0,0,0,0
Data 0,1,2,3,0,0,0,0,0,0,0,0,0
Data 0,1,2,3,4,0,0,0,0,0,0,0,0
Data 0,1,2,3,4,0,0,0,0,0,0,0,0
Data 0,1,2,3,4,5,0,0,0,0,0,0,0
Data 0,1,2,3,4,5,6,0,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,8,8,8,8,8

Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0

RaverDave

#21
i tried changing:

Function Handle_player(playerx,playery,WIdth,Height,mSpeedx,ThisMap,ThisLevel)

to

Function Handle_player(balls(B).xpos,balls(B).ypos,WIdth,Height,mSpeedx,ThisMap,ThisLevel)

RaverDave

It was out of pure desperation, as i was modifying it all for the types


Well anyhow its getting too mesyy

kevin

Well In the case of Ball objects movement.rebound, we really should stream line it a bit better..  

I'll try and replace the existing rebound/coliison code and we'll see what we get..

RaverDave

Oh man your too kind,if you could rem it alot also..I will be even more grateful!!


What I might do also is look into playbasics file handling and stuff, coz rather than bang in a load of data levels(pretty daunting) I might write a small editor! then save and load the levels in some sorta data format!
I have done this before with blitz basic and darkbasic pro so i dont expect too many problems(ahem)

kevin

#25
QuoteWhat I might do also is look into playbasics file handling and stuff, coz rather than bang in a load of data levels(pretty daunting) I might write a small editor

Good IDEA ! as I was going to bring that up sooner or later :)

kevin

#26
OK, Here's a bit of an edit.   Basically Since each balls info is stored within the TYPE array, we can just pass our new move_ball function the INdex of the Ball we wish to move, then do the movement calc/collision occur inside this function.  So we don't have to pass it a load of values, for no real reason.   Which is a bit cleaner code wise.  But all in all it pretty much does the same thing as before.  

I've made a few tiny change you can build upon, one is storing the Balls Width & Height In the balls() array.  Which will allow you (in the future, with a bit of tweaking) to build a version that can balls of various sizes...  





OpenScreen 640,480,32,2

;SetFPS 0
Mouse Off
ScreenVsync On

Global PlayerX=50
Global PlayerY=430
Global PlayerWidth =10
Global PlayerHeight =10
Global Speed=4
Global currlev=1
Global maxlev=99
Global tilenum=0
Global MyMap = GetFreeMap()
CreateMap MyMap,99

Global mapx=0
Global mapy=0
Global TileWidth=32
Global TileHeight=16
Global Number_of_tiles = 9
Global XVelo#=-4
Global Yvelo#=-4
Global yspeed#=-4
Global xspeed#=-4
Global b

Type tBall
      Status
      Xpos,Ypos
    Width,Height
      SpeedX,SpeedY
      newx
      newy
  Image
  LifeTimer
  FlashToggle
EndType

; create an array to house our list of balls
Dim Balls(1) As tBall



maketiles()


Repeat

; CReate the test Balls
testpos()

createnewlev()

Repeat
SetCursor 0,0
Cls 0
DrawMap MyMap,currlev,mapx,mapy


; loop through our list of balls
For b=0 To 1


 ; Call the MOve Ball function.

 ; This function steps the ball forward (along it's X+ Y speeds)
  ;and handles collision and rebound stuff all in one hit  

 Move_Ball(b,MyMap,1)


 ; After it's Moved, we draw the ball  
Circle balls(b).xpos,balls(b).ypos,5,1


; check if balls is leaving the screen along the Y axis, if it does, just flip the Y speed
If balls(b).ypos<=0
  balls(b).speedy=4
EndIf

If balls(b).ypos>=480
 balls(b).speedy=-4
EndIf


; check if balls is leaving the screen along the X axis, if it does, just flip the X speed
If balls(b).xpos<=0
  balls(b).speedx=4
EndIf

If balls(b).xpos>=640
 balls(b).speedx=-4
EndIf


Next





v=ScanCode()
If v=16
quit=1
EndIf


SetCursor 40,0
Ink RGB(255,255,255)
Print tilenum


Sync
Until quit=1 Or tilenum<=0
Inc currlev
Until currlev>maxlev













Function Move_Ball(ThisBall,ThisMap,ThisLevel)


; Calc the New  X & Y positions of the ball....

NewX =Balls(ThisBall).Xpos  +  Balls(ThisBall).SpeedX
NewY =Balls(ThisBall).Ypos  +   Balls(ThisBall).SpeedY

; Get the WIDTH and HEIGHT OF our ball.  
; While At the moment this might be a bit of extra overkill, in the future
; you might decide that the balls can be different sizes.  
  Width = Balls(ThisBall).width
  Height= Balls(ThisBall).Height
   

; ==============================================================
; Collision -Check If this Movement will hit the Level
; ===========================================================
If CheckMapImpact(ThisMap,ThisLevel,balls(b).xpos,balls(b).ypos,NewX,NEwY,Width,Height)  

; If there was impact with the map, then read our
; new position back.
 NewX=GetMapImpactX()
 NewY=GetMapImpactY()

TileWidth=GetMapBlockWidth(ThisMap)
TileHeight=GetMapBlockHeight(ThisMap)

TileX=NewX/TileWidth  
TileY=NewY/Tileheight

 If GetMapImpactLeft()
    Print "Impact occured on the LEFT side"  
 If (TileX-1)>-1
   For  lp=TileY To (NewY+HEight-1)/TileHeight
    If PeekLevelTile(ThisMap,ThisLevel,TileX-1,lp)<>0
      PokeLevelTile ThisMap,ThisLevel,TileX-1,lp,0
       Dec tilenum
       balls(ThisBall).speedX=4
     EndIf
   Next
 EndIf
 EndIf


   
If GetMapImpactRight()
     Print "Impact occured on the RIGHT side"  
; Kill Tile to the left of our position
If (TileX+1)=<GetLevelWidth(ThisMap,ThisLevel)

; Loop down the right edge of the players ball
 For  lp=TileY To (NewY+HEight-1)/TileHeight
   If PeekLevelTile(ThisMap,ThisLevel,TileX+1,lp)<>0
    PokeLevelTile ThisMap,ThisLevel,TileX+1,lp,0
     Dec tilenum
     balls(ThisBall).speedX=-4
  EndIf
 Next
EndIf

EndIf

If GetMapImpactTop()
  Print "Impact occured on the TOP side"  

; Kill Tile to the left of our position
If (TileY-1)>-1
For  Xlp=TileX To (NewX+Width-1)/TileWidth
 If PeekLevelTile(ThisMap,ThisLevel,xlp,TileY-1)<>0
   PokeLevelTile ThisMap,ThisLevel,xlp,TileY-1,0
   Dec tilenum
   balls(ThisBall).speedy=4
  EndIf
Next
EndIf

EndIf


If GetMapImpactBot()
   Print "Impact occured on the Bottom side"

 If (TileY+1)=<GetLevelHeight(ThisMap,ThisLevel)

   For  Xlp=TileX To (NewX+Width-1)/TileWidth
    If PeekLevelTile(ThisMap,ThisLevel,Xlp,TileY+1)<>0
      PokeLevelTile ThisMap,ThisLevel,Xlp,TileY+1,0
     Dec tilenum
     balls(ThisBall).speedy=-4
    EndIf
   Next
 EndIf

 EndIf
EndIf

;  Set the balls New Position

balls(ThisBall).xpos=NewX
balls(ThisBall).ypos=NewY


EndFunction








Function maketiles()
; Loop through and draw a series of randomly coloured Boxes to the screen
For lp=1 To Number_of_tiles
  xpos=lp*tileWidth
  r=Rnd(255)
  g=Rnd(255)
  b=Rnd(255)  
  BoxC Xpos,0,Xpos+TileWidth,TileHeight,1,RGB(r,g,b)
  col=RGB(r,g,b)
  c1=RGBFade(Col,100.0)
  ShadeBox xpos+1,ypos+1,Xpos+Tilewidth-1,Ypos+Tileheight-2,c1,c1,c2,c2  
Next
; Grab the box graphics that we've just drawn as image.
TempImage=GetFreeImage()
GetImage TempImage,0,0,xpos+TIleWidth,Tileheight
MakeMapGFX MyMAP,TempImage,TileWidth,TileHeight,Number_Of_Tiles,RGB(0,0,0)

EndFunction




Function createnewlev()
tilenum=0
If currlev>1
reset()
Restore 0
currlev=1
PlayerX=50
PlayerY=430
EndIf

CreateLevel MyMap,currlev, 100,100
For Ylp=0 To 14
For Xlp=0 To 12
 t=ReadData()
  If t>0
  tilenum=tilenum+1
 PokeLevelTile MyMap,currlev,Xlp,ylp,t
EndIf
Next xlp
Next ylp
EndFunction

Function reset()
XVelo#=-4
Yvelo#=-4
yspeed#=-4
xspeed#=-4
PlayerX=50
PlayerY=430
EndFunction



Function testpos()
; Init Ball zero
balls(0).xpos=Rnd(320)
balls(0).ypos=400
balls(0).speedx=-4
balls(0).speedy=-4
balls(0).Width=PlayerWidth
balls(0).Height=PlayerHeight


; Init Ball 1
balls(1).xpos=Rnd(320)
balls(1).ypos=400
balls(1).speedx=4
balls(1).speedy=-4
balls(1).Width=PlayerWidth
balls(1).Height=PlayerHeight

EndFunction

Function dump()

EndFunction




Rem levels data

Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,1,2,0,0,0,0,0,0,0,0,0,0
Data 0,1,2,3,0,0,0,0,0,0,0,0,0
Data 0,1,2,3,0,0,0,0,0,0,0,0,0
Data 0,1,2,3,4,0,0,0,0,0,0,0,0
Data 0,1,2,3,4,0,0,0,0,0,0,0,0
Data 0,1,2,3,4,5,0,0,0,0,0,0,0
Data 0,1,2,3,4,5,6,0,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,8,8,8,8,8

Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0



RaverDave


; PROJECT : Project1
; AUTHOR  : raverdave
; CREATED : 02/01/2006
; EDITED  : 02/01/2006

OpenScreen 640,480,32,2

;SetFPS 0
Mouse Off
ScreenVsync On

Global PlayerX=50
Global PlayerY=430
Global PlayerWidth =10
Global PlayerHeight =10
Global Speed=4
Global currlev=1
Global maxlev=99
Global tilenum=0
Global MyMap = GetFreeMap()
CreateMap MyMap,99

Global mapx=0
Global mapy=0
Global TileWidth=32
Global TileHeight=16
Global Number_of_tiles = 9
Global XVelo#=-4
Global Yvelo#=-4
Global yspeed#=-4
Global xspeed#=-4
Global b
Global numofballs=1
Global maxballs=5
Type tBall
     Status
     Xpos,Ypos
   Width,Height
     SpeedX,SpeedY
     newx
     newy
 Image
 LifeTimer
 FlashToggle
EndType

; create an array to house our list of balls
Dim Balls(maxballs) As tBall



maketiles()


Repeat

; CReate the test Balls
testpos()

createnewlev()

Repeat
SetCursor 0,0
Cls 0
DrawMap MyMap,currlev,mapx,mapy


; loop through our list of balls
For b=0 To numofballs


; Call the MOve Ball function.

; This function steps the ball forward (along it's X+ Y speeds)
;and handles collision and rebound stuff all in one hit  

Move_Ball(b,MyMap,1)


; After it's Moved, we draw the ball  
Circle balls(b).xpos,balls(b).ypos,5,1


; check if balls is leaving the screen along the Y axis, if it does, just flip the Y speed
If balls(b).ypos<=0
 balls(b).speedy=4
EndIf

If balls(b).ypos>=480
balls(b).speedy=-4
EndIf


; check if balls is leaving the screen along the X axis, if it does, just flip the X speed
If balls(b).xpos<=0
 balls(b).speedx=4
EndIf

If balls(b).xpos>=640
balls(b).speedx=-4
EndIf

Next
If v=30 And numofballs<maxballs
newball()
EndIf


v=ScanCode()
If v=16
quit=1
EndIf


SetCursor 40,0
Ink RGB(255,255,255)
Print tilenum


Sync
Until quit=1 Or tilenum<=0
Inc currlev
Until currlev>maxlev

Function Move_Ball(ThisBall,ThisMap,ThisLevel)


; Calc the New  X & Y positions of the ball....

NewX =Balls(ThisBall).Xpos  +  Balls(ThisBall).SpeedX
NewY =Balls(ThisBall).Ypos  +   Balls(ThisBall).SpeedY

; Get the WIDTH and HEIGHT OF our ball.  
; While At the moment this might be a bit of extra overkill, in the future
; you might decide that the balls can be different sizes.  
 Width = Balls(ThisBall).width
 Height= Balls(ThisBall).Height
 

; ==============================================================
; Collision -Check If this Movement will hit the Level
; ===========================================================
If CheckMapImpact(ThisMap,ThisLevel,balls(b).xpos,balls(b).ypos,NewX,NEwY,Width,Height)  

; If there was impact with the map, then read our
; new position back.
NewX=GetMapImpactX()
NewY=GetMapImpactY()

TileWidth=GetMapBlockWidth(ThisMap)
TileHeight=GetMapBlockHeight(ThisMap)

TileX=NewX/TileWidth  
TileY=NewY/Tileheight

If GetMapImpactLeft()
   Print "Impact occured on the LEFT side"  
If (TileX-1)>-1
  For  lp=TileY To (NewY+HEight-1)/TileHeight
   If PeekLevelTile(ThisMap,ThisLevel,TileX-1,lp)<>0
     PokeLevelTile ThisMap,ThisLevel,TileX-1,lp,0
      Dec tilenum
      balls(ThisBall).speedX=4
    EndIf
  Next
EndIf
EndIf


 
If GetMapImpactRight()
    Print "Impact occured on the RIGHT side"  
; Kill Tile to the left of our position
If (TileX+1)=<GetLevelWidth(ThisMap,ThisLevel)

; Loop down the right edge of the players ball
For  lp=TileY To (NewY+HEight-1)/TileHeight
  If PeekLevelTile(ThisMap,ThisLevel,TileX+1,lp)<>0
   PokeLevelTile ThisMap,ThisLevel,TileX+1,lp,0
    Dec tilenum
    balls(ThisBall).speedX=-4
 EndIf
Next
EndIf

EndIf

If GetMapImpactTop()
 Print "Impact occured on the TOP side"  

; Kill Tile to the left of our position
If (TileY-1)>-1
For  Xlp=TileX To (NewX+Width-1)/TileWidth
If PeekLevelTile(ThisMap,ThisLevel,xlp,TileY-1)<>0
  PokeLevelTile ThisMap,ThisLevel,xlp,TileY-1,0
  Dec tilenum
  balls(ThisBall).speedy=4
 EndIf
Next
EndIf

EndIf


If GetMapImpactBot()
  Print "Impact occured on the Bottom side"

If (TileY+1)=<GetLevelHeight(ThisMap,ThisLevel)

  For  Xlp=TileX To (NewX+Width-1)/TileWidth
   If PeekLevelTile(ThisMap,ThisLevel,Xlp,TileY+1)<>0
     PokeLevelTile ThisMap,ThisLevel,Xlp,TileY+1,0
    Dec tilenum
    balls(ThisBall).speedy=-4
   EndIf
  Next
EndIf

EndIf
EndIf

;  Set the balls New Position

balls(ThisBall).xpos=NewX
balls(ThisBall).ypos=NewY


EndFunction

Function maketiles()
; Loop through and draw a series of randomly coloured Boxes to the screen
For lp=1 To Number_of_tiles
 xpos=lp*tileWidth
 r=Rnd(255)
 g=Rnd(255)
 b=Rnd(255)  
 BoxC Xpos,0,Xpos+TileWidth,TileHeight,1,RGB(r,g,b)
 col=RGB(r,g,b)
 c1=RGBFade(Col,100.0)
 ShadeBox xpos+1,ypos+1,Xpos+Tilewidth-1,Ypos+Tileheight-2,c1,c1,c2,c2  
Next
; Grab the box graphics that we've just drawn as image.
TempImage=GetFreeImage()
GetImage TempImage,0,0,xpos+TIleWidth,Tileheight
MakeMapGFX MyMAP,TempImage,TileWidth,TileHeight,Number_Of_Tiles,RGB(0,0,0)

EndFunction

Function createnewlev()
tilenum=0
If currlev>1
reset()
Restore 0
currlev=1
PlayerX=50
PlayerY=430
EndIf

CreateLevel MyMap,currlev, 100,100
For Ylp=0 To 14
For Xlp=0 To 12
t=ReadData()
 If t>0
 tilenum=tilenum+1
PokeLevelTile MyMap,currlev,Xlp,ylp,t
EndIf
Next xlp
Next ylp
EndFunction

Function reset()
XVelo#=-4
Yvelo#=-4
yspeed#=-4
xspeed#=-4
PlayerX=50
PlayerY=430
EndFunction

Function testpos()
; Init Ball zero
balls(0).xpos=Rnd(320)
balls(0).ypos=400
balls(0).speedx=-4
balls(0).speedy=-4
balls(0).Width=PlayerWidth
balls(0).Height=PlayerHeight


; Init Ball 1
balls(1).xpos=Rnd(320)
balls(1).ypos=400
balls(1).speedx=4
balls(1).speedy=-4
balls(1).Width=PlayerWidth
balls(1).Height=PlayerHeight

EndFunction

Function dump()

EndFunction

Function newball()
Inc numofballs
balls(numofballs).xpos=320
balls(numofballs).ypos=400
balls(numofballs).speedx=-4
balls(numofballs).speedy=-4
EndFunction



Rem levels data

Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,1,2,0,0,0,0,0,0,0,0,0,0
Data 0,1,2,3,0,0,0,0,0,0,0,0,0
Data 0,1,2,3,0,0,0,0,0,0,0,0,0
Data 0,1,2,3,4,0,0,0,0,0,0,0,0
Data 0,1,2,3,4,0,0,0,0,0,0,0,0
Data 0,1,2,3,4,5,0,0,0,0,0,0,0
Data 0,1,2,3,4,5,6,0,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,0,0,0,0,0
Data 0,1,2,3,4,5,6,7,8,8,8,8,8

Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,1,0,0,0,0,0,0,0,0,0


RaverDave

try this code, press a during play,it seems to not pick up collisions correctly with a few bouncing around!! :D

kevin

You have to assign each ball a size...

ie.


Function newball()
Inc numofballs
balls(numofballs).xpos=320
balls(numofballs).ypos=400
balls(numofballs).speedx=-4
balls(numofballs).speedy=-4
balls(numofballs).Width=PlayerWidth
balls(numofballs).Height=PlayerHeight
EndFunction