summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-03-10 11:53:11 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2021-03-11 17:33:15 -0500
commit4c29543e44deb7a327b21b0af6a85a92e83ff103 (patch)
treed8522851bb86a7872100ec800392d48a2de99f7b /src
parent883490ba63110fca757610a169621953bf2bd288 (diff)
downloadtanetane-4c29543e44deb7a327b21b0af6a85a92e83ff103.tar.gz
tanetane-4c29543e44deb7a327b21b0af6a85a92e83ff103.tar.bz2
tanetane-4c29543e44deb7a327b21b0af6a85a92e83ff103.zip
Fixed improperly calculated sprite hitboxes
Also made sprite hitboxes bigger.

#15
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp8
-rw-r--r--src/map.h2
-rw-r--r--src/transform_system.cpp18
3 files changed, 14 insertions, 14 deletions
diff --git a/src/main.cpp b/src/main.cpp index 051c4d1..dcf96e5 100644 --- a/src/main.cpp +++ b/src/main.cpp
@@ -35,7 +35,7 @@ void loop(Renderer& renderer, std::mt19937& rng) {
35 35
36 int lucasSprite = game.emplaceSprite("lucas"); 36 int lucasSprite = game.emplaceSprite("lucas");
37 game.getSystem<TransformSystem>().initSprite(lucasSprite, warpLoc); 37 game.getSystem<TransformSystem>().initSprite(lucasSprite, warpLoc);
38 game.getSystem<TransformSystem>().setUpCollision(lucasSprite, {-8, -8}, {12, 8}, true); 38 game.getSystem<TransformSystem>().setUpCollision(lucasSprite, {-8, -8}, {16, 8}, true);
39 game.getSystem<AnimationSystem>().initSprite(lucasSprite, "../res/sprites/lucas_anim.txt"); 39 game.getSystem<AnimationSystem>().initSprite(lucasSprite, "../res/sprites/lucas_anim.txt");
40 game.getSystem<AnimationSystem>().setSpriteDirection(lucasSprite, Direction::down); 40 game.getSystem<AnimationSystem>().setSpriteDirection(lucasSprite, Direction::down);
41 game.getSprite(lucasSprite).normallyHasShadow = true; 41 game.getSprite(lucasSprite).normallyHasShadow = true;
@@ -48,7 +48,7 @@ void loop(Renderer& renderer, std::mt19937& rng) {
48 48
49 int kumaSprite = game.emplaceSprite("kuma"); 49 int kumaSprite = game.emplaceSprite("kuma");
50 game.getSystem<TransformSystem>().initSprite(kumaSprite, warpLoc); 50 game.getSystem<TransformSystem>().initSprite(kumaSprite, warpLoc);
51 game.getSystem<TransformSystem>().setUpCollision(kumaSprite, {-8, -8}, {12, 8}, false); 51 game.getSystem<TransformSystem>().setUpCollision(kumaSprite, {-8, -8}, {16, 8}, false);
52 game.getSystem<AnimationSystem>().initSprite(kumaSprite, "../res/sprites/kuma_anim.txt"); 52 game.getSystem<AnimationSystem>().initSprite(kumaSprite, "../res/sprites/kuma_anim.txt");
53 game.getSystem<AnimationSystem>().setSpriteDirection(kumaSprite, Direction::down); 53 game.getSystem<AnimationSystem>().setSpriteDirection(kumaSprite, Direction::down);
54 game.getSprite(kumaSprite).normallyHasShadow = true; 54 game.getSprite(kumaSprite).normallyHasShadow = true;
@@ -57,7 +57,7 @@ void loop(Renderer& renderer, std::mt19937& rng) {
57 57
58 int dusterSprite = game.emplaceSprite("duster"); 58 int dusterSprite = game.emplaceSprite("duster");
59 game.getSystem<TransformSystem>().initSprite(dusterSprite, warpLoc); 59 game.getSystem<TransformSystem>().initSprite(dusterSprite, warpLoc);
60 game.getSystem<TransformSystem>().setUpCollision(dusterSprite, {-8, -8}, {12, 8}, false); 60 game.getSystem<TransformSystem>().setUpCollision(dusterSprite, {-8, -8}, {16, 8}, false);
61 game.getSystem<AnimationSystem>().initSprite(dusterSprite, "../res/sprites/duster_anim.txt"); 61 game.getSystem<AnimationSystem>().initSprite(dusterSprite, "../res/sprites/duster_anim.txt");
62 game.getSystem<AnimationSystem>().setSpriteDirection(dusterSprite, Direction::down); 62 game.getSystem<AnimationSystem>().setSpriteDirection(dusterSprite, Direction::down);
63 game.getSprite(dusterSprite).normallyHasShadow = true; 63 game.getSprite(dusterSprite).normallyHasShadow = true;
@@ -66,7 +66,7 @@ void loop(Renderer& renderer, std::mt19937& rng) {
66 66
67 int boneySprite = game.emplaceSprite("boney"); 67 int boneySprite = game.emplaceSprite("boney");
68 game.getSystem<TransformSystem>().initSprite(boneySprite, warpLoc); 68 game.getSystem<TransformSystem>().initSprite(boneySprite, warpLoc);
69 game.getSystem<TransformSystem>().setUpCollision(boneySprite, {-8, -8}, {12, 8}, false); 69 game.getSystem<TransformSystem>().setUpCollision(boneySprite, {-8, -8}, {16, 8}, false);
70 game.getSystem<AnimationSystem>().initSprite(boneySprite, "../res/sprites/boney_anim.txt"); 70 game.getSystem<AnimationSystem>().initSprite(boneySprite, "../res/sprites/boney_anim.txt");
71 game.getSystem<AnimationSystem>().setSpriteDirection(boneySprite, Direction::down); 71 game.getSystem<AnimationSystem>().setSpriteDirection(boneySprite, Direction::down);
72 game.getSprite(boneySprite).normallyHasShadow = true; 72 game.getSprite(boneySprite).normallyHasShadow = true;
diff --git a/src/map.h b/src/map.h index 9418aad..8b79d7b 100644 --- a/src/map.h +++ b/src/map.h
@@ -22,7 +22,7 @@ struct Prototype {
22 std::string name; 22 std::string name;
23 vec2i pos; 23 vec2i pos;
24 vec2i collisionOffset {-8, -8}; 24 vec2i collisionOffset {-8, -8};
25 vec2i collisionSize {12, 8}; 25 vec2i collisionSize {16, 8};
26 std::string animationFilename; 26 std::string animationFilename;
27 std::string animName; 27 std::string animName;
28 Direction dir = Direction::down; 28 Direction dir = Direction::down;
diff --git a/src/transform_system.cpp b/src/transform_system.cpp index 055f546..4ed47c0 100644 --- a/src/transform_system.cpp +++ b/src/transform_system.cpp
@@ -61,9 +61,9 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i curLoc, vec2
61 vec2i horizMovement = { newLoc.x(), curLoc.y() }; 61 vec2i horizMovement = { newLoc.x(), curLoc.y() };
62 62
63 vec2i oldColUL = curLoc + sprite.collisionOffset; 63 vec2i oldColUL = curLoc + sprite.collisionOffset;
64 vec2i oldColDR = oldColUL + sprite.collisionSize; 64 vec2i oldColDR = oldColUL + sprite.collisionSize - vec2i{1,1};
65 vec2i newColUL = horizMovement + sprite.collisionOffset; 65 vec2i newColUL = horizMovement + sprite.collisionOffset;
66 vec2i newColDR = newColUL + sprite.collisionSize; 66 vec2i newColDR = newColUL + sprite.collisionSize - vec2i{1,1};
67 67
68 vec2i oldTileUL = oldColUL / map.getTileSize(); 68 vec2i oldTileUL = oldColUL / map.getTileSize();
69 vec2i newTileUL = newColUL / map.getTileSize(); 69 vec2i newTileUL = newColUL / map.getTileSize();
@@ -89,8 +89,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i curLoc, vec2
89 } 89 }
90 90
91 if (!result.horiz.blocked && enclosureZone) { 91 if (!result.horiz.blocked && enclosureZone) {
92 if (oldColDR.x() <= enclosureZone->dr.x() && 92 if (oldColDR.x() <= enclosureZone->dr.x()-1 &&
93 newColDR.x() > enclosureZone->dr.x()) { 93 newColDR.x() > enclosureZone->dr.x()-1) {
94 result.horiz.blocked = true; 94 result.horiz.blocked = true;
95 result.horiz.dir = Direction::right; 95 result.horiz.dir = Direction::right;
96 } 96 }
@@ -168,9 +168,9 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i curLoc, vec2
168 } 168 }
169 169
170 oldColUL = effectiveCurLoc + sprite.collisionOffset; 170 oldColUL = effectiveCurLoc + sprite.collisionOffset;
171 oldColDR = oldColUL + sprite.collisionSize; 171 oldColDR = oldColUL + sprite.collisionSize - vec2i{1,1};
172 newColUL = vertMovement + sprite.collisionOffset; 172 newColUL = vertMovement + sprite.collisionOffset;
173 newColDR = newColUL + sprite.collisionSize; 173 newColDR = newColUL + sprite.collisionSize - vec2i{1,1};
174 174
175 oldTileUL = oldColUL / map.getTileSize(); 175 oldTileUL = oldColUL / map.getTileSize();
176 newTileUL = newColUL / map.getTileSize(); 176 newTileUL = newColUL / map.getTileSize();
@@ -191,8 +191,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i curLoc, vec2
191 } 191 }
192 192
193 if (!result.vert.blocked && enclosureZone) { 193 if (!result.vert.blocked && enclosureZone) {
194 if (oldColDR.y() <= enclosureZone->dr.y() && 194 if (oldColDR.y() <= enclosureZone->dr.y()-1 &&
195 newColDR.y() > enclosureZone->dr.y()) { 195 newColDR.y() > enclosureZone->dr.y()-1) {
196 result.vert.blocked = true; 196 result.vert.blocked = true;
197 result.vert.dir = Direction::down; 197 result.vert.dir = Direction::down;
198 } 198 }
@@ -268,7 +268,7 @@ CharacterMedium TransformSystem::getMediumAtPosition(int spriteId, vec2i newLoc)
268 const Map& map = game_.getMap(); 268 const Map& map = game_.getMap();
269 269
270 vec2i newColUL = newLoc + sprite.collisionOffset; 270 vec2i newColUL = newLoc + sprite.collisionOffset;
271 vec2i newColDR = newColUL + sprite.collisionSize; 271 vec2i newColDR = newColUL + sprite.collisionSize - vec2i{1,1};
272 vec2i newTileUL = newColUL / map.getTileSize(); 272 vec2i newTileUL = newColUL / map.getTileSize();
273 vec2i newTileDR = newColDR / map.getTileSize(); 273 vec2i newTileDR = newColDR / map.getTileSize();
274 274