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
3 registered members (AndrewAMD, Ayumi, NewbieZorro), 14,141 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
Event problems #312456
02/24/10 21:48
02/24/10 21:48
Joined: Jun 2008
Posts: 146
Deutschland
M
M4sterm1nd Offline OP
Member
M4sterm1nd  Offline OP
Member
M

Joined: Jun 2008
Posts: 146
Deutschland
Hello GameStudio Com.

I hope you can help me I am already on despair.

On my current project, a little fake 2D game, I have a few problems.

So, it plays everything from the Weltraaum. You can see his spaceship from above and must dodge asteroids, and shoot down opponent. no sidescroll is the world ne open. So where can you fly where you want.

My problems:
- Some asteroids not simply explode
- Lasers and rockets did not hurt to learn the right values of the measures taken by the entity from health value

I think it is up to the event.

I am sorry to post my entire code because else connexion is difficult to detect.

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

function starfield(PARTICLE *p);
function fade_stars(PARTICLE *p);
function fire_effect(PARTICLE *p);
function fade_fire(PARTICLE *p);

function players_laser();
function move_plaser();
function remove_plaser();

function players_rocket();
function move_procket();
function remove_procket();

function neuer_asteroid();
function asteroid();
function schusstreffer_event();
function asteroid_destroy();
function asteroid_explodes();

function enemy_explodes();
function enemy_destroy();

function gegner_event();
function kill_player();

function blink();

function player_collisions();

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

var Raketenzaehler = 0;

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

STRING* explosion_pcx = "explo+9.pcx"	; // explosions sprite

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

BMAP* star_tga = "star.tga";
BMAP* fire_tga = "fire.tga";
BMAP* firered_tga = "fire4_red.tga";

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

action player1() // attach this action to the ship model
{
	var init_z;
	player = my; // I'm the player
	init_z = my.z;
	
	#define schaden skill51
	#define health skill52
	
	my.health = 100;
	my.schaden = 10;
	
	
	VECTOR player_speed, star_pos, temp, jet_offset, jet2_offset, jet3_offset, jet4_offset, jet5_offset, jet6_offset;
	var temp_x = 0, temp_y = 0;
	
	while (1)
	{
		// Triebwerkseffekt	
		vec_set(jet_offset.x, vector(-40, 50, 0)); 
		vec_set(jet2_offset.x, vector(-40, -50, 0));
		vec_set(jet3_offset.x, vector(10, 50, 0));
		vec_set(jet4_offset.x, vector(10, -50, 0));
		vec_set(jet5_offset.x, vector(-15, -65, 0));
		vec_set(jet6_offset.x, vector(-15, 65, 0));
		vec_rotate(jet_offset.x, my.pan);
		vec_rotate(jet2_offset.x, my.pan);
		vec_rotate(jet3_offset.x, my.pan);
		vec_rotate(jet4_offset.x, my.pan);
		vec_rotate(jet5_offset.x, my.pan);
		vec_rotate(jet6_offset.x, my.pan);
		vec_add(jet_offset.x, my.x);
		vec_add(jet2_offset.x, my.x);
		vec_add(jet3_offset.x, my.x);
		vec_add(jet4_offset.x, my.x);
		vec_add(jet5_offset.x, my.x);
		vec_add(jet6_offset.x, my.x);
		
		if((!key_a) || (!key_s) || (!key_w) || (!key_d))
		{
			temp_x = 0;
			temp_y = 0;
		}
		

		if(key_w)
		{
			temp_x += 20 * time_step;
			if (key_space)
			{
				temp_x += 20 * time_step;

				effect(fire_effect, 20, jet_offset.x, nullvector); // generate 20 fire particles each frame
				effect(fire_effect, 20, jet2_offset.x, nullvector);
			}
		
			else
			{
			effect(fire_effect, 10, jet_offset.x, nullvector); // generate 10 fire particles each frame
			effect(fire_effect, 10, jet2_offset.x, nullvector);
			}
		}
		
		if(key_s)
		{
			temp_x -= 20 * time_step;
			if (key_space)
			{
				temp_x -= 20 * time_step;

				effect(fire_effect, 20, jet3_offset.x, nullvector); // generate 20 fire particles each frame
				effect(fire_effect, 20, jet4_offset.x, nullvector);
			}
		
			else
			{
				effect(fire_effect, 10, jet3_offset.x, nullvector); // generate 10 fire particles each frame
				effect(fire_effect, 10, jet4_offset.x, nullvector);
			}
		}
		
		if(key_a)
		{
			temp_y += 20 * time_step;
			if (key_space)
			{
				temp_y += 20 * time_step;

				effect(fire_effect, 10, jet5_offset.x, nullvector);
			}
			
			else
			effect(fire_effect, 5, jet5_offset.x, nullvector);
		}
		
		if(key_d)
		{
			temp_y -= 20 * time_step;
			if (key_space)
			{
				temp_y -= 20 * time_step;

				effect(fire_effect, 10, jet6_offset.x, nullvector);
			}
			
			else
			effect(fire_effect, 5, jet6_offset.x, nullvector);
		}
			
		player_speed.x = temp_x;
		player_speed.y = temp_y;
		player_speed.z = 0;
		
		vec_set(temp.x,mouse_pos3d.x);
		vec_sub(temp.x,my.x);
		temp.z = 0;
		
		vec_to_angle(my.pan,temp);
		
		c_move(my,player_speed,NULLVECTOR,IGNORE_PASSABLE | GLIDE);
		
		my.emask |= (ENABLE_IMPACT | ENABLE_SCAN); // the player is sensitive to collisions with level blocks and entities
		my.event = player_collisions; // and runs this event function if it collides with something
		

		star_pos.x = my.x - 800 + random(1600); // x = -800...+1300
		star_pos.y = my.y - 800 + random(1600); // y = -800...+1300
		star_pos.z = 0;
		effect(starfield, 1, star_pos.x, nullvector);
		
		if(my.health <= 0)
		{
			asteroid_destroy();
		}
		
		wait (1);
	}
}

