2d space game

Miscellaneous Forums/Blitz Showcase/2d space game

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Cruis, you have it absolutely right. The FlyTo() method would move/turn the ship to get to its targetX, targetY within a certain distance and return true when done. This means you could also make it an autopilot for the player's ship. Here's some pseudocode:

type TSpaceShip

	field targetX,targetY

	' you could use to make the AI target something, not just a ship.

	method targetCoords(x,y)
		targetX=x;targetY=y
	end method

	method thrust()
		vx:+cos(angle)*ENGINE_SPEED
		vy:+sin(angle)*ENGINE_SPEED	
	end method

	method flyTo(specified_distance=100)

		local distance =distance(x,y,targetX,targetY)

		' if we're close enough, return true

		if distance < specified_distance return true

		' turn towards before flying...
		if turnedTowards(targetX,targetY)



			' now that we're facing we can fly there...
			' you might want to change the speed in here depending on the distance

			if distance > ONE_AU
				' fly at warp speed

				vx=cos(angle)*WARP_SPEED
				vy=sin(angle)*WARP_SPEED
			else

				' speed up until going at full speed
				thrust()
			endif


		else
			angle:+RotAngleTo(targetx,targety)	
		endif
	end method
end type