|
|
3f9996 |
|
|
|
833ed7 |
#include <helianthus.h></helianthus.h>
|
|
|
3f9996 |
|
|
|
a2530e |
Sprite ball, brick1, brick2, brick3;
|
|
|
f8c1ea |
Group edges;
|
|
|
f8c1ea |
Group movement;
|
|
|
09c823 |
Sound beep;
|
|
|
981405 |
|
|
|
3f9996 |
void init() {
|
|
|
981405 |
ball = createSpriteEx(200, 200, 64, 64);
|
|
|
09c823 |
spriteSetAnimation(ball, "data/sprite/breadball.png");
|
|
|
f8c1ea |
spriteSetColliderCircle(ball, 0, 0, -1);
|
|
|
f8c1ea |
spriteSetRotateToDirection(ball, TRUE);
|
|
|
a2530e |
|
|
|
981405 |
brick1 = createSpriteEx(200-32, 200+64, 64, 64);
|
|
|
09c823 |
spriteSetAnimation(brick1, "data/sprite/bricks.png");
|
|
|
650f35 |
spriteSetTintColor(brick1, rgb(0, 0, 1));
|
|
|
f8c1ea |
spriteSetColliderRectangle(brick1, 0, 0, 0, -1, -1, 20);
|
|
|
f8c1ea |
spriteSetBounciness(brick1, 0.5);
|
|
|
a2530e |
|
|
|
981405 |
brick2 = createSpriteEx(200+32, 200+64, 64, 64);
|
|
|
09c823 |
spriteSetAnimation(brick2, "data/sprite/bricks.png");
|
|
|
f8c1ea |
spriteSetColliderRectangle(brick2, 0, 0, 0, -1, -1, 20);
|
|
|
a2530e |
|
|
|
a2530e |
brick3 = createSpriteEx(200+32+64, 200+64, 64, 64);
|
|
|
a2530e |
spriteSetAnimation(brick3, "data/sprite/bricks.png");
|
|
|
a2530e |
spriteSetTintColor(brick3, rgba(1, 0, 1, 0.5));
|
|
|
a2530e |
spriteSetColliderRectangle(brick3, 0, 0, 0, -1, -1, 20);
|
|
|
a2530e |
spriteSetBounciness(brick3, 2);
|
|
|
a2530e |
|
|
|
f8c1ea |
movement = createGroup();
|
|
|
f8c1ea |
groupAdd(movement, ball);
|
|
|
f8c1ea |
groupAdd(movement, brick2);
|
|
|
a2530e |
|
|
|
f8c1ea |
edges = createEdgesGroup();
|
|
|
a2530e |
groupAdd(edges, brick1);
|
|
|
a2530e |
groupAdd(edges, brick3);
|
|
|
a2530e |
|
|
|
09c823 |
beep = createSound("data/sound/beep.ogg");
|
|
|
3f9996 |
}
|
|
|
3f9996 |
|
|
|
3f9996 |
void draw() {
|
|
|
981405 |
double dt = worldGetTimeStep();
|
|
|
f8c1ea |
double accel = 100;
|
|
|
a2530e |
|
|
|
f8c1ea |
double vx = spriteGetVelocityX(ball);
|
|
|
f8c1ea |
double vy = spriteGetVelocityY(ball);
|
|
|
f8c1ea |
if (keyDown("left")) spriteSetVelocityX(ball, vx - accel*dt);
|
|
|
f8c1ea |
if (keyDown("right")) spriteSetVelocityX(ball, vx + accel*dt);
|
|
|
f8c1ea |
if (keyDown("up")) spriteSetVelocityY(ball, vy - accel*dt);
|
|
|
f8c1ea |
if (keyDown("down")) spriteSetVelocityY(ball, vy + accel*dt);
|
|
|
a2530e |
|
|
|
09c823 |
if (mouseWentDown("left")) soundPlay(beep, FALSE);
|
|
|
5b96a1 |
if (mouseWentDown("middle")) {
|
|
|
5b96a1 |
char text[1000];
|
|
|
5b96a1 |
askTextEx("Test?", text, sizeof(text), TRUE, FALSE);
|
|
|
5b96a1 |
}
|
|
|
a2530e |
|
|
|
c1731e |
int collision = FALSE;
|
|
|
c1731e |
if (groupCollideBetween(movement, 1)) collision = TRUE;
|
|
|
c1731e |
if (groupPushGroup(edges, movement, 0.9)) collision = TRUE;
|
|
|
c1731e |
|
|
|
c1731e |
if (collision) soundPlay(beep, FALSE);
|
|
|
a2530e |
|
|
|
981405 |
drawSprites();
|
|
|
a2530e |
|
|
|
f8c1ea |
point(mouseX(), mouseY());
|
|
|
3f9996 |
}
|
|
|
3f9996 |
|
|
|
3f9996 |
int main() {
|
|
|
3f9996 |
worldSetInit(&init);
|
|
|
3f9996 |
worldSetDraw(&draw);
|
|
|
3f9996 |
worldRun();
|
|
|
a2530e |
return 0;
|
|
|
3f9996 |
}
|