Java-Gaming.org
 Featured games (81) games approved by the League of Dukes Games in Showcase (495) Games in Android Showcase (114) games submitted by our members Games in WIP (563) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Home Help Search Login Register
Pages: [1]
 ignore  |  Print
 What you think of my game until now? How can i make the archer move properly?  (Read 726 times) 0 Members and 1 Guest are viewing this topic.
Andre Lopes
 « Posted 2013-09-07 15:53:02 »

Heya guys!!!
Well, i have a little gameplay video to show, and hm, i was wondering, how can i make my archer and animals move properly in the slopes??
Heres the movement code i have, its from dermetfan but i changed so much due to my own needs hehe

So anyway, i need help, at least with theory so i can start drawning ideas and logics in my book

So heres the video :

http://www.youtube.com/watch?v=_SDAY_vuqeo

And heres the movement code of the archer :

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99  100  101  102  103  104  105  106  107  108  109  110  111  112  113  114  115  116  117  118  119  120  121  122  123  124  125  126  127  128  129  130  131  132  133  134  135  136  137 ` public void update(float delta) {        if (data.getCurrent_Health() <= 0) {            alive = false;        }        if (alive) {            // apply gravity            velocity.y -= gravity * delta;            // clamp velocity            if (velocity.y > speed) {                velocity.y = speed;            } else if (velocity.y < -speed) {                velocity.y = -speed;            }            // save old position            float oldX = getX(), oldY = getY(), tileWidth = collisionLayer.getTileWidth(), tileHeight = collisionLayer.getTileHeight();            boolean collisionX = false, collisionY = false;            // move on x            setX(getX() + velocity.x * delta);            if (velocity.x < 0) { // going left                // top left                TiledMapTileLayer.Cell cell = collisionLayer.getCell((int) (getX() / tileWidth), (int) ((getY() + getHeight()) / tileHeight));                if (cell != null) {                    collisionX = cell.getTile().getProperties().containsKey("blocked");                }                // middle left                if (!collisionX) {                    TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) (getX() / tileWidth), (int) ((getY() + getHeight() / 2) / tileHeight));                    if (cell1 != null) {                        collisionX = cell1.getTile().getProperties().containsKey("blocked");                    }                }                // bottom left                if (!collisionX) {                    TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) (getX() / tileWidth), (int) (getY() / tileHeight));                    if (cell1 != null) {                        collisionX = cell1.getTile().getProperties().containsKey("blocked");                    }                }            } else if (velocity.x > 0) { // going right                // top right                TiledMapTileLayer.Cell cell = collisionLayer.getCell((int) ((getX() + getWidth()) / tileWidth), (int) ((getY() + getHeight()) / tileHeight));                if (cell != null) {                    collisionX = cell.getTile().getProperties().containsKey("blocked");                }                // middle right                if (!collisionX) {                    TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((getX() + getWidth()) / tileWidth), (int) ((getY() + getHeight() / 2) / tileHeight));                    if (cell1 != null) {                        collisionX = cell1.getTile().getProperties().containsKey("blocked");                    }                }                // bottom right                if (!collisionX) {                    TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((getX() + getWidth()) / tileWidth), (int) (getY() / tileHeight));                    if (cell1 != null) {                        collisionX = cell1.getTile().getProperties().containsKey("blocked");                    }                }            }            // react to x collision            if (collisionX) {                setX(oldX);                velocity.x = 0;            }            // move on y            setY(getY() + velocity.y * delta);            if (velocity.y < 0) { // going down                // bottom left                TiledMapTileLayer.Cell cell = collisionLayer.getCell((int) (getX() / tileWidth), (int) (getY() / tileHeight));                if (cell != null) {                    collisionY = cell.getTile().getProperties().containsKey("blocked");                }                // bottom middle                if (!collisionY) {                    TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((getX() + getWidth() / 2) / tileWidth), (int) (getY() / tileHeight));                    if (cell1 != null) {                        collisionY = cell1.getTile().getProperties().containsKey("blocked");                    }                }                // bottom right                if (!collisionY) {                    TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((getX() + getWidth()) / tileWidth), (int) (getY() / tileHeight));                    if (cell1 != null) {                        collisionY = cell1.getTile().getProperties().containsKey("blocked");                    }                }                canJump = collisionY;            } else if (velocity.y > 0) { // going up                // top left                TiledMapTileLayer.Cell cell = collisionLayer.getCell((int) (getX() / tileWidth), (int) ((getY() + getHeight()) / tileHeight));                if (cell != null) {                    collisionY = cell.getTile().getProperties().containsKey("blocked");                }                // top middle                if (!collisionY) {                    TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((getX() + getWidth() / 2) / tileWidth), (int) ((getY() + getHeight()) / tileHeight));                    if (cell1 != null) {                        collisionY = cell1.getTile().getProperties().containsKey("blocked");                    }                }                // top right                if (!collisionY) {                    TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((getX() + getWidth()) / tileWidth), (int) ((getY() + getHeight()) / tileHeight));                    if (cell1 != null) {                        collisionY = cell1.getTile().getProperties().containsKey("blocked");                    }                }            }            // react to y collision            if (collisionY) {                setY(oldY);                velocity.y = 0;            }        }       .....                    }            }`
Andre Lopes
 « Reply #1 - Posted 2013-09-07 22:08:01 »

