Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/pebble-mario.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Dzyubenko <shadone@gmail.com>2013-04-14 23:36:09 +0400
committerDenis Dzyubenko <shadone@gmail.com>2013-04-15 00:21:16 +0400
commitb347f2705b1416d9b8b1ad26519d2bd1d38b45da (patch)
treeb47b474824c732a88d507e13ad9c697ba1a0ed90
parent9d5f4485923c78253915ee746e1ef92490d5a2e9 (diff)
Add jump animation
-rw-r--r--resources/src/images/block.pngbin222 -> 0 bytes
-rw-r--r--resources/src/resource_map.json7
-rw-r--r--src/pebble-mario.c173
3 files changed, 153 insertions, 27 deletions
diff --git a/resources/src/images/block.png b/resources/src/images/block.png
deleted file mode 100644
index 523ccdc..0000000
--- a/resources/src/images/block.png
+++ /dev/null
Binary files differ
diff --git a/resources/src/resource_map.json b/resources/src/resource_map.json
index 0f0ddae..889c734 100644
--- a/resources/src/resource_map.json
+++ b/resources/src/resource_map.json
@@ -11,11 +11,6 @@
"type":"png",
"defName":"IMAGE_MARIO_JUMP",
"file":"images/mario-jump.png"
- },
- {
- "type":"png",
- "defName":"IMAGE_BLOCK",
- "file":"images/block.png"
- }
+ }
]
}
diff --git a/src/pebble-mario.c b/src/pebble-mario.c
index a13787a..626415b 100644
--- a/src/pebble-mario.c
+++ b/src/pebble-mario.c
@@ -38,28 +38,79 @@ TextLayer text_minute_layer;
static char hour_text[] = "00";
static char minute_text[] = "00";
-GRect blocks_rect;
-GRect mario_rect;
+GRect blocks_down_rect;
+GRect blocks_up_rect;
+GRect mario_down_rect;
+GRect mario_up_rect;
+
+static int mario_is_down = 1;
-BmpContainer block_bmp;
BmpContainer mario_normal_bmp;
BmpContainer mario_jump_bmp;
+PropertyAnimation mario_animation_beg;
+PropertyAnimation mario_animation_end;
+
+PropertyAnimation block_animation_beg;
+PropertyAnimation block_animation_end;
+
+#define BLOCK_SIZE 50
+#define MARIO_JUMP_DURATION 50
+
+void draw_block(GContext *ctx, GRect rect, uint8_t width)
+{
+ GPoint p1;
+ GPoint p2;
+
+ int16_t x = rect.origin.x;
+ int16_t y = rect.origin.y;
+ int16_t w = rect.size.w;
+ int16_t h = rect.size.h;
+
+ for (; width != 0; --width) {
+ // top
+ p1 = GPoint(x, y);
+ p2 = GPoint(x + w, y);
+ graphics_draw_line(ctx, p1, p2);
+
+ // left
+ p1 = GPoint(x, y);
+ p2 = GPoint(x, y + h);
+ graphics_draw_line(ctx, p1, p2);
+
+ // right
+ p1 = GPoint(x + w, y);
+ p2 = GPoint(x + w, y + h);
+ graphics_draw_line(ctx, p1, p2);
+
+ // bottom
+ p1 = GPoint(x, y + h);
+ p2 = GPoint(x + w, y + h);
+ graphics_draw_line(ctx, p1, p2);
+
+ x += 1;
+ y += 1;
+ w -= 2;
+ h -= 2;
+ }
+}
+
void blocks_update_callback(Layer *layer, GContext *ctx)
{
(void)layer;
(void)ctx;
- GRect destination = layer_get_frame(&block_bmp.layer.layer);
-
- destination.origin.x = 0;
- destination.origin.y = 0;
-
- graphics_draw_bitmap_in_rect(ctx, &block_bmp.bmp, destination);
+ GRect rect;
- destination.origin.x = destination.size.w;
+ rect = GRect(layer->bounds.origin.x, layer->bounds.origin.y,
+ BLOCK_SIZE - 1, layer->frame.size.h - 1);
+ graphics_context_set_stroke_color(ctx, GColorBlack);
+ draw_block(ctx, rect, 5);
- graphics_draw_bitmap_in_rect(ctx, &block_bmp.bmp, destination);
+ rect = GRect(layer->bounds.origin.x + BLOCK_SIZE, layer->bounds.origin.y,
+ BLOCK_SIZE - 1, layer->frame.size.h - 1);
+ graphics_context_set_stroke_color(ctx, GColorBlack);
+ draw_block(ctx, rect, 5);
}
void mario_update_callback(Layer *layer, GContext *ctx)
@@ -67,12 +118,14 @@ void mario_update_callback(Layer *layer, GContext *ctx)
(void)layer;
(void)ctx;
- GRect destination = layer_get_frame(&mario_normal_bmp.layer.layer);
+ BmpContainer *bmp = mario_is_down ? &mario_normal_bmp : &mario_jump_bmp;
+
+ GRect destination = layer_get_frame(&bmp->layer.layer);
destination.origin.x = 0;
destination.origin.y = 0;
- graphics_draw_bitmap_in_rect(ctx, &mario_normal_bmp.bmp, destination);
+ graphics_draw_bitmap_in_rect(ctx, &bmp->bmp, destination);
}
void handle_init(AppContextRef ctx)
@@ -84,11 +137,13 @@ void handle_init(AppContextRef ctx)
resource_init_current_app(&APP_RESOURCES);
- blocks_rect = GRect(22, 10, 100, 50);
- mario_rect = GRect(32, 70, 80, 80);
+ blocks_down_rect = GRect(22, 7, BLOCK_SIZE*2, BLOCK_SIZE);
+ blocks_up_rect = GRect(22, 2, BLOCK_SIZE*2, BLOCK_SIZE-10);
+ mario_down_rect = GRect(32, 70, 80, 80);
+ mario_up_rect = GRect(32, 42, 80, 80);
- layer_init(&blocks_layer, blocks_rect);
- layer_init(&mario_layer, mario_rect);
+ layer_init(&blocks_layer, blocks_down_rect);
+ layer_init(&mario_layer, mario_down_rect);
blocks_layer.update_proc = &blocks_update_callback;
mario_layer.update_proc = &mario_update_callback;
@@ -112,7 +167,6 @@ void handle_init(AppContextRef ctx)
// text_layer_set_font(&text_minute_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT)));
layer_add_child(&blocks_layer, &text_minute_layer.layer);
- bmp_init_container(RESOURCE_ID_IMAGE_BLOCK, &block_bmp);
bmp_init_container(RESOURCE_ID_IMAGE_MARIO_NORMAL, &mario_normal_bmp);
bmp_init_container(RESOURCE_ID_IMAGE_MARIO_JUMP, &mario_jump_bmp);
}
@@ -121,13 +175,90 @@ void handle_deinit(AppContextRef ctx)
{
(void)ctx;
- bmp_deinit_container(&block_bmp);
bmp_deinit_container(&mario_normal_bmp);
bmp_deinit_container(&mario_jump_bmp);
}
+void mario_down_animation_started(Animation *animation, void *data)
+{
+ (void)animation;
+ (void)data;
+}
+
+void mario_down_animation_stopped(Animation *animation, void *data)
+{
+ (void)animation;
+ (void)data;
+ mario_is_down = 1;
+ layer_mark_dirty(&mario_layer);
+}
+
+void mario_jump_animation_started(Animation *animation, void *data)
+{
+ (void)animation;
+ (void)data;
+ mario_is_down = 0;
+ layer_mark_dirty(&mario_layer);
+}
+
+void mario_jump_animation_stopped(Animation *animation, void *data)
+{
+ (void)animation;
+ (void)data;
+
+ text_layer_set_text(&text_hour_layer, hour_text);
+ text_layer_set_text(&text_minute_layer, minute_text);
+
+ property_animation_init_layer_frame(&mario_animation_end, &mario_layer,
+ &mario_up_rect, &mario_down_rect);
+ animation_set_duration(&mario_animation_end.animation, MARIO_JUMP_DURATION);
+ animation_set_curve(&mario_animation_end.animation, AnimationCurveEaseIn);
+ animation_set_handlers(&mario_animation_end.animation, (AnimationHandlers){
+ .started = (AnimationStartedHandler)mario_down_animation_started,
+ .stopped = (AnimationStoppedHandler)mario_down_animation_stopped
+ }, 0);
+
+ animation_schedule(&mario_animation_end.animation);
+}
+
+void block_up_animation_started(Animation *animation, void *data)
+{
+ (void)animation;
+ (void)data;
+}
+
+void block_up_animation_stopped(Animation *animation, void *data)
+{
+ (void)animation;
+ (void)data;
+
+ property_animation_init_layer_frame(&block_animation_end, &blocks_layer,
+ &blocks_up_rect, &blocks_down_rect);
+ animation_set_duration(&block_animation_end.animation, MARIO_JUMP_DURATION);
+ animation_set_curve(&block_animation_end.animation, AnimationCurveEaseIn);
+ animation_schedule(&block_animation_end.animation);
+}
+
void handle_tick(AppContextRef app_ctx, PebbleTickEvent *event)
{
+ property_animation_init_layer_frame(&mario_animation_beg, &mario_layer,
+ &mario_down_rect, &mario_up_rect);
+ animation_set_duration(&mario_animation_beg.animation, MARIO_JUMP_DURATION);
+ animation_set_curve(&mario_animation_beg.animation, AnimationCurveEaseOut);
+ animation_set_handlers(&mario_animation_beg.animation, (AnimationHandlers){
+ .started = (AnimationStartedHandler)mario_jump_animation_started,
+ .stopped = (AnimationStoppedHandler)mario_jump_animation_stopped
+ }, 0);
+
+ property_animation_init_layer_frame(&block_animation_beg, &blocks_layer,
+ &blocks_down_rect, &blocks_up_rect);
+ animation_set_duration(&block_animation_beg.animation, MARIO_JUMP_DURATION);
+ animation_set_curve(&block_animation_beg.animation, AnimationCurveEaseOut);
+ animation_set_handlers(&block_animation_beg.animation, (AnimationHandlers){
+ .started = (AnimationStartedHandler)block_up_animation_started,
+ .stopped = (AnimationStoppedHandler)block_up_animation_stopped
+ }, 0);
+
char *hour_format;
if (clock_is_24h_style()) {
hour_format = "%H";
@@ -146,8 +277,8 @@ void handle_tick(AppContextRef app_ctx, PebbleTickEvent *event)
memmove(minute_text, &minute_text[1], sizeof(minute_text) - 1);
}
- text_layer_set_text(&text_hour_layer, hour_text);
- text_layer_set_text(&text_minute_layer, minute_text);
+ animation_schedule(&mario_animation_beg.animation);
+ animation_schedule(&block_animation_beg.animation);
}
void pbl_main(void *params)