done moving bone without accel
[livewp] / applet / src / fifteen.c
index c71c8fe..24347d4 100644 (file)
@@ -1,12 +1,74 @@
 #include <hildon/hildon.h>
+#include <time.h>
 #include "livewp-common.h"
 #include "livewp-actor.h"
+
+enum {
+    UP = 0,
+    RIGHT = 1,
+    DOWN = 2,
+    LEFT = 3
+};
+
+gint pg[16];
+Actor *actors[15];
+gint empty;
+
+void init_pg(gint *pg)
+{
+    srand(time(NULL));
+    gint i, j, t;
+    for (i=0; i<16; i++){
+        pg[i] = i;
+    }
+    for (i=0; i<15; i++){
+        j = rand()%15;
+        t = pg[i];
+        pg[i] = pg[j];
+        pg[j] = t;
+    }
+}
+
+void move(gint direction, AWallpaperPlugin *desktop_plugin)
+{
+    gint bone;
+    Actor *actor;
+    switch (direction) {
+        case UP:
+            bone = empty + 4;
+            if (bone > 15) return;
+            break;
+        case RIGHT:
+            bone = empty - 1;
+            if (empty % 4 == 0) return;
+            break;
+        case DOWN:
+            bone = empty - 4;
+            if (bone < 0) return;
+            break;
+        case LEFT:
+            bone = empty + 1;
+            if (bone % 4) return;
+    }
+    fprintf(stderr, "from %d to %d x=%d y=%d\n", bone, empty, (empty%4)*200, (empty/4)*120);
+    actor = actors[pg[bone]];
+    set_actor_position(actor, (empty%4)*200, (empty/4)*120, actor->z, desktop_plugin);
+    pg[empty] = pg[bone];
+    pg[bone] = 15;
+    empty = bone;
+}
+gboolean make_move(AWallpaperPlugin *desktop_plugin)
+{
+    move(RIGHT, desktop_plugin);
+    return TRUE;
+}
 int main( int   argc, char *argv[] )
 {
     GtkWidget *window;
     AWallpaperPlugin *desktop_plugin = g_new0 (AWallpaperPlugin, 1);
     Animation_WallpaperPrivate *priv = g_new0 (Animation_WallpaperPrivate, 1);
     Actor *actor;
+    gint i;
 
     hildon_gtk_init (&argc, &argv);
     g_set_application_name ("Simplest example");
@@ -14,13 +76,21 @@ int main( int   argc, char *argv[] )
     g_signal_connect (G_OBJECT (window), "delete_event",
                         G_CALLBACK (gtk_main_quit), NULL);
     priv->window = window;
-    priv->theme = g_strdup("Modern"); 
+    priv->theme = g_strdup("Fifteen"); 
+    priv->xapplet = 0;
+    priv->yapplet = 0;
     desktop_plugin->priv = priv;
-    actor = init_object(desktop_plugin, "sun", "sun.png", 
-                      10, 10, 6, 88, 88, 
+    init_pg(pg);
+    empty = 15;
+    for (i=0; i<15; i++){
+        actor = init_object(desktop_plugin, "bone", g_strdup_printf("%d.png", pg[i]+1), 
+                      (i%4)*200, (i/4)*120, 2, 200, 120, 
                       TRUE, TRUE, 100, 255, 
                       NULL, NULL, NULL);
+        actors[pg[i]] = actor;
+    }
     gtk_widget_show  (window);
+    g_timeout_add(4000, make_move, desktop_plugin);
     gtk_main ();
     return 0;
 }