How can i fix this?
http://img545.imageshack.us/img545/2733/9nmg.jpg

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99  100  101  102  103  104  105  106  107  108  109  110  111  112  113  114  115  116  117  118  119  120  121  122  123  124  125  126  127  128  129  130  131 `private int default_x_width = 38; //40    private int default_y_height = 40; //44        public void updateMovement(TiledMapTileLayer collisionLayer, Vector2 velocity, float gravity, float delta, float speed) {        //player.setOrigin(player.getOriginX() + player.getOriginX() / 3, player.getOriginY());        // apply gravity        velocity.y -= gravity * delta;        // clamp velocity        if (velocity.y > speed) {            velocity.y = speed;        } else if (velocity.y < -speed) {            velocity.y = -speed;        }        // save old position        float oldX = player.getX(), oldY = player.getY(), tileWidth = collisionLayer.getTileWidth(), tileHeight = collisionLayer.getTileHeight();        boolean collisionX = false, collisionY = false;        // move on x        player.setX(player.getX() + velocity.x * delta);        if (velocity.x < 0) { // going left            // top left            TiledMapTileLayer.Cell cell = collisionLayer.getCell((int) (player.getX() / tileWidth), (int) ((player.getY() + default_y_height) / tileHeight));            if (cell != null) {                collisionX = cell.getTile().getProperties().containsKey("blocked");            }            // middle left            if (!collisionX) {                TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) (player.getX() / tileWidth), (int) ((player.getY() + default_y_height / 2) / tileHeight));                if (cell1 != null) {                    collisionX = cell1.getTile().getProperties().containsKey("blocked");                }            }            // bottom left            if (!collisionX) {                TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) (player.getX() / tileWidth), (int) (player.getY() / tileHeight));                if (cell1 != null) {                    collisionX = cell1.getTile().getProperties().containsKey("blocked");                }            }        } else if (velocity.x > 0) { // going right            // top right            TiledMapTileLayer.Cell cell = collisionLayer.getCell((int) ((player.getX() + default_x_width) / tileWidth), (int) ((player.getY() + default_y_height) / tileHeight));            if (cell != null) {                collisionX = cell.getTile().getProperties().containsKey("blocked");            }            // middle right            if (!collisionX) {                TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((player.getX() + default_x_width) / tileWidth), (int) ((player.getY() + default_y_height / 2) / tileHeight));                if (cell1 != null) {                    collisionX = cell1.getTile().getProperties().containsKey("blocked");                }            }            // bottom right            if (!collisionX) {                TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((player.getX() + default_x_width) / tileWidth), (int) (player.getY() / tileHeight));                if (cell1 != null) {                    collisionX = cell1.getTile().getProperties().containsKey("blocked");                }            }        }        // react to x collision        if (collisionX) {            player.setX(oldX);            velocity.x = 0;        }        // move on y        player.setY(player.getY() + velocity.y * delta);        if (velocity.y < 0) { // going down            // bottom left            TiledMapTileLayer.Cell cell = collisionLayer.getCell((int) (player.getX() / tileWidth), (int) (player.getY() / tileHeight));            if (cell != null) {                collisionY = cell.getTile().getProperties().containsKey("blocked");            }            // bottom middle            if (!collisionY) {                TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((player.getX() + default_x_width / 2) / tileWidth), (int) (player.getY() / tileHeight));                if (cell1 != null) {                    collisionY = cell1.getTile().getProperties().containsKey("blocked");                }            }            // bottom right            if (!collisionY) {                TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((player.getX() + default_x_width) / tileWidth), (int) (player.getY() / tileHeight));                if (cell1 != null) {                    collisionY = cell1.getTile().getProperties().containsKey("blocked");                }            }            player.canJump = collisionY;        } else if (velocity.y > 0) { // going up            // top left            TiledMapTileLayer.Cell cell = collisionLayer.getCell((int) (player.getX() / tileWidth), (int) ((player.getY() + default_y_height) / tileHeight));            if (cell != null) {                collisionY = cell.getTile().getProperties().containsKey("blocked");            }            // top middle            if (!collisionY) {                TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((player.getX() + default_x_width / 2) / tileWidth), (int) ((player.getY() + default_y_height) / tileHeight));                if (cell1 != null) {                    collisionY = cell1.getTile().getProperties().containsKey("blocked");                }            }            // top right            if (!collisionY) {                TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((player.getX() + default_x_width) / tileWidth), (int) ((player.getY() + default_y_height) / tileHeight));                if (cell1 != null) {                    collisionY = cell1.getTile().getProperties().containsKey("blocked");                }            }        }        // react to y collision        if (collisionY) {            player.setY(oldY);            velocity.y = 0;        }    }`
Jeremy
 « Reply #2 - Posted 2013-09-07 23:20:28 »

