### some help with a space shooter

 Page : 1 2 3

UserMessage
Posted : Thursday, 08 July 2010, 10:06 | Permalink
j\'ordos

 I'm writing a simple 2D overhead 360 degrees space shooter in blitz3d. The problem I'm having is that I don't know how to calculate the ship's 'roll' (I have a bunch of frames for each ship with an image for each direction and varying stages of roll). Can anyone help me out here? Here's how the sprites are laid down (conveniently ripped from subspace aka continuum ) edit: in case it's useful, here's the player's update loop: .update_player Turn=KeyDown(pl\key_right)-KeyDown(pl\key_left) ;determine turn direction pl\angle#=pl\angle#+5*Turn*FL\SpeedFactor ;apply rotation If pl\angle#>359 ;check angle overflow pl\angle#=0 ElseIf pl\angle#<0 pl\angle#=359 EndIf Thrust=KeyDown(pl\key_up)-KeyDown(pl\key_down) ;determine thrust direction speedx#=0.1*Thrust*table_sin(Floor(pl\angle#)) ;calculate thrust speedy#=0.1*Thrust*table_Cos(Floor(pl\angle#)) pl\s#=pl\s#+speedx#*(Abs(pl\s+speedx)<3) ;apply thrust pl\t#=pl\t#-speedy#*(Abs(pl\t-speedy)<3) pl\x#=pl\x#+pl\s#*FL\Speedfactor# ;apply velocity to player position pl\y#=pl\y#+pl\t#*FL\Speedfactor# If KeyHit(pl\key_fireA) pr.projectile_f=New projectile_f pr\x#=pl\x#+15.5+15*table_sin(Floor(pl\angle#)) pr\y#=pl\y#+15.5-15*table_Cos(Floor(pl\angle#)) pr\s#=12*table_sin(Floor(pl\angle#))+pl\s# pr\t#=-12*table_cos(Floor(pl\angle#))+pl\t# EndIf If Thrust<>0 And pl\exhaust_t=0 calc1s#=table_sin(180+Floor(pl\angle#)-359*(pl\angle#>179));precalc sin&cos calc1c#=table_cos(180+Floor(pl\angle#)-359*(pl\angle#>179)) ex.exhaust=New exhaust ;exhaust 1 ex\x=screenxmid+10+15*Sin(170+Floor(pl\angle#)) ex\y=screenymid+10-15*Cos(170+Floor(pl\angle#)) ex\s#=thrust*4*calc1s#*FL\SpeedFactor ex\t#=thrust*4*calc1c#*FL\SpeedFactor ex\frame=0 ex.exhaust=New exhaust ;exhaust 2 ex\x=screenxmid+10+15*Sin(190+Floor(pl\angle#)) ex\y=screenymid+10-15*Cos(190+Floor(pl\angle#)) ex\s#=thrust*4*calc1s#*FL\SpeedFactor ex\t#=thrust*4*calc1c#*FL\SpeedFactor ex\frame=0 pl\exhaust_t=5 Else pl\exhaust_t=pl\exhaust_t-1*(pl\exhaust_t<>0) ;advance exhaust delay timer EndIf DrawImage gfx_wb,screenxmid,screenymid,200+Floor#(pl\angle#/9)+40*Int(pl\roll#) Return --> It seems to be working fine (aside from bullets sometimes not quite travelling the same direction as the ship is pointing), just need a way to add that roll effect
