shield graphics code and help

BlitzMax Forums/BlitzMax Programming/shield graphics code and help

hey everyone, I have been experimenting with different ways to create the shield, and shield effect for a game.

Instead of making an image which I can fit to the ship, which would take alot of work to resize it for each ship... I want to generate some sort of graphic using code. Ive searched and haven't seen any code trying this yet, so I was wondering if I could get some pointers in the right direction.

just so you can see what I have in mind, ill post the ignorance I was doing.

First I tried storing a DrawOval command in a variable, with variables for the current ship size.

local shieldimage = drawoval (ship.x , ship.y, imagewidth(shipimage), imageheight(shipimage))

of course i get an error, saying can't convert timage to int. So that was out.

then i tried just drawing the oval,

DrawOval(ship.x -ImageWidth(ship.shipimage)/2 , ship.y-ImageHeight(ship.shipimage)/2, ImageWidth(ship.shipimage),ImageHeight(ship.shipimage))

that was to get the oval directly over the ship. I had transparency and stuff set on it, so you can see through it.

but the oval rotates funny, and it cannt get it to rotate by its centre, so it goes around in a circle, when i turn the ship. circling the ship. auto mid handle and sethandle was no help either.

Basically i want that when the user raises the shield with the keyboard command, that the shield is now true, that part is easy, but i want the shield even though it is now "ON". to be invisible around the ship, until it is hit by projectile fire. I want to create and effect so that when it the shield glows bluish, witish sort of haze briefly then fades back to invisible....

what are some commands i can investigate to achieve this?

thanks in advance


DrawOval(ship.x -ImageWidth(ship.shipimage)/2 , ship.y-ImageHeight(ship.shipimage)/2, ImageWidth(ship.shipimage),ImageHeight(ship.shipimage))



sounds right. And if you want to rotate the oval around the ship (I may be wrong), you *should* be able to do:
SetHandle(imageWidth(ship.shipimage)/2,imageHeight(ship.shipImage)/2)



I want to create and effect so that when it the shield glows bluish, witish sort of haze briefly then fades back to invisible....


when thinking of this I would start out messing around with these:
SetBlend(lightblend)
setAlpha()
and some sort of clever animated image. And just reduce the alpha as time goes on.

when thinking of this I would start out messing around with these:
SetBlend(lightblend)
setAlpha()
and some sort of clever animated image. And just reduce the alpha as time goes on.



oh geez, ive done that before for cloaking, why the hell didn't i think of that? does this sort of thing happen to others? then again its been one year since ive looked at blitzmax code, and did all those "genious" things.

i need to go back to writing pseudo code, then putting the appropriate commands next to them. such as, cloak which is fade, (setalpha) till i get back into things.
thanks

hi, Cruis.In. As said, here is a small sample about scaling and already a small shield effect:

use arrows to move and a and y to zoom in and out:

Type TPlanet
	
	Global List:TList = New TList
	
	Field RealX:Int
	Field RealY:Int
	Field DrawX:Int
	Field DrawY:Int
	
	Field Size:Int
	
	
	Function Create:TPlanet(X:Int , Y:Int , Size:Int)
		Local P:TPlanet = New TPlanet
		P.RealX = X
		P.RealY = Y
		P.size = Size
		TPlanet.List.Addlast(P)
		Return P
	End Function
	
	Function Update(PX:Int , PY:Int ,RX:Int,RY:Int, Scale:Float) 
		For Local P:TPlanet = EachIn TPlanet.List
			Local Distance:Float = Distance2D(P.RealX , P.RealY , PX , PY)
			Local Angle:Float = (ATan2(P.Realy-py , P.RealX - px) + 360) Mod 360
			P.DrawX = RX + Cos(angle) * (Distance*Scale)
			P.DrawY = RY + Sin(angle) * (Distance*Scale)
			P.Draw(scale)
		Next
	End Function
	
	Method Draw(S:Float)
		DrawOval DrawX - (Size * s / 2) , DrawY - (Size * s / 2) , Size , Size
		SetColor 255,0,0
		DrawOval DrawX-5*s , DrawY-5*S , 10 , 10
		SetColor 255,255,255
	End Method
	
End Type

