[xiph-commits] r9652 - trunk/planarity

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Sat Jul 30 03:29:06 PDT 2005


Author: xiphmont
Date: 2005-07-30 03:29:03 -0700 (Sat, 30 Jul 2005)
New Revision: 9652

Added:
   trunk/planarity/finish.c
   trunk/planarity/finish.h
Modified:
   trunk/planarity/Makefile
   trunk/planarity/gamestate.c
   trunk/planarity/gamestate.h
   trunk/planarity/version.h
Log:
Add between-board 'yay' dialog.



Modified: trunk/planarity/Makefile
===================================================================
--- trunk/planarity/Makefile	2005-07-30 09:26:30 UTC (rev 9651)
+++ trunk/planarity/Makefile	2005-07-30 10:29:03 UTC (rev 9652)
@@ -17,9 +17,9 @@
 # bleeding-edge GTK 2.7/2.8 libs installed.
 
 SRC  = graph.c arrange.c gameboard.c generate.c gamestate.c button_base.c\
-	buttons.c buttonbar.c box.c pause.c
+	buttons.c buttonbar.c box.c pause.c finish.c
 OBJ  = graph.o arrange.o gameboard.o generate.o gamestate.o button_base.o\
-	buttons.o buttonbar.o box.o pause.o
+	buttons.o buttonbar.o box.o pause.o finish.o
 GCF  = `pkg-config --static --cflags "gtk+-2.0 >= 2.7.2"`
 
 # uncomment below for a normal dynamic build

