All pastes #144530 Raw Edit

Stuff

public text v1 · immutable
#144530 ·published 2006-08-22 15:55 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=1; //clear screen
static char now[50],  welcome[100],  points[10], yourscore[100], ready[50]; 
static int score=0;
static int flag;

void draw_reflex (PzWidget *wid, ttk_surface srf)
{
	h=ttk_screen->h;
	w=ttk_screen->w;
	sys = (wid->x + wid->w)/2;
	
	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, ttk_makecol(255,0,0),welcome);
			break;
		}
		case 2:
		{
			sprintf(ready,"READY...");
			ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,ready)/2), 40, ttk_makecol(255,0,0),ready);
			ttk_delay(i);
			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);
			ttk_widget_set_timer();
		}
		case 3:
		{
			sprintf(yourscore,"Your score is: %i, lower is better", score);
			ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,yourscore)/2), 50, ttk_makecol(255,0,0),yourscore);
			break;
		}
	}
}

int event_reflex (PzEvent *ev)
{
	int ret = TTK_EV_CLICK;
	switch (ev->type)
	{
		case PZ_EVENT_BUTTON_DOWN:
			switch(ev->arg)
			{
				case PZ_BUTTON_PLAY:
					x=2;
					wid->dirty++;
					break;
				case PZ_BUTTON_ACTION:
					x=3;
					wid->dirty++;
					break;
				case PZ_BUTTON_MENU:
					pz_close_window (ev->wid->win);
					break;
			}
	}
	return ret;
}

PzWindow *new_reflex_window()
{
    t=10;
	n=0;
	x=1;
	score=0;
	
	srand(time(0));
	i = rand() % 10000;
	
	window = pz_new_window ("reflex", PZ_WINDOW_NORMAL);
    wid = pz_add_widget(window, draw_reflex, event_reflex);
    ttk_widget_set_timer(wid, 100);
    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
 
    module = pz_register_module ("reflex", cleanup_reflex);
    pz_menu_add_action ("/Extras/Games/reflex", new_reflex_window);

}

PZ_MOD_INIT (init_reflex)