You need to use an appropriately sized capsule for your physics collision model.

JevaEngine, Latest Playthrough (This demo is networked with a centralized server model)

http://www.youtube.com/watch?v=rWA8bajpVXg
 Games published by our own members! Check 'em out!
Andre Lopes
 « Reply #3 - Posted 2013-09-08 00:52:12 »

You need to use an appropriately sized capsule for your physics collision model.

What you mean?
Am i not doing that now already? with default size width?
namrog84

JGO Ninja

Medals: 46
Projects: 4

Keep programming!

 « Reply #4 - Posted 2013-09-08 01:05:51 »

Right now, the default width is being based upon the image size, which by the looks of it, is probably 36wide, by 48 pixels wide

for example, I made an outline of whats happening

You can see the bounding box and why he is doing that.

What you need to do, is set probably defaultWidth/2  and then offset it a bit to be centered

So it looks and behaves more like

However,
many games do support a 'stand on ledge'  by 1 pixel type approach
megaman for example

As you can see here, the bounding box is slightly smaller than the character,  and his feet overlap the ground tile

However somegames actually use a combination box AND a 'circle'  for the character.  (box for left/right and top collsion) but then a circle for feet, so they can stand really close to the edge.  But because of the 'roundness' of the circle.  They could potentially slide off the edge.

However there are many approaches.

I would suggest looking at this site, it has some good information
http://www.emanueleferonato.com/2012/05/24/the-guide-to-implementing-2d-platformers/

"Experience is what you get when you did not get what you wanted"
Andre Lopes
 « Reply #5 - Posted 2013-09-08 01:38:03 »

"offset it a bit to be centered"

Does that mean to change the origin?
namrog84

JGO Ninja

Medals: 46
Projects: 4

Keep programming!

 « Reply #6 - Posted 2013-09-08 04:06:07 »

Depends on your logic and rendering code

But you need to cut your bounding box to about 2/3 of its current size (play around with it a bit)

Also offset your rendering sprite a bit too( try tweaking some settings, maybe the offset will do it)  there are several ways to go about fixing this.

But now that you have a slightly better idea of whats going on, you can try and fix it.

Also, your collision code that you posted before could use some work.  There are several ways, of simplifying it without having ot have so many nested tiledmap calls that you are currently doing.  Such as building a simple integer or boolean[][] 2d array of 'blocked' and open,  that you simply compile/construct when the map first loads.  May make it easier than what you have right now.

"Experience is what you get when you did not get what you wanted"
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Add your game by posting it in the WIP section, or publish it in Showcase. The first screenshot will be displayed as a thumbnail.
 Dwinin (28 views) 2014-09-12 09:08:26 Norakomi (57 views) 2014-09-10 13:57:51 TehJavaDev (72 views) 2014-09-10 06:39:09 Tekkerue (37 views) 2014-09-09 02:24:56 mitcheeb (57 views) 2014-09-08 06:06:29 BurntPizza (43 views) 2014-09-07 01:13:42 Longarmx (27 views) 2014-09-07 01:12:14 Longarmx (34 views) 2014-09-07 01:11:22 Longarmx (34 views) 2014-09-07 01:10:19 mitcheeb (40 views) 2014-09-04 23:08:59
 BurntPizza 33x princec 21x Riven 19x Rayvolution 17x ags1 16x basil_ 15x KevinWorkman 14x kevglass 12x theagentd 12x nsigma 11x LiquidNitrogen 10x SHC 8x HeroesGraveDev 7x The Lion King 7x cylab 6x EgonOlsen 6x
 List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27Resources for WIP games2014-08-01 16:20:17Resources for WIP games2014-08-01 16:19:50List of Learning Resources2014-07-31 16:29:50List of Learning Resources2014-07-31 16:26:06List of Learning Resources2014-07-31 11:54:12HotSpot Optionsby dleskov2014-07-08 01:59:08
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org