Added: trunk/planarity/finish.c
===================================================================
--- trunk/planarity/finish.c	2005-07-30 09:26:30 UTC (rev 9651)
+++ trunk/planarity/finish.c	2005-07-30 10:29:03 UTC (rev 9652)
@@ -0,0 +1,243 @@
+#include <math.h>
+#include <string.h>
+#include <gtk/gtk.h>
+#include <gdk/gdk.h>
+
+#include "graph.h"
+#include "gameboard.h"
+#include "gamestate.h"
+#include "button_base.h"
+#include "buttonbar.h"
+#include "finish.h"
+#include "box.h"
+
+static gint timer;
+static void (*callback)(Gameboard *);
+
+/* perform a single frame of animation for all pause dialog buttons/rollovers */
+static gboolean finish_animate_buttons(gpointer ptr){
+  Gameboard *g=(Gameboard *)ptr;
+  int ret=0;
+
+  ret=animate_button_frame(g);
+
+  if(!ret && timer!=0){
+    g_source_remove(timer);
+    timer=0;
+  }
+
+  if(!ret && callback)
+    // undeploy finished... call the undeploy callback
+    callback(g);
+
+  return ret;
+}
+
+static void finish_post (Gameboard *g){
+  // back to buttonbar activity!
+  pop_background(g);
+  setup_board(g);
+} 
+
+static void finish_quit (Gameboard *g){
+  quit();
+} 
+
+static void undeploy_buttons(Gameboard *g){
+  // undeploy pause buttons
+  button_clear_state(g);
+  buttons_ready=0;
+
+  {
+    buttonstate *b=states; 
+    b->target_x-=BUTTON_EXPOSE;
+  }
+  {
+    buttonstate *b=states+1; 
+    b->target_x-=BUTTON_EXPOSE;
+  }
+  {
+    buttonstate *b=states+10; 
+    b->target_x+=BUTTON_EXPOSE;
+  }
+}
+
+static void local_go (Gameboard *g){
+  undeploy_buttons(g);
+  callback = finish_post;
+  timer = g_timeout_add(BUTTON_ANIM_INTERVAL, finish_animate_buttons, (gpointer)g);
+}
+
+static void local_quit (Gameboard *g){
+  undeploy_buttons(g);
+  callback = finish_quit;
+  timer = g_timeout_add(BUTTON_ANIM_INTERVAL, finish_animate_buttons, (gpointer)g);
+}
+
+/* initialize the rather weird little animation engine */
+static void setup_finish_buttons(Gameboard *g,int bw, int bh){
+  int i;
+  int w=get_board_width();
+  int h=get_board_height();
+
+  states[0].rollovertext="exit gPlanarity";
+  states[1].rollovertext="level menu";
+  states[10].rollovertext="next level!";
+
+  states[0].callback = local_quit;
+  states[1].callback = 0; // for now
+  states[10].callback = local_go;
+
+  for(i=0;i<NUMBUTTONS;i++)
+    states[i].position=0;
+
+  states[0].position = 2; //center;
+  states[1].position = 2; //center;
+  states[10].position = 2; //center;
+
+  {
+    buttonstate *b=states;
+    b->target_x_active=
+      b->x_active=
+      b->target_x_active=
+      b->target_x= 
+      w/2 - bw/2 + FINISH_BUTTON_BORDER;
+    b->x=b->target_x_inactive=b->x_inactive=b->target_x - BUTTON_EXPOSE;
+    b->y = h/2 + bh/2 - FINISH_BUTTON_Y;
+  }
+
+  {
+    buttonstate *b=states+1;
+    b->target_x_active=
+      b->x_active=
+      b->target_x_active=
+      b->target_x= w/2;
+    b->x=b->target_x_inactive=b->x_inactive=b->target_x - BUTTON_EXPOSE;
+    b->y = h/2 + bh/2 - FINISH_BUTTON_Y;
+  }
+
+  {
+    buttonstate *b=states+10;
+    b->target_x_active=
+      b->x_active=
+      b->target_x_active=
+      b->target_x= 
+      w/2 + bw/2 - FINISH_BUTTON_BORDER;
+    b->x=b->target_x_inactive=b->x_inactive=b->target_x + BUTTON_EXPOSE;
+    b->y = h/2 + bh/2 - FINISH_BUTTON_Y;
+  }
+
+  for(i=0;i<NUMBUTTONS;i++)
+    if(states[i].position)
+      rollover_extents(g,states+i);  
+}
+
+static void render_text_centered(cairo_t *c, char *s, int x, int y){
+  cairo_text_extents_t ex;
+
+  cairo_text_extents (c, s, &ex);
+  cairo_move_to (c, x-(ex.width/2)-ex.x_bearing, y-(ex.height/2)-ex.y_bearing);
+  cairo_show_text (c, s);  
+}
+
+static void draw_finishbox(Gameboard *g){
+  int w= get_board_width();
+  int h= get_board_height();
+
+  push_background(g);
+  
+  cairo_t *c = cairo_create(g->background);
+  borderbox_path(c,
+		 w/2 - FINISHBOX_WIDTH/2,
+		 h/2 - FINISHBOX_HEIGHT/2,
+		 FINISHBOX_WIDTH,
+		 FINISHBOX_HEIGHT);
+  cairo_set_source_rgb(c,1,1,1);
+  cairo_fill(c);
+
+  centerbox(c,
+	    w/2 - FINISHBOX_WIDTH/2,
+	    h/2 - FINISHBOX_HEIGHT/2,
+	    FINISHBOX_WIDTH,
+	    SCOREHEIGHT);
+
+  centerbox(c,
+	    w/2 - FINISHBOX_WIDTH/2 ,
+	    h/2 + FINISHBOX_HEIGHT/2 - SCOREHEIGHT,
+	    FINISHBOX_WIDTH,
+	    SCOREHEIGHT);
+
+  {
+    cairo_matrix_t ma;
+    char time[160];
+    char buffer[160];
+    int  ho = get_elapsed() / 3600;
+    int  mi = get_elapsed() / 60 - ho*60;
+    int  se = get_elapsed() - ho*3600 - mi*60;
+    int y;
+    int time_bonus=get_initial_intersections()-get_elapsed();
+    if(time_bonus<0)time_bonus=0;
+
+    if(ho){
+      snprintf(time,160,"%d:%02d:%02d",ho,mi,se);
+    }else if (mi){
+      snprintf(time,160,"%d:%02d",mi,se);
+    }else{
+      snprintf(time,160,"%d seconds",se);
+    }
+
+    cairo_select_font_face (c, "Arial",
+			    CAIRO_FONT_SLANT_NORMAL,
+			    CAIRO_FONT_WEIGHT_BOLD);
+
+    cairo_matrix_init_scale (&ma, 18.,18.);
+    cairo_set_font_matrix (c,&ma);
+    cairo_set_source_rgba (c, TEXT_COLOR);
+
+    y=h/2-FINISHBOX_HEIGHT/2+SCOREHEIGHT/2;
+    render_text_centered(c,"Level Complete!", w/2,y);y+=45;
+
+    cairo_select_font_face (c, "Arial",
+			    CAIRO_FONT_SLANT_NORMAL,
+			    CAIRO_FONT_WEIGHT_NORMAL);
+    cairo_matrix_init_scale (&ma, 16.,16.);
+    cairo_set_font_matrix (c,&ma);
+
+    snprintf(buffer,160,"Elapsed: %s",time);
+    render_text_centered(c,buffer, w/2,y);y+=35;
+
+
+    snprintf(buffer,160,"Score: %d",get_initial_intersections());
+    render_text_centered(c,buffer, w/2,y);y+=24;
+    snprintf(buffer,160,"Bonus: %d",time_bonus);
+    render_text_centered(c,buffer, w/2,y);y+=45;
+
+    cairo_select_font_face (c, "Arial",
+			    CAIRO_FONT_SLANT_NORMAL,
+			    CAIRO_FONT_WEIGHT_BOLD);
+    snprintf(buffer,160,"Total score: %d",get_initial_intersections()+time_bonus);
+    render_text_centered(c,buffer, w/2,y);
+
+  }
+
+  cairo_destroy(c);
+}
+
+static void finish_post_undeploy(Gameboard *g){
+  // set up new buttons
+  setup_finish_buttons(g,FINISHBOX_WIDTH, FINISHBOX_HEIGHT);
+
+  // draw pausebox
+  draw_finishbox(g);
+
+  // deploy new buttons
+  callback=0;
+  timer = g_timeout_add(BUTTON_ANIM_INTERVAL, finish_animate_buttons, (gpointer)g);
+  buttons_ready=1;
+}
+
+void finish_level_dialog(Gameboard *g){
+  // undeploy buttonbar
+  undeploy_buttonbar(g,finish_post_undeploy);
+}
+

