1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
/*
* sprite_switch.c: スイッチスプライト特有の処理
*
* Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
* 1998- <masaki-c@is.aist-nara.ac.jp>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/* $Id: sprite_switch.c,v 1.1 2003/04/22 16:29:52 chikama Exp $ */
#include "config.h"
#include <stdio.h>
#include "portab.h"
#include "ags.h"
#include "sact.h"
#include "sactsound.h"
#include "sprite.h"
static int eventCB_switch(sprite_t *sp, agsevent_t *e);
static void cb_remove(sprite_t *sp);
// スイッチスプライトのイベント処理
static int eventCB_switch(sprite_t *sp, agsevent_t *e) {
int update = 0;
switch(e->type) {
case AGSEVENT_BUTTON_PRESS:
if (e->code != AGSEVENT_BUTTON_LEFT) return 0;
// ボタン押下時のスプライトがあれば、それを表示
if (sp->cg3) {
sp->curcg = sp->cg3;
update++;
}
sp->pressed = true;
break;
case AGSEVENT_BUTTON_RELEASE:
if (e->code != AGSEVENT_BUTTON_LEFT) return 0;
// ここにくるときは forcusが当たっているときしかこないので、
// curcg は cg2 に戻せばよい
if (sp->cg2) {
sp->curcg = sp->cg2;
update++;
}
// pressされたスプライトとreleaseされたスプライトが同じ場合
// にのみ、そのスプライトが押されたと判断
if (sp->pressed) {
sact.sp_result_sw = sp->no;
sact.waitkey = sp->no;
if (sp->numsound2) {
ssnd_play(sp->numsound2);
}
}
sp->pressed = false;
break;
}
if (update) {
sp_updateme(sp);
}
return update;
}
// スプライト削除時の処理
static void cb_remove(sprite_t *sp) {
// event listener の削除
spev_remove_eventlistener(sp);
}
/*
sp_new の時にスプライトの種類毎の初期化
@param sp: 初期化するスプライト
*/
void sp_sw_setup(sprite_t *sp) {
spev_add_eventlistener(sp, eventCB_switch);
sp->remove = cb_remove;
}
|