Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Ayumi), 662 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Simple walking program to get you started #215497
07/11/08 16:12
07/11/08 16:12
Joined: Apr 2008
Posts: 437
dracula Offline OP
Senior Member
dracula  Offline OP
Senior Member

Joined: Apr 2008
Posts: 437
Hi

I have used the walking function in the very latest (7.1) help file to demonstrate a very simple program for people like me who are starting to learn Lite-C. This program enables a user to walk cbabe around the terrain or level. I hope it helps. I need stuff like this myself to help me progress.
Copy and paste into SED, ensure you have cbabe.mdl or other and a terrain or a level created in WED in the same folder. Make sure also that you save file as ***.C ie do NOT have a .WDL extension as this is C Script.

#include <acknex.h>
#include <default.c>


// Conitec's function in a program for walking over ground
// control the player with the WASD keys
// player origin must be at the model center
// bounding box must be smaller than the player!
action player_walk()
{
// if necessary, adjust the bounding box to give the entity 'floor room' (see remarks)
// my.min_z *= 0.5;

var speed_down = 0; // downward speed by gravity
var anim_percent = 0; // animation percentage
VECTOR vFeet;
vec_for_min(vFeet,me); // vFeet.z = distance from player origin to lowest vertex

set(me,SHADOW); // you may want shadows ??

while (1)
{
// rotate the player using the [A] and [D] keys
my.pan += 5*(key_a-key_d)*time_step;

// determine the ground distance by a downwards trace
var dist_down;
if (c_trace(my.x,vector(my.x,my.y,my.z-5000),IGNORE_ME | IGNORE_PASSABLE | USE_BOX) > 0)
dist_down = my.z + vFeet.z - target.z; // get distance between player's feet and the ground
else
dist_down = 0;

// apply gravity when the player is in the air
if (dist_down > 0) // above floor, fall down with increasing speed
dist_down = clamp(dist_down,0,accelerate(speed_down,5,0.1));
else // on or below floor, set downward speed to zero
speed_down = 0;

// move the player using the [W] and [S] keys
var dist_ahead = 5*(key_w-key_s)*time_step;
dist_ahead = sign(dist_ahead)*(abs(dist_ahead) + 0.5*dist_down); // adapt the speed on slopes
c_move(me,vector(dist_ahead,0,0),vector(0,0,-dist_down),IGNORE_PASSABLE | GLIDE); // move the player

// animate the player according to its moved distance
if (dist_ahead != 0) // player is moving ahead
{
anim_percent += 1.3*dist_ahead; // 1.3 = walk cycle percentage per quant
ent_animate(me,"walk",anim_percent,ANM_CYCLE); // play the "walk" animation
}
else // player stands still
{
anim_percent += 5*time_step;
ent_animate(me,"stand",anim_percent,ANM_CYCLE); // play the "stand" animation
}
wait(1);
}
}

function main() // start of program
{
video_mode = 7;
//video_screen =1;

shadow_stencil = 1;

wait(1);

level_load("small.hmp");

wait(2);

ent_create("cbabe.mdl", vector(0,0,20), player_walk); // assumes you're using cbabe

//handle = media_loop("miami.mp3",NULL,20); // how about some nice music, 20 = vol level
video_window(NULL,NULL,0,"My simple demo game"); // change the window text from GameStudio

}


Last edited by dracula; 07/11/08 16:16.
Re: Simple walking program to get you started [Re: dracula] #271927
06/15/09 17:23
06/15/09 17:23
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline
Senior Member
NeoNeper  Offline
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
Arigato (^.~) tnks hehe
Very utily for me!


Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________
Re: Simple walking program to get you started [Re: NeoNeper] #271966
06/15/09 20:24
06/15/09 20:24
Joined: Dec 2008
Posts: 528
Wagga, Australia
the_mehmaster Offline
User
the_mehmaster  Offline
User

Joined: Dec 2008
Posts: 528
Wagga, Australia
Helpful snippet!
By the way, use the [code] flag next time you post code.


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

Gamestudio download | chip programmers | 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