Posted : Thursday, 15 July 2010, 05:01 | Permalink
j\'ordos

 I tried two solutions that someone provided me with but I can't get them to work correctly. I'm weak with math so could anyone check these formulas for any errors? First method I tried was using the inverse radius of a cricle: Function getcurvature(p1x#, p1y#, p2x#, p2y#, p3x#, p3y#) Local A#, B#, C#, D#, E#, F#, G#, cx#, cy#, rad# A = p2x - p1x B = p2y - p1y C = p3x - p1x D = p3y - p1y E = A * (p1x + p2x) + B * (p1y + p2y) F = C * (p1x + p3x) + D * (p1y + p3y) G = 2 * (A * (p3y - p2y) - B * (p3x - p2x)) If G = 0 Then Return 0 Else cx = (D * E - B * F) / G cy = (A * F - C * E) / G rad = Sqr((p1x - cx) ^ 2 + (p1y - cy) ^ 2) rad=1/rad Return rad EndIf End Function --> I found it in the blitz code database Results were odd though. Next I tried getting the sinus of the angle of a triangle Function get_curvature(p1x#, p1y#, p2x#, p2y#, p3x#, p3y#) Local dist1#,dist2#,dist3#,curve# dist1#=Sqr(Exp(p2x#-p1x#)+Exp(p2y#-p1y#)) dist2#=Sqr(Exp(p3x#-p2x#)+Exp(p3y#-p2y#)) dist3#=Sqr(Exp(p1x#-p3x#)+Exp(p1y#-p3y#)) curve#=Sin(ACos((Exp(dist1#)+Exp(dist2#)+Exp(dist3#)/(2*dist1#*dist2#)))) Return curve# End Function --> my own making so may be erroneous. here's the code to log the three coordinates I need for the formula: pl\clog=1-pl\clog pl\xlog#[pl\clog]=pl\x# pl\ylog#[pl\clog]=pl\y# pl\x#=pl\x#+pl\s#*FL\Speedfactor# ;apply velocity to player position pl\y#=pl\y#+pl\t#*FL\Speedfactor# pl\roll#=get_curvature(pl\x#,pl\y#,pl\xlog#[pl\clog],pl\ylog#[pl\clog],pl\xlog#[1-pl\clog],pl\ylog#[1-pl\clog]) --> Executed each cycle. Maybe that's too fast so the points are too close to each other? Might not be good for floating point inaccuracy? Also, I think I still need a way to detect a left or right roll with these formulas. On an unrelated note, is there any need to use a rectsoverlap() check before imagescollide() or does imagescollide do it's own bounding box check first? Thanks!
Posted : Thursday, 15 July 2010, 13:51 | Permalink
Mog

 Funny thing, I have all of Jeff Petersen's notes on his engines (the guy who made Continuum) but sadly, i'm not on my main PC Give me a while and i'll update you. I'm thinking that if it's anything like his other games, it's simply stepped through by a simple algorithm that corresponds with the frames through simple multiplication. I remember having to do the same for my Infantry project (another one of his games) and it being like that. Like said, give me a bit and i'll dig up those notes...-----I am Busy Mongoose - My Website Dev PC: AMD 8150-FX, 16gb Ram, GeForce GTX 680 2gb Current Project: Pyroxene
Posted : Thursday, 15 July 2010, 17:08 | Permalink
j\'ordos

 Hey that's be awesome! You had anything to do with infantry? Or did you try programming your own version? Subspace kept the upright frames and the rolling frames in seperate images (the rolling effect could be disabled), I just added them together since I thought it'd be easier that way. Anyway it'd be nice to have information on how the original did things!
Posted : Thursday, 15 July 2010, 22:25 | Permalink
Mog

 I was an early tester that came from the whole SubSpace crowd, and contributed some media over the years to the Harmless Games team... now a few players and myself are working on a newer client / server suite with things such as bots and heavier scripting capabilities. Anyways, I haven't played too much with SS/Con, what was the exact original media so i can kind of match it up to what i know -- You said you merged all of them into one file? -----I am Busy Mongoose - My Website Dev PC: AMD 8150-FX, 16gb Ram, GeForce GTX 680 2gb Current Project: Pyroxene
Posted : Friday, 16 July 2010, 05:39 | Permalink
j\'ordos

 Yes, subspace has one image file with all ships lumped together, but only the 'upright' image frames (no roll), like this: Then it has one image file for each ship (so 8 files in total) containing the rolling frames, just like the one I attached to the first post, except I added the upright frames to the center of that image, the idea being that I'd have a roll variable which would become negative for a roll in one direction and positive for a roll on the other direction (0 for upright). But the original files do not have the upright position in there.
Posted : Friday, 16 July 2010, 06:16 | Permalink
Mog

 Here's a quick idea until i work it out. You have 40 frames per angle/roll, and 5 roll sectors to left and right with one neutral in the middle. Dead center facing up is frame 200, so naturally -1 (Roll to Left) and +1 (roll to right) will fall at 200-40 (160) and 200+40 (240). Like said, sadly i'm not on my normal workstation and can only kludge together this quick code for blitz3D to display this idea. Mind you that the end frame is Starting frame +39 (since frame 0 is still technically a frame!), and within your game, you may want to round frames by angle to get the true frame you should be rendering - which off the top of my head, 360 / 40 = 9 steps between each frame. Graphics 800,600,0,2 SetBuffer BackBuffer() img=LoadAnimImage("wbroll.png",36,36,0,440) MidHandle img Global frame=200 Global endframe=frame+40 Global Roll=0 While Not KeyDown(1) frame=frame+1 If frame>Endframe Frame=frame-39 If KeyHit(203) Roll=Roll-1 CalculateRoll() EndIf If KeyHit(205) Roll=Roll+1 CalculateRoll() EndIf DrawImage img,400,300,frame Flip Cls Delay 20 Wend Function CalculateRoll() If Roll<-5 Roll=-5 If Roll>5 Roll=5 Frame=200+(Roll*40) endframe=frame+39 End Function --> -----I am Busy Mongoose - My Website Dev PC: AMD 8150-FX, 16gb Ram, GeForce GTX 680 2gb Current Project: Pyroxene
Posted : Friday, 16 July 2010, 07:33 | Permalink
j\'ordos

 Thanks but I already got that far: I originally checked if the player was both thrusting and turning at the same time, if true I would add/substract from a roll var which I capped at 5/-5. Then I'd display the ship like this: DrawImage gfx_wb,screenxmid,screenymid,200+Floor#(pl\angle#/9)+40*Int(pl\roll#) --> This works fine but if the player is still moving due to inertia and then turns his ship and only after turning starts thrusting again the ship will change direction without rolling. It's a minor issue now I look at it again, but in subspace it's done differently (the ship rolls even in the above mentioned case) and I'd like to emulate it as close as possible
Posted : Friday, 16 July 2010, 08:28 | Permalink
Mog

 I always thought in Subspace, when you turned it simply banked to whatever direction they were turning then slowly faded back to neutral. I'm trying to wrap my head around what you mean about it not banking after thrusting out of an inertial drift (right? is that what you meant?) that it doesn't bank.. So are you trying to only make it bank only when thrusting and turning? Bank only in inertial drift? Again, sorry for lack of further help and stumbling about, been on bare-minimal amount of sleep lately D: -----I am Busy Mongoose - My Website Dev PC: AMD 8150-FX, 16gb Ram, GeForce GTX 680 2gb Current Project: Pyroxene
Posted : Friday, 16 July 2010, 09:13 | Permalink
j\'ordos

 No, the ship only banks when the ship's vector changes, turning in place does not bank the ship. The code you provided would bank the ship when turning even when the ship's not moving. The effect I was trying to describe is when a player thrusts his ship forward, releases the thrust key - the ship continues to travel in the same direction and at the same speed due to frictionless physics - then the player would turn the ship without applying thrust. At this point the ship should not bank as it hasn't changed the actual direction it's traveling yet. Only when the player then applies thrust again, after turning the ship, should the ship bank. This is how it happens in the latest continuum client at least. The code I devised at first did not bank the ship unless the player was holding down both a turning key and a thrusting key. The two 'solutions' I attempted in my second post don't work properly. Sorry if it's a bit confusing, I don't know how to describe it any better.
Posted : Friday, 30 July 2010, 18:49 | Permalink
j\'ordos

 I could use some help making the AI ships 'lead' their shots. I have the following setup: first we get the distance between the player and the AI Dist=Sqr((np\x#-pl\x#)^2+(np\y#-pl\y#)^2) --> then we calculate the time needed for the projectile to cover that distance t#=dist/wb\speed ;wb stands for weapon_bomb --> and then we calculate the target x&y pos based on the player's current x&y speed and angle: tx#=pl\x#+(t#*pl\s#)*table_sin(Floor(pl\angle#)) ty#=pl\y#-(t#*pl\t#)*table_cos(Floor(pl\angle#)) --> The accuracy is appalling though. Feels like there is something inherently wrong with this code... Another problem is that it does not take into account the velocity of the AI spaceship, which is added to that of the bullet. bm\s#=wb\speed*table_sin(Floor(np\angle#))+np\s# ;bm stands for bomb bm\t#=-wb\speed*table_cos(Floor(np\angle#))+np\t# -->
Posted : Tuesday, 03 August 2010, 21:16 | Permalink
Teasy

Hey j\'ordos

## Ship roll

Here's a little program I baked for ya, which I hope mimics your desired ship roll behavior, from having read your elaborate explanations

-->
Ship roll 1.BB: Use cursor left/right to rotate and cursor up to thrust (Esc to quit).

From what I understood, you're looking for:
RollPosition = RotationVelocity * ThrustVelocity

I've marked the most relevant bits in the code with {@@} so you can easily locate the juicy parts

## Target intercept

Well, I've made another program for ya, which demonstrates 'artificial intelligence' firing at the player ship with prediction/interception.
It uses a math algorithm (which I don't understand ) from the BlitzCoder-era.

As a side-note, I've altered the ship roll behavior in the second program to be a bit more natural in my opinion

Also here I've marked the most relevant bits with {@@}.

-->
Ship roll 2 & intercept.BB: Use cursor left/right to rotate and cursor up to thrust (Esc to quit).

The InterceptAngle function (see below) has support for both source and target velocities, which is what I think you were after.

## Include files

Both programs use a separate math 'library' file and an input definition file, for my own convenience

Most stuff is fairly well commented/documented, but if you're ever in the dark, lemme know

-->
Math.Lib.BB: Collection of math functions and definitions.

-->
Input.Def.BB: Collection of input (keyboard, mouse) definitions.

I've added another bunch of these in the Code Snippets section of this website.

## ImagesCollide

I remember that some time ago I've read on the BlitzBasic forums that ImagesOverlap gets called inside BlitzBasic's own ImagesCollide function.
But I don't know if this has changed in any new releases, since there were some fixes related to the ImagesCollide function.

Personally I've always experienced the wrapping of the higher precision functions (including ImagesCollide) as extremely beneficial/reliable
Posted : Friday, 06 August 2010, 06:12 | Permalink
j\'ordos

 Wow that's awesome! I've been busy implementing the intercept thingy, I'm sure the rest of that math library will be very useful during this ordeal too (the input library too now that I think of it, but later, when I get to menu functions such as customize key bindings) Sadly it looks like the ship roll is still not what I meant it to be - I myself managed to get it as far as rolling only when the player was both thrusting and turning at the same time, which your first example seems to be doing. (I like the runtime generated ship, might have to steal that for the radar map or something ). What I'd like to do is to make it roll only when the ship actually changes it's course. here's an image of the event I've been trying to explain earlier where this code fails: A ship is cruising along at some speed. The ship is not thrusting but keeps it's momentum due to frictionless physics used. Then the player turns without thrusting. The ship does not and should not roll. Fine so far. The player stops turning and now the ship is pointing in another direction but still moving in it's original heading. The player applies thrust and the ship changes it's direction gradually: now it should roll but it doesn't in either of the two proposed setups (ship rolls when turning & ship rolls when turning and thrusting) since the player is only thrusting and not turning! Hopefully I managed to explain the problem clearly this time edit: The problem is minor ofcourse - I'm just wondering how this kind of effect can be done since it is implemented that way in subspace/continuum. Also it's current implementation may be harder to do for AI ships.
Posted : Friday, 06 August 2010, 15:50 | Permalink
Teasy

 Ahh, that's an interesting type of roll. It seems you're after the rotation deviation, so to speak, rather than the rotation velocity. E.g. the difference between the heading and the angle ('facing'), rather than the current rotational 'strength': RollPosition = RotationDeviation * ThrustVelocity I'll outline the steps I've taken to mimic this behavior. 1. Converting your diagram to a function using an AngleDifference function, most conveniently already located in the Math library Print AngleDifference( 90 , 0 ) ; + 90 left -1 Print AngleDifference( 90 , 180 ) ; - 90 right +1 Print AngleDifference( 90 , 270 ) ; -180 none 0 Print AngleDifference( 90 , 90 ) ; 0 none 0 Print AngleDifference( 90 , 0+45 ) ; 45 half left -.5 Print AngleDifference( 90 , 180+45 ) ; -135 half right +.5 WaitKey End --> 2. Deciding the type of interpolation/smoothing to use for the roll, adding a custom Tri (wave) function. ; 0 = 0 ; 45 = .5 ; 90 = 1 ; 135 = .5 ; 180 = 0 For i = 0 To 360 Step 45 lx1 = x1 x1 = i ly1 = y1 ly2 = y2 y1 = Sin( i ) * 50 + 100 y2 = Tri( i ) * 50 + 100 If i>0 Color 32,96,128 Line lx1,ly1 , x1,y1 Color 192,128,64 Line lx1,ly2 , x1,y2 End If Next WaitKey End Function Tri#( a# ) a = a + 90 a = RangeInt( a , 360 ) ;If a >= 360 ; a = a - 360 ;End If If a < 180 Return a/90-1 Else Return (270-a)/90 End If End Function --> 3. Final-testing the algorithm, wrapping the AngleDifference in either Sin() or Tri(). testalgo1 90,0 ; + 90 left -1 testalgo1 90,180 ; - 90 right +1 testalgo1 90,270 ; -180 none 0 testalgo1 90,90 ; 0 none 0 testalgo1 90,0+45 ; 45 half left -.5 testalgo1 90,180+45 ; -135 half right +.5 Function testalgo1( a1,a2 ) Print a1+" "+a2+" "+(-Tri( AngleDifference( a1,a2 ) )) End Function WaitKey End --> 4. And finally tweaking the existing game using the new code/formula. AppTitle "Ship roll test 3" ; Uses Input: Key_Up, Key_Left, Key_Right ; Uses Math: CapFloat, RangeFloat, ScalePoint, vx, vy, vd, va, AngleDifference ; Uses Local: drawship Include "q:\Dev\Blitz\Lib\Math.Lib.BB" Include "q:\Dev\Blitz\Lib\Input.Def.bb" Const sx = 320 Const sy = 240 Const maxthrust = 15 Const thrustintensity# = 0.003 Const maxrotate = 15 Const rotateintensity# = 0.2 Const maxspeed = 2 ; maximum velocity Graphics sx,sy , 0,3 SetBuffer BackBuffer() SetFont LoadFont( "Small Fonts" , 11 ) Local x# = sx/2 Local y# = sy/2 Local angle# ; 0..360 degrees; ship direction Local thrust ; (forward) thrust velocity (0 = none, n = max) {@@} Local rotate ; rotation velocity (-n = max left, 0 = none, +n = max right) {@@} Local roll ; -5 = full left, 0 = center, +5 = full right {@@} Local difference; angle difference between ship angle and heading (rotation deviation) {@@} Local xV#,yV# ; ship velocity (cartesian) Local dV#,aV# ; (polar; distance,angle) Local timer = CreateTimer( 60 ) Repeat ; ship rotation (velocity) If KeyDown( Key_Left ) rotate = rotate - 1 ElseIf KeyDown( Key_Right ) rotate = rotate + 1 Else ; stabilize rotation velocity If rotate < 0 rotate = rotate + 1 ElseIf rotate > 0 rotate = rotate - 1 End If End If ; limit rotation velocity boundary rotate = CapFloat( rotate , -maxrotate,+maxrotate ) ; add rotation velocity to ship rotation angle = angle + rotate*rotateintensity ; overflow rotation boundary angle = RangeFloat( angle , 360 ) ; ship thrust (velocity) If KeyDown( Key_Up ) thrust = thrust + 1 Else thrust = thrust - 1 End If ; limit thrust boundary thrust = CapFloat( thrust , 0,maxthrust ) ; add thrust vector to current velocity vector xV = xV + vx( thrust*thrustintensity,angle ) yV = yV + vy( thrust*thrustintensity,angle ) ; limit velocity vector dV = vd( xV,yV ) ; - remember current ship direction (heading) aV = va( xV,yV ) If dV > maxspeed dV = maxspeed xV = vx( dV,aV ) yV = vy( dV,aV ) End If ; move ship according to velocity vector x = x + xV y = y + yV ; overflow ship location boundary x = RangeFloat( x,sx ) y = RangeFloat( y,sy ) ; roll = rotation deviation * thrust velocity {@@} ; - 90 deg = max roll (left or right) ; - 0/180 deg = no roll difference = AngleDifference( angle , aV ) roll = Sin( difference ) * 5 * thrust / maxthrust ; render drawship x,y , angle,roll,thrust Color 176,255,0 Text 0,0 , "Thrust: "+thrust Text 0,10 , "Rotate: "+rotate Text 0,20 , "Roll: "+roll Flip WaitTimer timer Cls Until KeyHit( 1 ) End --> After tweaking some more, I ended up with reversing the roll (left=right), and choosing Sin() over Tri() for a more natural smoothness. I'm curious if this is the behavior you're looking for Well, I'm glad you like my ship And I hope you enjoy using it As well as any other code
Posted : Saturday, 07 August 2010, 09:22 | Permalink
Teasy

 I've added a beautiful flame effect, and a thicker ship AppTitle "Ship roll test 3b" ; Uses Input: Key_Up, Key_Left, Key_Right ; Uses Math: CapFloat, RangeFloat, ScalePoint, vx, vy, vd, va, AngleDifference Include "q:\Dev\Blitz\Lib\Math.Lib.BB" Include "q:\Dev\Blitz\Lib\Input.Def.bb" Const sx = 320 Const sy = 240 Const maxthrust = 15 Const thrustintensity# = 0.003 Const maxrotate = 15 Const rotateintensity# = 0.2 Const maxspeed = 2 ; maximum velocity Graphics sx,sy , 0,3 SetBuffer BackBuffer() SetFont LoadFont( "Small Fonts" , 11 ) Local x# = sx/2 Local y# = sy/2 Local angle# ; 0..360 degrees; ship direction Local thrust ; (forward) thrust velocity (0 = none, n = max) {@@} Local rotate ; rotation velocity (-n = max left, 0 = none, +n = max right) {@@} Local roll ; -5 = full left, 0 = center, +5 = full right {@@} Local difference; angle difference between ship angle and heading (rotation deviation) {@@} Local xV#,yV# ; ship velocity (cartesian) Local dV#,aV# ; (polar; distance,angle) Local timer = CreateTimer( 60 ) Repeat ; ship rotation (velocity) If KeyDown( Key_Left ) rotate = rotate - 1 ElseIf KeyDown( Key_Right ) rotate = rotate + 1 Else ; stabilize rotation velocity If rotate < 0 rotate = rotate + 1 ElseIf rotate > 0 rotate = rotate - 1 End If End If ; limit rotation velocity boundary rotate = CapFloat( rotate , -maxrotate,+maxrotate ) ; add rotation velocity to ship rotation angle = angle + rotate*rotateintensity ; overflow rotation boundary angle = RangeFloat( angle , 360 ) ; ship thrust (velocity) If KeyDown( Key_Up ) thrust = thrust + 1 Else thrust = thrust - 1 End If ; limit thrust boundary thrust = CapFloat( thrust , 0,maxthrust ) ; add thrust vector to current velocity vector xV = xV + vx( thrust*thrustintensity,angle ) yV = yV + vy( thrust*thrustintensity,angle ) ; limit velocity vector dV = vd( xV,yV ) ; - remember current ship direction (heading) aV = va( xV,yV ) If dV > maxspeed dV = maxspeed xV = vx( dV,aV ) yV = vy( dV,aV ) End If ; move ship according to velocity vector x = x + xV y = y + yV ; overflow ship location boundary x = RangeFloat( x,sx ) y = RangeFloat( y,sy ) ; roll = rotation deviation * thrust velocity {@@} ; - 90 deg = max roll (left or right) ; - 0/180 deg = no roll difference = AngleDifference( angle , aV ) roll = Sin( difference ) * 5 * thrust / maxthrust ; render drawship x,y , angle,roll,thrust Color 176,255,0 Text 0,0 , "Thrust: "+thrust Text 0,10 , "Rotate: "+rotate Text 0,20 , "Roll: "+roll Flip WaitTimer timer Cls Until KeyHit( 1 ) End Function drawship( xpos,ypos , angle,rollpos,thrust , r=128,g=192,b=255 ) ; Param xpos,ypos ; pixel location on screen of ship center of rotation ; Param angle ; 0..360 degrees (0=up) ; Param rollpos ; -5 = full left, 0 = center, +5 = full right ; Param thrust ; 0..maxthrust: used only for flame effect ; Param r,g,b ; ship color ; ship shape Local xT#,yT#,dT#,aT# ; top Local xL#,yL#,dL#,aL# ; left Local xR#,yR#,dR#,aR# ; right Local xB#,yB#,dB#,aB# ; bottom ; ship roll colors Local bL#,bR# ; brightness left/right ; boundary checking rollpos = CapFloat( rollpos , -5,+5 ) ; ship shape (grid coordinates) xT = 0 yT = 0 - 10 + 2 xL = 0 - 5 yL = 0 + 3 + 2 xR = 0 + 5 yR = 0 + 3 + 2 xB = 0 yB = 0 + 2 ; alter shape according to roll xL = xL - rollpos / 2 xR = xR - rollpos / 2 ; convert to distance/angle and rotate ship dT = vd( xT,yT ) aT = va( xT,yT ) + angle dL = vd( xL,yL ) aL = va( xL,yL ) + angle dR = vd( xR,yR ) aR = va( xR,yR ) + angle dB = vd( xB,yB ) aB = va( xB,yB ) + angle ; convert back to grid (x,y) and position ship xT = vx( dT,aT ) + xpos yT = vy( dT,aT ) + ypos xL = vx( dL,aL ) + xpos yL = vy( dL,aL ) + ypos xR = vx( dR,aR ) + xpos yR = vy( dR,aR ) + ypos xB = vx( dB,aB ) + xpos yB = vy( dB,aB ) + ypos ; colorize wings according to roll bL = ScalePoint( rollpos , -5,+5 , 0.5,1 ) bR = ScalePoint( rollpos , -5,+5 , 1,0.5 ) ; draw flame drawflame xpos,ypos , angle,rollpos,thrust ; draw ship ; (left wing) Color r*bL,g*bL,b*bL dLine xT,yT , xL,yL dLine xB,yB , xL,yL ; (right wing) Color r*bR,g*bR,b*bR dLine xT,yT , xR,yR dLine xB,yB , xR,yR ; (center) Color r,g,b dLine xT,yT , xB,yB End Function Function drawflame( xpos,ypos , angle,rollpos,thrust ) Local xT# ,yT# ,dT# ,aT# ; top (center) Local xTL#,yTL#,dTL#,aTL# ; top left Local xTR#,yTR#,dTR#,aTR# ; top right Local xBL#,yBL#,dBL#,aBL# ; bottom left Local xBR#,yBR#,dBR#,aBR# ; bottom right Local xB# ,yB# ,dB# ,aB# ; bottom (center) Local xS# ,yS# ; roll shift Local i# ; flame intensity Local r# ; flame fluxuation ; boundary check thrust = CapInt( thrust , 0,maxthrust ) ; no thrust: hide flame If thrust = 0 Return End If ; shift flame sideways during roll xS = - rollpos / 2.0 yS = 0 ; flame intensity/size according to thrust strength/velocity i = ScalePoint( thrust , 0,maxthrust , 0.3,0.8 ) ; flame fluxuation/point (random) deviation ; - further towards the bottom means more flux r = .5 ; flame shape ; - top (center) near ship bottom point xT = 0 + xS yT = 0 + 1.0*i + 2 + yS xTL = 0 - 2.5*i + xS + Rnd(-r,r) yTL = 0 + 2.5*i + 2 + yS + Rnd( 0,r*2) xTR = 0 + 2.5*i + xS + Rnd(-r,r) yTR = yTL ;+ Rnd(-r,r) xBL = 0 - 1.5*i + xS + Rnd(-r*1.0,r*1.0) yBL = 0 + 6.0*i + 2 + yS + Rnd( 0.0,r*2.0) xBR = 0 + 1.5*i + xS + Rnd(-r*1.0,r*1.0) yBR = yBL ;+ Rnd(-r,r) xB = 0 + xS ;+ Rnd(-r*2,r*2) yB = 0 + 7.5*i + 2 + yS + Rnd( 0.0,r*2.0) ; convert to distance/angle and rotate dT = vd( xT ,yT ) aT = va( xT ,yT ) + angle dTL = vd( xTL,yTL ) aTL = va( xTL,yTL ) + angle dTR = vd( xTR,yTR ) aTR = va( xTR,yTR ) + angle dBL = vd( xBL,yBL ) aBL = va( xBL,yBL ) + angle dBR = vd( xBR,yBR ) aBR = va( xBR,yBR ) + angle dB = vd( xB ,yB ) aB = va( xB ,yB ) + angle ; convert back to grid (x,y) and position xT = vx( dT ,aT ) + xpos yT = vy( dT ,aT ) + ypos xTL = vx( dTL,aTL ) + xpos yTL = vy( dTL,aTL ) + ypos xTR = vx( dTR,aTR ) + xpos yTR = vy( dTR,aTR ) + ypos xBL = vx( dBL,aBL ) + xpos yBL = vy( dBL,aBL ) + ypos xBR = vx( dBR,aBR ) + xpos yBR = vy( dBR,aBR ) + ypos xB = vx( dB ,aB ) + xpos yB = vy( dB ,aB ) + ypos ; bottom L/R Color 160,80,0 dLine xBL,yBL , xB,yB dLine xBR,yBR , xB,yB ; center L/R Color 255,128,0 dLine xTL,yTL , xBL,yBL dLine xTR,yTR , xBR,yBR ; top L/R Color 255,192,0 dLine xT,yT , xTL,yTL dLine xT,yT , xTR,yTR End Function ; draw doubled (thick) line (2h+2v) Function dLine( x1,y1 , x2,y2 ) Line x1 ,y1 , x2 ,y2 ;Return Line x1-1,y1 , x2-1,y2 Line x1 ,y1-1 , x2 ,y2-1 Line x1+1,y1 , x2+1,y2 Line x1 ,y1+1 , x2 ,y2+1 End Function -->
Posted : Sunday, 08 August 2010, 06:00 | Permalink
j\'ordos

 Yes, that finally looks like the effect I'm trying to achieve! No success in implementing it in my game yet, it'll take some time to let all that math sink in. :s Well for a radar screen I won't be using a flame effect and thicker ship but glad to see you're enjoying yourself! edit: and after all this I'll have to start tackling AI math... Argh I'll never make it!
Posted : Friday, 13 August 2010, 08:39 | Permalink
Teasy

 Hey, is there any chance/place to see your game in action? I'm curious what it feels like
Posted : Sunday, 10 October 2010, 13:22 | Permalink
j\'ordos

 Hey Teasy, terribly sorry I didn't see this sooner! Truth be told, I lost interest pretty soon after this without ever getting to the implementation of the mathematics part Recently I've gotten back into programming slowly and I suddenly wondered if there'd be anything new here The game is indeed 'playable' and I'd be happy to upload it. As I said - the rolling part hasn't been implemented yet and looks completely wrong. edit: You can download it here: users.telenet.be/V776822/Project/spacewars4.zip (~6.4Mb) There's a scrolling background and a single AI ship that hunts you (most of the time, it sometimes can get lost ), firing bombs at you occasionally. You can shoot back with bullets(unlimited) and bombs (of which you have three). edit2: I forgot the controls: arrow keys to move, ctrl to shoot bullets and tab to fire bombs. By the way; there's a small bug where you can go over the top speed because of the recoil caused by firing a bomb. Currently the speed doesn't drop back to normal when that happens and thrusting won't work anymore so you're stuck. Easy to fix but yeah...
Posted : Tuesday, 12 October 2010, 12:44 | Permalink
Teasy

Posted : Tuesday, 12 October 2010, 15:28 | Permalink
j\'ordos

 Sweet! Thanks a lot Teasy, the code is quite clear, looks like it required less changes than I first imagined! Glad to see you managed to decipher my code without much problems, luckily the program isn't too big yet Any suggestions you may have are of course welcome! I'm trying to make the game look as much like subspace/continuum as possible for now, but it isn't my eventual goal to make a clone. I Just wanted to make a 360 shooter set in space and subspace seemed like a good starting point (not in the least because I could rip it's graphics ) There's still heaps of work left to do, and AI seems like the next step... I can use any advice anyone can give me on that Thanks for the other small edits by the way (except for disabling reverse thrust perhaps ), I love my game now <3
Posted : Tuesday, 19 October 2010, 09:10 | Permalink
Teasy

Posted : Thursday, 21 October 2010, 12:44 | Permalink
j\'ordos

Posted : Thursday, 21 October 2010, 21:46 | Permalink
Teasy

Posted : Friday, 22 October 2010, 10:15 | Permalink
j\'ordos

 Wow this is an enormous improvement for the AI! Excellent work Teasy, I love teamwork ^^ Ah I understand the handle/object use a bit better now. Thx for the quick overview. Looks like I'll need to use the target var as intended then, so I can use it to track both player as AI ships. Also I eventually want to have some capital ships flying around which may (or may not) become an entirely different class. I will need to find some images for large ships though, there are none in subspace/continuum. I'm still going over all the changes (an extra if then condition for the reverse thrust! The horror! ), thanks for the optimizations, those will be useful as I want to have lots of little ships duking it out . The doubled sin/cos table is a great idea! There does seem to be something wrong with the accurate tables though; you only used them for the debris scattering which didn't scatter anymore. Replacing the accurate table with the standard 9 degree interleaved one fixed it though. Can't see anything wrong with them at first glance... Dim table_sinA#(sincostablesize) Dim table_cosA#(sincostablesize) For a=0 To sincostablesize table_sin(a)=Sin(a) table_cos(a)=Cos(a) Next .. For a=0 To 8 dm.debris_m=New debris_m dm\img=junk_jv dm\x#=screenxmid+np\x# dm\y#=screenymid+np\y# dm\s#=table_sinA(Rand(44)*a)+(np\s#) dm\t#=table_cosA(Rand(44)*a)-(np\t#) dm\frame#=10*a dm\frame_end=dm\frame#+9 Next --> (by the way, there wouldn't be any way to preserve tabs when copying code from here would there? ) I'm aware of the automatic integer conversion but that uses int and not floor isn't it? I remember having a reason for wanting floor instead of int, though I can't remember it The interlace effect is fun by the way, works wonders on the background! (at least when in turbo mode) though it does make me dizzy when the grid is on :s Would be better if the UI wasn't affected I think... anyway, I'm off doing some more work!

 Page : 1 2 3
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 527|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
 Latest PostsRotate a 1bpp image? Jayenkai Fri 18:53 AL MICKSES A MACKEY TRACKEY Jayenkai Fri 17:10 Rhythm Heaven Megamix Jayenkai Fri 17:04 NetBreak? Kuron Fri 16:11 Siri Where'd I park my car? : BOOM! Jayenkai Fri 15:04 Don't Stream That Scene Kuron Fri 15:00 ''Virtual''!!! steve_ancell Fri 13:18 Happy Birthday Rychan rychan Fri 08:55 Nintendo Switch GfK Fri 05:35 AGameAWeek : 2016 - Part Two Jayenkai Thu 06:51 More

 Latest Items Woot : Getting Noticed... for Gameboy Dev!rychan Fri 08:56 Dev-Diary : 1st Ever Wed Workshop Progresszzoom Thu 23:12 Showcase : Biomorph FractalsAndy_A Wed 12:43 Snippet : Fisheye Lens EffectJayenkai Wed 11:50 Snippet : 2D BallsJayenkai Wed 06:22 Showcase : Mining Map AI DemoStealth Tue 19:41 Showcase : Biotic Limit - Games For Better (2 Days) Editionrychan Mon 12:27 Dev-Diary : Intellivision Controller Adapterspinal Sun 11:33 Snippet : Contour Map from DataHoboBen Fri 18:14 Snippet : FPS Control (WASD+Mouse)Pakz Wed 22:30 Article : Concurrency in C#Afr0 Sun 12:28 Snippet : Mandelbrot in BMaxJayenkai Sun 03:37 News : Newsletter #281HoboBen Fri 04:18 News : Newsletter #280Jayenkai Sat 05:10 Blog : Monkey-X Box2D: Learning from my perspective... Hopefully!steve_ancell Sun 14:49More

Who's Online
Cower
Fri, at 23:16
Jayenkai
Fri, at 22:35
Kuron
Fri, at 20:36
blanko1324
Fri, at 20:21
GfK
Fri, at 17:31
shroom_monk
Fri, at 17:20
steve_ancell
Fri, at 16:19
spinal
Fri, at 15:24
rockford
Fri, at 15:04
Krakatomato
Fri, at 14:11