#include <helianthus.h>
#include "phisics.h"
static Sprite ball, brick1, brick2, brick3;
static Group edges;
static Group movement;
static Sound beep;
void phisicsInit() {
ball = createSpriteEx(200+1, 200+1, 64-2, 64-2, createAnimation("data/sprite/breadball.png"));
spriteSetColliderCircle(ball, 0, 0, -1);
spriteSetRotateToDirection(ball, TRUE);
brick1 = createSpriteEx(200-32, 200+64, 64, 64, createAnimation("data/sprite/bricks.png"));
spriteSetTintColor(brick1, colorByRGB(0, 0, 1));
spriteSetColliderRectangle(brick1, 0, 0, 0, -1, -1, 20);
spriteSetBounciness(brick1, 0.5);
spriteSetMassLevel(brick1, 1);
spriteSetDebug(brick1, TRUE);
brick2 = createSpriteEx(200+32+1, 200+64+1, 64-2, 64-2, createAnimation("data/sprite/bricks.png"));
spriteSetColliderRectangle(brick2, 0, 0, 0, -1, -1, 20);
spriteSetDebug(brick2, TRUE);
brick3 = createSpriteEx(200+32+64, 200+64, 64, 64, createAnimation("data/sprite/bricks.png"));
spriteSetTintColor(brick3, colorByRGBA(1, 0, 1, 0.5));
spriteSetColliderRectangle(brick3, 0, 0, 0, -1, -1, 20);
spriteSetBounciness(brick3, 2);
spriteSetMassLevel(brick3, 1);
movement = createGroup();
groupAdd(movement, ball);
groupAdd(movement, brick2);
edges = createEdgesGroup();
groupAdd(edges, brick1);
groupAdd(edges, brick3);
beep = createSound("data/sound/beep.ogg");
}
void phisicsDraw() {
double dt = windowGetFrameTime();
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);
int collision = FALSE;
if (groupCollideBetween(movement)) collision = TRUE;
if (groupCollideGroup(edges, movement)) collision = TRUE;
if (collision) soundPlay(beep, FALSE);
}