action gegner()
{
	while (!player) {wait (1);}
	my.z = player.z; // align the power source entity at the same height with the player
	my.pan = random(360); // start with a random set of angles
	
	#define schaden skill51
	#define health skill52
	
	my.health = 100;
	my.schaden = 10;
	
	VECTOR temp,gegnergeschwindigkeit,jet_offset;
	
	vec_set(gegnergeschwindigkeit,vector(5,0,0));
	
	c_setminmax(me);
	set(my, POLYGON);
	
	while(1)
	{
		my.z = player.z;
		my.emask |= (ENABLE_BLOCK | ENABLE_IMPACT); 
		my.event = gegner_event; 
		
		// Triebwerkseffekt	
		vec_set(jet_offset.x, vector(-65, 0, 0)); 
		vec_rotate(jet_offset.x, my.pan);
		vec_add(jet_offset.x, my.x);
		
		c_scan(my.x,my.pan,vector(360,20,750),IGNORE_ME | SCAN_LIMIT);
		
		if(you)
		{
			vec_set(temp,your.x);
			vec_sub(temp,my.x);
			vec_to_angle(my.pan,temp);
		}
		
		if(result > 450)
		{
			c_move(me,gegnergeschwindigkeit,NULLVECTOR,IGNORE_PASSABLE);
			
			effect(fire_effect, 10, jet_offset.x, nullvector);
		}
		
		if(my.health <= 0)
		{
			enemy_destroy();
		}
		
		wait(1);
	}
	
}

function gegner_event()
{
	switch (event_type)
	{
		case EVENT_BLOCK:
		{
			my.health -= 10;
			
			blink();
			
			vec_to_angle(my.pan, normal);
			return;
		}
		
		case EVENT_IMPACT:
		{
			my.health -= you.schaden;
			you.health -= my.schaden;
			
			blink();
			return;
		}
	}
}


function blink()
{
	while(EVENT_BLOCK || EVENT_IMPACT)
	{
		my.ambient = 100;
		while(my.ambient > 0)
		{
			my.ambient -= 5;
			wait(1);
		}
		return;
	}
}

