rendered paste body/*
* soccer.c
*
*
* Created by Peter Noone on 8/22/06.
* Copyright 2006 __MyCompanyName__. All rights reserved.
*
*/
#include <stdio.h>
#include "pz.h"
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
static PzModule *module;
static ttk_surface ball;
static ttk_surface field;
static ttk_surface goal;
static TWindow *window;
static TWidget *wid;
static int b=0; //see if button is pressed
static int w, h, bpp, sys;
static int imgh,imgw; //goal dimens.
static int s = rand() % 150; //s= ball's x coordinate
static int y,d; //delay=d
static int p=1;
static char over[100];
static char start[100], startover[100];
static char score[50];
void draw_soccer (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;
ttk_fillrect (srf, 0, 0, ttk_screen->w, ttk_screen->h, ttk_makecol(0,255,0));
ttk_blit_image (goal, srf, 135, 200);
ttk_blit_image (field, srf, wid->x + (wid->w - imgw) / 2, wid->y + (wid->h - imgh) / 2);
switch(p)
{
case 1:
{
sprintf(start,"Press play to start.");
ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,start)/2), 50, ttk_makecol(0,0,255),start);
break;
}
case 2:
{
ttk_blit_image (ball, srf, s, y);
if(y!=200)
{
y++;
break;
}
else if(y==200 && x>=135 && x<=185)
{
sprintf(score,"GOAL GOAL GOAL GOAL GOAL");
ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,score)/2), 50, ttk_makecol(0,0,255),score);
d-=3;
sprintf(start,"Press play to play again.");
ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,startover)/2), 50, ttk_makecol(0,0,255),startover);
break;
}
else
{
sprintf(over,"you missed");
ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,over)/2), 50, ttk_makecol(0,0,255),over);
break;
}
}
break;
}
}
static int event_soccer (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)
{
s++;
wid->dirty++;
break;
} //forward scroll
else
{
s--;
wid->dirty++;
break;
} //backwards scroll
case PZ_EVENT_BUTTON_DOWN: // or "case PZ_EVENT_BUTTON_UP:"
switch (e->arg)
{
case PZ_BUTTON_ACTION: //center / action button
wid->dirty++;
break;
case PZ_BUTTON_MENU: //menu button
pz_close_window(e->wid->win);
break;
case PZ_BUTTON_PLAY: //play button
p=2;
wid->dirty++;
break;
case PZ_BUTTON_NEXT: //forward button
d+=10;
break;
case PZ_BUTTON_PREVIOUS: //previous button
d-=10;
break;
case PZ_BUTTON_HOLD :
break;
/*hold if used BUTTON_DOWN reacts imediatly if BUTTON_UP reacts when hold is released*/
}
break;
case PZ_EVENT_TIMER: //timer function
break;
default:
ret = TTK_EV_UNUSED; //do nothing
break;
}
return ret;
}
PzWindow *new_soccer_window(ttk_surface srf)
{
window = pz_new_window ("soccer", PZ_WINDOW_NORMAL);
wid = pz_add_widget(window, draw_soccer, event_soccer);
return pz_finish_window (window);
d=8;
p=1;
y=10;
b=0;
ttk_fillrect (srf, 0, 0, ttk_screen->w, ttk_screen->h, ttk_makecol(0,255,0));
srand(time(0));
s = rand() % 100;
y=5;
ttk_surface_get_dimen (field, &imgw, &imgh);
}
void cleanup_soccer()
{
}
void init_soccer()
{
w =ttk_screen->w; //gets screen width
h =ttk_screen->h; //gets screen hieght
bpp =ttk_screen->bpp; //gets colour depth
ball = ttk_load_image (pz_module_get_datapath (module, "soccer.png"));
field = ttk_load_image (pz_module_get_datapath (module, "field.png"));
goal = ttk_load_image (pz_module_get_datapath (module, "goal.png"));
module = pz_register_module ("soccer", cleanup_soccer);
pz_menu_add_action ("/Extras/Games/soccer", new_soccer_window);
}
PZ_MOD_INIT (init_soccer)