Create Enemy Path / AI

Monkey Forums/Monkey Programming/Create Enemy Path / AI

Monking(Posted 2013) [#1]
I'm new to Monkey Programming so by now I've no idea what to start with.
I read the book and get the simple knowledge.

But now, I wish to study my first game, simplest one, maze like Pacman.
Well, I face the problem of creating enemy.

There are two type of enemy, first is move with path,
eg: this enemy is move from position 0,0 to 128,0 then move back and vice versa

The second enermy could be A.I, like finding a way to go..and when meet player..he will chase it..some sort of that..

I'm using fantomEngine..is that fantomEngine can do some sort like this..
as I tried to create 2 classes, like for example
Class game Extends App and another Class Enermy..
it would not draw out the image..
so I was running out of idea..

Any Relevant example ?? Example codes is preferable, Thank You.


dawlane(Posted 2013) [#2]
Well I haven't the time to post any code but GameInternals should give you some ideas as it's what they did with pacman.

My advice to anyone new to Monkey ( or any programming language ) is not to use any engine until you can write some code of your own as it can take some understanding when things go wrong and make it had for anyone who hasn't got said engine to help out..

An object that moves back and forth is one of the easiest things to do.
You have a direction value that you flip when your object have reached it's objective.

give x a start position say 400
give d a direction as -5

in a loop
if x < 200 Or x > 600 Then d = -d
x+=d

Problem you will find with this approach is when you try and go diagonally. Then your better off using vectors. Have a look on google there should be plenty of tutorials out the for sprite movement that can be easily adapted to work with monkey.

Check out these Invader Jim tutorials.


Why0Why(Posted 2013) [#3]
Definitely watch the excellent tutorial videos by Invader Jim:

http://www.monkeycoder.co.nz/Community/posts.php?topic=3318


MikeHart(Posted 2013) [#4]
fantomEngine supports something like a pacman game definately very well with its path finding methods and the waypoints.

If you want to create own classes for each different object, you can do this with customclasses (user defined classes) which extend ftObject. There is already an example shipping with fE that shows how to use a cusotm class but I will upload a multiclass example soon too.


MikeHart(Posted 2013) [#5]
And please post the code you have so me or someone else can try to help you.


MikeHart(Posted 2013) [#6]
Here is an example with multiple classes and custom objects:

http://www.fantomgl.com/?p=521


Supertino(Posted 2013) [#7]
Fantastic A* *path finding) tutorial here http://www.policyalmanac.org/games/aStarTutorial.htm very useful for maze/pacman games - if you can't follow this you'll struggle with AI.


Monking(Posted 2013) [#8]
Thank you for everyone comments,
I guess I've more to learn..

By the way, respond to MikeHart,
I should upload my demo coding..here:
https://www.dropbox.com/s/9gbr65kazvyllk2/First_Maze.zip

I'm using the latest fantomEngine from here:
http://code.google.com/p/fantomengine/

Well, before viewing the coding of this demo..
I suggest anyone who downloaded has some preparation to view this horrible coding..

Well, maybe dawlane is right..
I should learn the basic instead of using any engine..

I know my coding and programming skill is horrible,
so I can accept any suggestion.
Any suggestion is appreciated.
Thank you very much.


dawlane(Posted 2013) [#9]
One suggestion I would make is modularise your code as it does three things

1) Makes it easier to read
2) Easier to mantain
3) Easier to debug.

And always use Strict
Try and keep your game enemies, players, maze/levels, etc as separate classes from your main Game class. All your main game class needs to do is control when to do what.


dawlane(Posted 2013) [#10]
And another thing learn about functions methods and return types

Something that wont work but should give you some ideas. Can't give a proper example as I'm on a machine that has got monkey installed.
In One file called sprites.monkey


In monkeygame.monkey



mteo77(Posted 2013) [#11]
Hello.
Here there some code for a simple "follow path" movement type.
The path is stored in an array that you can modify (just change the values!).
It has some simple object structures and object creation, also it will react to user input to change speed and curve approximation.
It has some math but hopefully you will understand it.
I don't use strict mode yet, and it's pretty well explained (hopefully).
This can be the basis for a simple AI, it's not a pathfinding routine but its a start!



mteo77(Posted 2013) [#12]
Sorry for my english but i am tired and ready to hit the sack...


Monking(Posted 2013) [#13]
Okay thanks, I try my best.


Gerry Quinn(Posted 2013) [#14]
When doing AI it's easiest to start with a really simple one (e.g. never change direction and turn at random at any corner). Then you can ensure that everything is working before slotting in more elaborate ones.