Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / DBPro Sample to DGDK.NET

Author
Message
JKatt
17
Years of Service
User Offline
Joined: 5th Jul 2007
Location:
Posted: 7th Jul 2007 03:45
Ok, since there is a lack of DGDK code on here, I've been kinda trying to learn by converting the DBPro examples to their .Net counterpart. So, if anyone is familiar with those samples, they can see what it looks like in DGDK .Net.

I've done a couple. This is the SpriteExample one. I basically did it code for code in a linear fashion, so it's not all OOP, but at least people can get an idea of how similar the two packages really are and the possiblities of converting your DBPro app to .Net... The only problem with this code is that the cool zooming in and out of the spaceship (via scaling) doesn't really seem to work, and I don't know why (down at the bottom of the code list). Also, I made a couple of changes just messing around to slow down the spin of the asteroids and to speed up the background. If you know why the scaling doesn't work, let me know.

Thanks...

JKatt

// Init
InitDarkGDK("Insert your own God Awful Long Code Here");

// Standard Setup Code For All Examples

oDBCore.SyncOn();
oDBCore.SyncRate(0);
oDBCamera.BackdropOn();
oDBCamera.BackdropColor(0);

// Load Images

oDBImage.SetImageColorKey(255, 0, 255);
oDBSprite.CreateAnimatedSprite(1,"C:\\Program Files\\Dark Basic Software\\Dark Basic Professional\\Help\\examples\\sprite\\animspr.bmp",4,4,16);
oDBImage.LoadImage("C:\\Program Files\\Dark Basic Software\\Dark Basic Professional\\Help\\examples\\sprite\\ship.bmp",2);
oDBImage.LoadImage("C:\\Program Files\\Dark Basic Software\\Dark Basic Professional\\Help\\examples\\sprite\\backdrop.bmp",3);

// Setup Backdrop Sprite

oDBSprite.Sprite(1001,0,0,3);
oDBSprite.Sprite(1002,0,0,3);
oDBSprite.SetSpritePriority(1001,0);
oDBSprite.SetSpritePriority(1002,0);
oDBSprite.SizeSprite(1001,1024,1024);
oDBSprite.SizeSprite(1002,1024,1024);

//Setup Asteroid Sprite

oDBSprite.Sprite(1, 320, 240, 16);
oDBSprite.SizeSprite(1, 128, 128);
oDBSprite.OffsetSprite(1, 64, 64);

// Array For Finer Asteroid Data

float[] ast = new float [100];

// Copy Animating Sprite

for(int t = 2; t < 99; t++)
{
oDBSprite.CloneSprite(1,t);
oDBSprite.Sprite(t,oDBCore.RND(640+356)-128,oDBCore.RND(1400)-400,16);
ast[t] = oDBSprite.SpriteY(t);
oDBSprite.RotateSprite(t,oDBCore.RND(350));
oDBSprite.SetSpriteFrame(t,oDBCore.RND(15));
oDBSprite.SetSprite(t,0,1);
float a = oDBCore.RND(350);
float s = 32;
float sss = 64 + (oDBCore.COS(a) * s);
oDBSprite.SizeSprite(t,(int)sss,(int)sss);
oDBSprite.OffsetSprite(t,(int)sss / 2,(int)sss / 2);
if (t < 50)
{
oDBSprite.SetSpritePriority(t, 1);
}
else
{
oDBSprite.SetSpritePriority(t, 3);
}
}

// Setup Ship Sprite

oDBSprite.Sprite(100,200,140,2);
oDBSprite.SetSpritePriority(100,2);

// Backdrop Shift
float shiftx = 0.0f;
float sya = 0.0f;
float sy = 0.0f;

while(oDBP.LoopGDK)
{
shiftx = shiftx + 20.0f;
sya = oDBCore.WrapValue(sya + .75f);
sy = -260+(oDBCore.COS(sya)*260);
if (shiftx>1024.0)
{
shiftx = shiftx - 1024f;
}

oDBSprite.Sprite(1001, 0 - (int)shiftx, (int)sy, 3);
oDBSprite.Sprite(1002, 1024 - (int)shiftx, (int)sy, 3);

// Control Sprite Auto-Animation

for (int t = 1; t < 99; t++)
{
float a = oDBCore.WrapValue(oDBSprite.SpriteAngle(t) + 1 + oDBCore.RND(2));
oDBSprite.RotateSprite(t, 90);
oDBSprite.MoveSprite(t, -3);
ast[t] = ast[t] - ((oDBCore.SIN(sya) * 0.3f));

if(oDBSprite.SpriteX(t)<-128)
{
oDBSprite.MoveSprite(t,(640+256));
}

a = oDBCore.RND(20);
oDBSprite.Sprite(t,oDBSprite.SpriteX(t),((int)ast[t]), oDBSprite.SpriteImage(t));
oDBSprite.PlaySprite(t,1,16,50);
oDBSprite.RotateSprite(t, a);
}

// Glide Ship

float g = 0.0f;
g = oDBCore.WrapValue(g + 1.0f);
float h = 0.0f;
h = oDBCore.WrapValue(h + .5f);
oDBSprite.Sprite(100, 200, (int)(140 + oDBCore.SIN(g) * 10f), 2);
oDBSprite.ScaleSprite(100,(100 + oDBCore.SIN(h)* 20.0f));
oDBSprite.RotateSprite(100,(oDBCore.SIN(sya) * 10.0f));
oDBCore.Sync();
}

Login to post a reply

Server time is: 2024-09-29 01:22:55
Your offset time is: 2024-09-29 01:22:55