Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,143,304 members, 7,780,720 topics. Date: Thursday, 28 March 2024 at 08:34 PM |
Nairaland Forum / Science/Technology / Programming / Help!!! Help!!! How To Make Enemy Follow Player In Javafx (1473 Views)
Why Is Nobody Talking About Javafx .. / I Need Help With Javafx Tableview Code. / Thunder Strike The CEO Of Sun Microsystems If JavaFX Fails! (2) (3) (4)
Help!!! Help!!! How To Make Enemy Follow Player In Javafx by llbhuds: 9:41am On Dec 07, 2014 |
hello guys, im cloning the satellite attack game as a project for my first yr. everything seems to be working fine so far except the magnetic asteroid that needs to move slowly towards the spaceship which i have been unable accomplished for few days now and the game is due for presentation next week. i will be glad if the gurus in the house can help me out. below is the code for the magnetic asteroid class. I AM USING NETBEANS AS MY JVM. |
Re: Help!!! Help!!! How To Make Enemy Follow Player In Javafx by nollyj: 2:14pm On Dec 07, 2014 |
One solution is to get a random distant from where the actor is currently standing and this will be the starting location of the enemy. // the player should have a direction public enum PlayerDirection{ LEFT, RIGHT, UP, DOWN }; Example // get actors x and y location coordinates int xActorPosition = actorObject.getX(); int yActorPosition = actorObject.getY(); // create enemyObject MagneticObject asteroid = new MagneticObject("Asteroid", "pathToAsteroid", 64); // initial starting position of asteroid int yNewPosition = yActorPosition + initiationDistanceBetweenActorAndEnemy(); asteroid.setLocation(xActorPosition, yNewPosition); private int initiationDistanceBetweenActorAndEnemy(){ // example return an int within 50 and 100 return Game.getRandomNumber(50, 100); } Now to move the enemy toward the player int minDistance = 10; int maxDistance = 20; // get the distance between the player and enemy int dis = enemyDistanceToPlayer(); private int enemyDistanceToPlayer(){ } First get the direction of the Player or where the Player is facing or positioned in regard to the enemy private void moveEnemyTowardsPlayer(){ if(Player.getX() - Enemy.getY() <= maxDistance){ // the enemy or actor can fire bullet } PlayerDirection direction = PlayerDirection.LEFT; int enemySpeed = actor.getSpeed() + 3; switch (direction) { case LEFT: asteroid.setSpeed(enemySpeed); break; case RIGHT: asteroid.setSpeed(enemySpeed); break; case UP: asteroid.setSpeed(enemySpeed); break; case DOWN: asteroid.setSpeed(enemySpeed); break; } } I hope that this little idea will help you Best of luck |
Re: Help!!! Help!!! How To Make Enemy Follow Player In Javafx by llbhuds: 7:09pm On Dec 07, 2014 |
thanks for you help @nollyj but it doesn't seems to work. no idea why because there isnt any bug while i compiled it but the game isnt running after adding this codes ( after modification of the codes). |
Re: Help!!! Help!!! How To Make Enemy Follow Player In Javafx by nollyj: 8:29pm On Dec 07, 2014 |
I wrote the code to give you some insight about the problem. I did not test it since the game is part of a framework you are working on there is no way I can test the code independently |
Re: Help!!! Help!!! How To Make Enemy Follow Player In Javafx by llbhuds: 6:42am On Dec 08, 2014 |
Yea i know its just an idea nd thats why i tried to use d few i i Think should help, mind u, the code gave me alot if ideas but still cant make it follow d spaceship. I can send d codes to u as a zip file so mayb u can check it nd help me. mchris3k@yahoo.com u can send a mail here incase u dont wanna drop urs thanks |
Re: Help!!! Help!!! How To Make Enemy Follow Player In Javafx by nollyj: 10:56am On Dec 08, 2014 |
llbhuds: I would have loved to help but I have limited time now and your deadline is within the week. If I finish what I am doing by tomorrow I will let you know. |
Re: Help!!! Help!!! How To Make Enemy Follow Player In Javafx by llbhuds: 10:00pm On Dec 08, 2014 |
Ok. Thanks for ur time |
(1) (Reply)
Rate Me: I Have Completed Coding Of A Mobile Social Network (afroblacks.com) / A Php Mysql Server That Works Well On Android Version 8.0 / Tit Bits From Elmac Digital Library
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 14 |