function player_collisions() // this is player's event function
{
	switch (event_type)
	{
		case EVENT_BLOCK:
		{
			my.health -= 10;
			
			blink();
			
			vec_to_angle(my.pan, normal);
			return;
		}
		
		case EVENT_IMPACT:
		{
			my.health -= you.schaden;
			you.health -= my.schaden;
			
			blink();
			return;
		}
	}

}


///////////////////////////////
function main()
{
	vec_set(sky_color, vector(1, 1, 1));
	fps_max = 80;
	
	video_screen = 1;
	
	level_load("spaceshooter.WMB");
	wait(5);
	
	random_seed(0);
	
	mouse_mode = 2;
		
	BMAP* Maus_tga = bmap_create("Maus.tga");
	mouse_map = Maus_tga;
	mouse_spot.x = bmap_width(Maus_tga)/2;
	mouse_spot.y = bmap_height(Maus_tga)/2;

	
	while(1)
	{
			
		vec_set(camera.x,player.x);
		vec_add(camera.x,vector(0,0,1200));
		vec_set(camera.pan,vector(0,-90,0));
		
		mouse_pos.x = mouse_cursor.x;
		mouse_pos.y = mouse_cursor.y;
		
		
		on_mouse_left = players_laser;
		on_mouse_right = players_rocket;
		
		// zufalls Asteroiden
		if(total_secs == 10)
		{
			ent_create("asteroid.mdl",vector(random(4000)-2000,random(4000)-2000,1000),neuer_asteroid);
			
			total_secs = 0;
		}
		
		
		wait(1);
	}
		
}

function neuer_asteroid()
{
	while(my.z > player.z)
	{
		c_move(me,NULLVECTOR,vector(0,0,-5),IGNORE_PASSABLE);
		wait(1);
	}
	
	asteroid();
}


function starfield(PARTICLE *p)
{
	p.alpha = 5 + random(50);
	p.bmap = star_tga;
	p.size = 2 + random(1); // generate stars with random sizes
	p.flags |= (BRIGHT | TRANSLUCENT);
	p.event = fade_stars;
}

function fade_stars(PARTICLE *p)
{
	p.alpha -= 0.5 * time_step; // fade out the stars
	if (p.alpha < 0) 
	{
		p.lifespan = 0;
	}
}


// Triebwerk 

function fire_effect(PARTICLE *p)
{
	p->vel_x = (1 - random(2)) / 5; // set a random particle speed on the x and y axis
	p->vel_y = (1 - random(2)) / 5;
	p->vel_z = 0;
	p.alpha = 25 + random(50); // and a random transparency
	p.bmap = fire_tga;
	p.size = 10; // gives the size of the fire particles
	p.flags |= (BRIGHT | MOVE);
	p.event = fade_fire;
}

function rocketfire_effect(PARTICLE *p)
{
	p->vel_x = (1 - random(2)) / 5; // set a random particle speed on the x and y axis
	p->vel_y = (1 - random(2)) / 5;
	p->vel_z = 0;
	p.alpha = 25 + random(50); // and a random transparency
	p.bmap = firered_tga;
	p.size = 10; // gives the size of the fire particles
	p.flags |= (BRIGHT | MOVE);
	p.event = fade_fire;
}


function fade_fire(PARTICLE *p)
{
	p.alpha -= 25 * time_step; // fade out the fire particles quickly
	if (p.alpha < 0) 
		p.lifespan = 0; // and remove them completely when they become invisble
}

// Schießen (Laser)


function players_laser()
{
	
	VECTOR plaser_offset;
	vec_set(plaser_offset.x, vector(20, 0, 0)); 
	vec_rotate(plaser_offset.x, player.pan);
	vec_add(plaser_offset.x, player.x);
	ent_create("laser1.mdl", plaser_offset.x, move_plaser);

	wait (1); 
}

function players_rocket()
{
	Raketenzaehler += 0.5;
	
	VECTOR plaser_offset;
	
	if(fraction(Raketenzaehler))
	vec_set(plaser_offset.x, vector(0, 20, 0));
	
	else
	vec_set(plaser_offset.x, vector(0, -20, 0)); 
	
	vec_rotate(plaser_offset.x, player.pan);
	vec_add(plaser_offset.x, player.x);
	ent_create("rakete.mdl", plaser_offset.x, move_procket);

	wait (1); 
}



