Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first iteration #115

Merged
merged 1 commit into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Classes/MainScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,21 @@ void MainScene::showImGui() {
_player->changeHp(-1);
}
}
if (ImGui::Button("FireBullet")) {
if (_player) {
_player->changeBulletCreator(new FireBulletCreator(ShootingCharacter::playerPhysMask()));
}
}
if (ImGui::Button("IdleBullet")) {
if (_player) {
_player->changeBulletCreator(new IdleBulletCreator(ShootingCharacter::playerPhysMask()));
}
}
if (ImGui::Button("IceBullet")) {
if (_player) {
_player->changeBulletCreator(new IceBulletCreator(ShootingCharacter::playerPhysMask()));
}
}
//Position
ImGui::Text("Position X: %f Y: %f", _player->getPosition().x, _player->getPosition().y);
//HP
Expand Down
3 changes: 3 additions & 0 deletions Classes/Trigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ void Trigger::onCollision() {
isActivated = true;
_TMM->getTiledMap()->getLayer(FG + triggerFunc.at(2))->setVisible(false);
break;
case 5:
isActivated = true;
_player->changeBulletCreator(new FireBulletCreator(ShootingCharacter::playerPhysMask()));
}
}

Expand Down
3 changes: 2 additions & 1 deletion Classes/Trigger.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class Trigger : public b2Sprite
{"SA", 0},
{"SM", 1},
{"LL", 2},
{"LD", 3}
{"LD", 3},
{"BF", 5}
};
bool isActivated = false;
std::string triggerFunc;
Expand Down
37 changes: 31 additions & 6 deletions Classes/bullets/FireBullet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,34 @@ FireBullet* FireBullet::create(cocos2d::Node* world, Vec2 pos, Vec2 dest, b2Filt
bullet->setCoords(pos, dest);
bullet->getFixtureDef()->filter = filter;
bullet->ordinaryOptions(world, pos);
bullet->setCooldown();
return bullet;
}
CC_SAFE_DELETE(bullet);
return nullptr;
}

void FireBullet::setCooldown() {
Vec2 nDest = getDest();
nDest.normalize();
nDest *= 10;
double k = getDest().x / nDest.x;
_attackConstCooldown = 0.25*(1/k);//k;
}

