Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 18,561 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
A few beginners problems #348801
11/30/10 19:58
11/30/10 19:58
Joined: Nov 2010
Posts: 7
Sweden
J
jakk_zeven Offline OP
Newbie
jakk_zeven  Offline OP
Newbie
J

Joined: Nov 2010
Posts: 7
Sweden
I just started to learn Lite-C and began with the workshop. After almost going through everything I decided to use the car model and create a little racing game to get things started. I realise that it may not be the best starting point, but it shouldnt be to hard. But I have run into some problems with my code.

Im trying to make the car drop a bomb by pressing ctrl, but instead of one it creates a whole trail of bombs.

Also Im working on getting a sprite to work as a boostpad but that is not going to well either.

Im not looking for anyone to give me code, that wouldnt help learning at all. Im just looking for some pointers to what commands and so on I should look into.

Keep in mind that Im just starting out with this so the code is probably kind of messy. But here it is(the code looks slightly different here but that should just be the indentation):


racing.c
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include "weapons.c"
#include "player.c"
#include "panels.c"
#include "functions.c"
///////////////////////////////

function main()
{
video_mode=7;
fps_max=60;
mouse_mode = 4;

//level_load ("racing.wmb");


wait (2);

}
//////////////////////////////////////////


weapons.c

function bomb_drop(x,y,z,nrofbombs)
{
if (nrofbombs==1)

ent_create("bomb.mdl",vector(x,y,z),NULL);
return(nrofbombs=0);

}

///////////////////////////////////////////

player.c

//Car definitions and variables
ENTITY* car;

var acc = 0.5;
var speed = 0;
var boost = 0;

//Weapon definitions
var nrofbombs = 1;


//Topview follow cam
function update_camera()
{
while(1)
{
vec_set(camera.x,vector(car.x,car.y,1000));
camera.tilt=-90;
wait(1);
}
}

//playercontrolled car
action my_car()
{
car = me;
my.ambient = 0;
while (1)
{
// move the car using relative_speed
if (key_cul)
my.pan += 4*time_step; // increase the pan angle of the car
if (key_cur)
my.pan -= 4*time_step; // decrease the pan angle of the car
if (key_cuu ) // press and hold the "Space" key to move the car
speed += acc*time_step;
c_move (my, vector(speed*time_step, 0, 0), nullvector, USE_POLYGON | IGNORE_PASSENTS);
if (speed >= 50)
speed = 50;

if (!key_cuu )
speed -= 0.2*time_step;

if (speed <= 0)
speed = 0;

if (key_cud)
speed -= 0.5*time_step;

if (key_ctrl)
bomb_drop(my.x,my.y,10,nrofbombs);

update_camera();

wait (1);
}
}

//////////////////////////////////////////////////////////

panels.c

//Main menu


PANEL* main_menu =
{
//mouse_mode = 4;
pos_x = 400;
pos_y = 300;
button(0,0,"start_pressed.jpg","start.jpg","start.jpg",open_level,NULL,NULL);
flags = SHOW | OVERLAY;
}

///////////////////////////////////////////////////////////

functions.c

action boostplate()
{
ENTITY* boostaction;
boostaction = my;
if ((vector(car.x,car.y,0)) == (vector(my.x,my.y,0)))
{
var x;
x=0;
while (x < 100)
{

speed = 80;
x+=1;
wait(1);
if (x==100)
{
boost=0;

}
}
}
}

function open_level()
{
reset(main_menu,SHOW);
mouse_mode=0; //doesn't work
level_load("racing.wmb");
wait(1);
}

Re: A few beginners problems [Re: jakk_zeven] #348803
11/30/10 20:11
11/30/10 20:11
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
function bomb_drop(x,y,z,nrofbombs)
{
while(key_ctrl){wait(1);}
...



For the boost plate, you can use a c_trace from your car downward.
c_trace returns the you pointer of the boost plate or the texture. You have to test what serves your purpose better.

Re: A few beginners problems [Re: Pappenheimer] #348871
12/01/10 11:52
12/01/10 11:52
Joined: Nov 2010
Posts: 7
Sweden
J
jakk_zeven Offline OP
Newbie
jakk_zeven  Offline OP
Newbie
J

Joined: Nov 2010
Posts: 7
Sweden
I will look into c_trace, thanks.

But the while(key_ctrl) just delayed the trail until the key is released.

function bomb_drop(x,y,z,nrofbombs)
{
while(key_ctrl)
{
wait(1);
}
if (nrofbombs>=0)
nrofbombs-=1;
ent_create("bomb.mdl",vector(x,y,z),NULL);
//return(nrofbombs=0);

}

Isnt it supposed to hold until the key is released and then execute the rest of the code?

Re: A few beginners problems [Re: jakk_zeven] #348879
12/01/10 14:05
12/01/10 14:05
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Yes, you are right.
I didn't think of that.
You can set a countdown to prevent creating further bombs within a certain time frame after dropping a bomb.


var bomb_stop;
if(bomb_stop < 0)
{
bomb_stop += time_step;
if(key_ctrl)
{
bomb_stop = -10;//choose your value here
bomb_drop(my.x,my.y,10,nrofbombs);
}
}


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1