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 (TedMar), 1,420 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
jumper game code #384336
10/02/11 02:28
10/02/11 02:28
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline OP
Senior Expert
Pappenheimer  Offline OP
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Nothing special, but I can't stop playing it, once I started it from SED.

Just copy it and save it as "jumper.c" or what ever to start it from SED.

No credits required. I'm not even sure, if there already was a similar contribution.

In case you are playing it, please tell me, if you find something annoying in it.
Questions or suggestions are surely welcome, as well.

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

var jump = 0;
var right_left = 0;
var height = 0;
var height_level = 0;

PANEL* height_level_pnl =
{
	digits(20,20,4, Arial#24, 1, height_level);
	flags = SHOW;
}

function sky_color_func()
{
	sky_color.blue = height_level;
	if(height_level > 255)sky_color.blue = 255;
	if(sky_color.blue < 0)sky_color.blue = 0;
	sky_color.red = height_level-150;
	if(height_level < 150)sky_color.red = 0;
	if(height_level > 405)sky_color.red = 255;
	sky_color.green = height_level-200;
	if(height_level < 200)sky_color.green = 0;
	if(height_level > 455)sky_color.green = 255;
}

function jumper()
{
	wait(-1);
	player = my;
	jump = -2;
	camera.x -= 500;
	while(1)
	{
		camera.y = my.y;
		camera.z = my.z;
		if(my.z < 0){ my.z = 0; my.y = 0;}
		if(jump >= -12 * time_step) jump -= 1.6 * time_step;//has to be time corrected
		right_left = ((key_a - key_d) + (key_cul - key_cur) + (joy_1 - joy_4)) * 4.3;
		c_move(my, vector(0, right_left, 0), vector(0, 0, jump), IGNORE_MODELS);
		height_level = integer(my.z * 0.01);
		sky_color_func();
		wait(1);
	}
}

function bouncer()
{
	my.skill1 = height_level;
	set(my, PASSABLE);
	while(player == NULL){wait(1);}
	set(my, LIGHT);
	my.lightrange = 50;
	vec_set(my.blue,vector(random(255),random(255),random(255)));
	while(1)
	{
		if(vec_dist(player.x, my.x) < 15)
		{
			jump = 47*time_step;//time_step, only with restricted framerates
//			height_level = my.skill1;
		}
		wait(1);
	}
}

function main()
{
   pan_setcolor(height_level_pnl,1,1,COLOR_RED);
	fps_max = 60;
	level_load("");
	ent_create(SPHERE_MDL, vector(180,0,0), jumper);
	
	ent_create(CUBE_MDL, vector(180,0,0), bouncer);
	
	while(height < 50000)
	{
		height += 100;
		ent_create(CUBE_MDL, vector(180,random(120),height), bouncer);
		height_level += 1;
	}
}



Re: jumper game code [Re: Pappenheimer] #384338
10/02/11 02:55
10/02/11 02:55
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Pretty neat. Above a height_level of ~430 you cannot see bright cubes anymore because of the bright background.
I would rather use event_impact (and player.z > block.z) instead of hundreds of while loops. I would make the blocks disappear after the player jumps on them to increase tension. If you realize both suggestions, make sure no two consecutive blocks are directly above another, otherwise you probably cannot make the jump.
Additionally, I would replace the *time_step multiplications as follows:
jump -= 1.6 * time_step;//has to be time corrected
jump = maxv(jump,-12);
...
c_move(my, nullvector, vector(0, right_left*time_step, jump*time_step),...
...
jump = 47;


Your game has given me an idea:
Why don't we users create small game examples like the one you've posted (maybe improve it a little) that get shipped with future Gamestudio releases/ updates? I think the current samples folder lacks some real playable games.
The reward for the creator could be fame and some cheap advertising, f.i. displaying a link to his own website.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: jumper game code [Re: Superku] #384371
10/02/11 13:20
10/02/11 13:20
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline OP
Senior Expert
Pappenheimer  Offline OP
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Your last mentioned idea gives my code more honour than it deserves. ^^

What I actually thought of, is a row of small examples in the wiki with copy and paste code that you can start right from the SED without any assets required.

The code should be as small and easy to understood as possible.

I tried something with jumping, but it is still to cumbersome (beside the fact that you can't use it with collision detection yet):
Code:
//JUMP with SPACE, MOVE with A and D or the curser keys!

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

var jump_rel_height = 100;
var jump_abs_height = 0;
var jump_mode = 0;

function jumper()
{
	while(1)
	{
		if(my.z <= 0)
		{
			my.z = 0;
			if(key_space)
			{
				jump_mode = 1;
				jump_abs_height = my.z + jump_rel_height;
			}
		}
		if(jump_mode == 1)
		{
			vec_lerp(my.z, my.z, jump_abs_height,0.05);
		}
		if(my.z >= jump_abs_height-0.5)
		{
			jump_mode = 0;
		}
		if(jump_mode == 0)
		{
			my.z -= 30 * time_step;
		}
		my.y += ((key_a - key_d) + (key_cul - key_cur) + (joy_1 - joy_4));
		wait(1);
	}
}

function main()
{
	level_load("");
	ent_create(SPHERE_MDL, vector(0,0,0), jumper);
	camera.x -= 500;
}



This was an attempt, because of the discussion about a constant jump height within different frame rates.

EDIT:
Just want to appologize that I don't answer all of your suggestions, your post is packed with them!

At least a few answers:
- I don't delete the blocks because I don't like the approach where one has to start always from the beginning. It is a design decision.
- You are right with the while loops, but in this case it has almost no impact on my system.
- The impact_event results probably in an absolute different gameplay, while I like especially this 'fly' through those blocks in a row.

On the idea of small games for the sample folder:
At least there should be a link to the section with game scripts on the Acknex Resources...

Last edited by Pappenheimer; 10/02/11 14:28.
Re: jumper game code [Re: Pappenheimer] #386052
10/27/11 16:05
10/27/11 16:05
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline OP
Senior Expert
Pappenheimer  Offline OP
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
New jumper code

Just created a small code in a workshop for kids, that solves the jumping part different that those others, because one boy was interested in a game called Icy Tower.
As always, I tried to keep it as simple as possible, but I didn't find an easier way than introducing at least c_move and c_trace to them.
c_trace is used here the other way round than usual, it traces only from center to the 'feet', testing whether c_trace returns anything, if it returns something, it means it is on ground, and therefor jumping is allowed.

Use the cursor keys for playing.
Code:
#include <acknex.h>
#include <default.c>
#define PRAGMA_ZERO

function player_one();//Dies ist ein Prototyp
function plattform();

var height = 0;

function main()
{
	fps_max = 60;
	level_load(NULL);
	ent_create(SPHERE_MDL,vector(600,0,0), player_one);
	ent_create(CUBE_MDL,vector(600,0,-20), plattform);
	
	while(height < 10000)
	{
		height += 100;
		ent_create(SPHERE_MDL,vector(600,random(100)-50+height*0.001,height), plattform);
	}
}

var jump = 0;

function player_one()
{
	player = me;
	while(me)//Wiederholung
	{
		camera.z = player.z;
		if(c_trace(vector(my.x,my.y,my.z-0),vector(my.x,my.y,my.z-2),IGNORE_ME|USE_BOX) > 0)
		{
			jump = key_cuu*8;
		}
		jump += -0.2;
		c_move(me,vector(0,key_cul - key_cur,jump),vector(0,0,0), GLIDE);
		wait(1);//Warten auf die anderen Funktionen
	}
}

function plattform()
{
	set(my, POLYGON);
	my.scale_y = 3;
	while(player == NULL)
	{
		wait(1);
	}
	while(me)//Wiederholung
	{
		if(player.z > my.z + 200)
		{
			ent_remove(me);
		}
		wait(1);//Warten auf die anderen Funktionen
	}
}




Moderated by  adoado, checkbutton, mk_1, Perro 

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