Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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 1087 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 Duke


Medals: 1
Projects: 1


Co-op Freak


« Reply #1 - Posted 2010-06-01 13:51:42 »

http://www.red3d.com/cwr/steer/ 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 Duke


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 Duke


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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (67 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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
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!