-
-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add fallblocks [ci skip] * Update game object factory [ci skip] * Add images [ci skip] * Update objects file * update due to review * Delete cave-5x8.png [ci skip]
- Loading branch information
1 parent
70f01c2
commit fa14dce
Showing
26 changed files
with
284 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(supertux-sprite | ||
(action | ||
(name "normal") | ||
(hitbox 0 32 123 32) | ||
(images "branchleft.png") | ||
) | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(supertux-sprite | ||
(action | ||
(name "normal") | ||
(hitbox 5 32 123 32) | ||
(images "branchright.png") | ||
) | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(supertux-sprite | ||
(action | ||
(name "normal") | ||
(hitbox 0 32 64 96) | ||
(images "cave-2x3.png") | ||
) | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(supertux-sprite | ||
(action | ||
(name "normal") | ||
(hitbox 0 32 96 64) | ||
(images "cave-3x2.png") | ||
) | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(supertux-sprite | ||
(action | ||
(name "normal") | ||
(hitbox 0 32 96 128) | ||
(images "cave-3x4.png") | ||
) | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(supertux-sprite | ||
(action | ||
(name "normal") | ||
(hitbox 0 32 128 96) | ||
(images "cave-4x3.png") | ||
) | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(supertux-sprite | ||
(action | ||
(name "normal") | ||
(hitbox 0 32 128 128) | ||
(images "cave-4x4.png") | ||
) | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(supertux-sprite | ||
(action | ||
(name "normal") | ||
(hitbox 0 32 128 192) | ||
(images "cave-4x6.png") | ||
) | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(supertux-sprite | ||
(action | ||
(name "normal") | ||
(hitbox 0 32 160 96) | ||
(images "cave-5x3.png") | ||
) | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(supertux-sprite | ||
(action | ||
(name "normal") | ||
(hitbox 0 32 160 224) | ||
(images "cave-5x7.png") | ||
) | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(supertux-sprite | ||
(action | ||
(name "normal") | ||
(hitbox 0 32 192 128) | ||
(images "cave-6x4.png") | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Copyright (C) 2020 Daniel Ward <weluvgoatz@gmail.com> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#include "object/fallblock.hpp" | ||
|
||
#include "audio/sound_manager.hpp" | ||
#include "object/player.hpp" | ||
#include "object/camera.hpp" | ||
#include "sprite/sprite.hpp" | ||
#include "supertux/sector.hpp" | ||
#include "supertux/tile.hpp" | ||
#include "math/random.hpp" | ||
#include "util/reader_mapping.hpp" | ||
|
||
FallBlock::FallBlock(const ReaderMapping& reader) : | ||
MovingSprite(reader, "images/objects/fallblock/cave-4x4.sprite", LAYER_OBJECTS, COLGROUP_STATIC), | ||
state(IDLE), | ||
physic(), | ||
timer() | ||
{ | ||
SoundManager::current()->preload("sounds/cracking.wav"); | ||
SoundManager::current()->preload("sounds/thud.ogg"); | ||
physic.enable_gravity(false); | ||
} | ||
|
||
void | ||
FallBlock::update(float dt_sec) | ||
{ | ||
switch (state) | ||
{ | ||
case IDLE: | ||
set_group(COLGROUP_STATIC); | ||
if (found_victim_down()) | ||
{ | ||
state = SHAKE; | ||
SoundManager::current()->play("sounds/cracking.wav"); | ||
timer.start(0.5f); | ||
} | ||
break; | ||
case SHAKE: | ||
if (timer.check()) | ||
{ | ||
state = FALL; | ||
physic.reset(); | ||
physic.enable_gravity(true); | ||
} | ||
break; | ||
case FALL: | ||
m_col.m_movement = physic.get_movement (dt_sec); | ||
set_group(COLGROUP_MOVING_STATIC); | ||
break; | ||
case LAND: | ||
m_col.m_movement = physic.get_movement (dt_sec); | ||
set_group(COLGROUP_MOVING_STATIC); | ||
break; | ||
} | ||
} | ||
|
||
HitResponse | ||
FallBlock::collision(GameObject& other, const CollisionHit& hit) | ||
{ | ||
auto fallblock = dynamic_cast<FallBlock*> (&other); | ||
if (fallblock && hit.bottom && (state == FALL || state == LAND)) | ||
{ | ||
physic.set_velocity_y(0.0f); | ||
return CONTINUE; | ||
} | ||
|
||
auto player = dynamic_cast<Player*>(&other); | ||
if (state == IDLE && player && player->get_bbox().get_bottom() < m_col.m_bbox.get_top()) | ||
{ | ||
state = SHAKE; | ||
SoundManager::current()->play("sounds/cracking.wav"); | ||
timer.start(0.5f); | ||
} | ||
return FORCE_MOVE; | ||
} | ||
|
||
void | ||
FallBlock::collision_solid(const CollisionHit& hit) | ||
{ | ||
if (hit.top || hit.bottom || hit.crush) | ||
{ | ||
physic.set_velocity(0.0f, 0.0f); | ||
} | ||
|
||
if (state == FALL && hit.bottom) | ||
{ | ||
Sector::get().get_camera().shake(0.125f, 0.0f, 10.0f); | ||
SoundManager::current()->play("sounds/thud.ogg"); | ||
state = LAND; | ||
} | ||
} | ||
|
||
void | ||
FallBlock::draw(DrawingContext& context) | ||
{ | ||
Vector pos = get_pos(); | ||
// shaking | ||
if (state == SHAKE && state != IDLE && state != FALL && state != LAND) | ||
{ | ||
pos.x += static_cast<float>(graphicsRandom.rand(-8.0f, 8.0f)); | ||
pos.y += static_cast<float>(graphicsRandom.rand(-5.0f, 5.0f)); | ||
} | ||
m_sprite->draw(context.color(), pos, m_layer); | ||
} | ||
|
||
bool | ||
FallBlock::found_victim_down() const | ||
{ | ||
if (auto* player = Sector::get().get_nearest_player(m_col.m_bbox)) | ||
{ | ||
const Rectf& player_bbox = player->get_bbox(); | ||
Rectf crush_area_down = Rectf(m_col.m_bbox.get_left()+1, m_col.m_bbox.get_bottom(), | ||
m_col.m_bbox.get_right()-1, std::max(m_col.m_bbox.get_bottom(),player_bbox.get_top()-1)); | ||
if ((player_bbox.get_top() >= m_col.m_bbox.get_bottom()) | ||
&& (player_bbox.get_right() > (m_col.m_bbox.get_left() - 4)) | ||
&& (player_bbox.get_left() < (m_col.m_bbox.get_right() + 4)) | ||
&& (Sector::get().is_free_of_statics(crush_area_down, this, false))) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (C) 2020 Daniel Ward <weluvgoatz@gmail.com> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#ifndef HEADER_SUPERTUX_OBJECT_FALLBLOCK_HPP | ||
#define HEADER_SUPERTUX_OBJECT_FALLBLOCK_HPP | ||
|
||
#include "object/moving_sprite.hpp" | ||
#include "supertux/physic.hpp" | ||
#include "supertux/timer.hpp" | ||
|
||
class Player; | ||
|
||
class FallBlock : public MovingSprite | ||
|
||
{ | ||
public: | ||
FallBlock(const ReaderMapping& reader); | ||
|
||
virtual void update(float dt_sec) override; | ||
|
||
virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override; | ||
virtual void collision_solid(const CollisionHit& hit) override; | ||
|
||
virtual void draw(DrawingContext& context) override; | ||
|
||
virtual std::string get_class() const override { return "fallblock"; } | ||
virtual std::string get_display_name() const override { return _("Falling Platform"); } | ||
|
||
protected: | ||
enum State | ||
{ | ||
IDLE, | ||
SHAKE, | ||
FALL, | ||
LAND | ||
}; | ||
|
||
private: | ||
State state; | ||
|
||
Physic physic; | ||
Timer timer; | ||
|
||
bool found_victim_down() const; | ||
|
||
private: | ||
FallBlock(const FallBlock&) = delete; | ||
FallBlock& operator=(const FallBlock&) = delete; | ||
}; | ||
|
||
#endif | ||
|
||
/* EOF */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters