rendered paste body/*
* soccer.c
*
*
* Created by Peter Noone on 8/22/06.
* Copyright 2006 Peter is the Shit. 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 w, h, bpp, sys;
static int imgh,imgw; //field dimens.
static int s,f; //s= ball's x coordinate, y coordinate movement
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,0,0);
switch(p)
{
case 1:
{
sprintf(start,"Press action 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 && s>=135 && s<=185)
{
sprintf(score,"GOAL GOAL GOAL GOAL GOAL");
sprintf(startover,"Press play to play again. The ball will move faster");
ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,score)/2), 50, ttk_makecol(0,0,255),score);
ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,startover)/2), 70, ttk_makecol(0,0,255),startover);
}
else if(y>=200 && s<135)
{
sprintf(over,"you missed");
sprintf(startover,"Press action to play again.");
ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,over)/2), 50, ttk_makecol(0,0,255),over);
ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,startover)/2), 70, ttk_makecol(0,0,255),startover);
f+=3;
}
else if(y>=200 && s>185)
{
sprintf(over,"you missed");
sprintf(startover,"Press action to play again.");
ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,over)/2), 50, ttk_makecol(0,0,255),over);
ttk_text (srf,ttk_textfont, (sys)-(ttk_text_width(ttk_textfont,startover)/2), 70, ttk_makecol(0,0,255),startover);
}
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+=3;
wid->dirty++;
break;
} //forward scroll
else
{
s-=3;
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
f=2;
p=2;
y=5;
s= rand() % 200;
wid->dirty++;
break;
case PZ_BUTTON_MENU: //menu button
pz_close_window(e->wid->win);
break;
case PZ_BUTTON_PLAY: //play button
f+=2;
p=2;
y=5;
s= rand() % 200;
wid->dirty++;
break;
case PZ_BUTTON_NEXT: //forward button
f+=3;
break;
case PZ_BUTTON_PREVIOUS: //previous button
f-=3;
break;
case PZ_BUTTON_HOLD :
break;
/*hold if used BUTTON_DOWN reacts imediatly if BUTTON_UP reacts when hold is released*/
}
case PZ_EVENT_TIMER: //timer function
//ttk_delay(d);
y=y+f;
wid->dirty++;
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);
pz_widget_set_timer(wid, 20);
return pz_finish_window (window);
d=20;
p=1;
y=10;
f=2;
ttk_fillrect (srf, 0, 0, ttk_screen->w, ttk_screen->h, ttk_makecol(0,255,0));
srand(time(0));
s = rand() % 200;
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", NULL);
pz_menu_add_action ("/Extras/Games/soccer", new_soccer_window);
}
PZ_MOD_INIT (init_soccer)