void FireBullet::shoot(Vec2 targetPos, IBulletTypeCreator* bulletCreator) {
if (_attackCooldown <= 0) {
_attackCooldown = 0.5;
_attackCooldown = _attackConstCooldown;
Vec2 pos = getPosition();
Vec2 dest = targetPos; //+ pos;
Vec2 newDest = dest;
newDest.rotate(Vec2(), 0.9f);
//newDest.rotate(Vec2(), 0.1f);
newDest.normalize();
newDest *= getContentSize().height;
Vec2 pos1 = pos + newDest;
//dest.y *= -1;
dest.normalize();
dest *= PLAYER_BULLET_SPEED;
//dest.normalize();
//dest *= PLAYER_BULLET_SPEED;
_shootingPattern->shoot(pos1, dest, bulletCreator);
_fireCount++;
}
Expand Down Expand Up @@ -89,6 +98,8 @@ FireBlast* FireBlast::create(cocos2d::Node* world, Vec2 pos, Vec2 dest, b2Filter
//bullet->init();
bullet->setCoords(pos, dest);
bullet->_moveDest = bullet->getDest();
bullet->_moveDest.rotate(Vec2(), M_PI/2);
bullet->setAngleMoveParam();
bullet->getFixtureDef()->filter = filter;
bullet->ordinaryOptions(world, pos);
return bullet;
Expand All @@ -97,12 +108,26 @@ FireBlast* FireBlast::create(cocos2d::Node* world, Vec2 pos, Vec2 dest, b2Filter
return nullptr;
}

void FireBlast::setAngleMoveParam() {
Vec2 nDest = getDest();
nDest.normalize();
nDest *= 10;
double k = getDest().x / nDest.x;
_moveDest *= (0.66f);
_moveAngle = M_PI * 2 / (30*(1/k));
}

int FireBlast::getDamage() {
return 0;
}

void FireBlast::move(float dt) {

_moveDest.rotate(Vec2(), 360/60 );
getBody()->SetLinearVelocity(b2Vec2(getDest().x + _moveDest.x, getDest().y + _moveDest.y));
_moveDest.rotate(Vec2(), _moveAngle);
setPosition(getPosition() + _moveDest);
//Vec2 sdest = getDest() + _moveDest;
//dest *= dt / 0.016;
//getBody()->SetLinearVelocity(b2Vec2(_moveDest.x, _moveDest.y));
getBody()->SetLinearVelocity(b2Vec2(getDest().x, getDest().y));
//getBody()->SetLinearVelocity(b2Vec2(getDest().x + _moveDest.x, getDest().y + _moveDest.y));
}
4 changes: 4 additions & 0 deletions Classes/bullets/FireBullet.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class FireBullet : public Bullet, ShootingCharacter {

void shoot(cocos2d::Vec2 targetPos, IBulletTypeCreator* bulletCreator) override;
private:
void setCooldown();
int _fireCount; //created fires
float _attackConstCooldown;
};

class FireBlast : public Bullet {
Expand All @@ -27,5 +29,7 @@ class FireBlast : public Bullet {
int getDamage() override;

private:
void setAngleMoveParam();
Vec2 _moveDest;
double _moveAngle;
};
2 changes: 1 addition & 1 deletion Classes/bullets/IShootingPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void ShotGunShootingPattern::shoot(Vec2 pos, Vec2 dest, IBulletTypeCreator* bull

void CircleShootingPattern::shoot(Vec2 pos, Vec2 dest, IBulletTypeCreator* bulletCreator) {
float a = -0.13;
for (int i = 0; i < 12; i++) {
for (int i = -6; i < 6; i++) {
Vec2 newDest = dest;
newDest.rotate(Vec2(), a * i);
_parent->createBulletOnParent(bulletCreator, pos, newDest);
Expand Down
3 changes: 3 additions & 0 deletions Classes/bullets/PlayerHookBullet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ void PlayerHookBullet::update(float dt) {
if (_hooked) {
getBody()->SetLinearVelocity(b2Vec2(0, 0));
}
if (!_hooked && _moveTime <= 0) {
setOnRemove();
}
Bullet::update(dt);
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/characters/ShootingCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const float ShootingCharacter::PLAYER_ATTACK_COOLDOWN = 0.2f;
const float ShootingCharacter::PLAYER_BIG_ATTACK_COOLDOWN = 1;
const float ShootingCharacter::ENEMY_ATTACK_COOLDOWN = 0.5f;
const int ShootingCharacter::PLAYER_BULLET_SPEED = 10;

const int ShootingCharacter::PLAYER_HOOK_SPEED = 15;

b2Filter ShootingCharacter::playerPhysMask() {
b2Filter filter;
Expand Down
11 changes: 6 additions & 5 deletions Classes/characters/ShootingCharacter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ class ShootingCharacter {
static const float PLAYER_BIG_ATTACK_COOLDOWN;
static const float ENEMY_ATTACK_COOLDOWN;
static const int PLAYER_BULLET_SPEED;
protected:
float _attackCooldown;
static const int PLAYER_HOOK_SPEED;

b2Filter playerPhysMask();
b2Filter enemyPhysMask();
b2Filter hookPhysMask();
static b2Filter playerPhysMask();
static b2Filter enemyPhysMask();
static b2Filter hookPhysMask();

protected:
float _attackCooldown;
IShootingPattern* _shootingPattern;
};

23 changes: 17 additions & 6 deletions Classes/player/Player.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Player.h"
#include "box2d/b2dRootWorldNode.h"
#include "IShootingPattern.h"
//#include "IShootingPattern.h"
#include "external/json/document.h"

USING_NS_CC;
Expand Down Expand Up @@ -113,7 +113,10 @@ bool Player::init() {
//Hook
_hook = nullptr;
_hookBody = DrawNode::create();
_hookPattern = new IdleShootingPattern(this);
addChild(_hookBody);
//shoot
_bulletCreator = new IdleBulletCreator(playerPhysMask());

//Animation
//Idle animation
Expand Down Expand Up @@ -303,7 +306,8 @@ void Player::mousePressed(cocos2d::Event* event) {
EventMouse* mouse = dynamic_cast<EventMouse*>(event);

if (mouse->getMouseButton() == EventMouse::MouseButton::BUTTON_LEFT) {
shoot(clickPosCalculate(mouse), new FireBulletCreator(playerPhysMask()));
//shoot(clickPosCalculate(mouse), _bulletCreator);
shoot(clickPosCalculate(mouse), _bulletCreator);
//hit();
setAnimState(eAnimState::Attack);
}
Expand All @@ -313,6 +317,10 @@ void Player::mousePressed(cocos2d::Event* event) {
}
}

void Player::changeBulletCreator(IBulletTypeCreator* bulletCreator) {
_bulletCreator = bulletCreator;
}

void Player::move(float dt) {
//UNDONE moving
if (getBody()->GetLinearVelocity().x < _maxSpeed && _curSpeed > 0) {
Expand Down Expand Up @@ -340,12 +348,15 @@ void Player::shoot(Vec2 targetPos, IBulletTypeCreator* bulletCreator) {
Vec2 dest = targetPos - pos;
dest.normalize();
dest.y *= -1;
dest *= PLAYER_BULLET_SPEED;
if (auto isHook = dynamic_cast<PlayerHookBullet*>(bulletCreator)) {
if (auto isHook = dynamic_cast<HookBulletCreator*>(bulletCreator)) {
dest *= PLAYER_HOOK_SPEED;
//dest += {getBody()->GetLinearVelocity().x, getBody()->GetLinearVelocity().y};
_hookPattern->shoot(pos, dest, bulletCreator);
}
else {
dest *= PLAYER_BULLET_SPEED;
_shootingPattern->shoot(pos, dest, bulletCreator);
}

_shootingPattern->shoot(pos, dest, bulletCreator);
}
}

Expand Down
8 changes: 8 additions & 0 deletions Classes/player/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ShootingCharacter.h"
#include "PlayerHookBullet.h"
#include "MeleeCharacter.h"
#include "IShootingPattern.h"

enum class eJumpState {
None,
Expand Down Expand Up @@ -56,7 +57,14 @@ class Player : public ShootingCharacter, public MeleeCharacter, public b2Sprite

//functions for testing
int getJumpCount() const;

//for change bullets
void changeBulletCreator(IBulletTypeCreator* bulletCreator);
private:
//shoot
IBulletTypeCreator* _bulletCreator;
IdleShootingPattern* _hookPattern;

//functions
void move(float dt);
void jump(float dt);
Expand Down
7 changes: 6 additions & 1 deletion Resources/maximum.tmx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="500" height="500" tilewidth="64" tileheight="64" infinite="0" nextlayerid="9" nextobjectid="25">
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="500" height="500" tilewidth="64" tileheight="64" infinite="0" nextlayerid="9" nextobjectid="28">
<tileset firstgid="1" source="Texture1.tsx"/>
<tileset firstgid="1025" source="Texture2.tsx"/>
<objectgroup id="8" name="ObjectLayer" offsetx="24" offsety="152">
Expand All @@ -13,6 +13,11 @@
<property name="ReturnSmth" value="ASD11 SD22"/>
</properties>
</object>
<object id="27" x="10980" y="9941" width="137" height="150">
<properties>
<property name="ReturnSmth" value="BF"/>
</properties>
</object>
</objectgroup>
<layer id="2" name="Collidable" width="500" height="500" offsetx="24" offsety="152">
<data encoding="csv">
Expand Down
2 changes: 1 addition & 1 deletion Resources/nodeProperties/bullets.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"name": "PlayerHookBullet",
"specifications": {
"damage": 100,
"moveTime": 2.0,
"moveTime": 0.8,
"lifeTime": 7.0
},
"components": {
Expand Down
4 changes: 2 additions & 2 deletions proj.win32/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Size=400,213
Collapsed=1

[Window][Debug]
Pos=1080,566
Size=357,214
Pos=1046,589
Size=357,185
Collapsed=0