I am using this code for my moorhuhn like game. it allows me to use the mouse to slide the game screen from side to side using the mouse or the arrow keys.
The code is behaving just like I want to , and havent causing me any troubles until I started to test the game for more than 2 minutes. I have a counter that gives the player 3 minutes, and if you find it you can get 30 seconds more... Well it is working fine!
The problem is : When I have been playing for a while...maybe 2-5 minutes then I get this error:
crash in init_cusor_support ; wait(1)
How come? Why does it crash? What am I doing wrong?
Code:
// ----------------------------------------------------------------------------
// BMAPS:
bmap crosshair_map = <crosshair.tga>;
// ----------------------------------------------------------------------------
// VARS:
var scrborder_size = 50;
//Sets the range at the side of the screen where scrolling starts, default = 20
var scroll_speed = 20;//original 20
//speed of scrolling, default = 10
var level_borders[2] = -4000,4000;//original -512,512
//how far the camera can slide in x direction, default: -512,512
//var time_step = 2;
// ----------------------------------------------------------------------------
// FUNCTIONS:
//her blir kameraet som følger musepekeren laget//
function move_camera()
{
var i;
while(1)
{
i = int((pointer.x - (screen_size.x / 2)) / ((screen_size.x / 2) - scrborder_size));
camera.x = clamp(camera.x + i * scroll_speed * time,level_borders[0],level_borders[1]);
wait(1);
}
}
//muse pekeren blir satt her slik at den får et sikte//
function set_mouse(_mode)
{
mouse_mode = _mode;
mouse_map = crosshair_map;
mouse_range = 100000;//dette har jeg lagt til//original 5000
mouse_spot.x = bmap_width(crosshair_map) / 2;
mouse_spot.y = bmap_height(crosshair_map) / 2;
while(mouse_mode)
{
mouse_pos.x = pointer.x;
mouse_pos.y = pointer.y;
mouse_pos.x = clamp(mouse_pos.x,0,screen_size.x - bmap_width(crosshair_map));
wait(1);
}
}
//-------her har jeg lagt til (med hjelp) høyre og ventsre piltast//
//-------slik at jeg kan scrolle bildet frem og tilbake med piltastene//
var cursor_move; //added!
function move_camera2()
{
var i;
while(1)
{
i = int((pointer.x - (screen_size.x / 2)) / ((screen_size.x / 2) - scrborder_size));
camera.x = clamp(camera.x + (i + cursor_move) * scroll_speed * time,level_borders[0],level_borders[1]); //changed!
init_cursor_support();
wait(1);
}
}
//her blir piltastene kalt//
function init_cursor_support()
{
while(1)
{
cursor_move = (key_cur - key_cul); <-- its here i get the crash
wait(1); <-- and here
}
}
function init_mouse_2()
{
set_mouse(2); //set the mouse_mode to 2
move_camera(); //now let the camera move
move_camera2();//kamera til piltastene
}