function move_plaser()
{
	c_setminmax(me);
	set(my, PASSABLE);
	set(my, POLYGON);
	my.pan = player.pan; 

	my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY); 
	my.event = remove_plaser; 
	
	#define schaden skill51
	#define health skill52
	
	my.schaden = 10;
	my.health = 10;
	
	while (my) 
	{
		if (vec_dist(my.x, player.x) > 70) 
			reset(my, PASSABLE); 
			
		if (vec_dist(my.x, player.x) > 900)
			remove_plaser();	
			
		c_move(my, vector(75 * time_step, 0, 0), nullvector, IGNORE_PASSABLE); 
		wait (1);
	}
}

function move_procket()
{
	c_setminmax(me);
	set(my, PASSABLE);
	set(my, POLYGON);
	my.pan = player.pan; 

	my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY); 
	my.event = remove_procket; 
	
	#define schaden skill51
	#define health skill52
	
	my.schaden = 50;
	my.health = 10;
	
	// Triebwerkseffekt
		VECTOR jet_offset;

	while (my) 
	{
		if (vec_dist(my.x, player.x) > 70) 
			reset(my, PASSABLE); 
			
		if (vec_dist(my.x, player.x) > 900)
			remove_procket();	
			
		c_move(my, vector(50 * time_step, 0, 0), nullvector, IGNORE_PASSABLE); 
		
		vec_set(jet_offset.x, vector(-15, 0, 0)); 
		vec_rotate(jet_offset.x, my.pan);
		vec_add(jet_offset.x, my.x);
		
		effect(rocketfire_effect, 10, jet_offset.x, nullvector); // generate 20 fire particles each frame
		
		wait (1);
	}
}

function remove_plaser() 
{
	wait (1);
	ent_remove(my);
}

function remove_procket() 
{
	wait (1);
	ent_create (explosion_pcx, my.x, asteroid_explodes); // create the explosion sprite	
	ent_remove(my);
}


action asteroid()
{
	c_setminmax(me);
	set(my, POLYGON);

	while (!player) {wait (1);}
	my.z = player.z; // align the power source entity at the same height with the player
	my.pan = random(360); // start with a random set of angles

	
	#define health skill51
	#define schaden skill52

	my.health = 30;
	my.schaden = 10;
	
	my.emask |= (ENABLE_IMPACT | ENABLE_BLOCK);
	my.event = schusstreffer_event;
	
	VECTOR asteroidengeschwindigkeit;
	var i = random(5);
	vec_set(asteroidengeschwindigkeit,vector(i, 0, 0));

	while (my)
	{
		my.z = player.z;
		
		c_move(my,asteroidengeschwindigkeit,NULLVECTOR,IGNORE_PASSABLE);
		
		if(my.health <= 0)
		{
			asteroid_destroy();
		}
		
		wait (1);
	}
}

function schusstreffer_event()
{
	switch (event_type)
	{
		case EVENT_BLOCK:
		{
			vec_to_angle(my.pan, bounce);
			return;
		}
	
		case EVENT_IMPACT:
		{
			my.health -= you.schaden;
			you.health -= my.schaden;
		
			blink();
			return;
		}
	}

}

function asteroid_destroy()
{
	vec_add(my.x, vector(0,0,5));
	ent_create (explosion_pcx, my.x, asteroid_explodes); // create the explosion sprite			
	wait (-0.2);	
	ent_remove(my);
}

