Implemented hoe
This commit is contained in:
parent
33de4a8d1f
commit
91c0da855b
@ -1,6 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>Player
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ItemCollection>
|
||||
|
||||
<GameObject name="Stone hoe">
|
||||
<Transform />
|
||||
<Sprite src="sprites/items/HoeStone.sprite" />
|
||||
<SpriteRenderer />
|
||||
<Item name="Stone pickaxe"
|
||||
description="The most basic type of pickaxe. It can break small stones."
|
||||
level="1" />
|
||||
<Weapon damage="0.5"
|
||||
critProbability="0"
|
||||
critDamage="0"
|
||||
attackDuration="0.2" />
|
||||
<Hoe />
|
||||
</GameObject>
|
||||
|
||||
<!--
|
||||
<GameObject name="Stone pickaxe">
|
||||
<Transform />
|
||||
<SpriteRenderer sprite="sprites/items/StonePickaxe.sprite" />
|
||||
@ -13,5 +28,5 @@
|
||||
attackDuration="0.5" />
|
||||
<PickaxeItem />
|
||||
</GameObject>
|
||||
|
||||
-->
|
||||
</ItemCollection>
|
10
assets/sprites/items/HoeStone.sprite
Normal file
10
assets/sprites/items/HoeStone.sprite
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Sprite name="StoneHoe"
|
||||
anchorX="0" anchorY="0.1">
|
||||
<State name="Normal">
|
||||
<Frame tileSet="sprites/items/hoe.png" cell="0" w="1" h="1" duration="1" />
|
||||
</State>
|
||||
<State name="Attack">
|
||||
<Frame tileSet="sprites/items/hoe.png" cell="1" w="1" h="1" duration="1" />
|
||||
</State>
|
||||
</Sprite>
|
BIN
assets/sprites/items/hoe.png
Normal file
BIN
assets/sprites/items/hoe.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 266 B |
BIN
assets_original/hoe.xcf
Normal file
BIN
assets_original/hoe.xcf
Normal file
Binary file not shown.
43
src/components/items/Hoe.cpp
Normal file
43
src/components/items/Hoe.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Hoe.cpp
|
||||
*
|
||||
* Created on: Dec 2, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#include <components/items/Hoe.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace farmlands {
|
||||
namespace components {
|
||||
namespace items {
|
||||
|
||||
Hoe::Hoe()
|
||||
{
|
||||
}
|
||||
|
||||
Hoe::~Hoe()
|
||||
{
|
||||
}
|
||||
|
||||
model::Component* Hoe::clone()
|
||||
{
|
||||
return new Hoe();
|
||||
}
|
||||
|
||||
void Hoe::dump(unsigned level)
|
||||
{
|
||||
for (unsigned i = 0; i < level; i++)
|
||||
std::cout<<" ";
|
||||
|
||||
std::cout << " .Component: Hoe\n";
|
||||
}
|
||||
|
||||
void Hoe::performAttack(float x, float y, model::Direction d)
|
||||
{
|
||||
}
|
||||
|
||||
} /* namespace items */
|
||||
} /* namespace components */
|
||||
} /* namespace farmlands */
|
34
src/components/items/Hoe.h
Normal file
34
src/components/items/Hoe.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Hoe.h
|
||||
*
|
||||
* Created on: Dec 2, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#ifndef COMPONENTS_ITEMS_HOE_H_
|
||||
#define COMPONENTS_ITEMS_HOE_H_
|
||||
|
||||
#include <model/Component.h>
|
||||
#include <model/Direction.h>
|
||||
|
||||
namespace farmlands {
|
||||
namespace components {
|
||||
namespace items {
|
||||
|
||||
class Hoe: public model::Component
|
||||
{
|
||||
public:
|
||||
Hoe();
|
||||
virtual ~Hoe();
|
||||
|
||||
virtual model::Component* clone() override;
|
||||
virtual void dump(unsigned level) override;
|
||||
|
||||
void performAttack(float x, float y, model::Direction d);
|
||||
};
|
||||
|
||||
} /* namespace items */
|
||||
} /* namespace components */
|
||||
} /* namespace farmlands */
|
||||
|
||||
#endif /* COMPONENTS_ITEMS_HOE_H_ */
|
@ -19,8 +19,8 @@ Weapon::Weapon()
|
||||
critProbability(0),
|
||||
critDamage(0),
|
||||
attackDuration(1.0f),
|
||||
m_sprite(nullptr),
|
||||
m_attackTimeLeft(0)
|
||||
attackTimeLeft(0),
|
||||
m_sprite(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@ -46,22 +46,22 @@ void Weapon::onInitialize()
|
||||
|
||||
void Weapon::onPreRender()
|
||||
{
|
||||
m_sprite->setState(m_attackTimeLeft > 0);
|
||||
m_sprite->setState(attackTimeLeft > 0);
|
||||
}
|
||||
|
||||
void Weapon::onUpdateLogic()
|
||||
{
|
||||
if (m_attackTimeLeft > 0)
|
||||
if (attackTimeLeft > 0)
|
||||
{
|
||||
m_attackTimeLeft -= GameState::current().elapsedTime;
|
||||
attackTimeLeft -= GameState::current().elapsedTime;
|
||||
}
|
||||
}
|
||||
|
||||
void Weapon::performAttack(float x, float y, model::Direction d)
|
||||
{
|
||||
if (m_attackTimeLeft <= 0)
|
||||
if (attackTimeLeft <= 0)
|
||||
{
|
||||
m_attackTimeLeft = attackDuration;
|
||||
attackTimeLeft = attackDuration;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,10 +41,10 @@ namespace items {
|
||||
float critDamage;
|
||||
|
||||
float attackDuration; // In seconds
|
||||
float attackTimeLeft;
|
||||
|
||||
private:
|
||||
basic::Sprite* m_sprite;
|
||||
float m_attackTimeLeft;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <GameState.h>
|
||||
#include <components/items/Giftable.h>
|
||||
#include <components/items/Hoe.h>
|
||||
#include <components/items/Item.h>
|
||||
#include <components/items/Weapon.h>
|
||||
#include <components/player/PlayerController.h>
|
||||
@ -45,7 +46,8 @@ PlayerController::PlayerController()
|
||||
m_facingDirection(Direction::South),
|
||||
m_walking(false),
|
||||
m_running(false),
|
||||
m_currentItem(nullptr)
|
||||
m_currentItem(nullptr),
|
||||
m_currentWeapon(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@ -81,6 +83,11 @@ void PlayerController::handleAttackEvents(SDL_Event& event)
|
||||
if (weapon)
|
||||
weapon->performAttack(m_transform->x, m_transform->y, m_facingDirection);
|
||||
|
||||
// Tools
|
||||
Hoe* hoe = m_currentItem->component<Hoe>();
|
||||
if (hoe)
|
||||
hoe->performAttack(m_transform->x, m_transform->y, m_facingDirection);
|
||||
|
||||
// Gift behavior
|
||||
Giftable* giftable = m_currentItem->component<Giftable>();
|
||||
if (giftable)
|
||||
@ -115,11 +122,7 @@ void PlayerController::handleInventoryEvents(SDL_Event& event)
|
||||
|
||||
// Instantiate new object
|
||||
m_currentItem = GameObject::instantiate(itemPrefab, "Current item", gameObject);
|
||||
|
||||
// Print some information
|
||||
// Item* item = itemPrefab->component<Item>();
|
||||
// std::string name = (item == nullptr) ? "unknown" : item->name;
|
||||
// std::cout << "Instantiated object " << slot << " (" << name << ")\n";
|
||||
m_currentWeapon = m_currentItem->component<Weapon>();
|
||||
}
|
||||
else if (0 <= slot)
|
||||
{
|
||||
@ -135,19 +138,16 @@ void PlayerController::onUpdateLogic()
|
||||
// Compute movement velocity
|
||||
float velMultiplier = PlayerWalkVelocity;
|
||||
|
||||
// if (m_attackTimeLeft)
|
||||
// {
|
||||
// velMultiplier = PlayerAttackVelocity;
|
||||
// --m_attackTimeLeft;
|
||||
// } else
|
||||
|
||||
if (Input::instance().pressed(GameKey::Run))
|
||||
if (m_currentWeapon && m_currentWeapon->attackTimeLeft > 0)
|
||||
{
|
||||
velMultiplier = PlayerAttackVelocity;
|
||||
}
|
||||
else if (Input::instance().pressed(GameKey::Run))
|
||||
{
|
||||
velMultiplier = PlayerRunVelocity;
|
||||
m_running = true;
|
||||
}
|
||||
|
||||
|
||||
// Make movement time independent
|
||||
velMultiplier *= GameState::current().elapsedTime;
|
||||
|
||||
@ -189,8 +189,8 @@ void PlayerController::onPreRender()
|
||||
|
||||
// Set animation velocity
|
||||
float animVelocity = (m_running) ? 1.0f : 0.7f;
|
||||
// if (m_attackTimeLeft)
|
||||
// animVelocity = 0.1f;
|
||||
if (m_currentWeapon && m_currentWeapon->attackTimeLeft > 0)
|
||||
animVelocity = 0.1f;
|
||||
|
||||
sprite->animationVelocity = animVelocity;
|
||||
|
||||
@ -222,11 +222,6 @@ Direction PlayerController::getDirection(float vx, float vy)
|
||||
return VelocitySignDirections[xx + 1][yy + 1];
|
||||
}
|
||||
|
||||
void PlayerController::attack()
|
||||
{
|
||||
// For now - nothing
|
||||
}
|
||||
|
||||
void PlayerController::dump(unsigned level)
|
||||
{
|
||||
for (unsigned i = 0; i < level; i++)
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define CONTROLLER_PLAYERCONTROLLER_H_
|
||||
|
||||
#include <components/basic/Transform.h>
|
||||
#include <components/items/Weapon.h>
|
||||
#include <model/Component.h>
|
||||
#include <model/Direction.h>
|
||||
|
||||
@ -39,13 +40,14 @@ namespace player {
|
||||
void handleInventoryEvents(SDL_Event& event);
|
||||
|
||||
bool canMove(float x, float y);
|
||||
void attack();
|
||||
|
||||
basic::Transform* m_transform;
|
||||
model::Direction m_facingDirection;
|
||||
bool m_walking, m_running;
|
||||
|
||||
model::GameObject* m_currentItem;
|
||||
items::Weapon* m_currentWeapon;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ void ResourceManager::loadGame()
|
||||
GameState::current().scene = storage::parse<model::Scene>(R::Scenes::Game);
|
||||
GameState::current().scene->root.onCreate();
|
||||
|
||||
// storage::parseCollection(R::Items::Tools, GameState::current().itemPrefabs);
|
||||
storage::parseCollection(R::Items::Tools, GameState::current().itemPrefabs);
|
||||
storage::parseCollection(R::Items::Weapons, GameState::current().itemPrefabs);
|
||||
}
|
||||
|
||||
|
@ -17,51 +17,53 @@ namespace resources {
|
||||
Player = 0,
|
||||
items_Lvl2Sword = 1,
|
||||
items_Stone_pickaxe = 2,
|
||||
items_Lvl1Sword = 3,
|
||||
items_Sword = 4,
|
||||
items_HoeStone = 3,
|
||||
items_Lvl1Sword = 4,
|
||||
items_Sword = 5,
|
||||
items_Hoe = 6,
|
||||
};
|
||||
enum Scenes
|
||||
{
|
||||
Game = 5,
|
||||
Game = 7,
|
||||
};
|
||||
enum Fonts
|
||||
{
|
||||
DejaVuSans = 6,
|
||||
DejaVuSans = 8,
|
||||
};
|
||||
enum Tilesets
|
||||
{
|
||||
PlayerTiles = 7,
|
||||
Ground = 8,
|
||||
PlayerTiles = 9,
|
||||
Ground = 10,
|
||||
};
|
||||
enum Ui
|
||||
{
|
||||
Mini_inventory = 9,
|
||||
Cursor = 10,
|
||||
Mini_inventory = 11,
|
||||
Cursor = 12,
|
||||
};
|
||||
enum Levels
|
||||
{
|
||||
Farm_Background = 11,
|
||||
Farm = 12,
|
||||
Farm_Background = 13,
|
||||
Farm = 14,
|
||||
};
|
||||
enum Config
|
||||
{
|
||||
Default = 13,
|
||||
Default = 15,
|
||||
};
|
||||
enum Items
|
||||
{
|
||||
Tools = 14,
|
||||
Weapons = 15,
|
||||
Tools = 16,
|
||||
Weapons = 17,
|
||||
};
|
||||
}
|
||||
|
||||
const int RInfo_Sprites_Begin = 0;
|
||||
const int RInfo_Scenes_Begin = 5;
|
||||
const int RInfo_Fonts_Begin = 6;
|
||||
const int RInfo_Tilesets_Begin = 7;
|
||||
const int RInfo_Ui_Begin = 9;
|
||||
const int RInfo_Levels_Begin = 11;
|
||||
const int RInfo_Config_Begin = 13;
|
||||
const int RInfo_Items_Begin = 14;
|
||||
const int RInfo_Scenes_Begin = 7;
|
||||
const int RInfo_Fonts_Begin = 8;
|
||||
const int RInfo_Tilesets_Begin = 9;
|
||||
const int RInfo_Ui_Begin = 11;
|
||||
const int RInfo_Levels_Begin = 13;
|
||||
const int RInfo_Config_Begin = 15;
|
||||
const int RInfo_Items_Begin = 16;
|
||||
|
||||
/**
|
||||
* This array contains the names of all the files, and the corresponding file type.
|
||||
@ -70,8 +72,10 @@ namespace resources {
|
||||
{ "sprites/Player.sprite", ResourceType::Sprite },
|
||||
{ "sprites/items/Lvl2Sword.sprite", ResourceType::Sprite },
|
||||
{ "sprites/items/stone_pickaxe.sprite", ResourceType::Sprite },
|
||||
{ "sprites/items/HoeStone.sprite", ResourceType::Sprite },
|
||||
{ "sprites/items/Lvl1Sword.sprite", ResourceType::Sprite },
|
||||
{ "sprites/items/sword.png", ResourceType::Texture },
|
||||
{ "sprites/items/hoe.png", ResourceType::Texture },
|
||||
{ "scenes/Game.scene", ResourceType::Scene },
|
||||
{ "fonts/DejaVuSans.ttf", ResourceType::Font },
|
||||
{ "tilesets/PlayerTiles.png", ResourceType::Texture },
|
||||
|
@ -313,6 +313,9 @@ GameObject* parse<GameObject> (boost::property_tree::ptree& root)
|
||||
else if (child.first == "Giftable")
|
||||
gameObj->addComponent(parse<Giftable>(child.second));
|
||||
|
||||
else if (child.first == "Hoe")
|
||||
gameObj->addComponent(parse<Hoe>(child.second));
|
||||
|
||||
else if (child.first == "Item")
|
||||
gameObj->addComponent(parse<Item>(child.second));
|
||||
|
||||
@ -356,6 +359,17 @@ Configuration* parse<Configuration> (boost::property_tree::ptree& root)
|
||||
return config;
|
||||
}
|
||||
|
||||
template <>
|
||||
Hoe* parse<Hoe> (boost::property_tree::ptree& root)
|
||||
{
|
||||
// Ensure we are on the scene node (property tree seems to add root of its own)
|
||||
if (root.front().first == "Hoe")
|
||||
root = root.front().second;
|
||||
|
||||
Hoe* hoe = new Hoe();
|
||||
return hoe;
|
||||
}
|
||||
|
||||
template <>
|
||||
Item* parse<Item> (boost::property_tree::ptree& root)
|
||||
{
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <components/basic/Transform.h>
|
||||
#include <components/DebugController.h>
|
||||
#include <components/items/Giftable.h>
|
||||
#include <components/items/Hoe.h>
|
||||
#include <components/items/Item.h>
|
||||
#include <components/items/Weapon.h>
|
||||
#include <components/player/PlayerController.h>
|
||||
@ -56,6 +57,9 @@ namespace storage {
|
||||
template <>
|
||||
components::items::Giftable* parse<components::items::Giftable> (boost::property_tree::ptree& root);
|
||||
|
||||
template <>
|
||||
components::items::Hoe* parse<components::items::Hoe> (boost::property_tree::ptree& root);
|
||||
|
||||
template <>
|
||||
components::items::Item* parse<components::items::Item> (boost::property_tree::ptree& root);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user