All pastes #141091 Raw Edit

Miscellany

public text v1 · immutable
#141091 ·published 2006-08-20 20:34 UTC
rendered paste body
#include <stdio.h>

#include "pz.h"
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>


static PzModule *module;

static TWindow *window;

static TWidget *wid;
static int w, h, bpp;
static int sys;

static int i; //random number
static int n; //for variable
static int t;
static int x; //clear screen
static char now[50]; //NOW
static int score=0;
static char welcome[100];
static char ready[30];
static int flag;
static char points[10];
//static int s; //random time
static char yourscore[100];

void draw_reflex (PzWidget *wid, ttk_surface srf)
{
	h=ttk_screen->h;
	w=ttk_screen->w;
	sys = (wid->x + wid->w)/2;
	ttk_color fg = ttk_ap_getx("window.fg")->color;
	
	switch(x)
	{
		case 1:
		{
			sprintf(welcome,"Welcome to Reflex Tester, press play to start.");
			ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,welcome)/2), 50, fg,welcome);
		}
		case 2:
		{
			
			srand(time(0));
			i = rand() % 500;

			sprintf(ready,"READY....");
			ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,ready)/2), 40, ttk_makecol(0,0,0),ready);
			while(n!=i)
			{
				n++;
			}
			ttk_fillrect (srf, 0, 0, ttk_screen->w, ttk_screen->h, ttk_makecol(255,0,0));
			sprintf(now,"PRESS ACTION NOW!!!");
			ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,now)/2), 60, ttk_makecol(0,0,0),now);
			while(!flag)
			{
				score++;
				sprintf(points,"%i",score);
				ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,points)/2), t, fg,points);
				t+=10;
			}
		}
		case 3:
		{
			sprintf(yourscore,"Your score is: %i", score);
			ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,yourscore)/2), 50, fg,yourscore);
		}
	}
}

static int event_reflex (PzEvent *e)
{

int ret = TTK_EV_CLICK;

switch(e->type) {

   case PZ_EVENT_SCROLL: //scroll function
     TTK_SCROLLMOD( e->arg, 10);
      if( e->arg > 0){break;} //forward scroll
      else {break;}      //backwards scroll

   case PZ_EVENT_BUTTON_DOWN:     // or "case PZ_EVENT_BUTTON_UP:"
      switch (e->arg) {
      case PZ_BUTTON_ACTION: //center / action button
		x=3;
		flag=1;
		wid->dirty++;
		break;

      case PZ_BUTTON_MENU:   //menu button
		pz_close_window(e->wid->win);
         break;

      case PZ_BUTTON_PLAY:   //play button
		 x=2;
		 wid->dirty++;
         break;

      case PZ_BUTTON_NEXT:    //forward button
         break;

      case PZ_BUTTON_PREVIOUS: //previous button
         break;

      case PZ_BUTTON_HOLD :   

         break;
      /*hold if used BUTTON_DOWN reacts imediatly if BUTTON_UP reacts when hold is released*/
      default:
		ret = TTK_EV_UNUSED;  //score++; //do nothing if not buttons pressed
		//wid->dirty++;
      }

   case PZ_EVENT_TIMER: //timer function
      break;

   default:
      ret = TTK_EV_UNUSED; //do nothing
      break;

   }
   return ret;

}

PzWindow *new_reflex_window()
{
	t=10;
	flag=0;
	score=0;
	x=1;
	window = pz_new_window ("Reflex", PZ_WINDOW_NORMAL);
    wid = pz_add_widget(window, draw_reflex, event_reflex);
    return pz_finish_window (window);
}

void cleanup_reflex()
{

}

void init_reflex()
{
    w =ttk_screen->w; //gets screen width
	h =ttk_screen->h; //gets screen hieght
    bpp =ttk_screen->bpp; //gets colour depth
 
    pz_menu_add_action ("/Extras/Games/Reflex", new_reflex_window);

}

PZ_MOD_INIT (init_reflex)