
-----------------------------------
18729
Mon Sep 25, 2006 9:43 pm

Need Help with Collision
-----------------------------------
can someone help me with my collision in my asteroids game. the rocks explode even when its not touching the ship. it explodes a few pixels away only on the left side thouhg....not on the right

setscreen ("graphics:640;480,nocursor")
var shippic : int := Pic.FileNew ("Spaceship.bmp")
var rock1pic : int := Pic.FileNew ("Rock1.bmp")
var rock2pic : int := Pic.FileNew ("Rock2.bmp")
var rock3pic : int := Pic.FileNew ("Rock3.bmp")
var rock4pic : int := Pic.FileNew("Rock4.bmp")
var rock5pic : int := Pic.FileNew("Rock5.bmp")
var boompic : int := Pic.FileNew("Boom.bmp")
var laserpic : int := Pic.FileNew ("Laser.bmp")
var shipxcenter : int := 290
var shipycenter : int := 0
var rock1xcenter : int := Rand.Int (10, 630)
var rock1ycenter : int := maxy + 20
var rock2xcenter : int := Rand.Int (10, 630)
var rock2ycenter : int := maxy + 20
var rock3xcenter : int := Rand.Int (10, 630)
var rock3ycenter : int := maxy + 20
var rock4xcenter : int := Rand.Int (10,630)
var rock4ycenter : int := maxy + 20
var rock5xcenter : int := Rand.Int (10,630)
var rock5ycenter : int := maxy + 20
var boomxcenter : int := 0
var boomycenter : int := 0 
var laserxcenter : int :=-10
var laserycenter : int :=-10
var shoot: boolean :=false
var chars : array char of boolean
var key : string(1):=""
var speedofship : int := 10
var font1 : int := Font.New ("comicsans:12")
var score : int := 0
var lives : int := 3
procedure DrawShip (x, y : int)
    Pic.Draw (shippic, x, y, picMerge)
end DrawShip
procedure DrawRock (x, y ,rockpic: int)
    Pic.Draw (rockpic, x, y, picMerge)
end DrawRock
procedure DrawBoom(x,y :int)
    Pic.Draw(boompic,x,y,picMerge)
    end DrawBoom
procedure DrawLaser (x, y : int)
    Pic.Draw (laserpic, x, y, picMerge)
end DrawLaser
 DrawShip (shipxcenter, shipycenter)
 procedure Collision(X1:int,Y1:int,var X2:int,var Y2:int,pic1:int,pic2:int)
  if X1+Pic.Width(pic1)/2>X2-Pic.Width(pic2)/2 and X1-Pic.Width(pic1)/2Y2-Pic.Width(pic2)/2 and Y1-Pic.Width(pic1)/2=maxy+10 then
   laserxcenter:=-10
   laserycenter:=-10
   shoot:=false
   end if
    if chars (KEY_UP_ARROW) then
        shipycenter := shipycenter + speedofship
    end if
    if chars (KEY_RIGHT_ARROW) then
        shipxcenter := shipxcenter + speedofship
    end if
    if chars (KEY_LEFT_ARROW) then
        shipxcenter := shipxcenter - speedofship
    end if
    if chars (KEY_DOWN_ARROW) then
        shipycenter := shipycenter - speedofship
    end if
    DrawShip (shipxcenter, shipycenter)
    if shipxcenter = maxx - Pic.Width (shippic) then
        shipxcenter := maxx - Pic.Width (shippic)
    end if
    if shipycenter = maxy - Pic.Height (shippic) then
        shipycenter := maxy - Pic.Height (shippic)
    end if
    DrawRock (rock1xcenter, rock1ycenter,rock1pic)
    rock1ycenter := rock1ycenter - 1
    if rock1ycenter 