Hi alphabravoab,
I had a quick look at this and came up with a simple solution:
// Project: selfpong
// Created: 2015-11-06
// set window properties
SetWindowTitle( "selfpong" )
SetWindowSize( 1024, 1024, 0 )
// set display properties
SetVirtualResolution( 1024, 1024 )
SetOrientationAllowed( 1, 1, 1, 1 )
global ballx as integer
global bally as integer
global ballxdir as integer
global ballydir as integer
global x as integer
global y as integer
global reset as integer
global score as integer
global w as integer
global e as integer
ball_img =LoadImage("ball.png")
ball = CreateSprite(ball_img)
paddlesstanding=LoadImage("paddle2.png")
paddleslay=LoadImage("paddle1.png")
paddleN=CreateSprite(paddleslay)
paddleS=CreateSprite(paddleslay)
paddleE=CreateSprite(paddlesstanding)
paddleW=CreateSprite(paddlesstanding)
block_img =loadImage("brick.png")
block=createSprite(block_img)
SetSpriteSize(block,200,200)
SetSpritePositionByOffset(block,450,450)
x= GetPointerX()-65
y= GetPointerY()
score=0
ballx=512
bally=512
ballydir=5
ballxdir=4
do
SetSpritePositionByOffset(ball, ballx, bally)
ballx = ballx + ballxdir
bally = bally + ballydir
// this stop the ball going off the screen
if ballx < 0
ballx = 0
ballxdir = ballxdir*-1
endif
if ballx > 1000
ballx = 1000
ballxdir = ballxdir*-1
endif
if bally < 0
bally = 0
ballydir = ballydir*-1
endif
if bally > 1000
bally = 1000
ballydir = ballydir*-1
endif
SetSpritePosition(paddleN,x,0)
SetSpritePosition(paddleS,X,979)
SetSpritePosition(paddleE,979, y)
SetSpritePosition(paddleW,0, y)
if GetButtonPressed(1)
ballx=512
bally=512
score=0
endif
x= GetPointerX()
y= GetPointerY()
if GetSpriteCollision (paddleN,ball)=1
ballydir=10
score=score +10
endif
if GetSpriteCollision (paddleS,ball)=1
ballydir=-10
score=score +10
endif
if GetSpriteCollision (paddleE,ball)=1
ballxdir=-10
score=score +10
endif
if GetSpriteCollision (paddleW,ball)=1
ballxdir=10
score=score +10
endif
if GetSpriteCollision (block,ball)=1
// determine the difference in the x and y coordinates between the block and the ball
// the block is being position using it's offset - ie the centre of the sprite - to make the maths work correctly
diff_x = abs(w - ballx)
diff_y = abs(e - bally)
if diff_x = diff_y
// if they are equal then reverse both direction
ballxdir=-ballxdir
ballydir=-ballydir
else
if diff_x > diff_y
// if the x difference is smaller than the y difference then only change the x direction
ballxdir=-ballxdir
else
// if the y difference is smaller than the x difference then only change the y direction
ballydir=-ballydir
endif
endif
score=score+50
// you don't need to delete and recreate the block sprite (this can cause slow down if you're doing this with a lot of sprites)
// you just need to reposition it.
//DeleteSprite(block)
//block=createSprite(block_img)
repeat
// this repeat loop ensure that the block does not reposition itself on the ball
w=random(300,700)
e=Random2(300,700)
// the block is being positioned using the offset (ie the centre of the sprite) to make the maths when determine direction correction
setspritepositionByOffset(block, w,e)
until GetSpriteCollision (block,ball) = 0
endif
print (score)
Sync()
loop
When the ball hits the block the code compares the position of the ball to the position of the block and from this it can tell with the ball has hit the bottom/top of the block or the sides. If it hits the top/bottom then the y direction is reversed. If it hits the sides then the x direction is changed.
I also added a couple of other bits and pieces but the most important one is that the block sprite should not be deleted and recreated whilst the game is being played as this can slow the app down if you're using a lot of sprite or on an old device. In this case the block can simply be repositioned. If the blocks are being destroyed when the ball hits them then just position the block somewhere off the screen where it won't get bit by the ball: -1000,-1000 for example. This is a rather crude way of doing this but it'll work fine for what you're doing.