void SausageEntity::readCollidingEntity(CollidingSpriteEntity* entity) { if (!isDying && !isAgonising && collideWithEntity(entity)) { if (entity->getType() == ENTITY_PLAYER || entity->getType() == ENTITY_BOLT ) { PlayerEntity* playerEntity = dynamic_cast<PlayerEntity*>(entity); BoltEntity* boltEntity = dynamic_cast<BoltEntity*>(entity); if (playerEntity != NULL && !playerEntity->isDead()) dying(); else if (boltEntity != NULL && !boltEntity->getDying() && boltEntity->getAge() > 0.05f) collideWithBolt(boltEntity); } else // collision with other enemy ? { if (entity->getType() >= ENTITY_ENEMY && entity->getType() <= ENTITY_ENEMY_MAX) { if (this != entity) { EnemyEntity* enemyEntity = static_cast<EnemyEntity*>(entity); if (enemyEntity->canCollide()) collideWithEnemy(enemyEntity); } } } } }
void ImpEntity::collideWithEnnemy(GameEntity* collidingEntity) { EnemyEntity* entity = static_cast<EnemyEntity*>(collidingEntity); if (entity->getMovingStyle() == movFlying) { setVelocity(Vector2D(entity->getX(), entity->getY()).vectorTo(Vector2D(x, y), creatureSpeed )); } }
void SnakeEntity::readCollidingEntity(CollidingSpriteEntity* entity) { if (!isDying && !isAgonising && collideWithEntity(entity)) { if (entity->getType() == ENTITY_PLAYER || entity->getType() == ENTITY_BOLT ) { PlayerEntity* playerEntity = dynamic_cast<PlayerEntity*>(entity); BoltEntity* boltEntity = dynamic_cast<BoltEntity*>(entity); if (playerEntity != NULL && !playerEntity->isDead()) { int meleeLevel = 0; if (snakeType == SnakeTypeBlood) { if (rand() % 3 == 0) { meleeType = ShotTypePoison; meleeDamages = 4; meleeLevel = 1; } else { meleeType = ShotTypeStandard; meleeDamages = 8; } } if (playerEntity->hurt(getHurtParams(meleeDamages, meleeType, meleeLevel, false, SourceTypeMelee, enemyType, false))) { float xs = (x + playerEntity->getX()) / 2; float ys = (y + playerEntity->getY()) / 2; SpriteEntity* star = new SpriteEntity(ImageManager::getInstance().getImage(IMAGE_HURT_IMPACT), xs, ys); star->setFading(true); star->setZ(y+ 100); star->setLifetime(0.7f); star->setType(ENTITY_EFFECT); star->setSpin(400.0f); } inflictsRecoilTo(playerEntity); } else if (boltEntity != NULL && !boltEntity->getDying() && boltEntity->getAge() > 0.05f) { collideWithBolt(boltEntity); } } else // collision with other enemy ? { if (entity->getType() >= ENTITY_ENEMY && entity->getType() <= ENTITY_ENEMY_MAX_COUNT) { if (this != entity) { EnemyEntity* enemyEntity = static_cast<EnemyEntity*>(entity); if (enemyEntity->canCollide()) collideWithEnemy(enemyEntity); } } } } }
void WitchEntity::collideWithEnnemy(GameEntity* collidingEntity) { EnemyEntity* entity = static_cast<EnemyEntity*>(collidingEntity); if (entity->getMovingStyle() == movWalking) { setVelocity(Vector2D(entity->getX(), entity->getY()).vectorTo(Vector2D(x, y), creatureSpeed )); computeFacingDirection(); } }
void BatEntity::collideWithEnnemy(GameEntity* collidingEntity) { EnemyEntity* entity = static_cast<EnemyEntity*>(collidingEntity); if (entity->getMovingStyle() == movFlying) { setVelocity(Vector2D(entity->getX(), entity->getY()).vectorTo(Vector2D(x, y), BAT_SPEED )); computeFacingDirection(); } }
void EnemyCache::spawnEnemyOfType(int enemyType) { CCArray* enemiesOfType = (CCArray*)enemies->getObjectAtIndex(enemyType); Ref* enemy; CCARRAY_FOREACH(enemiesOfType, enemy) { EnemyEntity *entity = (EnemyEntity*)enemy; // find the first free enemy and respawn it if (!entity->isVisible()) { //CCLOG(@"spawn enemy type %i", enemyType); entity->spawn(entity); break; } }
void SlimePetEntity::readCollidingEntity(CollidingSpriteEntity* entity) { if (canCollide() && collideWithEntity(entity)) { if (entity->getType() >= ENTITY_ENEMY && entity->getType() <= ENTITY_ENEMY_MAX_COUNT) { EnemyEntity* enemyEntity = static_cast<EnemyEntity*>(entity); if (enemyEntity->canCollide()) { if (attackDelay <= 0.0f) { enemyEntity->hurt(getHurtParams(12, ShotTypeStandard,0, false, SourceTypeMelee, EnemyTypeNone,false)); attackDelay = 0.65f; float xs = (x + enemyEntity->getX()) / 2; float ys = (y + enemyEntity->getY()) / 2; SpriteEntity* star = new SpriteEntity(ImageManager::getInstance().getImage(IMAGE_HURT_IMPACT), xs, ys); star->setFading(true); star->setZ(y+ 100); star->setLifetime(0.7f); star->setType(ENTITY_EFFECT); star->setSpin(400.0f); } if (enemyEntity->getMovingStyle() == movWalking) { Vector2D vel = Vector2D(enemyEntity->getX(), enemyEntity->getY()).vectorTo(Vector2D(x, y), 100.0f ); giveRecoil(false, vel, 0.3f); } } } } }
EnemyEntity* MyGame::buildEnemyEntity(Vector3 pos) { EnemyEntity* ee = new EnemyEntity(new SceneNode(enemy),new PhysicsNode()); ee->ConnectToSystems(); ee->GetPhysicsNode().SetPosition(pos); ee->GetPhysicsNode().addCV(new CollisionSphere(ee->GetPhysicsNode().GetPosition(),50.0f)); ee->GetPhysicsNode().dynamic = false; ee->GetPhysicsNode().sleep = true; ee->GetPhysicsNode().gravity = true; ee->GetRenderNode().SetBoundingRadius(25.0f); ee->GetRenderNode().SetModelScale(Vector3(25.0f)); ee->GetRenderNode().SetShader(enemyShader); return ee; }
void SpiderWebEntity::readCollidingEntity(CollidingSpriteEntity* entity) { if (!isDying && !isAgonising && collideWithEntity(entity)) { if (entity->getType() == ENTITY_PLAYER || entity->getType() == ENTITY_BOLT ) { PlayerEntity* playerEntity = dynamic_cast<PlayerEntity*>(entity); BoltEntity* boltEntity = dynamic_cast<BoltEntity*>(entity); if (!isFromPlayer && playerEntity != NULL && !playerEntity->isDead()) { if (!playerEntity->isSpecialStateActive(SpecialStateSlow)) { playerEntity->setSpecialState(SpecialStateSlow, true, 0.1f, 0.33f, 0.0f); // TODO hurt(getHurtParams(2, ShotTypeStandard, 0, false, SourceTypeMelee, EnemyTypeNone, false)); } } else if (!isFromPlayer && boltEntity != NULL && !boltEntity->getDying() && boltEntity->getAge() > 0.05f) { EnemyEntity::collideWithBolt(boltEntity); } } else // collision with other enemy ? { if (entity->getType() >= ENTITY_ENEMY && entity->getType() <= ENTITY_ENEMY_MAX) { if (this != entity) { EnemyEntity* enemyEntity = static_cast<EnemyEntity*>(entity); if (enemyEntity->canCollide()) collideWithEnemy(enemyEntity); } } } } }
void ObstacleEntity::readCollidingEntity(CollidingSpriteEntity* entity) { if (entity == this) return; if (!isDying && !isAgonising && collideWithEntity(entity)) { if (entity->getType() == ENTITY_BOLT ) { BoltEntity* boltEntity = dynamic_cast<BoltEntity*>(entity); if (!boltEntity->getDying() && boltEntity->getAge() > 0.05f) { EnemyEntity::collideWithBolt(boltEntity); correctFrame(); } } else if (entity->getType() == ENTITY_ENEMY_BOLT ) { EnemyBoltEntity* boltEntity = dynamic_cast<EnemyBoltEntity*>(entity); if (!boltEntity->getDying() && boltEntity->getAge() > 0.05f) { EnemyEntity::collideWithBolt(boltEntity); correctFrame(); } } else if (entity->getType() >= ENTITY_ENEMY && entity->getType() <= ENTITY_ENEMY_MAX) { EnemyEntity* enemyEntity = dynamic_cast<EnemyEntity*>(entity); if (!enemyEntity->getDying() && enemyEntity->canCollide()&& enemyEntity->getMovingStyle() != movFlying) { hurt(getHurtParams(hp, ShotTypeStandard, 0, false, SourceTypeMelee, enemyEntity->getEnemyType(), false)); } } } }
MyGame::MyGame() { //Init variables ammo = 0; force = 0; waveno=0; cube = new OBJMesh(MESHDIR"cube.obj"); cube->SetTexture(SOIL_load_OGL_texture( TEXTUREDIR"Barren Reds.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS)); if(!cube->GetTexture()) { cout << "barren reds is playing up" << endl; } quad = Mesh::GenerateQuad(); enemy = new OBJMesh(MESHDIR"ico2.obj"); enemy ->SetTexture(SOIL_load_OGL_texture( TEXTUREDIR"leo.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS)); if(!enemy->GetTexture()) { cout << "leopard skins f****d" << endl; } sphere = new OBJMesh(MESHDIR"ico2.obj"); sphere->SetTexture(SOIL_load_OGL_texture( TEXTUREDIR"swirl.tga", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS)); if(!sphere->GetTexture()) { cout << "swirl is BUM" << endl; } player = new OBJMesh(MESHDIR"ico2.obj"); player->SetTexture(SOIL_load_OGL_texture( TEXTUREDIR"cliff.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS)); if(!player->GetTexture()) { cout << "cliff is f****d" << endl; } CubeMap = SOIL_load_OGL_cubemap( TEXTUREDIR"interstellar_ft.tga", TEXTUREDIR"interstellar_bk.tga", TEXTUREDIR"interstellar_up.tga", TEXTUREDIR"interstellar_dn.tga", TEXTUREDIR"interstellar_rt.tga", TEXTUREDIR"interstellar_lf.tga", SOIL_LOAD_RGB, SOIL_CREATE_NEW_ID,0); enemy->SetCubeMap(CubeMap); if(!CubeMap) cout << "cube maps f*****g broken"; bumpShader = new Shader(SHADERDIR"bumpVertex.glsl",SHADERDIR"bumpFragment.glsl"); if(!bumpShader->LinkProgram()) { return; } enemyShader = new Shader(SHADERDIR"perPixelVertex.glsl",SHADERDIR"enemyFragment.glsl"); if(!enemyShader->LinkProgram()) { return; } heightmap = new HeightMap(TEXTUREDIR"stage1.raw"); heightmap->SetTexture(SOIL_load_OGL_texture( TEXTUREDIR"grass.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS)); heightmap->SetBumpMap(SOIL_load_OGL_texture( TEXTUREDIR"grassbump.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS)); SetTextureRepeating(heightmap->GetBumpMap(),true); if(!heightmap->GetTexture()){ cout << "height maps f*****g broken" << endl; } if(!heightmap->GetBumpMap()) { cout << "height map bump map f*****g broken" << endl; } for(int i = 0; i < NO_PROJECTILES; ++i) { projectiles[i] = BuildSphereEntity(25.0f); projectiles[i]->GetPhysicsNode().SetPosition(Vector3((51.0f* i) + 100.0f,500.0f,30.0f * i)); projectiles[i]->GetPhysicsNode().sleep = true; } for(int i = 0; i < NO_LASERS; ++i) { PhysicsSystem::GetPhysicsSystem().AddLaser(buildLaserEntity()); } PlanePos = Vector3(2048.0f,100.0f,2048.0f); // y = 450.0f playerEntity = buildPlayerEntity(); PhysicsSystem::GetPhysicsSystem().SetPlayer(playerEntity); allEntities.push_back(playerEntity); allEntities.push_back(BuildHeightmapEntity()); for(int i = 0; i < NO_PROJECTILES; ++i) { allEntities.push_back(projectiles[i]); } for(int i = 0; i < 10; ++i) { EnemyEntity* ee = buildEnemyEntity(Vector3(PlanePos.x + 150,PlanePos.y + 150, PlanePos.z + (i * 90) - 270)); ee->SetY(100.0f + (100.0f * i)); allEntities.push_back(ee); PhysicsSystem::GetPhysicsSystem().AddEnemy((ee)); } //gameCamera = new Camera(-2.0f,270.0f,Vector3(-360.0f,450.0f,3408.0f)); //gameCamera = new TPCamera(); gameCamera = new CameraMan(playerEntity->circleT); gameCamera->toggleLock(); Renderer::GetRenderer().SetCamera(gameCamera); ret = new Reticule(WIDTH,HEIGHT,FOV,ASPECT, gameCamera); //ret->c = gameCamera; Renderer::GetRenderer().SetReticule(ret); PhysicsSystem::GetPhysicsSystem().SetReticule(ret); //ret = new Reticule(); }
void Entity::updatePosition(cocos2d::Vec2 pos){ if(frameChangeCount-- < 0){ frameChangeCount = 3; this->changeFrame(); } // If the current position is (still) outside the screen no adjustments should be made! // This allows entities to move into the screen from outside. bool hasCollision = false; Rect screenRect = GameScene::getScreenRect(); Rect boundingBox = this->boundingBox(); boundingBox.origin.x += screenRect.origin.x; boundingBox.origin.y += screenRect.origin.y; if (screenRect.intersectsRect(boundingBox)) { auto screenSize = GameScene::getScreenRect().size; float halfWidth = this->getContentSize().width * 0.5f; float halfHeight = this->getContentSize().height * 0.5f; // Cap the position so the Ship's sprite stays on the screen if (pos.x < halfWidth){ pos.x = halfWidth; if (dynamic_cast<EnemyEntity*>(this)){ EnemyEntity *entity = dynamic_cast<EnemyEntity*>(this); entity->changeDirection(); } } else if(pos.x > (screenSize.width - halfWidth)){ pos.x = screenSize.width - halfWidth; if (dynamic_cast<EnemyEntity*>(this)){ EnemyEntity *entity = dynamic_cast<EnemyEntity*>(this); entity->changeDirection(); } } if (pos.y < halfHeight){ pos.y = halfHeight; if (dynamic_cast<EnemyEntity*>(this)) { EnemyEntity *entity = dynamic_cast<EnemyEntity*>(this); entity->changeDirection(); } } else if(pos.y > (screenSize.height - halfHeight)){ pos.y = screenSize.height - halfHeight; if (dynamic_cast<EnemyEntity*>(this)) { EnemyEntity *entity = dynamic_cast<EnemyEntity*>(this); entity->changeDirection(); } } if(this->getRotation() == 0) { hasCollision = this->checkUpCollision(pos); } else if (this->getRotation() == 90) { hasCollision = this->checkRightCollision(pos); } else if(this->getRotation() == 180) { hasCollision = this->checkDownCollision(pos); } else if(this->getRotation() == 270) { hasCollision = this->checkLeftCollision(pos); } } if (!hasCollision) { this->setPosition(pos); } else if(dynamic_cast<EnemyEntity *>(this)){ auto entity = dynamic_cast<EnemyEntity *>(this); entity->changeDirection(); } }