News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Complicated problem SOLVED: real location as opposed to location on map

Started by esper, December 05, 2007, 05:52:56 PM

Previous topic - Next topic

esper

Hey everyone.

I'm writing a fairly complicated game. It's something of a combination of Solar Winds and Roadwar 2000. I hate to do this to you guys, but I've got a fairly large amount of code I'm trying to sort through here and I can't figure out for the life of me why this bloody ridiculous program won't work.

So here's the deal... At the beginning of the game (lines 176 to 628 in the "Initialization" module) I create a galaxy 300,000 pixels by 300,000 pixels and generate 25-75 random suns, then populate the suns with anywhere from 0 to ten planets. During this process, I give the suns and planets x locations and y locations (sun(i).xloc#,  sun(i).yloc#,  planet(num).xloc#,  and planet(num).yloc#) ranging between -150000 and 150000. For the planets, their location is based on the location of their respective sun (which sometimes causes overlapping issues, but this is something I'll deal with later), but still fall within those boundaries.

When you either press the "M" key or click on the button labelled "Star(M)ap" in the lower right-hand corner of the HUD, you are brought to the starmap. The starmap consists of two stages: the actual full starmap and the radar. On the actual starmap, you can initially see every star in the universe and the initial 8 planets (and one ice giant) of our solar system. If you want to see every planet in the whole universe, edit line 216 of the initialization module to say planet(num).discovered=1.

When you press the left or right arrow keys while viewing the starmap, you get the radar. On the radar, you can see any nearby objects (regardless of your having discovered them yet or not), "nearby" being based on the global sensorrange as set in line 43 of the initialization module. Here, we get to my problem...

On the starmap, everything seems to be in the right place. On the radar, all of the suns are located properly, and you can fly into their center and have your shipx# and shipy# coordinates match sun(i).xloc# and sun(i).yloc# coordinates. HOWEVER, the planets are not properly aligned. For example, your starting location is 0,0. Earth's is 200,-200.  However, if you fly into the center of the earth, your location is actually 0,-333. I have tried altering the planet's location to be based on getimagewidth()/2 and getimageheight()/2, I have tried finding the offset and programming the game to actually offset them by that amount (but it turns out the amount of the offset is different for each planet). The way it is now, I understand that it's wrong, but still, it should put you at the top-left corner of the planet instead of the center, not way out in deep space like it's doing.

So, if anyone thinks they can help me, that would be great. It's a complicated project, especially considering I'm very, very, VERY new to programming anything but Atari 2600-style games and text adventures, neither of which I've done since 1990. My code is complicated, messy, and sometimes I compensate for not knowing enough of the language by overcomplicating what could be a much simpler code. So, any help is greatly appreciated.

You can find the file here:
http://www.geocities.com/esper_ian/games.html (It's the red link entitled "My space adventure game(incomplete)" at the bottom of the page)

And, to help you out, here are some key locations in the code regarding the radar:

179,180,initialization: the x and y variables (sun(i).xloc# and sun(i).yloc#) are set

183,184,initialization: the x and y coordinates are transferred to a smaller number based on the size of the universe and the size of the map window for displaying on the starmap..

202,203,initialization: the x and y coordinates of our sun, Sol, is set

300-354,initialization: the xloc# and yloc# positions of the planets are set, by calculating a random direction and a cumulative distance from the sun. Below this, the positions of the planets in this solar system are set manually.

Any functions regarding moving through space can be found in the main module under their respective function names.

766-778,main: under the function draw_celestial_bodies, this is where the planets are actually drawn to the scene buffer.

126-254,menus: this is where the starmap and radar are drawn.

196-199,menus: this is where the suns are drawn on the radar. In the term sensorx#=((sun(i).xloc#-shipx#)/(sensorrange/600))+300, sensorrange/600 reduces the size of the sensor display to fit into a window 600x600, and the 300 is to move it toward the center of the screen rather than basing calculations on the edge of the screen.

208-210,menus: this is where the planets are drawn on the radar. As you can see, it uses the exact same terminology as the algorithm that positions the sun on the radar.

The calculations module tells the program how far the ship is to move based on the direction it is facing.

-----------------------------

Thanks, in advance, just for looking at this tangled mess of gobbledeygook. I really appreciate any help that anyone might be able to render. Please, be kind, as I am relatively new to programming and I'm not quite sure yet how any of this is supposed to work. Oh, and brownie points go to anyone who can tell me why the code that randomly generates sun names in lines 186-198 of the initialization module (the name data is in the data module) is re-using names even though I built a safeguard to protect against that very thing in lines 192-197.




esper

Okay, sorry to have wasted anyone's time who was trying to figure this out. Here's the solution:

drawrotatedimage planet(num).imagenum,planet(num).xloc#+(getscreenwidth()/2),planet(num).yloc#+(getscreenheight()/2),0,planet(num).radius#,planet(num).radius#,getimagewidth(planet(num).imagenum)/-2,getimageheight(planet(num).imagenum)/-2,1

The image was appearing at the top left corner of the screen, but the ship's starting location, 0,0, where all other coordinates originate from, is not 0,0 on the screen, it's right in the middle of the screen, hence having to adjust everything else to meet it.