Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (616)
Games in Android Showcase (173)
games submitted by our members
Games in WIP (659)
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  
  AI, Kinda  (Read 1336 times)
0 Members and 1 Guest are viewing this topic.
Offline Zerolife

Senior Newbie

« Posted 2010-06-01 01:13:32 »

Im trying to just make a simple game to simulate typical life from day to do (wild life)

I got to the point where I am adding bugs, specifically lightning bugs, and I got extremely confused -.-

I have nothing to post, just need some theory here. I want to make a lightning bug for a 2D platform like setup, to make it fly around like a lightning bug would. I have the lightning bug lighting up as it should and all that, I just cant figure out how to change the direction and all that well. I really have no idea where to start with this, so any help would be great. Thanks in advance.
Offline Karmington

Senior Devvie

Medals: 1
Projects: 1

Co-op Freak

« Reply #1 - Posted 2010-06-01 13:51:42 » has some nice demo applets from which you can choose what you are aiming for, the source however is in c++. Should help you in the right direction though, "wander" might be what youre looking for

Offline Zerolife

Senior Newbie

« Reply #2 - Posted 2010-06-01 15:19:23 »

You were right, I was looking for wandering, though I'm not quite sure I completely get it.

I know I will need a direction for the main object, and then also a direction that the main object will try to align itself with I guess? How would I manage to convert all that to actually move the object itself? Thats where I get caught up mainly. I've never actually tried to move an object with just a direction variable myself. Sorry if it seems like a stupid question. I think I'm missing something completely. -digs into massive brain dump of mathematical equations- I'll update if I think of something, otherwise, any responses will be helpful!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Karmington

Senior Devvie

Medals: 1
Projects: 1

Co-op Freak

« Reply #3 - Posted 2010-06-01 18:59:40 »

Well, give them a couple of vectors x and y, move them over time first, get them to move about in straight lines, then
changing direction around in a circle, then you will have the pieces with which to build the wander mechanism.

Offline Mads

JGO Ninja

Medals: 26
Projects: 3
Exp: 6 years

One for all!

« Reply #4 - Posted 2010-06-01 19:22:07 »

You need to add a cycle for your game, and repaint what needs to be repainted(moved).
For example you could have a cycle at 200 ms. Each time 200 ms has passed, the program should run trough a painting method, repainting the bug at a different location if it had moved.

I just said 200 ms as it would cause lo lag, but you can make it 30 ms, so it looks more flowing.

Offline Zerolife

Senior Newbie

« Reply #5 - Posted 2010-06-01 22:10:54 »

how I handle the direction of which I add and subject to x and y is all wrong. Thats my main issue right now.

I've seen people around using floating points for this, but I am not exactly sure on how they work with that. Can anyone help me out with that? I know that I will be doing something along the lines of x+=Math.cos(angle); and y+=Math.sin(angle); but I am not sure on how to handle that angle. Ideally Id like to store angle as an int that is just between 0 and 360, just so I can understand it in my mind, but if there is some other way that I must deal with that is fine. Not sure if I am asking this right or not, but hopefully someone will make sense of this nonsense. In my defense, I am confused as hell -.-
Offline zoto

Senior Devvie

Medals: 4

« Reply #6 - Posted 2010-06-01 22:54:09 »

You are using 2 different ways to represent the angle, as degrees(0-360) and as radians. to keep it in degrees but treat it as radians let java convert it for you.
Math.sin( Math.toRadians(angle) ) 
Offline Zerolife

Senior Newbie

« Reply #7 - Posted 2010-06-01 23:01:01 »

My god. Thank you! That was exactly what I needed. I don't know how I skipped over even thinking about it that way. That completely fixed my issue and everything is now working as it should. Now all I need is a smart way to keep the stupid object in a certain box, but it all works now, and that is what matters. Thanks everyone for the help. I appreciate it.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Coldstream24 (18 views)
2015-09-03 00:41:28

Andrew_3ds (30 views)
2015-09-01 19:08:10

afikri (20 views)
2015-08-31 09:30:22

afikri (27 views)
2015-08-31 09:30:07

afikri (15 views)
2015-08-31 09:27:24

afikri (17 views)
2015-08-31 09:26:40

Roquen (32 views)
2015-08-29 11:30:54

GamerC4 (39 views)
2015-08-22 20:38:50

GamerC4 (37 views)
2015-08-22 20:37:18

GamerC4 (43 views)
2015-08-22 20:37:01
HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30 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‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!