Type TPlayer
	Field RealX:Int
	Field RealY:Int
	Field DrawX:Int
	Field DrawY:Int
	
	Field Size:Int
	Field ShieldPower:Float = 100
	Field ShieldActive:Int = False
	Field ShieldTimer:Int 
	
	Function Create:TPlayer(X:Int , Y:Int , Size:Int)
		Local P:TPlayer = New TPlayer
		P.RealX = X
		P.RealY = Y
		P.Size = Size
		P.DrawX = GraphicsWidth() / 2
		P.DrawY = GraphicsHeight() / 2
		Return P
	End Function
	
	Method Update(s:Float)
		CheckShieldCol(s)
		
		
					
		SetColor 255 , 0 , 0
		SetAlpha 1.0
		DrawRect DrawX - (Size*s / 2) , DrawY - (Size*s / 2) , Size , Size
		SetColor 255 , 255 , 255
		
		If Shieldactive = True Then
			SetBlend LightBlend
			SetColor 0, 0 , (255.0 / 100.0) * ShieldPower
			'Print (MilliSecs()-ShieldTimer) + " : " + ShieldTimer
			If MilliSecs()-ShieldTimer < 2000 Then
				SetAlpha 0.5
			Else
				SetAlpha (0.3*Sin((MilliSecs() - ShieldTimer)/((MilliSecs() - ShieldTimer)/2000))+0.2)
			EndIf
			If MilliSecs()-ShieldTimer >= 4000 Then Shieldactive = False

			
			DrawOval DrawX - (Size * s ) , DrawY - (Size * s ) , Size*2 , Size*2
		EndIf
		SetBlend Alphablend
		SetAlpha 1.0
		SetColor 255 , 255 , 255
		
		If KeyDown(KEY_Right) Then RealX:+ 1
		If KeyDown(KEY_Left) Then RealX:- 1

		If KeyDown(KEY_Up) Then RealY:- 1
		If KeyDown(KEY_Down) Then RealY:+ 1
		
		If KeyDown(KEy_F1) Then ShieldPower:- 0.1
		If KeyDown(KEy_F2) Then ShieldPower:+ .1
		
		If Shieldpower < 0 Then ShieldPower = 0
		If Shieldpower > 100 Then ShieldPower = 100
		
	End Method
	
	Method CheckShieldCol(s:Float)
		For Local P:TPlanet = EachIn TPlanet.List
			'Print  Distance2D(P.DrawX , P.DrawY , DrawX  , DrawY)
			If Distance2D(P.DrawX , P.DrawY , DrawX , DrawY) < (Size + (P.Size / 2))*S
					ShieldActive = True
					ShieldTimer = MilliSecs() 
				Return
			'Else
			'	ShieldActive = False
			EndIf
		Next
	End Method
	
End Type

Global G:TGraphics = Graphics(800,600 , 0 , 60)

Local P:TPlayer = TPlayer.Create(100 , 100 , 50)
Local Scale:Float = 1.0

For Local I:Int = 0 To 15
	TPlanet.Create(Rnd(-1800,1800) , Rnd(-1600,1600) , Rnd(30 , 80) )
Next

While Not KeyHit(Key_Escape)
	Cls
	SetScale scale , scale
	
	P.Update(scale)
	TPlanet.Update(P.RealX,P.RealY,P.DrawX,P.DrawY,Scale)
	
	If KeyDown(Key_A) Then Scale:+ 0.01
	If KeyDown(Key_Y) Then Scale:- 0.01
	
	SetScale 1.0,1.0
	
	DrawText "Realx : " + P.RealX + " RealY : " + P.RealY , 20 , 20
	DrawText "Scale : " + Scale , 20 , 40
	DrawText "SP    : " + P.ShieldPower,20,60
	
	Flip
Wend

Function Distance2D#(x0# , y0# , x1# , y1#)
	Local dx# = x0-x1
	Local dy# = y0-y1
	Return Sqr(dx*dx + dy*dy)
End Function


If you have questions, then simply ask here or email me ;)

hi klepto thanks.

theres a command to check for collision between an image and a drawn oval or rect?

CollideRect



this is what id like.

why not place an image over the ship that you could scale ?

ahh.. man sometimes i just don't think of these things.

I could set the width and height of said image to be a variable equal to the width and height of the current chosen ship, using imagewidth() and imageheight().
that solves the problem of the varying size right? just set the scale of the shield image to the size of the current ship graphic....

am I on the right track?