1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.replica.replicaisland; 18 19 import com.replica.replicaisland.CollisionParameters.HitType; 20 21 22 public class SelectDialogComponent extends GameComponent { 23 private HitReactionComponent mHitReact; 24 private Vector2 mLastPosition; 25 26 public SelectDialogComponent() { 27 super(); 28 setPhase(ComponentPhases.THINK.ordinal()); 29 mLastPosition = new Vector2(); 30 } 31 32 @Override 33 public void reset() { 34 mHitReact = null; 35 mLastPosition.zero(); 36 } 37 38 @Override 39 public void update(float timeDelta, BaseObject parent) { 40 HotSpotSystem hotSpot = sSystemRegistry.hotSpotSystem; 41 if (hotSpot != null && mHitReact != null) { 42 GameObject parentObject = (GameObject)parent; 43 final Vector2 currentPosition = parentObject.getPosition(); 44 if (mLastPosition.distance2(parentObject.getPosition()) > 0.0f) { 45 mLastPosition.set(currentPosition); 46 47 final int hitSpot = hotSpot.getHotSpot(parentObject.getCenteredPositionX(), currentPosition.y + 10); 48 switch(hitSpot) { 49 case HotSpotSystem.HotSpotType.NPC_SELECT_DIALOG_1_1: 50 case HotSpotSystem.HotSpotType.NPC_SELECT_DIALOG_1_2: 51 case HotSpotSystem.HotSpotType.NPC_SELECT_DIALOG_1_3: 52 case HotSpotSystem.HotSpotType.NPC_SELECT_DIALOG_1_4: 53 case HotSpotSystem.HotSpotType.NPC_SELECT_DIALOG_1_5: 54 case HotSpotSystem.HotSpotType.NPC_SELECT_DIALOG_2_1: 55 case HotSpotSystem.HotSpotType.NPC_SELECT_DIALOG_2_2: 56 case HotSpotSystem.HotSpotType.NPC_SELECT_DIALOG_2_3: 57 case HotSpotSystem.HotSpotType.NPC_SELECT_DIALOG_2_4: 58 case HotSpotSystem.HotSpotType.NPC_SELECT_DIALOG_2_5: 59 { 60 int event = GameFlowEvent.EVENT_SHOW_DIALOG_CHARACTER1; 61 int index = hitSpot - HotSpotSystem.HotSpotType.NPC_SELECT_DIALOG_1_1; 62 63 if (hitSpot >= HotSpotSystem.HotSpotType.NPC_SELECT_DIALOG_2_1) { 64 event = GameFlowEvent.EVENT_SHOW_DIALOG_CHARACTER2; 65 index = hitSpot - HotSpotSystem.HotSpotType.NPC_SELECT_DIALOG_2_1; 66 } 67 68 mHitReact.setSpawnGameEventOnHit(HitType.COLLECT, event, index); 69 } 70 break; 71 } 72 } 73 } 74 } 75 76 public void setHitReact(HitReactionComponent hit) { 77 mHitReact = hit; 78 } 79 } 80