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 / Need help with sprites

Author
Message
LostNightRecon
14
Years of Service
User Offline
Joined: 12th Nov 2010
Location: Angola, IN
Posted: 13th Nov 2010 05:42 Edited at: 13th Nov 2010 15:33
Need to make it so a sprite spawns in a point on the other sprite. Its to be like space invaders where you shoot at the gun on the ship. Its where my issue is. If anyone can please help me.

oops didn't include the code...

#include "DarkGDK.h"
//Final project
//Michael Serens

//Funcition prototypes
void MoveShip(int &);
void Setup();
void Fire();

//global constants
int Shipx = 320;
int Shipy = 250;
int x = Shipx/2 ;
int y = Shipy + 10;

//Sprite Constants
const int Ship = 1;
const int Space = 2;
const int Planet = 3;
const int Shot = 5;

void DarkGDK()
{
//Show the name of the game
dbSetWindowTitle("Planet Defender");

//Display the intro screen then wait for the key press
dbLoadImage("Intro.bmp", 1);
dbPasteImage(1, 0, 0);
dbWaitKey();

//run the set up program
Setup();

//screen refresh
dbSyncOn();
dbSyncRate(60);

//Game Loop
while ( LoopGDK () )
{
//clear the screen
dbCLS();

//detect motion for the ship then move it
MoveShip(Shipx);
dbSprite(Ship, Shipx, Shipy, 4);

//Shoot on space to hit an object
Fire();

//resync the screen
dbSync();
}

dbWaitKey();

}


void Setup()
{

//set in the intro screen then the space with the planet.
dbLoadImage("Planet.bmp", 2);
dbLoadImage("Space.bmp", 3);
dbLoadImage("Ship.bmp", 4);
dbLoadImage("Shot.bmp", 5);

//Create the sprites
dbSprite(Space, 0, 0, 3);
dbSprite(Planet, 0, 300, 2);
dbSprite(Ship, Shipx, Shipy, 4);
dbSprite(Shot, x, y, 5);

//hide sprites that are not needed full time
dbHideSprite(Shot);
}

void MoveShip (int &Shipx)
{
if ( dbLeftKey() )
{
if(Shipx !=0 )
{
Shipx--;
}
}
if ( dbRightKey() )
{
if(Shipx != 589)
{
Shipx++;
}
}
}
void Fire()
{
//turn off the sync
dbSyncOff();

//show the shot
if(dbReturnKey())
{
dbSprite(Shot, x, y, 5);
}

dbMoveSprite(Shot, 1);

/* if()
{
dbHideSprite(Shot);
}*/
}

Attachments

Login to view attachments
Dodga
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 13th Nov 2010 23:32
If you mean you want the sprite to spawn where another sprite is but a little offset you could do something like this

int offsetX=10;
int offsetY=10;
int SpriteToSpawn=1;
int TargetSprite=2;

dbPasteSprite(SpriteToSpawn, dbSpriteX(TargetSprite)+offsetX, dbSpriteY(TargetSprite)+offsetY);
LostNightRecon
14
Years of Service
User Offline
Joined: 12th Nov 2010
Location: Angola, IN
Posted: 14th Nov 2010 01:50
Thank you. It spawns right just got to fix the value of the offset. That helped relieve a lot of head ache.
Dodga
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 15th Nov 2010 07:32
No problem, glad I could be of help good luck with the project.

Login to post a reply

Server time is: 2024-11-19 16:35:46
Your offset time is: 2024-11-19 16:35:46