Added: trunk/planarity/finish.h
===================================================================
--- trunk/planarity/finish.h	2005-07-30 09:26:30 UTC (rev 9651)
+++ trunk/planarity/finish.h	2005-07-30 10:29:03 UTC (rev 9652)
@@ -0,0 +1,7 @@
+#define FINISH_BUTTON_BORDER 35
+#define FINISH_BUTTON_Y 25
+#define FINISHBOX_WIDTH 200
+#define FINISHBOX_HEIGHT 300
+
+extern void finish_level_dialog(Gameboard *g);
+

Modified: trunk/planarity/gamestate.c
===================================================================
--- trunk/planarity/gamestate.c	2005-07-30 09:26:30 UTC (rev 9651)
+++ trunk/planarity/gamestate.c	2005-07-30 10:29:03 UTC (rev 9652)
@@ -7,6 +7,7 @@
 #include "gamestate.h"
 #include "buttons.h"
 #include "buttonbar.h"
+#include "finish.h"
 
 Gameboard *gameboard;
 
@@ -223,7 +224,7 @@
     if(get_elapsed()<initial_intersections)
       score+=initial_intersections-get_elapsed();
     level++;
-    undeploy_buttonbar(gameboard,setup_board);
+    undeploy_buttonbar(gameboard,finish_level_dialog);
   }
 }
 
@@ -235,6 +236,10 @@
   return score + initial_intersections-get_num_intersections();
 }
 
+int get_initial_intersections(){
+  return initial_intersections;
+}
+
 int get_objective(){
   return objective;
 }
@@ -248,7 +253,7 @@
 }
 
 char *get_level_string(){
-  return "\"original level\"";
+  return "original-style";
 }
 
 int main(int argc, char *argv[]){

Modified: trunk/planarity/gamestate.h
===================================================================
--- trunk/planarity/gamestate.h	2005-07-30 09:26:30 UTC (rev 9651)
+++ trunk/planarity/gamestate.h	2005-07-30 10:29:03 UTC (rev 9652)
@@ -22,3 +22,4 @@
 extern int paused_p();
 extern time_t get_elapsed();
 extern void set_timer(time_t off);
+extern int get_initial_intersections();

Modified: trunk/planarity/version.h
===================================================================
--- trunk/planarity/version.h	2005-07-30 09:26:30 UTC (rev 9651)
+++ trunk/planarity/version.h	2005-07-30 10:29:03 UTC (rev 9652)
@@ -1,2 +1,2 @@
 /* DO NOT EDIT: Automated versioning hack [Thu Jul 21 05:46:15 EDT 2005] */
-/* DO NOT EDIT: Automated versioning hack [Sat Jul 30 05:26:04 EDT 2005] */
+/* DO NOT EDIT: Automated versioning hack [Sat Jul 30 06:28:05 EDT 2005] */



More information about the commits mailing list