#include <helianthus.h>
Sprite ball, brick1, brick2, brick3;
Group edges;
Group movement;
Sound beep;
void init() {
ball = createSpriteEx(200, 200, 64, 64);
spriteSetAnimation(ball, "data/sprite/breadball.png");
spriteSetColliderCircle(ball, 0, 0, -1);
spriteSetRotateToDirection(ball, TRUE);
brick1 = createSpriteEx(200-32, 200+64, 64, 64);
spriteSetAnimation(brick1, "data/sprite/bricks.png");
spriteSetTintColor(brick1, rgb(0, 0, 1));
spriteSetColliderRectangle(brick1, 0, 0, 0, -1, -1, 20);
spriteSetBounciness(brick1, 0.5);
brick2 = createSpriteEx(200+32, 200+64, 64, 64);
spriteSetAnimation(brick2, "data/sprite/bricks.png");
spriteSetColliderRectangle(brick2, 0, 0, 0, -1, -1, 20);
brick3 = createSpriteEx(200+32+64, 200+64, 64, 64);
spriteSetAnimation(brick3, "data/sprite/bricks.png");
spriteSetTintColor(brick3, rgba(1, 0, 1, 0.5));
spriteSetColliderRectangle(brick3, 0, 0, 0, -1, -1, 20);
spriteSetBounciness(brick3, 2);
movement = createGroup();
groupAdd(movement, ball);
groupAdd(movement, brick2);
edges = createEdgesGroup();
groupAdd(edges, brick1);
groupAdd(edges, brick3);
beep = createSound("data/sound/beep.ogg");
}
void draw() {
double dt = worldGetTimeStep();
double accel = 100;
double vx = spriteGetVelocityX(ball);
double vy = spriteGetVelocityY(ball);
if (keyDown("left")) spriteSetVelocityX(ball, vx - accel*dt);
if (keyDown("right")) spriteSetVelocityX(ball, vx + accel*dt);
if (keyDown("up")) spriteSetVelocityY(ball, vy - accel*dt);
if (keyDown("down")) spriteSetVelocityY(ball, vy + accel*dt);
if (mouseWentDown("left")) soundPlay(beep, FALSE);
int collision = FALSE;
if (groupCollideBetween(movement, 1)) collision = TRUE;
if (groupPushGroup(edges, movement, 0.9)) collision = TRUE;
if (collision) soundPlay(beep, FALSE);
drawSprites();
point(mouseX(), mouseY());
}
int main() {
worldSetInit(&init);
worldSetDraw(&draw);
worldRun();
return 0;
}