3D Games
ACTION camera_move
{
_camera = 1;
while(_camera == 1)
{
_player_intentions();
// set force and aforce value from user input
// -old method- ACCEL aspeed,aforce,0.9;
camera_aspeed.pan += (TIME * aforce.pan) - (0.9 * camera_aspeed.pan);
camera_aspeed.tilt += (TIME * aforce.tilt) - (0.9 * camera_aspeed.tilt);
camera_aspeed.roll += (TIME * aforce.roll) - (0.9 * camera_aspeed.roll);
CAMERA.PAN += camera_aspeed.PAN * TIME;
CAMERA.TILT += camera_aspeed.TILT * TIME;
CAMERA.ROLL += camera_aspeed.ROLL * TIME;
// Calculate cameras new speed
// -old method- ACCEL speed,force,0.9;
camera_speed.x += (TIME * force.x) - (0.9 * camera_speed.x);
camera_speed.y += (TIME * force.y) - (0.9 * camera_speed.y);
camera_speed.z += (TIME * force.z) - (0.9 * camera_speed.z);
// calculate relative distance
dist.x = camera_speed.x * TIME;
dist.y = camera_speed.y * TIME;
dist.z = camera_speed.z * TIME;
// Replace move_view with XYZ displacement
//move_view CAMERA,dist,NULLSKILL;
vec_rotate(dist.x,CAMERA.pan);
vec_add(CAMERA.X, dist.X);
wait(1);
}
}
// use WSAD to walk, keys left / right to rotate the camera around the player
// use the mouse wheel to zoom in / out and the up / down keys to set the height of the camera
action player_cam()
// player / camera code
{
VECTOR temp;
VECTOR temp2;
var movement_speed = 5;
// movement speed
var anim_percentage;
var cam_angle = 90;
// set the initial camera angle here
var cam_dist = 250;
// set the default zoom in factor here
var cam_height = 150;
// set the default camera height here
player = my;
// I'm the player
while (1)
{
if((!key_w) && (!key_s))
// the player isn't moving at all?
{
ent_animate(my, "stand", anim_percentage, ANM_CYCLE);
// and play the "stand" animation
}
else
// the player is moving?
{
ent_animate(my, "walk", anim_percentage, ANM_CYCLE);
// and play the "walk" animation
}
// zoom in / out using the mouse wheel
cam_dist += 0.2 * mickey.z * time_step;
// limit the distance between the camera and the player to 20...500
cam_dist = clamp(cam_dist, 20, 500);
// set the height of the camera using the up / down cursor keys
cam_height += 3 * (key_cuu - key_cud) * time_step;
// limit the height of the camera to 50...300
cam_height = clamp(cam_height, 50, 300);
// rotate the player using the A / D keys
my.pan += 4 * (key_a - key_d) * time_step;
anim_percentage += 5 * time_step;
// 5 = animation speed
camera.x = player.x - cam_dist * cos(cam_angle);
camera.y = player.y - cam_dist * sin(cam_angle);
cam_angle += 5 * (key_cur - key_cul) * time_step;
// 5 gives the camera rotation speed
camera.z = player.z + cam_height;
vec_set(temp2.x, my.x);
vec_sub(temp2.x, camera.x);
vec_to_angle(camera.pan, temp2);
// rotate the camera towards the player at all times
temp.x = movement_speed * (key_w - key_s) * time_step;
temp.y = 0;
temp.z = 0;
c_move (my, temp.x, nullvector, IGNORE_PASSABLE | GLIDE);
wait (1);
}
}
TEXT* mymessage_txt =
{
pos_x = 300;
pos_y = 50;
string("Hello there, stranger!");
}
action my_object()
{
while (!player) {wait (1);
}
while (1)
{
//if the player comes close to the object
if (vec_dist(player.x, my.x) < 100)
//play with 100
{
if (key_space)
{
while (key_space) {wait (1);
}
//wait until the space key is released set(mymessage_txt, VISIBLE);
//and then display the message
wait (-3);
//for 3 seconds reset(mymessage_txt, VISIBLE);
// now hide the message
}
}
wait (1);
}
}
void main()
{
// video_aspect = 4./3.;
// start in 4 / 3 mode
video_aspect = 16./9.;
// start in 16 / 9 widescreen mode - force this aspect
// video_aspect = 16./10.;
// start in 16 / 10 widescreen mode
level_load (test_wmb);
fps_max = 70;
video_mode = 7;
// run in 800x600 pixels if possible
video_depth = 32;
// 32 bit mode
}
#include <acknex.h>
#include <default.c>
#include <mtlView.c> // include the built-in Poisson filter
STRING* test_wmb = "test.wmb";
void main()
{
shadow_stencil = 3;
// use accelerated z-pass shadows
stencil_blur(1);
// blur the shadows using the built-in Poisson shader
level_load (test_wmb);
video_screen = 1;
// start in full screen mode
fps_max = 70;
video_mode = 7;
// run in 800x600 pixels
video_depth = 32;
// 32 bit mode
}
action my_soldier() // simple test action
{
set (my, SHADOW);
}
BMAP* pointer_tga = "pointer.tga";
action players_code() // attach this action to your player
{
var movement_speed = 10;
// movement speed
VECTOR temp;
player = my;
// I'm the player
set (my, INVISIBLE);
// 1st person player
while (1)
{
my.pan -= 7 * mouse_force.x * time_step;
camera.x = my.x;
camera.y = my.y;
camera.z = my.z + 50 + 1.1 * sin(my.skill44);
// play with 50 and 1.1
camera.pan = my.pan;
camera.tilt += 5 * mouse_force.y * time_step;
vec_set (temp.x, my.x);
// trace 10,000 quants below the player
temp.z -= 10000;
temp.z = -c_trace (my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX) + 15;
// play with 15
temp.x = movement_speed * (key_w - key_s) * time_step;
temp.y = movement_speed * (key_a - key_d) * 0.6 * time_step;
c_move (my, temp.x, nullvector, IGNORE_PASSABLE | GLIDE);
wait (1);
}
}
function mouse_startup()
{
mouse_mode = 1;
mouse_map = pointer_tga;
while (1)
{
vec_set(mouse_pos, mouse_cursor);
wait(1);
}
}
action player1()
{
VECTOR temp;
var camera_distance = 200;
player = my;
// I'm the player
while (1)
{
// player's pan is controlled by the mouse and the "A" and "D" keys
player.pan -= 10 * mouse_force.x * time_step - 1.5 * (key_a - key_d);
camera.x = player.x - camera_distance * cos(player.pan);
// keep the camera behind the player
camera.y = player.y - camera_distance * sin(player.pan);
// at the distance given by camera_distance
camera.z = player.z + 100;
// and 100 quants above the player
camera.pan = player.pan;
// the camera has the same pan angle with the player
camera.tilt += 7 * mouse_force.y * time_step;
// and can tilt freely
if (!mouse_left) // the left mouse button wasn't pressed? Then take care of the regular animations (stand, walk)
{
if (key_w + key_s > 0) // if the player is walking
{
ent_animate(my, "walk", my.skill46, ANM_CYCLE);
// play its "walk" frames animation
// the animation speed increases when the player presses the "shift" key
my.skill46 += 5 * (1 + key_shift * 0.7) * time_step;
my.skill46 %= 100;
// loop the animation
}
else // if the player is standing
{
ent_animate(my, "stand", my.skill48, ANM_CYCLE);
// play the "stand" frames animation
my.skill48 += 2 * time_step;
// "stand" animation speed
my.skill48 %= 100;
// loop the animation
}
}
else // the left mouse button was pressed here
{
my.skill40 = 0;
while (my.skill40 < 100) // play the "attack" animation until its end
{
ent_animate(my, "attack", my.skill40, NULL);
// play the "attack" animation only once
my.skill40 += 2 * time_step;
// "attack" animation speed
wait (1);
}
}
vec_set (temp, my.x);
// trace 10,000 quants below the player
temp.z -= 10000;
// and adjust its height accordingly, placing its feet on the ground
temp.z = - c_trace (my.x, temp, IGNORE_ME | IGNORE_PASSABLE | USE_BOX) + 15;
// play with 15
// move the player using the "W" and "S" keys;
the speed increases to 200% if the player presses the "shift" key
temp.x = 10 * (key_w - key_s) * (1 + 1 * key_shift) * time_step;
temp.y = 0;
my.skill47 += c_move (my, temp, nullvector, IGNORE_PASSABLE);
wait (1);
}
}
action player_move { player = my;
// ich bin ab jetzt die
Spielfigur my.health = 100;
// Ich habe 100 Lebenspunkte
while(my.health > 0) // während meine Lebensenergie größer
als 0 ist { player_dist.x = (key_pressed(move_forward)-
key_pressed(move_back))*10*time;
player_dist.y =
(key_pressed(move_left)-key_pressed(move_right))*10*time;
camera.tilt -= 10*-mouse_force.y*time;
player.pan -= 10*
(mouse_force.x+(key_pressed(turn_left)-
key_pressed(turn_right)))*time;
camera_pos();
schwerkraft();
if(key_pressed(run) == 1){player_dist.x *=2;
player_dist.y
*= 2;
} if(key_pressed(jumpkey) == 1){jump();
}
if(key_pressed(crawl) == 1) {
player_dist.z-=10;
//nach
unten „schieben“ player_dist.x /= 2;
//läuft langsamer
player_dist.y /= 2;
//läuft langsamer
} move_mode =
ignore_passable+glide;
ent_move(player_dist, nullvector);
wait(1);
}
}
function Bewegung() {
ent_nr = my.ent_id;
if(my._move_force > 0) { my._absoldis_X =
(cos(ent_array1[ent_nr*10+8])*
(my._move_force/my._gewicht))*time;
my._absoldis_Y =
(sin(ent_array1[ent_nr*10+8])*
(my._move_force/my._gewicht))*time;
} if(my._move_force
<= 0 && my._move_x == 0 && my._move_y == 0) {
my._absoldis_X = 0;
my._absoldis_Y = 0;
}
move_mode
= ignore_passable + activate_trigger + glide;
ent_move(nullvector,my._absoldis_X);
}