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 / Dark GDK platfomer game HELP

Author
Message
Dark GDK platformer game
10
Years of Service
User Offline
Joined: 12th May 2013
Location:
Posted: 12th May 2013 11:04
can somebody help me check what is the problem here...the player is not moving and jumping.

// Dark GDK - The Game Creators - www.thegamecreators.com

// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application

// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
#include <time.h>

int player;
void Load_media()
{
dbLoadImage("platformblue.jpg",1);
dbLoadImage("player.bmp",2);
dbLoadImage("Penguins.jpg",3);

}

void generate_level(int num_blocks, int Xblock_size, int Yblock_size)
{
int player=100;
int gap=1000;
int Yblock=0;
dbSprite(player,10,10,2);

for (int i=0; i<num_blocks; i++)
{
Yblock=dbSpriteY(i)+dbRnd(gap);
dbSprite(i,dbRnd(500),Yblock,1);
dbSizeSprite(i, Xblock_size, Yblock_size);
}
}

int x=100;
void movement()
{
if (dbRightKey()==1){x+=1;}
if (dbLeftKey()==1){x-=1;}
dbSprite(player,x,dbSpriteY(player),2);
}

void move_blocks()
{
for (int i=0; i<40; i++)
{
dbMoveSprite(i,-1);
}
}

void reset_blocks()
{
for (int i=0;i < 40;i++)
{
if (dbSpriteY(i) > 1000)
{
dbSprite(i,dbRnd(500),-40,1);
}

}
}

int jump_timer=0;
float speed = -0.5;
bool falling = false;

void jumping()
{
if (dbSpriteCollision(player,0)==0)
{
jump_timer++;
dbMoveSprite(player,speed);
falling = true;
}
else
{
falling = false;
jump_timer=0;
speed = -0.5;
}
}

float playerY;
float jump_speed = -2;
bool player_jumping = false;

void gravity()
{
playerY=dbSpriteY(player)+jump_speed;
if (player_jumping == true)
{
jump_speed=jump_speed + 0.07;
}
dbSprite(player,dbSpriteX(player),playerY,2);
if (jump_speed > 0.5f)
{
//play sound
jump_speed = -3;
player_jumping = false;
}
if (jump_timer > 20){speed=speed-0.1;}
}
void DarkGDK(void)
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetDisplayMode(500,650,32);
srand(time(NULL));
Load_media();
generate_level(40,40,11);
// our main loop
while ( LoopGDK ( ) )
{
movement();
move_blocks();
reset_blocks();
jumping();
gravity();
dbPasteImage(3,0,0);
// update the screen
dbSync ( );
}

// return back to windows
return;
}
Timidon
18
Years of Service
User Offline
Joined: 26th Jun 2005
Location: Bakersfield, Ca. USA.
Posted: 18th May 2013 03:47
I would figure we would need to see more, can you make the above a standalone exicuteable and include the media, might be able to help a bit more. if we can see it, try and compile it.

There are many answers but just one question" ~ Jerilith the Mad
Bored of the Rings
User Banned
Posted: 18th Jun 2013 08:16
Try using jump_timer = dbTimer() and then doing a subtraction in your conditions code e.g see below code taken from a mario clone platform game:



The variable "jumping" is just a boolean variable to test if the character is jumping or not e.g. if the jump key has been pressed and if the character is touching the ground.

In your example code, I couldn't see where you are testing to see if the user has pressed the key for jumping etc....

Login to post a reply

Server time is: 2024-04-19 21:52:38
Your offset time is: 2024-04-19 21:52:38