// Constructor for this entity type // Notes: Do not allocate space for the entity itself! This is handled // by the entity factory. This function is for allocation of // any other necessary memory. Perhaps a dynamically allocated // string, or other various memory allocations that are to be // pointed to by this entity. void ItemParticleConstruct( ENTITY *self, float *x, float *y ) { VECTOR2D vel = { (float)RandomInt( -ITEM_PARTICLE_VELOCITY_RANGE, ITEM_PARTICLE_VELOCITY_RANGE ), (float)RandomInt( -ITEM_PARTICLE_VELOCITY_RANGE, ITEM_PARTICLE_VELOCITY_RANGE ) }, accel = { 0 }; ALD ALdata = { 0 }; // Add various components AddSpriteComponent( self, FIND_DATA( P_IMAGE, IMAGE_TABLE, "ItemParticle.AEArt" ), ENABLE_CAM ); AddPositionComponent( self, (int)x, (int)y ); AddPhysicsComponent( self, (int)&vel, (int)&accel ); AddActionListComponent( self ); // Set the properties flag of this object self->properties = 0; self->CLASS_NAME = CLASS_NAME; self->zOrder = 1; ALdata.flag |= BLOCKING; ALdata.ID = ALT_PAUSE; ALdata.timerEnd = ITEM_PARTICLE_DELAY; ActionListAddAction( (AL *)self->comps.AL, &ALdata ); ALdata.ID = ALT_DESTROY; ActionListAddAction( (AL *)self->comps.AL, &ALdata ); }
// --- DATA_PROC AVP_bool DATA_PARAM DATA_Merge( HDATA data, AVP_dword* addr, HDATA data2, AVP_dword* addr2, HDATA* result, AVP_dword flags, AVP_Merge_Param* param ) { if ( !data || !data2 || (result && *result == data) ) { _RPT0( _CRT_ASSERT, "Bad parameters" ); return 0; } FIND_DATA( data, addr ); FIND_DATA( data2, addr2 ); if ( !result ) result = &data; _RPT0( _CRT_ASSERT, "Merge is not working at the moment !" ); return 0; }
// // ClassUpdate // Purpose: This update function modifies the owner's current velocity // by the component's constants if specific input conditions are met // void PlaCUpdate( PLAC *self, float *dt ) { VECTOR2D inputVector = { 0 }, pos = { 0 }; SendEntityMessage( self->base.owner, EM_GETINVEC, (int)&inputVector, 0 ); SendEntityMessage( self->base.owner, EM_GETPOS, (int)&pos.x_, (int)&pos.y_ ); // Initiate jump if canJump currently if(IsKeyPressed( VK_UP ) && self->canJump && self->playerState != PLAYER_STATE_ATTACKING_1) { self->canJump = FALSE; inputVector.y_ = PLAYER_JUMP_HEIGHT; self->jumping = TRUE; SendEntityMessage( self->base.owner, EM_SETHTBTM, FALSE, 0 ); SendEntityMessage( self->base.owner, EM_SETINVEC, (int)&inputVector, 0 ); } // Enable jumping if hit a tile on bottom of player if(!self->jumping && !IsKeyPressed( VK_UP ) && self->canJump == FALSE) { inputVector.y_ = 0; SendEntityMessage( self->base.owner, EM_SETINVEC, (int)&inputVector, 0 ); self->canJump = TRUE; } // Move left if(IsKeyPressed( VK_LEFT ) && self->playerState != PLAYER_STATE_ATTACKING_1) { inputVector.x_ = -LEFT_RIGHT_SPEED; self->playerState = PLAYER_STATE_MOVING; self->faceDir = FALSE; SendEntityMessage( self->base.owner, EM_SETINVEC, (int)&inputVector, 0 ); } // Move right if(IsKeyPressed( VK_RIGHT ) && self->playerState != PLAYER_STATE_ATTACKING_1) { inputVector.x_ = LEFT_RIGHT_SPEED; self->playerState = PLAYER_STATE_MOVING; self->faceDir = TRUE; SendEntityMessage( self->base.owner, EM_SETINVEC, (int)&inputVector, 0 ); } // Zero input vector x if left or right key not pressed else if(!IsKeyPressed( VK_RIGHT ) && !IsKeyPressed( VK_LEFT )) { inputVector.x_ = 0; SendEntityMessage( self->base.owner, EM_SETINVEC, (int)&inputVector, 0 ); } // Space bar for attacking! if(IsKeyPressed( VK_SPACE ) && !self->jumping && self->playerState != PLAYER_STATE_ATTACKING_1) { DDD data = { 0 }; data.damage = 10; data.WH.x_ = 1.f; data.WH.y_ = 1.f; data.delay = .30f; SendEntityMessage( self->base.owner, EM_GETPOS, (int)&data.pos.x_, (int)&data.pos.y_ ); self->playerState = PLAYER_STATE_ATTACKING_1; inputVector.x_ = 0; SendEntityMessage( self->base.owner, EM_SETINVEC, (int)&inputVector, 0 ); if(self->faceDir) data.pos.x_ += 4.f; else data.pos.x_ -= 5.f; CreateEntity( "DAMAGE_DEALER", (int)&data, (int)FIND_DATA( P_IMAGE, IMAGE_TABLE, "TestDamage.AEArt" ) ); } if(IsKeyPressed( VK_I ) && self->inventoryDT == 0) { self->inventoryDT += *dt; SendEntityMessage( self->base.owner, EM_INVTDRAW, 0, 0 ); } if(self->inventoryDT < INVENTORY_BUTTON_DEBOUNCE_TIME && self->inventoryDT != 0 && !IsKeyPressed( VK_I )) { self->inventoryDT += *dt; } if(self->inventoryDT >= INVENTORY_BUTTON_DEBOUNCE_TIME) { self->inventoryDT = 0; } // Update player's attack if(self->playerState == PLAYER_STATE_ATTACKING_1) { self->dt += *dt; // Reset timer + player state if time threshold met + not press space if(self->dt > PLAYER_ATTACK_SPEED_SECONDS && !IsKeyPressed( VK_SPACE )) { self->dt = 0; self->playerState = PLAYER_STATE_IDLE; } } // Idle the player if no keys are pressed and not jumping or attacking if(!IsKeyPressed( VK_LEFT ) && !IsKeyPressed( VK_RIGHT ) && !IsKeyPressed( VK_SPACE ) && !self->jumping && self->playerState != PLAYER_STATE_ATTACKING_1) { self->playerState = PLAYER_STATE_IDLE; } SendEntityMessage( self->base.owner, EM_CLDOFFLC, (int)"RUNNING_RIGHT", 0 ); SendEntityMessage( self->base.owner, EM_CLDOFFLC, (int)"RUNNING_LEFT", 0 ); SendEntityMessage( self->base.owner, EM_CLDOFFLC, (int)"JUMPING_RIGHT", 0 ); SendEntityMessage( self->base.owner, EM_CLDOFFLC, (int)"JUMPING_LEFT", 0 ); SendEntityMessage( self->base.owner, EM_CLDOFFLC, (int)"ATTACK_1_LEFT", 0 ); SendEntityMessage( self->base.owner, EM_CLDOFFLC, (int)"ATTACK_1_RIGHT", 0 ); SendEntityMessage( self->base.owner, EM_CLDOFFLC, (int)"IDLE_RIGHT", 0 ); SendEntityMessage( self->base.owner, EM_CLDOFFLC, (int)"IDLE_LEFT", 0 ); switch(self->playerState) { case PLAYER_STATE_IDLE: if(self->faceDir && !self->jumping) // facing right SendEntityMessage( self->base.owner, EM_CLDONLC, (int)"IDLE_RIGHT", 0 ); else if(!self->jumping) SendEntityMessage( self->base.owner, EM_CLDONLC, (int)"IDLE_LEFT", 0 ); if(self->faceDir && self->jumping) SendEntityMessage( self->base.owner, EM_CLDONLC, (int)"JUMPING_RIGHT", 0 ); else if(self->jumping) SendEntityMessage( self->base.owner, EM_CLDONLC, (int)"JUMPING_LEFT", 0 ); break; case PLAYER_STATE_MOVING: if(self->faceDir && !self->jumping) // facing right SendEntityMessage( self->base.owner, EM_CLDONLC, (int)"RUNNING_RIGHT", 0 ); else if(!self->jumping) SendEntityMessage( self->base.owner, EM_CLDONLC, (int)"RUNNING_LEFT", 0 ); if(self->faceDir && self->jumping) SendEntityMessage( self->base.owner, EM_CLDONLC, (int)"JUMPING_RIGHT", 0 ); else if(self->jumping) SendEntityMessage( self->base.owner, EM_CLDONLC, (int)"JUMPING_LEFT", 0 ); break; case PLAYER_STATE_ATTACKING_1: if(self->faceDir) // facing right SendEntityMessage( self->base.owner, EM_CLDONLC, (int)"ATTACK_1_RIGHT", 0 ); else SendEntityMessage( self->base.owner, EM_CLDONLC, (int)"ATTACK_1_LEFT", 0 ); break; case PLAYER_STATE_HIT: if(self->faceDir) // facing right SendEntityMessage( self->base.owner, EM_CLDONLC, (int)"HIT_RIGHT", 0 ); else SendEntityMessage( self->base.owner, EM_CLDONLC, (int)"HIT_LEFT", 0 ); break; } }
// --- DATA_PROC AVP_bool DATA_PARAM DATA_Serialize( HDATA data, AVP_dword* addr, AVP_Serialize_Data* opt, void* buffer, AVP_dword buffer_size, AVP_dword* size_out ) { AVP_word magic; AVP_dword version; AVP_dword max_size; AVP_dword* include; AVP_dword* exclude; AVP_bool root_siblings; Serialize sz; Buffer_Proc flush; FIND_DATA( data, addr ); /* size_to_save = sizeof( ((AVP_Serialize_Data*)0)->magic ) + // magic number sizeof( ((AVP_Serialize_Data*)0)->version ) + // version sizeof( ((AVP_Serialize_Data*)0)->translate_method ) + // translate_method sizeof( ((AVP_Serialize_Data*)0)->header_size ); // header size */ if ( opt ) { include = opt->props_include; exclude = opt->props_exclude; opt->version = 1; } else { include = 0; exclude = 0; } if ( buffer ) { if ( buffer_size ) { max_size = buffer_size; flush = opt ? opt->proc : 0; } else { _RPT0( _CRT_ASSERT, "Bad parameters" ); if ( size_out ) *size_out = 0; return 0; } } else { flush = 0; max_size = (AVP_dword)-1; } init_put_bytes( &sz, buffer, max_size, flush, opt ? opt->user_data : 0 ); magic = 0xadad; if ( put_word(&sz, &magic) != sizeof(magic) ) { if ( size_out ) *size_out = sz.tsize; return 0; } version = 1; if ( opt ) { root_siblings = opt->root_siblings; opt->version = 1; } else root_siblings = 1; if ( put_dword (&sz, &version) != sizeof(version) ) { if ( size_out ) *size_out = sz.tsize; return 0; } if ( put_dword (&sz, &sz.crc_cluster) != sizeof(sz.crc_cluster) ) { if ( size_out ) *size_out = sz.tsize; return 0; } sz.crc = -1; if ( 0 == DATA_Put(&sz,(AVP_Data*)data,root_siblings,include,exclude) ) { if ( size_out ) *size_out = sz.tsize; return 0; } else { AVP_dword res = flush_put_bytes( &sz ); if ( size_out ) *size_out = sz.tsize; return res != 0; } }
// Constructor for this entity type // Notes: Do not allocate space for the entity itself! This is handled // by the entity factory. This function is for allocation of // any other necessary memory. Perhaps a dynamically allocated // string, or other various memory allocations that are to be // pointed to by this entity. void HeroConstruct( ENTITY *self, int hp ) { VECTOR2D vel = { 0.f, 0.f }, accel = { 0 }, pos = { 5.0f, 20.0f }, widthHeight = { 4.f, 9.f }; GlobalCamInit( 0, 0, self ); // Add cloud component AddCloudComponent( self, 101, ENABLE_CAM ); // Insert loci into cloud SendComEM( self->comps.GC, EM_INSLOCUS, (int)AllocateAnimationLocus( "RUNNING_RIGHT", 0.f, 0.f, 0, .15f, "ManRun1.AEArt", "ManRun2.AEArt", "ManRun3.AEArt", "ManRun4.AEArt", "ManRun5.AEArt", "ManRun6.AEArt", 0 ), 0 ); SendComEM( self->comps.GC, EM_INSLOCUS, (int)AllocateImageLocus( "JUMPING_RIGHT", 0.f, 0.f, FIND_DATA( P_IMAGE, IMAGE_TABLE, "ManJump.AEArt" ), 0 ), 0 ); SendComEM( self->comps.GC, EM_INSLOCUS, (int)AllocateImageLocus( "JUMPING_LEFT", 2.f, 0.f, FIND_DATA( P_IMAGE, IMAGE_TABLE, "ManJumpFlipX.AEArt" ), 0 ), 0 ); SendComEM( self->comps.GC, EM_INSLOCUS, (int)AllocateAnimationLocus( "RUNNING_LEFT", -2.f, 0.f, 0, .15f, "ManRun1FlipX.AEArt", "ManRun2FlipX.AEArt", "ManRun3FlipX.AEArt", "ManRun4FlipX.AEArt", "ManRun5FlipX.AEArt", "ManRun6FlipX.AEArt", 0 ), 0 ); SendComEM( self->comps.GC, EM_INSLOCUS, (int)AllocateAnimationLocus( "ATTACK_1_RIGHT", -3.f, 0.f, 0, PLAYER_ATTACK_SPEED_SECONDS / 7.f, "ManSwing1.AEArt", "ManSwing2.AEArt", "ManSwing3.AEArt", "ManSwing4.AEArt", "ManSwing5.AEArt", "ManSwing6.AEArt", "ManSwing7.AEArt", 0 ), 0 ); SendComEM( self->comps.GC, EM_INSLOCUS, (int)AllocateAnimationLocus( "ATTACK_1_LEFT", -2.f, 0.f, 0, PLAYER_ATTACK_SPEED_SECONDS / 7.f, "ManSwing1FlipX.AEArt", "ManSwing2FlipX.AEArt", "ManSwing3FlipX.AEArt", "ManSwing4FlipX.AEArt", "ManSwing5FlipX.AEArt", "ManSwing6FlipX.AEArt", "ManSwing7FlipX.AEArt", 0 ), 0 ); SendComEM( self->comps.GC, EM_INSLOCUS, (int)AllocateImageLocus( "IDLE_RIGHT", 1.f, 0.f, FIND_DATA( P_IMAGE, IMAGE_TABLE, "WeaponMan.AEArt" ), 0 ), 0 ); SendComEM( self->comps.GC, EM_INSLOCUS, (int)AllocateImageLocus( "IDLE_LEFT", 1.f, 0.f, FIND_DATA( P_IMAGE, IMAGE_TABLE, "WeaponManFlipX.AEArt" ), 0 ), 0 ); // Set the properties flag of this object self->properties = PLAYER | DRAWME | GRAVITYME; // Add in additional components AddPositionComponent( self, (int)&pos.x_, (int)&pos.y_ ); AddPhysicsComponent( self, (int)&vel, (int)&accel ); AddSquareComponent( self, (int)&widthHeight.x_, (int)&widthHeight.y_ ); AddPlaCComponent( self ); AddHitPointsComponent( self, hp ); AddSmallInventoryComponent( self ); // Any other required initializations self->CLASS_NAME = CLASS_NAME; }