function asteroid_explodes() // drives the explosion sprite
{
	set (my, PASSABLE); // the explosion sprite is passable

	my.scale_x = 0.4;
	my.scale_y = my.scale_x;
	my.scale_z = my.scale_x;
	set (my, BRIGHT); // set its bright flag
	my.ambient = 100; // give it an ambient of 100
	set (my, TRANSLUCENT); // and make it transparent
	my.alpha = 100; // but we set it to be completely opaque for now
	my.roll = random(360);
	while (my.frame < 9) // go through all the animation frames
	{
		if (my.frame > 2) // a part of the explosion animation was played?
		{
			if (you) // if the enemy ship hasn't been removed yet
				set(you, INVISIBLE); // then make it invisible (the ship and the explosion sprite have overlapped during the 2 animation frames)
		}
		my.frame += 0.7 * time_step; // 0.7 gives the animation speed
		wait (1);
	}

	while (my.alpha > 0) // now fade the last frame quickly
	{
		my.alpha -= 50 * time_step; // 50 = fading speed
		wait (1);
	}
	ent_remove (my); // time to remove the explosion sprite
}

function enemy_destroy()
{
	vec_add(my.x, vector(0,0,5));
	ent_create (explosion_pcx, my.x, enemy_explodes); // create the explosion sprite			
	wait (-0.2);	
	ent_remove(my);
}

function enemy_explodes() // drives the explosion sprite
{
	set (my, PASSABLE); // the explosion sprite is passable

	my.scale_x = 0.8;
	my.scale_y = my.scale_x;
	my.scale_z = my.scale_x;
	set (my, BRIGHT); // set its bright flag
	my.ambient = 100; // give it an ambient of 100
	set (my, TRANSLUCENT); // and make it transparent
	my.alpha = 100; // but we set it to be completely opaque for now
	my.roll = random(360);
	while (my.frame < 9) // go through all the animation frames
	{
		if (my.frame > 2) // a part of the explosion animation was played?
		{
			if (you) // if the enemy ship hasn't been removed yet
				set(you, INVISIBLE); // then make it invisible (the ship and the explosion sprite have overlapped during the 2 animation frames)
		}
		my.frame += 0.7 * time_step; // 0.7 gives the animation speed
		wait (1);
	}

	while (my.alpha > 0) // now fade the last frame quickly
	{
		my.alpha -= 50 * time_step; // 50 = fading speed
		wait (1);
	}
	ent_remove (my); // time to remove the explosion sprite
}




Thanks for reading.

Please help me.

And Sorry is google translate

Re: Event problems [Re: M4sterm1nd] #312458
02/24/10 22:04
02/24/10 22:04
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Are you kidding me? You have posted this 30 minutes before in another forum!!


"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: Event problems [Re: Superku] #312460
02/24/10 22:17
02/24/10 22:17
Joined: Jun 2008
Posts: 146
Deutschland
M
M4sterm1nd Offline OP
Member
M4sterm1nd  Offline OP
Member
M

Joined: Jun 2008
Posts: 146
Deutschland
first it was over 60 minutes

and you have tellet me no will read it.
I have thinking here Have I a bedder chance.

sorry for my bad english

Re: Event problems [Re: M4sterm1nd] #312462
02/24/10 22:24
02/24/10 22:24
Joined: Sep 2009
Posts: 1,032
Budapest
Aku_Aku Offline
Serious User
Aku_Aku  Offline
Serious User

Joined: Sep 2009
Posts: 1,032
Budapest
I would help to you. First of all you have to make shorter your code that you publish.
You achieve it if you locate the part(s) of your program where you suspect the problem lies.
AFAIK & IMHO approx. 20-40 lines are readable for bug hunting.
Go for it...

Re: Event problems [Re: Aku_Aku] #312466
02/24/10 22:57
02/24/10 22:57
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Wow, 60 minutes...
I've told you how to solve it.


"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: Event problems [Re: Superku] #312512
02/25/10 10:34
02/25/10 10:34
Joined: Mar 2002
Posts: 7,727
old_bill Offline
Senior Expert
old_bill  Offline
Senior Expert

Joined: Mar 2002
Posts: 7,727
I highly doubt that someone from Conitec will work through your 500 lines of code.

Besides that, making double posts regarding the same subject is considered as spam here,
so please stay away from that in the future.

You should follow SuperKu's advice and try to isolate your problem to a few lines of code,
otherwise it's very unlikely that someone will help you out on this forums.


Success is walking from failure to failure with no loss of enthusiasm.

Moderated by  old_bill, Tobias 

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