Line data Source code
1 0 : /* 2 : 3 : OOTrumble.h 4 : 5 : Implements cute, fuzzy trumbles. 6 : 7 : Oolite 8 : Copyright (C) 2004-2013 Giles C Williams and contributors 9 : 10 : This program is free software; you can redistribute it and/or 11 : modify it under the terms of the GNU General Public License 12 : as published by the Free Software Foundation; either version 2 13 : of the License, or (at your option) any later version. 14 : 15 : This program is distributed in the hope that it will be useful, 16 : but WITHOUT ANY WARRANTY; without even the implied warranty of 17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 : GNU General Public License for more details. 19 : 20 : You should have received a copy of the GNU General Public License 21 : along with this program; if not, write to the Free Software 22 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 23 : MA 02110-1301, USA. 24 : 25 : */ 26 : 27 : #import <Foundation/Foundation.h> 28 : #import "OOOpenGL.h" 29 : 30 : 31 : @class PlayerEntity, AI, OOSound, OOTexture; 32 : 33 0 : #define TRUMBLE_MAX_ROTATION 15.0 34 0 : #define TRUMBLE_MAX_ROTATIONAL_VELOCITY 5.0 35 : 36 0 : #define TRUMBLE_GROWTH_RATE 0.01 37 : 38 0 : enum trumble_animation 39 : { 40 : TRUMBLE_ANIM_NONE = 0, 41 : TRUMBLE_ANIM_IDLE, 42 : TRUMBLE_ANIM_BLINK, 43 : TRUMBLE_ANIM_SNARL, 44 : TRUMBLE_ANIM_PROOT, 45 : TRUMBLE_ANIM_SHUDDER, 46 : TRUMBLE_ANIM_STONED, 47 : TRUMBLE_ANIM_SPAWN, 48 : TRUMBLE_ANIM_SLEEP, 49 : TRUMBLE_ANIM_DIE 50 : }; 51 : 52 0 : enum trumble_eyes 53 : { 54 : TRUMBLE_EYES_NONE = 0, 55 : TRUMBLE_EYES_OPEN, 56 : TRUMBLE_EYES_SHUT, 57 : TRUMBLE_EYES_WIDE 58 : }; 59 : 60 0 : enum trumble_mouth 61 : { 62 : TRUMBLE_MOUTH_NONE = 0, 63 : TRUMBLE_MOUTH_POUT, 64 : TRUMBLE_MOUTH_GROWL, 65 : TRUMBLE_MOUTH_SNARL, 66 : TRUMBLE_MOUTH_NORMAL 67 : }; 68 : 69 : 70 0 : @interface OOTrumble: NSObject 71 : { 72 : @private 73 0 : PlayerEntity *player; // owning entity (not retained) 74 : // 75 0 : unichar digram[2]; // seed for pseudo-randomly setting up Trumble (pair of characters) 76 : // 77 0 : GLfloat colorBase[4]; // color of Trumble 78 0 : GLfloat colorPoint1[4]; // color of Trumble (variation 1) 79 0 : GLfloat colorPoint2[4]; // color of Trumble (variation 2) 80 0 : GLfloat colorEyes[4]; // color of Trumble (eye color) 81 0 : GLfloat *pointColor[6]; // pointscheme 82 : // 83 0 : GLfloat hunger; // behaviour modifier 0.0 (satiated) to 1.0 (starving) 84 0 : GLfloat discomfort; // behaviour modifier 0.0 (very happy) to 1.0 (extremely uncomfortable) 85 : // 86 0 : GLfloat size; // 0.0 -> max_size 87 0 : GLfloat max_size; // 0.90 -> 1.25 88 0 : GLfloat growth_rate; // diff to size per sec. 89 : // 90 0 : GLfloat rotation; // CW rotation in radians (starts at 0.0) 91 0 : GLfloat rotational_velocity; // +r (radians/sec) 92 : // 93 0 : NSPoint position; // x, y onscreen relative to center of screen 94 0 : NSPoint movement; // +x, +y (screen units / sec) 95 : // 96 0 : NSPoint eye_position; // current position of eyes relative to their starting position 97 0 : NSPoint mouth_position; // current position of eyes relative to their starting position 98 : // 99 0 : double animationTime; // set to 0.0 at start of current animation 100 0 : double animationDuration; // set to 0.0 at start of current animation 101 : // 102 0 : enum trumble_animation animation; // current animation sequence 103 0 : enum trumble_animation nextAnimation; // next animation sequence 104 : // 105 0 : int animationStage; // sub-sequence within animation 106 : // 107 0 : enum trumble_mouth mouthFrame; // which mouth position - determines what part of the texture to display 108 0 : enum trumble_eyes eyeFrame; // which eye position - determines what part of the texture to display 109 : // 110 0 : OOTexture *texture; 111 : // 112 0 : GLfloat saved_float1, saved_float2; 113 : // 114 0 : BOOL readyToSpawn; 115 : } 116 : 117 0 : - (id) initForPlayer:(PlayerEntity *)p1; 118 0 : - (id) initForPlayer:(PlayerEntity *)p1 digram:(NSString*) digramString; 119 : 120 0 : - (void) setupForPlayer:(PlayerEntity *)p1 digram:(NSString*) digramString; 121 : 122 0 : - (void) spawnFrom:(OOTrumble *)parentTrumble; 123 : 124 0 : - (void) calcGrowthRate; 125 : 126 0 : - (unichar *) digram; 127 0 : - (NSPoint) position; 128 0 : - (NSPoint) movement; 129 0 : - (GLfloat) rotation; 130 0 : - (GLfloat) size; 131 0 : - (GLfloat) hunger; 132 0 : - (GLfloat) discomfort; 133 : 134 : // AI methods here 135 0 : - (void) actionIdle; 136 0 : - (void) actionBlink; 137 0 : - (void) actionSnarl; 138 0 : - (void) actionProot; 139 0 : - (void) actionShudder; 140 0 : - (void) actionStoned; 141 0 : - (void) actionPop; 142 0 : - (void) actionSleep; 143 0 : - (void) actionSpawn; 144 : 145 0 : - (void) randomizeMotionX; 146 0 : - (void) randomizeMotionY; 147 : 148 0 : - (void) drawTrumble:(double) z; 149 0 : - (void) updateTrumble:(double) delta_t; 150 : 151 0 : - (void) updateIdle:(double) delta_t; 152 0 : - (void) updateBlink:(double) delta_t; 153 0 : - (void) updateSnarl:(double) delta_t; 154 0 : - (void) updateProot:(double) delta_t; 155 0 : - (void) updateShudder:(double) delta_t; 156 0 : - (void) updateStoned:(double) delta_t; 157 0 : - (void) updatePop:(double) delta_t; 158 0 : - (void) updateSleep:(double) delta_t; 159 0 : - (void) updateSpawn:(double) delta_t; 160 : 161 0 : - (NSDictionary *)dictionary; 162 0 : - (void) setFromDictionary:(NSDictionary *)dict; 163 : 164 : @end