Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 946 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Print Thread
Rate Thread
snowing #348237
11/24/10 11:37
11/24/10 11:37
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
Here is a simple snowing script.
It is a demo with a simple black box getting more and more covered with white dots.
snowing demo
The dots are very small (it depends on the size of the skin), so I want to add additional painting around the dots, but when I use the following part, it shows weird effects and eventually crashes. Maybe, someone has an idea to solve this issue?
Thanks in advance.
Code:
while(coords_cur_x <= (coords_x + coords_area))
			{
				pixel_to_bmap(canvas,coords_cur_x, coords_cur_y,pixel);
				coords_cur_y += 1;
				if(coords_cur_y > (coords_y + coords_area))
				{
					coords_cur_x += 1;
					coords_cur_y = coords_y - coords_area;
				}
			}



This is the whole script.
Code:
#include <litec.h>
#include <d3d9.h>

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

#define PRAGMA_ZERO

BMAP* canvas;

var format; 
var pixel;
var coords_x;
var coords_y;

function snowing()
{
	while(1)
	{
		c_trace(vector(random(30)-15,random(30)-15, 100), vector(random(30)-15,random(30)-15, -100), IGNORE_PASSABLE | IGNORE_ME | SCAN_TEXTURE | ACTIVATE_SHOOT);
		wait(1);				
	}	
}

function snowEvent()
{
	coords_x = hit.u1;
	coords_y = hit.v1;
}

action get_snow()//needs an own variable to prevent it from colliding with similar tarrain actions
{
	set(my, POLYGON);
 	my.emask |= ENABLE_SHOOT;
  	my.event = snowEvent;
	while(1)
	{
//		if(mouse_left)
//		{
//			while(mouse_left){wait(1);}
//			coords_x = random(10);
//			coords_y = random(10);
			var coords_area = 1;
			var coords_cur_x = coords_x - coords_area;
			var coords_cur_y = coords_y - coords_area;
			canvas = bmap_for_entity(my, 0);	//1 is the number of the skin
	
			format = bmap_lock(canvas, 0); // lock the canvas bitmap
			pixel = pixel_for_vec(vector(255,255,255), 100, format);
			pixel_to_bmap(canvas, coords_x, coords_y, pixel); // now write the pixel at the coords_x, coords_y position
//			while(coords_cur_x <= (coords_x + coords_area))
//			{
//				pixel_to_bmap(canvas,coords_cur_x, coords_cur_y,pixel);
//				coords_cur_y += 1;
//				if(coords_cur_y > (coords_y + coords_area))
//				{
//					coords_cur_x += 1;
//					coords_cur_y = coords_y - coords_area;
//				}
//			}
			bmap_unlock(canvas); // unlock the bitmap now
			bmap_to_mipmap(canvas);
//		}
		wait(1);
	}
}

function main()
{
	level_load(NULL);
	camera.z = 30;
	camera.tilt = -90;
	ent_create("cube_black.mdl", vector(0,0,0), get_snow);
	snowing();
}



Re: snowing [Re: Pappenheimer] #348241
11/24/10 12:18
11/24/10 12:18
Joined: Apr 2005
Posts: 4,506
Germany
F
fogman Offline
Expert
fogman  Offline
Expert
F

Joined: Apr 2005
Posts: 4,506
Germany
The only thing that comes to my mind:
coords_x & coords_y is not initialized.
So at gamestart they can theoretically hold any number.
Maybe try this:
var coords_x = 0;
var coords_y = 0;


no science involved
Re: snowing (pixel_to_bmap problem) [Re: fogman] #348286
11/24/10 19:09
11/24/10 19:09
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
The problems must relate to the while(coords.....)-loop..., because coords_x & coords_y immediately get their values.

Re: snowing (pixel_to_bmap problem) [Re: Pappenheimer] #348287
11/24/10 19:16
11/24/10 19:16
Joined: Apr 2005
Posts: 4,506
Germany
F
fogman Offline
Expert
fogman  Offline
Expert
F

Joined: Apr 2005
Posts: 4,506
Germany
Are you really sure?
The manual @ ent_create: "The given action will start immediately after creation"

But coords_x & coords_y get their values afterwards,
because you are calling "snowing()" after the creation.

But itīs really a raw guess, not more.




no science involved
Re: snowing (pixel_to_bmap problem) [Re: Pappenheimer] #348288
11/24/10 19:23
11/24/10 19:23
Joined: Jul 2007
Posts: 959
nl
F
flits Offline
User
flits  Offline
User
F

Joined: Jul 2007
Posts: 959
nl
the problem is i gues that you paint on a pixel that is lower then0 or higher then amount of pixel of the bmap that wil result into a crash


"empty"
Re: snowing (pixel_to_bmap problem) [Re: flits] #348297
11/24/10 20:00
11/24/10 20:00
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
flits is right. I found that hint in this thread Pixelwerte???

Here is the working code:
Code:
#include <litec.h>
#include <d3d9.h>

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

#define PRAGMA_ZERO

BMAP* canvas;

var format; 
var pixel;
var coords_x = 0;
var coords_y = 0;

function snowing()
{
	while(1)
	{
		c_trace(vector(random(30)-15,random(30)-15, 100), vector(random(30)-15,random(30)-15, -100), IGNORE_PASSABLE | IGNORE_ME | SCAN_TEXTURE | ACTIVATE_SHOOT);
		wait(1);				
	}	
}

function snowEvent()
{
	coords_x = hit.u1;
	coords_y = hit.v1;
}


action get_snow()
{

	var coords_area = 4;
	var coords_cur_x = coords_x - coords_area;
	var coords_cur_y = coords_y - coords_area;
	set(my, POLYGON);
 	my.emask |= ENABLE_SHOOT;
  	my.event = snowEvent;
	while(1)
	{
			coords_cur_x = coords_x - coords_area*0.5;
			coords_cur_y = coords_y - coords_area*0.5;
			canvas = bmap_for_entity(my, 0);	//1 is the number of the skin
	
			format = bmap_lock(canvas, 0); // lock the canvas bitmap
			pixel = pixel_for_vec(vector(255,255,255), 100, format);
			pixel_to_bmap(canvas, coords_x, coords_y, pixel); // now write the pixel at the coords_x, coords_y position
			while(coords_cur_x <= (coords_x + coords_area))
			{
				if((coords_cur_x < canvas.width ) && (coords_cur_y < canvas.height))
				{
					if((coords_cur_x > 0) && (coords_cur_y > 0))
					{
						pixel_to_bmap(canvas,coords_cur_x, coords_cur_y,pixel);
					}
				}
				coords_cur_y += 1;
				if(coords_cur_y > (coords_y + coords_area))
				{
					coords_cur_x += 1;
					coords_cur_y = coords_y - coords_area;
				}
			}
			bmap_unlock(canvas); // unlock the bitmap now
			bmap_to_mipmap(canvas);
		wait(1);
	}
}

function main()
{
	level_load(NULL);
	camera.z = 30;
	camera.tilt = -90;
	ent_create("cube_black.mdl", vector(0,0,0), get_snow);
	snowing();
}



This was the required addition:
Code:
if((coords_cur_x < canvas.width ) && (coords_cur_y < canvas.height))
{
	if((coords_cur_x > 0) && (coords_cur_y > 0))
	{
[...]
	}
}



resolved and result: snowing (pixel_to_bmap) [Re: Pappenheimer] #348321
11/24/10 23:21
11/24/10 23:21
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
I changed the code a bit.
Now a function cycles through all given entities of a level to add the polygon flag and the snow event.
Just in case that someone can use this, here is a small demo with the script included:
snowing demo
Thanks for your interest and help! laugh


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