@mailman, post #270
@Jacques, post #271
@mailman, post #272
@Jacques, post #273
@mailman, post #275
@mailman, post #278
@tukinem, post #281
@selur, post #282
@tukinem, post #284
@tukinem, post #287
@tukinem, post #288
/////////////////////////////// // Initialize variables float delta_time = 0.1;//time scale float mass = 1; //weight of ball float drag = 0; //to be described on surface that ball is rolling over float force = 0; //to be described on object ball is striking int Ball_sprite_Y = 40; //Ball Y position float ball_yy = Ball_sprite_Y; //floating point X position float yVelocity = 0;//speed of the ball in the Y plane (ball is steered using this) float yAcceleration = 0;//works with force and velocity float yForce = 0; //Y descriptor of force (used in steering ball) int Ball_sprite_X = 0; //Ball X position float ball_xx = Ball_sprite_X; //floating point X position float xVelocity = 0;//speed of the ball in the X plane (ball is steered using this) float xAcceleration = 0;//works with force and velocity float xForce = 0; //X descriptor of force (used in steering ball) float gravity2 = 10; //constant gravity. Tweak this value until the ball feels right with downwards motion. float gravity = 0; // works with gravity 2 float ballAngle = 0; //used for calculations involving degrees float ballAngle = 0; //used for calculations involving radians float velocity = 25; //overall speed of ball //end variables ///////////////////////////////
gravity = -gravity2; xForce = drag * xVelocity; //force is a product of velocity and drag xAcceleration = -xForce / mass; //acceleration is a product of force / mass xVelocity += xAcceleration * delta_time;//break motion in time scale chunks ball_xx += xVelocity * delta_time;//move ball in X plane using time scale chunks yForce = drag * yVelocity; yAcceleration = gravity - yForce / mass; yAcceleration = -yAcceleration; yVelocity += yAcceleration * delta_time; ball_yy += -yVelocity * delta_time; //using - Yvelocity drags the ball downwards // remove the decimal point behind the calculations for plotting the sprite Ball_sprite_X = (int)ball_xx; Ball_sprite_Y = (int)ball_yy;
@andydansby, post #289
@andydansby, post #290
@andydansby, post #290
@tukinem, post #291
int Ball_sprite_Y = 40; //Ball Y position float ball_yy = Ball_sprite_Y; //floating point X position
LET Ball_sprite_Y = 40; //Ball Y position LET ball_yy = Ball_sprite_Y; //floating point X position
yVelocity += yAcceleration * delta_time;
LET yVelocity = yVelocity + yAcceleration * delta_time;
@andydansby, post #293
@andydansby, post #295
ball_sprite_Y.w = 40; WORD ball_sprite_Y.q = 40; float
yVelocity + yAcceleration * delta_time
@andydansby, post #295
NEWTYPE.TB x.q; x position y.q; y position speed.q; speed vector.q; angle End NEWTYPE DEFTYPE.TB ball; variable type declaration Dim kol.b(2); table of collisions corners of the ball level.b = 3 klatka.b l.b = 0 r.b = 0 tunel.b k.b alfa.q = Pi/180; conversion degrees to radians ;################## ;loading shapes BitMap 0,16,16,7 BitMap 0,320,256,4 LoadBitMap 0,"GFX/flippers" For a = 0 To 4 GetaShape 91+a,155,a*41+a+1,56,41 GetaShape 96+a,212,a*41+a+1,64,41 Next BitMap 0,320,200,2 LoadBitMap 0,"GFX/panel",3 For a = 0 To 23 GetaShape 64+a,a*13,0,13,19 Next For a = 0 To 2 GetaShape 88+a,a*13,19,13,19 Next For a = 0 To 9 GetaShape 48+a,a*13,38,13,19 Next Free BitMap 0 resetball{}; base position of the ball bmy.w = 294; scroll screen g.q = 0.1; gravitation px.w; x position of reading colour index py.w; y position of reading colour index ;starting screen Statement uruchom{level} BitMap 1,320,512,7; bitmapa gornego playfieldu BitMap 3,320,20,2; panel BitMap 2,320,512,4; bitmapa robocza BitMap 4,320,512,7; bitmapa 2 Buffer 4,16384 Select level Case 1 src$="LEV1/" Case2 src$="LEV2/" Case 3 src$="LEV3/" Case 4 src$="LEV4/" End Select BitMap 0,320,256,7 LoadBitMap 0,src$+"sprites.ilbm" GetaShape 0,0,0,14,14; pilka Handle 0,7,7 LoadBitMap 0,src$+"flip.ilbm" Use BitMap 0 For a = 0 To 14 GetaShape 10+a,1+a+a*16,211,16,21; lewa lapka GetaShape 25+a,1+a+a*16,235,16,21; prawa lapka Next For a = 0 To 6 GetaShape 3+a,1+a+a*32,1,32,21; sruba Next BitMap 0,320,512,7 Buffer 0,16384 LoadBitMap 0,src$+"bmap.ilbm",0; dolna bitmapa + kolory CopyBitMap 0,4 LoadBitMap 2,src$+"work.ilbm" LoadBitMap 1,src$+"bmapup.ilbm" End Statement ;bottom panel Statement panel{tekst$} BLITZ Use BitMap 3 For a=1 To Len(tekst$) l$=Mid$(tekst$,a,1) znak=Asc(l$) If znak=32 Then znak=64 Block znak,a*16-16,0 Next If Len(tekst$)<20 For a=Len(tekst$) To 19 Blit 64,a*16,0 Next EndIf End Statement AMIGA uruchom{2}; starting level 2 muzyka{2}; start music VWait 10 BLITZ ball\speed=1 ball\vector=300 InitCopList 0,44,216,$13017,8,128,0 InitCopList 2,44,216,$14,0,16,0; coplist for bitmap collisions InitCopList 1,262,20,$2,0,4,0 DisplayPalette 0,0 DisplayPalette 1,3 CreateDisplay 0,1 DisplayBitMap 0,db,0,bmy DisplayBitMap 1,3 While NOT RawStatus($45) ;################## ;flippers If RawStatus($60); LSHIFT If l<4 Then l+1 Else If l>0 Then l-1 EndIf If RawStatus($61); RSHIFT If r<4 Then r+1 Else If r>0 Then r-1 EndIf ;################## ;shoot start the ball If RawStatus($4d); Down Arrow If sruba<18 Then sruba+1 Else If sruba>0 If ball\x>=196 AND ball\y>=456 Then ball\speed = -sruba sruba = -1 EndIf EndIf db = 4 - db; DOUBLE BUFFER If klatka<7 Then klatka+1 Else klatka = 0; FRAMES LIMITS ;################## ;COLOURS LEGEND: ;0 - colour empty ;1 - down wall ;2 - stop horizontally ball ;3 - right up corner ;4 - left up corner ;5 - right down bow ;6 - rolling the ball ;7 - horizontally bouncing ;8 - left down bow ;9 - forced track ;10 - triangles ;11 - flippers ;################## ;PHYSIC THE BALL :DDD ;################## Use BitMap 2 kol(0) = Point(ball\x+7*Sin(alfa*(ball\vector-45)),ball\y-7*Cos(alfa*(ball\vector-45))) kol(1) = Point(ball\x+7*Sin(alfa*ball\vector),ball\y-7*Cos(alfa*ball\vector)) kol(2) = Point(ball\x+7*Sin(alfa*(ball\vector+45)),ball\y-7*Cos(alfa*(ball\vector+45))) ball\x+ball\speed*Sin(alfa*ball\vector); new X position ball\y-ball\speed*Cos(alfa*ball\vector); new Y position ;################## ;scroll of the screen If bmy>8 If ball\y-bmy < 100 Then bmy-8 EndIf If bmy<294 If ball\y-bmy > 150 Then bmy+4 EndIf ;################## ;BLITTING Use BitMap 1 If ball\y<503 Then GetaShape 2,ball\x-7,ball\y-7,14,14; shape gornego playfieldu UnBuffer db If sruba>0 For a=0 To 4 Step 4 Use BitMap a Block 3+sruba/3,288,482 Next Else If sruba=-1 For a = 0 To 4 Step 4 Use BitMap a Block 3,288,482 Next sruba = 0 EndIf EndIf Use BitMap db ;flippers Select l Case 0 BBlit db,10,88,464 BBlit db,11,104,468 BBlit db,12,120,477 Case 1 BBlit db,13,88,464 BBlit db,14,104,466 BBlit db,15,120,470 Case 2 BBlit db,16,88,464 BBlit db,17,104,464 BBlit db,18,120,465 Case 3 BBlit db,19,88,463 BBlit db,20,104,460 BBlit db,21,120,460 Case 4 BBlit db,22,88,459 BBlit db,23,104,453 BBlit db,24,120,450 End Select Select r Case 0 BBlit db,25,161,477 BBlit db,26,177,468 BBlit db,27,193,464 Case 1 BBlit db,28,161,470 BBlit db,29,177,466 BBlit db,30,193,464 Case 2 BBlit db,31,161,465 BBlit db,32,177,464 BBlit db,33,193,464 Case 3 BBlit db,34,161,460 BBlit db,35,177,460 BBlit db,36,193,462 Case 4 BBlit db,37,161,450 BBlit db,38,177,453 BBlit db,39,193,459 End Select Use BitMap 2 Block 91+l,80,450 Block 96+r,160,450 ;blitting the ball and tricky dual playfield Use BitMap db If ball\y<503 Then BBlit db,0,ball\x,ball\y Plot ball\x+7*Sin(alfa*(ball\vector-45)),ball\y-7*Cos(alfa*(ball\vector-45)),96 Plot ball\x+7*Sin(alfa*ball\vector),ball\y-7*Cos(alfa*ball\vector),96 Plot ball\x+7*Sin(alfa*(ball\vector+45)),ball\y-7*Cos(alfa*(ball\vector+45)),96 If tunel=0 AND ball\y<503 Then BBlit db,2,ball\x-7,ball\y-7 DisplayBitMap 0,db,0,bmy VWait; vertical blank If klatka = 1 Then Gosub panel Wend ;music reset MTMasterVolume 0 MTPlay On VWait 50; oczekiwanie na wylaczenie muzyki MTPlay Off End ;################## ;underprograms panel: Use BitMap 3 If bonus=0 napis$=Str$(kol(0))+" "+Str$(kol(1))+" "+Str$(kol(2)) panel{napis$} Else panel{" BONUS"} bonus=0 VWait 150 EndIf Return
@tukinem, post #296
struct enemy_entities { unsigned char x0; // 0 to 255 travel from enemy unsigned char y0; // 0 to 172 travel from enemy unsigned char sprite; // Sprite type of the enemy, 0 not active unsigned char movement; // bullet movement type, from one of the predefined ones unsigned char energy; // enemy hit points unsigned char gun; // what type of gun the baddy has } enemy_entities[20];
for (temp1 = 0; temp1 < 20; temp1 ++) { enemy_entities[temp1].x0 = 0; enemy_entities[temp1].y0 = 0; enemy_entities[temp1].sprite = 0; enemy_entities[temp1].movement= 0; enemy_entities[temp1].energy= 0; enemy_entities[temp1].gun= 0; }
enemy_entities[0].x0 = 25; enemy_entities[0].y0 = 30; enemy_entities[0].sprite = 1; //basic baddy enemy_entities[0].movement= 1;//moves left right enemy_entities[0].energy= 5;//5 hits before dead enemy_entities[0].gun= 0;// no gun //....... // fill in the rest of the baddies.
while (playerLive == 1) { for (baddy = 0; baddy < 20; baddy++) { if (enemy_entities [baddy].energy == 0); { enemy_entities [baddy].sprite = 0; }//end if }//end for }//end playerlive
@andydansby, post #298
@andydansby, post #299
;;--------------------------- ;convert radians to degrees Function radian2degree:Word{radian:Quick} Quick degree = 0 degree = radian * (180/pi) Function Return degree End Function
;--------------------------- ;convert degrees to radians Function degree2radian:Quick{degree:Quick} Quick radian = 0 radian = degree * (pi/180) Function Return radian End Function
Function Max:Float{xxx:Float, yyy:Float} Float Max = 0; If xxx > yyy Max = xxx; else Max = xxx; EndIf Function Return Max End Function
Function Min:Float{xxx:Float, yyy:Float} Float Min = 0; If xxx > yyy Min = yyy; else Min = xxx; EndIf Function Return Min End Function
;--------------------------- ;calculate ATAN 2 ;normal ATAN does not return a quadrant, here's an alternate ;https://developer.download.nvidia.com/cg/atan2.html Function ATAN2:Float{yyy:Float, xxx:Float} float t0, t1, t3, t4; t3 = Abs(xxx); t1 = Abs(yyy); t0 = Max(t3, t1); t1 = Min(t3, t1); t3 = 1.0 / t0; t3 = t1 * t3; t4 = t3 * t3; t0 = - 0.013480470; t0 = t0 * t4 + 0.057477314; t0 = t0 * t4 - 0.121239071; t0 = t0 * t4 + 0.195635925; t0 = t0 * t4 - 0.332994597; t0 = t0 * t4 + 0.999995630; t3 = t0 * t3; ;t3 = (Abs(yyy) > Abs(xxx)) ? M_PI_2 - t3 : t3; If Abs(yyy) > Abs(xxx) t3 = (Pi + Pi) - t3; else t3 = t3; EndIf ;t3 = (xxx > 0) ? Pi - t3 : t3; If xxx > 0 t3 = Pi - t3; else t3 = t3; EndIf ;t3 = (yyy < 0) ? -t3 : t3; If yyy < 0 t3 = -t3; else t3 = t3; EndIf Function Return t3 End Function
;--------------------------- ;calculate slope of ball path ;; unfortunately pure ATAN does not calculate the quadrant Function slope{x1, y1, x2, y2} float slopeAngle = 0.0 float degrees = 0 float xxx = x2 - x1 float yyy = y1 - y2 float zzz = 0 zzz = yyy / xxx; rise over run ;slopeAngle = ATan(zzz);Atan usually does not return a quadrant slopeAngle = ATAN2(yyy,xxx) degrees = slopeAngle * 180.0 / M_PI; ; convert to degrees ;keep angle from going silly If degrees < 0.0 { degrees = degrees + 360.0; } EndIf If degrees > 360.0 { degrees = degrees - 360.0; } EndIf Function Return degrees End Function
;--------------------------- ;calculate X portion of Newton physics Function newtonX{Ball_sprite_X:Word} float xForce = 0.0 float drag = 0.0; float xVelocity = 0.0 float xAcceleration = 0.0 float mass = 0.5 float delta_time = .1 float ball_xx = 0 Word Ball_sprite_X = 0 xForce = drag * xVelocity xAcceleration = -xForce / mass xVelocity = xVelocity + xAcceleration * delta_time ball_xx = ball_xx + xVelocity * delta_time; Ball_sprite_X = (int)ball_xx; Function Return Ball_sprite_X End Function
;--------------------------- ;calculate Y portion of Newton physics Function newtonY{Ball_sprite_Y:Word} float yForce = 0.0 float drag = 0.0; float yVelocity = 0.0 float yAcceleration = 0.0 float mass = 0.5 float delta_time = .1 float ball_yy = 0 float gravity = 9.5 ;will have to adjust word Ball_sprite_Y = 0 yForce = drag * yVelocity; yAcceleration = gravity - yForce / mass yAcceleration = -yAcceleration; pull ball downwards, may have to adjust yVelocity = yVelocity + yAcceleration * delta_time; ball_yy = ball_yy - yVelocity * delta_time; Function Return Ball_sprite_Y End Function