summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--res/scripts/common.lua16
-rw-r--r--src/character_system.cpp6
-rw-r--r--src/script_system.cpp3
-rw-r--r--src/sprite.h1
4 files changed, 22 insertions, 4 deletions
diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 45b596d..af25333 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua
@@ -284,3 +284,19 @@ end
284function RemoveExpression(spriteName) 284function RemoveExpression(spriteName)
285 DestroyNamedSprite(AliasForSpriteExpression(spriteName)) 285 DestroyNamedSprite(AliasForSpriteExpression(spriteName))
286end 286end
287
288--- Turns on clipping for the player.
289-- This allows walking through solid objects. For debug only!
290function StartClipping()
291 local playerId = getPlayerSprite()
292 local playerSprite = getSprite(playerId)
293 playerSprite.clipping = true
294end
295
296--- Turns off clipping for the player.
297-- For debug only!
298function StopClipping()
299 local playerId = getPlayerSprite()
300 local playerSprite = getSprite(playerId)
301 playerSprite.clipping = false
302end
diff --git a/src/character_system.cpp b/src/character_system.cpp index 6e15eac..99b6929 100644 --- a/src/character_system.cpp +++ b/src/character_system.cpp
@@ -117,7 +117,7 @@ void CharacterSystem::tick(double dt) {
117 CollisionResult collision = game_.getSystem<TransformSystem>().checkCollision(spriteId, pLoc, sprite.dir); 117 CollisionResult collision = game_.getSystem<TransformSystem>().checkCollision(spriteId, pLoc, sprite.dir);
118 bool blocked = collision.horiz.blocked || collision.vert.blocked; 118 bool blocked = collision.horiz.blocked || collision.vert.blocked;
119 119
120 if (collision.horiz.blocked) { 120 if (collision.horiz.blocked && !sprite.clipping) {
121 pLoc.x() = sprite.loc.x();//(newColPosDR * map.getTileSize() - (collisionBox / 2)).x() - 1; 121 pLoc.x() = sprite.loc.x();//(newColPosDR * map.getTileSize() - (collisionBox / 2)).x() - 1;
122 } else if (collision.horiz.colliderSprite != -1) { 122 } else if (collision.horiz.colliderSprite != -1) {
123 Sprite& collider = game_.getSprite(collision.horiz.colliderSprite); 123 Sprite& collider = game_.getSprite(collision.horiz.colliderSprite);
@@ -127,7 +127,7 @@ void CharacterSystem::tick(double dt) {
127 } 127 }
128 } 128 }
129 129
130 if (collision.vert.blocked) { 130 if (collision.vert.blocked && !sprite.clipping) {
131 pLoc.y() = sprite.loc.y();//(newColPosDR * map.getTileSize() - (collisionBox / 2)).x() - 1; 131 pLoc.y() = sprite.loc.y();//(newColPosDR * map.getTileSize() - (collisionBox / 2)).x() - 1;
132 } else if (collision.vert.colliderSprite != -1) { 132 } else if (collision.vert.colliderSprite != -1) {
133 Sprite& collider = game_.getSprite(collision.vert.colliderSprite); 133 Sprite& collider = game_.getSprite(collision.vert.colliderSprite);
@@ -137,7 +137,7 @@ void CharacterSystem::tick(double dt) {
137 } 137 }
138 } 138 }
139 139
140 if (blocked && sprite.characterState == CharacterState::Running) { 140 if (blocked && sprite.characterState == CharacterState::Running && !sprite.clipping) {
141 stopRunning(spriteId); 141 stopRunning(spriteId);
142 game_.getMixer().playSound("../res/sfx/bump.wav"); 142 game_.getMixer().playSound("../res/sfx/bump.wav");
143 } 143 }
diff --git a/src/script_system.cpp b/src/script_system.cpp index 769a872..2e02edf 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp
@@ -37,7 +37,8 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) {
37 return sprite.frames[sprite.animations[sprite.animationId].frameIndices[sprite.animationFrame]]; 37 return sprite.frames[sprite.animations[sprite.animationId].frameIndices[sprite.animationFrame]];
38 }, 38 },
39 "persistent", &Sprite::persistent, 39 "persistent", &Sprite::persistent,
40 "paused", &Sprite::paused); 40 "paused", &Sprite::paused,
41 "clipping", &Sprite::clipping);
41 42
42 engine_.new_usertype<MessageSystem>( 43 engine_.new_usertype<MessageSystem>(
43 "message", 44 "message",
diff --git a/src/sprite.h b/src/sprite.h index 35ca7aa..3d2e9df 100644 --- a/src/sprite.h +++ b/src/sprite.h
@@ -77,6 +77,7 @@ public:
77 CharacterState characterState = CharacterState::Still; 77 CharacterState characterState = CharacterState::Still;
78 StepType stepType = StepType::none; 78 StepType stepType = StepType::none;
79 int runningSfxChannel = -1; 79 int runningSfxChannel = -1;
80 bool clipping = false;
80 81
81 // Input 82 // Input
82 bool controllable = false; 83 bool controllable = false;