SetVirtualResolution(800, 600)
SetClearColor(125, 125, 125)
backSpr = CreateSprite(0)
SetSpriteSize(backSpr, 400, 300)
SetSpriteColor(backSpr, 100, 100, 100, 255)
SetSpriteDepth(backSpr, 20)
backSpr = CloneSprite(backSpr)
SetSpritePosition(backSpr, 400, 300)
text1 = CreateText("no offset, sprite x:200, y:150")
SetTextSize(text1, 15)
SetTextAlignment(text1, 1)
SetTextPosition(text1, 200, 20)
sprite1 = CreateSprite(0)
SetSpriteSize(sprite1, 150, 150)
SetSpritePosition(sprite1, 200, 150)
text2 = CreateText("75/75 offset, x:600, y:150")
SetTextSize(text2, 15)
SetTextAlignment(text2, 1)
SetTextPosition(text2, 600, 20)
sprite2 = CloneSprite(sprite1)
SetSpriteOffset(sprite2, 75, 75)
SetSpritePosition(sprite2, 600, 150)
text3 = CreateText("75/75 offset, x:200, y:450 BY OFFSET")
SetTextSize(text3, 15)
SetTextAlignment(text3, 1)
SetTextPosition(text3, 200, 320)
sprite3 = CloneSprite(sprite1)
SetSpriteOffset(sprite3, 75, 75)
SetSpritePositionByOffset(sprite3, 200, 450)
do
Sync()
loop
// -----------------------------------------------------------
// Load ball object
// -----------------------------------------------------------
Function loadBall()
ball.sprite = CreateSprite (ball.image)
SetSpriteVisible(ball.sprite, FALSE)
ball.x# = SCREEN_WIDTH/2
ball.y# = SCREEN_HEIGHT/2 + 50
ball.xv# = INITIAL_VELOCITY_BALL_X;
ball.yv# = INITIAL_VELOCITY_BALL_Y;
ball.width = GetSpriteWidth(ball.sprite)
ball.height = GetSpriteHeight(ball.sprite)
ball.framewidth = ball.width / 3
SetSpriteOffSet(ball.sprite, ball.framewidth/2, ball.height/2)
SetSpriteAnimation(ball.sprite, 28, ball.height,3)
PlaySprite(ball.sprite, 5, 1, 1 , 2)
EndFunction
// -----------------------------------------------------------
// Render function
// -----------------------------------------------------------
Function render()
SetSpritePositionByOffSet(ball.sprite, ball.x#, ball.y#)
SetSpritePosition(player.sprite, player.x#, player.y#)
ShowLogs()
EndFunction
// -----------------------------------------------------------
// Ball movement handling
// -----------------------------------------------------------
Function HandleBallMove()
ball.x# = ball.x# + ball.xv#
ball.y# = ball.y# + ball.yv#
if ball.x# > (SCREEN_WIDTH-(ball.framewidth/2))
ball.x# = (SCREEN_WIDTH-(ball.framewidth/2))
ball.xv# = ball.xv# * -1
PlaySound(hit_sound)
Log(">>>>>> x,xoffset,ball.x = " + Str(GetSpriteX(ball.sprite)) + "," + Str(GetSpriteXByOffSet(ball.sprite)) + "," + Str(ball.x#))
else
if ball.x# < (ball.framewidth/2)
ball.x# = (ball.framewidth/2)
ball.xv# = ball.xv# * -1
PlaySound(hit_sound)
Log(">>>>>> x,xoffset,ball.x = " + Str(GetSpriteX(ball.sprite)) + "," + Str(GetSpriteXByOffSet(ball.sprite)) + "," + Str(ball.x#))
EndIf
EndIf
// Reaching the top means you made it!
if ball.y# < (ball.height/2)
gameState = 20
EndIf
End Function
SetSpritePositionByOffset( bla,bla,bla) Will automatically offset to the center of the sprite,
For example if the current offset is the center of the sprite this command will place the center of the sprite at the given coordinates.
*********
* ** *
* * * *
* * * *
* ** *
*********