We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › Space Battles Mini-Game
Page Index Toggle Pages: 1
Space Battles Mini-Game (Read 3288 times)
Space Battles Mini-Game
May 4th, 2005, 7:52am
 
EDIT: This post was previously called Draw Points To Target.

Finally! I've figured it out...

This may have taken me many years to figure out, long since my first attempt at adding AI to a computer game version of Asteroids... but here is something -

Draw Points To Target
http://mkv25.net/?item_id=99

A function that will try and turn the shortest distance towards a target and move towards it. Very useful for plotting routes. I finally worked out a (stable?) system that works for all angles. I've always had trouble around the 360 - 0 angle, where my code has been unsure which way to turn.

Please take a look at the code and see if you can think of ways to improve the logic. I'm sure you can see the aim - start off facing in a direction (vertically down) and then turn and step forwards towards the target (mouseX, mouseY) until the target is reached.

I intend to use this logic to build a simple space battles game.
Re: Draw Points To Target
Reply #1 - May 9th, 2005, 7:45pm
 
that looks nice. Maybe I can learn something from your code. Tell us, when your game is finished.
Move Towards Target
Reply #2 - May 9th, 2005, 9:52pm
 
Well I'm making progress, I'll keep posting here.

The next step was to get an object to move around using the navigation logic. You can see here:
http://mkv25.net/?item_id=100

My next steps will be a) to add sliders/scroll bars to move the accesible area around. b) have a stack of space ships of different types that can be individually selected. c) logic to stop ships flying into each other (without damaging each other).

I intend to make use of multiple files to break the code down. Ic an see the spaceShip class getting quite large in the future.
Slider Bars / Scroll Pane
Reply #3 - May 10th, 2005, 11:34pm
 
So as progress goes I made a slider class and drew a picture which you can slide around, using the sliders.

I was wondering, is there any way to include Swing components in processing?

Anyhow, heres my latest addition:
http://mkv25.net/?item_id=101
Re: Draw Points To Target
Reply #4 - May 11th, 2005, 12:48am
 
it is possible (at least it was in alpha) buts its messy, at least in my opinion, because its just like you would do it in java.

i remember some one asked this during alpha and fry told them yes and explained how to do it, then explained how that  wasn't exactly what procesing was about, that it was to be able to experiment with gui and graphics and things easily

oh, and by the way, i think you should add something to the code for move to target, that if the target is inside the minimum turning radius, to manevure until it is possible to get it (dont know how though, maybe back up x pixels?)
Re: Draw Points To Target
Reply #5 - May 11th, 2005, 1:40am
 
nah, you can't use swing components inside a p5 app.. if you want to use swing components, you need to make a regular java application using something like eclipse, which you can embed a processing applet inside of, since an applet is just a "Component" (though not JComponent) like any other.
Re: Draw Points To Target
Reply #6 - May 14th, 2005, 6:31am
 
Thanks fry, I didn't think so - it'd get really messy considering processing handles much of the GUI things on its own.

Like I said, I'd keep posting any new developments towards my game... I've been playing with an object stack, draggable objects, and interface classes:
(see, I actually learnt something on my java course =))

http://mkv25.net/index.php?item_id=102
http://mkv25.net/applets/changeFocus_a1/
(source files)


Edit:
(BTW the description in the code/on the webpage is slightly wrong because I wrote it before I wrote the actual code, and changed my mind half way through).
Re: Draw Points To Target
Reply #7 - May 14th, 2005, 6:38am
 
mythmon wrote on May 11th, 2005, 12:48am:
oh, and by the way, i think you should add something to the code for move to target, that if the target is inside the minimum turning radius, to manevure until it is possible to get it (dont know how though, maybe back up x pixels)


Sorry Mythmon, just caught your post... thanks again for the info on processing/swing.

I wasn't sure what to do about targets within the minimum turning circle. For a start I hadn't considered reverse movement - but that would be the fastest way to turn to a close target so I presume I should implement something along those lines.

I don't want to get bogged down with the movement too badly at this stage. I've got plans for fleshing out everything with a turn based movement system, e.g. movement points per turn, each player selecting their units and giving commands etc.

I'll be keeping it modulated tho, so if I do think up new movement methods I can easily drop them in. (I keep thinking about an S-shaped move where the end angle correlates to the start angle).
Re: Sliders
Reply #8 - May 14th, 2005, 6:45am
 
I think I'll go back and improve my sliders. They currently feel very choppy since only one click is required to set their final position... and I noticed myself trying to smoothly drag along the bar, which is fine so long as I don't move outside the bar.

Also, dragging from left->right and just catching the bottom of the vertical slider sends the bar/box/value right down to the bottom in one jump. This is where my hasFocus idea will come in handy...

ref: http://mkv25.net/?item_id=101
Page Index Toggle Pages: 1