/*
Copyright(C) 2022 Lari Varjonen <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301, USA.
https://lark3ri.fi
*/
var style_elm = document.createElement("style");
document.head.appendChild(style_elm);
style_elm.sheet.insertRule(`
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
`);
var DISPLAY = {};
DISPLAY.scale = 50;
DISPLAY.can = document.createElement("canvas");
document.body.appendChild(DISPLAY.can);
DISPLAY.ctx = DISPLAY.can.getContext("2d");
function set_canvas() {
DISPLAY.can.width = window.innerWidth;
DISPLAY.can.height = window.innerHeight;
DISPLAY.width = window.innerWidth;
DISPLAY.height = window.innerHeight;
var ax = 0;
var ay = 0;
var bx = DISPLAY.width/2;
var by = DISPLAY.height/2;
DISPLAY.corner_distance = Math.sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
}
window.addEventListener("resize", set_canvas, false);
set_canvas();
var KEY_CHECK = {};
KEY_CHECK.frame_count0 = 0;
KEY_CHECK.frame_count1 = 0;
KEY_CHECK.fast_repeate = 2;
KEY_CHECK.one = true;
KEY_CHECK.key_state = [];
KEY_CHECK.UP = [];
KEY_CHECK.DOWN = [];
KEY_CHECK.LEFT = [];
KEY_CHECK.RIGHT = [];
KEY_CHECK.CAMERA_MOVE_UP = [];
KEY_CHECK.CAMERA_MOVE_LEFT = [];
KEY_CHECK.CAMERA_MOVE_DOWN = [];
KEY_CHECK.CAMERA_MOVE_RIGHT = [];
KEY_CHECK.STRAFING_LEFT = [];
KEY_CHECK.STRAFING_RIGHT = [];
KEY_CHECK.PAUSE = [];
KEY_CHECK.STRAFING_UP = [];
KEY_CHECK.STRAFING_DOWN = [];
KEY_CHECK.DEBUG_MODE = [];
KEY_CHECK.FIRE = [];
KEY_CHECK.SEC_FIRE = [];
KEY_CHECK.ENTER = [];
KEY_CHECK.BACK = [];
KEY_CHECK.key = function(keyc, repeatedly = true, wait_key_up = false) {
// no repeat - keydown
if (!keyc[1] && this.key_state[keyc[0]].state) {
keyc[1] = 1;
if (!repeatedly && !wait_key_up) return true;
}
// no repeat - keyup
else if (keyc[1] && !this.key_state[keyc[0]].state) {
keyc[1] = 0;
if (!repeatedly && wait_key_up) return true;
}
// repeat - keydown
if (keyc[1] && repeatedly && !wait_key_up) return true;
return false;
}
KEY_CHECK.set_key = function(key, key_code, code) {
key[0] = key_code;
key[1] = false;
while (this.key_state.length <= key_code+1) {
this.key_state.push({state:false,code:"",key:[]});
}
this.key_state[key_code].code = code;
this.key_state[key_code].key = key;
}
KEY_CHECK.set_key(KEY_CHECK.UP, 38, "ArrowUp");
KEY_CHECK.set_key(KEY_CHECK.DOWN, 40, "ArrowDown");
KEY_CHECK.set_key(KEY_CHECK.LEFT, 37, "ArrowLeft");
KEY_CHECK.set_key(KEY_CHECK.RIGHT, 39, "ArrowRight");
KEY_CHECK.set_key(KEY_CHECK.PAUSE, 80, "KeyP");
KEY_CHECK.set_key(KEY_CHECK.DEBUG_MODE, 84, "KeyT");
KEY_CHECK.set_key(KEY_CHECK.CAMERA_MOVE_UP, 87, "KeyW");
KEY_CHECK.set_key(KEY_CHECK.CAMERA_MOVE_LEFT, 65, "KeyA");
KEY_CHECK.set_key(KEY_CHECK.CAMERA_MOVE_DOWN, 83, "KeyS");
KEY_CHECK.set_key(KEY_CHECK.CAMERA_MOVE_RIGHT, 68, "KeyD");
KEY_CHECK.set_key(KEY_CHECK.STRAFING_LEFT, 81, "KeyQ");
KEY_CHECK.set_key(KEY_CHECK.STRAFING_RIGHT, 69, "KeyE");
KEY_CHECK.set_key(KEY_CHECK.STRAFING_UP, 82, "KeyR");
KEY_CHECK.set_key(KEY_CHECK.STRAFING_DOWN, 70, "KeyF");
KEY_CHECK.set_key(KEY_CHECK.FIRE, 90, "KeyZ");
KEY_CHECK.set_key(KEY_CHECK.SEC_FIRE, 88, "KeyX");
KEY_CHECK.set_key(KEY_CHECK.ENTER, 13, "Enter");
KEY_CHECK.set_key(KEY_CHECK.BACK, 8, "Backspace");
document.onkeydown = function(e) {
e = e || window.event;
if (e.key.includes("Arrow")) {
e.preventDefault();
}
if (MENU.waiting_key_press) {
MENU.waiting_key_press_callback(e.keyCode, e.code);
return;
}
if (MENU.waiting_name_write) {
MENU.waiting_name_write_callback(e.keyCode, e.code, e.shiftKey);
return;
}
if (e.keyCode > KEY_CHECK.key_state.length-1) {
return;
}
KEY_CHECK.key_state[e.keyCode].state = true;
};
document.onkeyup = function(e) {
e = e || window.event;
if (e.key.includes("Arrow")) {
e.preventDefault();
}
if (e.keyCode > KEY_CHECK.key_state.length-1) {
return;
}
KEY_CHECK.key_state[e.keyCode].state = false;
}
var GAME = {};
GAME.started_once = false;
GAME.game_pause = false;
GAME.menu_pause = false;
GAME.level_depth = 440;
GAME.game_mode = 0;
GAME.game_over = false;
GAME.cam = {
x: 0,
y: 0,
z: 0,
ah: 0,
av: Math.PI/2,
speed: 12
};
GAME.debug_cam = {
x: 0,
y: 0,
z: 0,
ah: 0,
av: Math.PI/2
};
GAME.map = {
current_level: 0,
x: 40,
y: 0,
z: 0,
level_start_timer: {
accu: 0,
count: 200
},
current_level_cam_positions: [],
allow_rotate: [true,true,true,false]
};
GAME.screen_text = {
value: "GAME OVER",
type: 0,
x: 0,
y: 0,
color: {r:255,g:255,b:255},
center: 0,
scale: 14*4,
spacing: 4,
characters: []
};
GAME.map.levels = [
{
lines: [],
rails: [],
cam_positions: [],
color: {r:0,g:0,b:255},
enem_types: [0,1],
enem_probability: [
{
spawn_freq: 30,
freq_margin: 60,
rail_switch_speed: 120,
rail_switch_speed_margin: 50,
},
{
spawn_freq: 100,
freq_margin: 60,
rail_switch_speed: 120,
rail_switch_speed_margin: 50,
fire_rate: 128,
fire_rate_margin: 20,
big_bullet_fire_rate: 400,
big_bullet_fire_rate_margin: 480,
}
],
allow_spikes: true,
spikes_probability: {
spawn_freq: 800,
freq_margin: 400,
stop_position: 110,
stop_position_margin: 50,
speed: 0.15,
speed_margin: 0.02
},
item_types: [0],
item_probability: [
{
spawn_freq: 1100,
freq_margin: 300,
speed: 0.5,
speed_margin: 0.2,
rail_switch_speed: -1,
rail_switch_speed_margin: 0,
}
],
enem_limit: 12,
item_limit: 3,
starting_rail: 0,
direction: true,
goto_next_level_score: 120000
},
{
lines: [
[ { x:0,y:-50,z:-33 }, { x:0,y:-30,z:-33 } ],
[ { x:0,y:-30,z:-33 }, { x:0,y:-10,z:-33 } ],
[ { x:0,y:-10,z:-33 }, { x:0,y:10,z:-33 } ],
[ { x:0,y:10,z:-33 }, { x:0,y:30,z:-33 } ],
[ { x:0,y:30,z:-33 }, { x:0,y:50,z:-33 } ],
],
rails: [
{ x:0,y:-40,z:-33,a:-Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:-20,z:-33,a:-Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:0,z:-33,a:-Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:20,z:-33,a:-Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:40,z:-33,a:-Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
],
cam_positions: [],
color: {r:50,g:255,b:50},
enem_types: [0,1],
enem_probability: [
{
spawn_freq: 30,
freq_margin: 60,
rail_switch_speed: 120,
rail_switch_speed_margin: 50,
},
{
spawn_freq: 100,
freq_margin: 60,
rail_switch_speed: 120,
rail_switch_speed_margin: 50,
fire_rate: 128,
fire_rate_margin: 20,
big_bullet_fire_rate: 400,
big_bullet_fire_rate_margin: 480,
}
],
allow_spikes: true,
spikes_probability: {
spawn_freq: 800,
freq_margin: 400,
stop_position: 110,
stop_position_margin: 50,
speed: 0.15,
speed_margin: 0.02
},
item_types: [0],
item_probability: [
{
spawn_freq: 1100,
freq_margin: 300,
speed: 0.5,
speed_margin: 0.2,
rail_switch_speed: -1,
rail_switch_speed_margin: 0,
}
],
enem_limit: 12,
item_limit: 3,
starting_rail: 2,
direction: true,
goto_next_level_score: 120000
},
{
lines: [
[ { x:0,y:-20,z:-40 }, { x:0,y:0,z:-40 } ],
[ { x:0,y:0,z:-40 }, { x:0,y:20,z:-40 } ],
[ { x:0,y:20,z:-40 }, { x:0,y:20,z:-20 } ],
[ { x:0,y:20,z:-20 }, { x:0,y:40,z:-20 } ],
[ { x:0,y:40,z:-20 }, { x:0,y:40,z:0 } ],
[ { x:0,y:40,z:0 }, { x:0,y:40,z:20 } ],
[ { x:0,y:40,z:20 }, { x:0,y:20,z:20 } ],
[ { x:0,y:20,z:20 }, { x:0,y:20,z:40 } ],
[ { x:0,y:20,z:40 }, { x:0,y:0,z:40 } ],
[ { x:0,y:0,z:40 }, { x:0,y:-20,z:40 } ],
[ { x:0,y:-20,z:40 }, { x:0,y:-20,z:20 } ],
[ { x:0,y:-20,z:20 }, { x:0,y:-40,z:20 } ],
[ { x:0,y:-40,z:20 }, { x:0,y:-40,z:0 } ],
[ { x:0,y:-40,z:0 }, { x:0,y:-40,z:-20 } ],
[ { x:0,y:-40,z:-20 }, { x:0,y:-20,z:-20 } ],
[ { x:0,y:-20,z:-20 }, { x:0,y:-20,z:-40 } ]
],
rails: [
{ x:0,y:-10,z:-40,a:-Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:10,z:-40,a:-Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:20,z:-30,a:-Math.PI, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:30,z:-20,a:-Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:40,z:-10,a:-Math.PI, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:40,z:10,a:-Math.PI, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:30,z:20,a:Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:20,z:30,a:-Math.PI, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:10,z:40,a:Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:-10,z:40,a:Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:-20,z:30,a:0, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:-30,z:20,a:Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:-40,z:10,a:0, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:-40,z:-10,a:0, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:-30,z:-20,a:-Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:-20,z:-30,a:0, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 }
],
cam_positions: [],
color: {r:0,g:0,b:255},
enem_types: [0,1],
enem_probability: [
{
spawn_freq: 30,
freq_margin: 60,
rail_switch_speed: 120,
rail_switch_speed_margin: 50,
},
{
spawn_freq: 100,
freq_margin: 60,
rail_switch_speed: 120,
rail_switch_speed_margin: 50,
fire_rate: 128,
fire_rate_margin: 20,
big_bullet_fire_rate: 400,
big_bullet_fire_rate_margin: 480,
}
],
allow_spikes: true,
spikes_probability: {
spawn_freq: 800,
freq_margin: 400,
stop_position: 110,
stop_position_margin: 50,
speed: 0.15,
speed_margin: 0.02
},
item_types: [0],
item_probability: [
{
spawn_freq: 1100,
freq_margin: 300,
speed: 0.5,
speed_margin: 0.2,
rail_switch_speed: -1,
rail_switch_speed_margin: 0,
}
],
enem_limit: 12,
item_limit: 3,
starting_rail: 13,
direction: false,
goto_next_level_score: 120000,
},
{
lines: [
[ { x:0,y:-50,z:0 }, { x:0,y:-50,z:-20 } ],
[ { x:0,y:-50,z:-20 }, { x:0,y:-30,z:-20 } ],
[ { x:0,y:-30,z:-20 }, { x:0,y:-30,z:-40 } ],
[ { x:0,y:-30,z:-40 }, { x:0,y:-10,z:-40 } ],
[ { x:0,y:-10,z:-40 }, { x:0,y:-10,z:-60 } ],
[ { x:0,y:-10,z:-60 }, { x:0,y:10,z:-60 } ],
[ { x:0,y:10,z:-60 }, { x:0,y:10,z:-40 } ],
[ { x:0,y:10,z:-40 }, { x:0,y:30,z:-40 } ],
[ { x:0,y:30,z:-40 }, { x:0,y:30,z:-20 } ],
[ { x:0,y:30,z:-20 }, { x:0,y:50,z:-20 } ],
[ { x:0,y:50,z:-20 }, { x:0,y:50,z:0 } ],
],
rails: [
{ x:0,y:-50,z:-10,a:0, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:-40,z:-20,a:-Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:-30,z:-30,a:0, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:-20,z:-40,a:-Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:-10,z:-50,a:0, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:0,z:-60,a:-Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:10,z:-50,a:Math.PI, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:20,z:-40,a:-Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:30,z:-30,a:Math.PI, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:40,z:-20,a:-Math.PI/2, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
{ x:0,y:50,z:-10,a:Math.PI, items:[], player_bullets:[], enem_bullets:[], big_bullets:[], spike:0 },
],
cam_positions: [],
color: {r:255,g:0,b:255},
enem_types: [0,1],
enem_probability: [
{
spawn_freq: 30,
freq_margin: 60,
rail_switch_speed: 120,
rail_switch_speed_margin: 50,
},
{
spawn_freq: 100,
freq_margin: 60,
rail_switch_speed: 120,
rail_switch_speed_margin: 50,
fire_rate: 128,
fire_rate_margin: 20,
big_bullet_fire_rate: 400,
big_bullet_fire_rate_margin: 480,
}
],
allow_spikes: true,
spikes_probability: {
spawn_freq: 800,
freq_margin: 400,
stop_position: 110,
stop_position_margin: 50,
speed: 0.15,
speed_margin: 0.02
},
item_types: [0],
item_probability: [
{
spawn_freq: 1100,
freq_margin: 300,
speed: 0.5,
speed_margin: 0.2,
rail_switch_speed: -1,
rail_switch_speed_margin: 0,
}
],
enem_limit: 12,
item_limit: 3,
starting_rail: 5,
direction: false,
goto_next_level_score: 0,
}
];
// Making the level Triangle.
// \
for(var level_position = 1, starting_point = 4, i = []; i.length < 6;) {
var z = (i.length<1)?GAME.map.levels[level_position].lines[starting_point][1].z:i[i.length-1].z;
var y = (i.length<1)?GAME.map.levels[level_position].lines[starting_point][1].y:i[i.length-1].y;
if (i.length<1) {
i.push({ z:z,y:y });
z = i[0].z;
y = i[0].y;
}
var az = z + Math.cos((-Math.PI / 180) * 30) * 20;
var ay = y + Math.sin((-Math.PI / 180) * 30) * 20;
i.push({ z:az,y:ay });
var rz = z + Math.cos((-Math.PI / 180) * 30) * 10;
var ry = y + Math.sin((-Math.PI / 180) * 30) * 10;
GAME.map.levels[level_position].rails.push({
x:0, y:ry, z:rz, a:(-Math.PI / 180) * 30,
items:[],
player_bullets:[],
enem_bullets:[],
big_bullets:[],
spike:0
});
if (i.length == 6) {
for (var u = 1; u < i.length; u++) {
var az = i[u-1].z;
var ay = i[u-1].y;
var bz = i[u].z;
var by = i[u].y;
GAME.map.levels[level_position].lines.push([ { x:0,y:ay,z:az }, { x:0,y:by,z:bz } ]);
}
}
}
// /
for(var level_position = 1, starting_point = 9, i = []; i.length < 6;) {
var z = (i.length<1)?GAME.map.levels[level_position].lines[starting_point][1].z:i[i.length-1].z;
var y = (i.length<1)?GAME.map.levels[level_position].lines[starting_point][1].y:i[i.length-1].y;
if (i.length<1) {
i.push({ z:z,y:y });
z = i[0].z;
y = i[0].y;
}
var az = z + Math.cos((-Math.PI / 180) * 150) * 20;
var ay = y + Math.sin((-Math.PI / 180) * 150) * 20;
i.push({ z:az,y:ay });
var rz = z + Math.cos((-Math.PI / 180) * 150) * 10;
var ry = y + Math.sin((-Math.PI / 180) * 150) * 10;
GAME.map.levels[level_position].rails.push({
x:0, y:ry, z:rz, a:(-Math.PI / 180) * 150,
items:[],
player_bullets:[],
enem_bullets:[],
big_bullets:[],
spike:0
});
if (i.length == 6) {
for (var u = 1; u < i.length; u++) {
var az = i[u-1].z;
var ay = i[u-1].y;
var bz = i[u].z;
var by = i[u].y;
GAME.map.levels[level_position].lines.push([ { x:0,y:ay,z:az }, { x:0,y:by,z:bz } ]);
}
}
}
// Making the level Circle.
for (var spaces = 12, i = ((Math.PI*2)/spaces)/2; i < Math.PI*2; i+=(Math.PI*2)/spaces) {
var az = Math.cos(-i) * 38;
var ay = Math.sin(-i) * 38;
var bz = Math.cos(-i+(Math.PI*2)/spaces) * 38;
var by = Math.sin(-i+(Math.PI*2)/spaces) * 38;
GAME.map.levels[0].lines.push([{ x:0,y:-ay,z:-az },{ x:0,y:-by,z:-bz }]);
}
for (var spaces = 12, i = 0; i < Math.PI*2; i+=(Math.PI*2)/spaces) {
var az = Math.cos(-i) * 36.5;
var ay = Math.sin(-i) * 36.5;
GAME.map.levels[0].rails.push({
x:0, y:-ay, z:-az, a:-i+Math.PI/2,
items:[],
player_bullets:[],
enem_bullets:[],
big_bullets:[],
spike:0
});
}
function set_cam_positions(level) {
for (var i = 0; i < GAME.map.levels[level].rails.length; i++) {
var z = GAME.map.levels[level].rails[i].z;
var y = GAME.map.levels[level].rails[i].y;
var a = get_angle(0, 0, z, y);
z = Math.cos(a) * GAME.cam.speed;
y = Math.sin(a) * GAME.cam.speed;
GAME.map.levels[level].cam_positions.push({z:z,y:y});
}
}
set_cam_positions(0);
set_cam_positions(1);
set_cam_positions(2);
set_cam_positions(3);
GAME.player = {
lines: [
[
[ { x:0,y:0,z:-2 }, { x:20,y:20,z:-2 } ],
[ { x:20,y:20,z:-2 }, { x:30,y:20,z:-2 } ],
[ { x:30,y:20,z:-2 }, { x:40,y:10,z:-2 } ],
[ { x:40,y:10,z:-2 }, { x:20,y:10,z:-2 } ],
[ { x:20,y:10,z:-2 }, { x:10,y:0,z:-2 } ],
[ { x:10,y:0,z:-2 }, { x:20,y:-10,z:-2 } ],
[ { x:20,y:-10,z:-2 }, { x:40,y:-10,z:-2 } ],
[ { x:40,y:-10,z:-2 }, { x:30,y:-20,z:-2 } ],
[ { x:30,y:-20,z:-2 }, { x:20,y:-20,z:-2 } ],
[ { x:20,y:-20,z:-2 }, { x:0,y:0,z:-2 } ],
[ { x:0,y:0,z:2 }, { x:20,y:20,z:2 } ],
[ { x:20,y:20,z:2 }, { x:30,y:20,z:2 } ],
[ { x:30,y:20,z:2 }, { x:40,y:10,z:2 } ],
[ { x:40,y:10,z:2 }, { x:20,y:10,z:2 } ],
[ { x:20,y:10,z:2 }, { x:10,y:0,z:2 } ],
[ { x:10,y:0,z:2 }, { x:20,y:-10,z:2 } ],
[ { x:20,y:-10,z:2 }, { x:40,y:-10,z:2 } ],
[ { x:40,y:-10,z:2 }, { x:30,y:-20,z:2 } ],
[ { x:30,y:-20,z:2 }, { x:20,y:-20,z:2 } ],
[ { x:20,y:-20,z:2 }, { x:0,y:0,z:2 } ]
]
],
width: 20,
current_frame: 0,
current_rail: 0,
speed: 0,
color: {r:255,g:255,b:255},
bullet_type: 0,
big_bullet_type: 0,
is_alive: false,
is_god: false,
is_unlimited_ammo: false,
is_debug_mode: false,
after_revive_god_time: 100,
rapidfire_speed: 5,
rapidfire_accu: 0,
x: 40,
y: 0,
z: 0,
base_score: 0,
lifes: {
value: 0,
padding: 8,
hide_padding: true,
x: -8,
y: 1,
color: {r:255,g:255,b:255},
},
score: {
value: 0,
padding: 9,
hide_padding: false,
x: -4,
y: 0,
color: {r:255,g:0,b:0},
},
current_level: {
value: 1,
padding: 0,
hide_padding: false,
x: 1,
y: 1,
color: {r:255,g:255,b:255},
},
bullet_count: {
value: 0,
padding: 8,
hide_padding: true,
x: -13,
y: 0,
color: {r:255,g:255,b:0},
},
big_bullet_count: {
value: 0,
padding: 0,
hide_padding: false,
x: 6,
y: 0,
color: {r:0,g:255,b:255},
},
is_reviving: false,
revive_anim_stages: [
{switch:true, accu:0, count:100},
{switch:false, accu:0}
]
};
GAME.enems = [];
GAME.items = [];
GAME.enem = [
{
lines: [
[
[ { x:0,y:20,z:0 }, { x:0,y:10,z:10 } ],
[ { x:0,y:10,z:10 }, { x:0,y:-10,z:-10 } ],
[ { x:0,y:-10,z:-10 }, { x:0,y:-20,z:0 } ]
],
[
[ { x:0,y:20,z:0 }, { x:0,y:10,z:-10 } ],
[ { x:0,y:10,z:-10 }, { x:0,y:-10,z:10 } ],
[ { x:0,y:-10,z:10 }, { x:0,y:-20,z:0 } ]
]
],
add_score: 1234,
lifes: 0,
add_bullets: 4,
current_frame: 0,
current_rail: 0,
direction: false,
max_speed: 2.3,
min_speed: 1.6,
speed: 0,
bullet_type: -1,
big_bullet_type: -1,
frame_switch_speed: 20,
rail_switch_speed: 120,
frame_switch_accu: 0,
rail_switch_accu: 0,
spawn_freq_: 0,
spawn_freq_accu: 0,
color: {r:255,g:0,b:0},
x: 0,
y: 0,
z: 0
},
{
lines: [
[
[ { x:0,y:10,z:2 }, { x:20,y:20,z:2 } ],
[ { x:20,y:20,z:2 }, { x:20,y:0,z:2 } ],
[ { x:20,y:0,z:2 }, { x:0,y:10,z:2 } ],
[ { x:0,y:-10,z:2 }, { x:20,y:0,z:2 } ],
[ { x:20,y:0,z:2 }, { x:20,y:-20,z:2 } ],
[ { x:20,y:-20,z:2 }, { x:0,y:-10,z:2 } ],
[ { x:0,y:10,z:-2 }, { x:20,y:20,z:-2 } ],
[ { x:20,y:20,z:-2 }, { x:20,y:0,z:-2 } ],
[ { x:20,y:0,z:-2 }, { x:0,y:10,z:-2 } ],
[ { x:0,y:-10,z:-2 }, { x:20,y:0,z:-2 } ],
[ { x:20,y:0,z:-2 }, { x:20,y:-20,z:-2 } ],
[ { x:20,y:-20,z:-2 }, { x:0,y:-10,z:-2 } ]
]
],
add_score: 12345,
lifes: 2,
add_bullets: 10,
current_frame: 0,
current_rail: 0,
direction: false,
max_speed: 2,
min_speed: 1,
speed: 0,
bullet_type: 0,
big_bullet_type: 0,
fire_rate: 128,
big_bullet_fire_rate: 0,
frame_switch_speed: -1,
rail_switch_speed: 120,
frame_switch_accu: 0,
rail_switch_accu: 0,
fire_rate_accu: 0,
big_bullet_rate_accu: 0,
spawn_freq_: 0,
spawn_freq_accu: 0,
color: {r:0,g:255,b:255},
x: 0,
y: 0,
z: 0
}
];
GAME.item = [
{
lines: [[],[]],
bullet_amount: 0,
big_bullet_amount: 6,
current_frame: 0,
current_rail: 0,
speed: 0,
frame_switch_speed: 30,
rail_switch_speed: 0,
frame_switch_accu: 0,
rail_switch_accu: 0,
spawn_freq_: 0,
spawn_freq_accu: 0,
color: {r:0,g:255,b:255},
x: 0,
y: 0,
z: 0
},
];
for (var i = 0; i < 8; i++) {
var x = Math.cos(((Math.PI*2)/8)*i) * 5;
var y = Math.sin(((Math.PI*2)/8)*i) * 5;
var ax = 0;
var ay = 0;
var az = 5;
var bx = x;
var by = y;
var bz = 0;
GAME.item[0].lines[0].push([{x:ax,y:ay,z:az},{x:bx,y:by,z:bz}]);
az = -5;
GAME.item[0].lines[0].push([{x:ax,y:ay,z:az},{x:bx,y:by,z:bz}]);
}
for (var i = 0; i < 8; i++) {
var x = Math.cos(((Math.PI*2)/8)*i) * 4;
var y = Math.sin(((Math.PI*2)/8)*i) * 4;
var ax = 0;
var ay = 0;
var az = 4;
var bx = x;
var by = y;
var bz = 0;
GAME.item[0].lines[1].push([{x:ax,y:ay,z:az},{x:bx,y:by,z:bz}]);
az = -4;
GAME.item[0].lines[1].push([{x:ax,y:ay,z:az},{x:bx,y:by,z:bz}]);
}
GAME.bullet = [
{
lines: [
[ { x:0,y:0,z:2 }, { x:0,y:2,z:0 } ],
[ { x:0,y:2,z:0 }, { x:0,y:0,z:-2 } ],
[ { x:0,y:0,z:-2 }, { x:0,y:-2,z:0 } ],
[ { x:0,y:-2,z:0 }, { x:0,y:0,z:2 } ],
[ { x:0,y:0,z:2 }, { x:2,y:0,z:0 } ],
[ { x:2,y:0,z:0 }, { x:0,y:0,z:-2 } ],
[ { x:0,y:0,z:-2 }, { x:-2,y:0,z:0 } ],
[ { x:-2,y:0,z:0 }, { x:0,y:0,z:2 } ]
],
current_rail: 0,
speed: 6,
color: {r:255,g:255,b:0},
x: 0,
y: 0,
z: 0
}
];
GAME.spawn_spike_accu = 0;
GAME.spawn_spike_freq = 0;
GAME.spike = {
lines: [
[ { x:0,y:0,z:2 }, { x:0,y:2,z:0 } ],
[ { x:0,y:2,z:0 }, { x:0,y:0,z:-2 } ],
[ { x:0,y:0,z:-2 }, { x:0,y:-2,z:0 } ],
[ { x:0,y:-2,z:0 }, { x:0,y:0,z:2 } ],
[ { x:0,y:0,z:2 }, { x:2,y:0,z:0 } ],
[ { x:2,y:0,z:0 }, { x:0,y:0,z:-2 } ],
[ { x:0,y:0,z:-2 }, { x:-2,y:0,z:0 } ],
[ { x:-2,y:0,z:0 }, { x:0,y:0,z:2 } ]
],
add_score: 123,
add_bullets: 2,
current_rail: 0,
speed: 0,
cut_amount: 60,
color: {r:0,g:255,b:0},
x: 0,
y: 0,
z: 0,
is_alive: true,
stop_position: 0
};
GAME.big_bullet = [
{
detonate_time: 0.5,
current_rail: 0,
duration: 500,
duration_accu: 0,
detonated: false,
color: {r:255,g:0,b:255},
is_enem_bullet: false,
}
];
GAME.effect_lines = [];
GAME.goto_map_animation_stages = [
{switch: false, accu:0, count:100},
{
switch: false,
player_speed: 0,
player_max_speed: 30,
player_speed_increment: 0.2,
cam_speed: 0,
cam_max_speed: 5,
cam_speed_increment: 0.1,
stars_increase_speed: 0.2,
stars_decrease_speed: 0.17
},
{
switch: false,
accu: 0,
count: 75,
fadeout_speed: 4
}
];
GAME.stars_add_speed = 0;
GAME.stars_add_speed_ = 0;
var STARS = {};
STARS.update = function(living_stars) {
if (living_stars.length < 333) {
var pi = Math.random() * (Math.PI * 2);
var speed = Math.random();
var speedup_speed = Math.random();
var r = Math.floor(Math.random() * (255 - 50) + 50);
var g = Math.floor(Math.random() * (255 - 50) + 50);
var b = Math.floor(Math.random() * (255 - 50) + 50);
living_stars.push({distance:0,speed,pi,speedup_speed,r,g,b});
}
for (var i = 0; i < living_stars.length; i++) {
living_stars[i].distance += living_stars[i].speed + GAME.stars_add_speed;
living_stars[i].speed += living_stars[i].speedup_speed/48;
if (living_stars[i].distance > DISPLAY.corner_distance) {
living_stars.splice(i, 1);
i--;
}
}
}
STARS.draw = function(living_stars) {
for (var i = 0; i < living_stars.length; i++) {
var x = (DISPLAY.width / 2) + Math.cos(living_stars[i].pi) * living_stars[i].distance;
var y = (DISPLAY.height / 2) + Math.sin(living_stars[i].pi) * living_stars[i].distance;
var size = living_stars[i].distance / 200;
DISPLAY.ctx.beginPath();
DISPLAY.ctx.fillStyle = `rgba(${living_stars[i].r}, 0, 0, 0.5)`;
DISPLAY.ctx.fillRect(x-1,y-1,size,size);
DISPLAY.ctx.closePath();
DISPLAY.ctx.beginPath();
DISPLAY.ctx.fillStyle = `rgba(0, ${living_stars[i].g}, 0, 0.5)`;
DISPLAY.ctx.fillRect(x,y,size,size);
DISPLAY.ctx.closePath();
DISPLAY.ctx.beginPath();
DISPLAY.ctx.fillStyle = `rgba(0, 0, ${living_stars[i].b}, 0.5)`;
DISPLAY.ctx.fillRect(x+1,y+1,size,size);
DISPLAY.ctx.closePath();
}
}
var NUMBER = {};
NUMBER.lines = [
[
[ { x:0,y:0 }, { x:1,y:0 } ],
[ { x:1,y:0 }, { x:1,y:2 } ],
[ { x:1,y:2 }, { x:0,y:2 } ],
[ { x:0,y:2 }, { x:0,y:0 } ]
],
[
[ { x:0.5,y:0 }, { x:0.5,y:2 } ]
],
[
[ { x:0,y:0 }, { x:1,y:0 } ],
[ { x:1,y:0 }, { x:1,y:1 } ],
[ { x:1,y:1 }, { x:0,y:1 } ],
[ { x:0,y:1 }, { x:0,y:2 } ],
[ { x:0,y:2 }, { x:1,y:2 } ]
],
[
[ { x:0,y:0 }, { x:1,y:0 } ],
[ { x:0,y:1 }, { x:1,y:1 } ],
[ { x:0,y:2 }, { x:1,y:2 } ],
[ { x:1,y:0 }, { x:1,y:2 } ]
],
[
[ { x:0,y:0 }, { x:0,y:1 } ],
[ { x:0,y:1 }, { x:1,y:1 } ],
[ { x:1,y:0 }, { x:1,y:2 } ]
],
[
[ { x:0,y:0 }, { x:1,y:0 } ],
[ { x:0,y:0 }, { x:0,y:1 } ],
[ { x:1,y:1 }, { x:0,y:1 } ],
[ { x:1,y:1 }, { x:1,y:2 } ],
[ { x:0,y:2 }, { x:1,y:2 } ]
],
[
[ { x:0,y:0 }, { x:0,y:2 } ],
[ { x:0,y:0 }, { x:1,y:0 } ],
[ { x:0,y:1 }, { x:1,y:1 } ],
[ { x:0,y:2 }, { x:1,y:2 } ],
[ { x:0,y:2 }, { x:1,y:2 } ],
[ { x:1,y:1 }, { x:1,y:2 } ]
],
[
[ { x:0,y:0 }, { x:1,y:0 } ],
[ { x:1,y:0 }, { x:1,y:2 } ]
],
[
[ { x:0,y:0 }, { x:1,y:0 } ],
[ { x:1,y:0 }, { x:1,y:2 } ],
[ { x:1,y:2 }, { x:0,y:2 } ],
[ { x:0,y:2 }, { x:0,y:0 } ],
[ { x:1,y:1 }, { x:0,y:1 } ]
],
[
[ { x:0,y:0 }, { x:1,y:0 } ],
[ { x:1,y:0 }, { x:1,y:2 } ],
[ { x:0,y:1 }, { x:0,y:0 } ],
[ { x:1,y:1 }, { x:0,y:1 } ],
[ { x:0,y:2 }, { x:1,y:2 } ]
]
];
NUMBER.scale = 16;
NUMBER.spacing = 12;
NUMBER.x = 0;
NUMBER.y = 0;
NUMBER.draw_value = function(value, x ,y, color, padding, hide_padding) {
var display_scale = (DISPLAY.scale / 100) + 0.5;
var from_top = 80;
if (display_scale < 1) {
from_top *= display_scale;
}
this.y = from_top + -DISPLAY.can.height / 2;
this.y /= display_scale;
this.x = -(this.scale + this.spacing) + this.spacing;
this.x /= 2;
var move_right = 0;
var value_str = value.toString(10);
var x_ = this.x;
var y_ = this.y;
x_ += x * (this.scale + this.spacing);
y_ += y * ((this.scale * 2) + this.spacing);
for (var i = 0; i < padding - value_str.length; i++) {
if (!hide_padding) {
var number_lines = this.lines[0];
for (var u = 0; u < number_lines.length; u++) {
var ax = number_lines[u][0].x;
var ay = number_lines[u][0].y;
var bx = number_lines[u][1].x;
var by = number_lines[u][1].y;
ax *= this.scale;
ay *= this.scale;
bx *= this.scale;
by *= this.scale;
ax += move_right + x_;
ay += y_;
bx += move_right + x_;
by += y_;
DISPLAY.draw_line(
ax, ay, bx, by,
color.r, color.g, color.b,
GAME.hud.scale, GAME.hud.lja
);
}
}
move_right += this.scale + this.spacing;
}
for (var i = 0; i < value_str.length; i++) {
var number_lines = this.lines[value_str[i]];
for (var u = 0; u < number_lines.length; u++) {
var ax = number_lines[u][0].x;
var ay = number_lines[u][0].y;
var bx = number_lines[u][1].x;
var by = number_lines[u][1].y;
ax *= this.scale;
ay *= this.scale;
bx *= this.scale;
by *= this.scale;
ax += move_right + x_;
ay += y_;
bx += move_right + x_;
by += y_;
DISPLAY.draw_line(
ax, ay, bx, by,
color.r, color.g, color.b,
GAME.hud.scale, GAME.hud.lja
);
}
move_right += this.scale + this.spacing;
}
}
TEXT = {};
TEXT.ascii = [
[0x00, 0x00, 0x00, 0x00, 0x00] // 20
,[0x00, 0x00, 0x5f, 0x00, 0x00] // 21 !
,[0x00, 0x07, 0x00, 0x07, 0x00] // 22 "
,[0x14, 0x7f, 0x14, 0x7f, 0x14] // 23 #
,[0x24, 0x2a, 0x7f, 0x2a, 0x12] // 24 $
,[0x23, 0x13, 0x08, 0x64, 0x62] // 25 %
,[0x36, 0x49, 0x55, 0x22, 0x50] // 26 &
,[0x00, 0x05, 0x03, 0x00, 0x00] // 27 '
,[0x00, 0x1c, 0x22, 0x41, 0x00] // 28 (
,[0x00, 0x41, 0x22, 0x1c, 0x00] // 29 )
,[0x14, 0x08, 0x3e, 0x08, 0x14] // 2a *
,[0x08, 0x08, 0x3e, 0x08, 0x08] // 2b +
,[0x00, 0x50, 0x30, 0x00, 0x00] // 2c ,
,[0x08, 0x08, 0x08, 0x08, 0x08] // 2d -
,[0x00, 0x60, 0x60, 0x00, 0x00] // 2e .
,[0x20, 0x10, 0x08, 0x04, 0x02] // 2f /
,[0x3e, 0x51, 0x49, 0x45, 0x3e] // 30 0
,[0x00, 0x42, 0x7f, 0x40, 0x00] // 31 1
,[0x42, 0x61, 0x51, 0x49, 0x46] // 32 2
,[0x21, 0x41, 0x45, 0x4b, 0x31] // 33 3
,[0x18, 0x14, 0x12, 0x7f, 0x10] // 34 4
,[0x27, 0x45, 0x45, 0x45, 0x39] // 35 5
,[0x3c, 0x4a, 0x49, 0x49, 0x30] // 36 6
,[0x01, 0x71, 0x09, 0x05, 0x03] // 37 7
,[0x36, 0x49, 0x49, 0x49, 0x36] // 38 8
,[0x06, 0x49, 0x49, 0x29, 0x1e] // 39 9
,[0x00, 0x36, 0x36, 0x00, 0x00] // 3a :
,[0x00, 0x56, 0x36, 0x00, 0x00] // 3b ;
,[0x08, 0x14, 0x22, 0x41, 0x00] // 3c <
,[0x14, 0x14, 0x14, 0x14, 0x14] // 3d =
,[0x00, 0x41, 0x22, 0x14, 0x08] // 3e >
,[0x02, 0x01, 0x51, 0x09, 0x06] // 3f ?
,[0x32, 0x49, 0x79, 0x41, 0x3e] // 40 @
,[0x7e, 0x11, 0x11, 0x11, 0x7e] // 41 A
,[0x7f, 0x49, 0x49, 0x49, 0x36] // 42 B
,[0x3e, 0x41, 0x41, 0x41, 0x22] // 43 C
,[0x7f, 0x41, 0x41, 0x22, 0x1c] // 44 D
,[0x7f, 0x49, 0x49, 0x49, 0x41] // 45 E
,[0x7f, 0x09, 0x09, 0x09, 0x01] // 46 F
,[0x3e, 0x41, 0x49, 0x49, 0x7a] // 47 G
,[0x7f, 0x08, 0x08, 0x08, 0x7f] // 48 H
,[0x00, 0x41, 0x7f, 0x41, 0x00] // 49 I
,[0x20, 0x40, 0x41, 0x3f, 0x01] // 4a J
,[0x7f, 0x08, 0x14, 0x22, 0x41] // 4b K
,[0x7f, 0x40, 0x40, 0x40, 0x40] // 4c L
,[0x7f, 0x02, 0x0c, 0x02, 0x7f] // 4d M
,[0x7f, 0x04, 0x08, 0x10, 0x7f] // 4e N
,[0x3e, 0x41, 0x41, 0x41, 0x3e] // 4f O
,[0x7f, 0x09, 0x09, 0x09, 0x06] // 50 P
,[0x3e, 0x41, 0x51, 0x21, 0x5e] // 51 Q
,[0x7f, 0x09, 0x19, 0x29, 0x46] // 52 R
,[0x46, 0x49, 0x49, 0x49, 0x31] // 53 S
,[0x01, 0x01, 0x7f, 0x01, 0x01] // 54 T
,[0x3f, 0x40, 0x40, 0x40, 0x3f] // 55 U
,[0x1f, 0x20, 0x40, 0x20, 0x1f] // 56 V
,[0x3f, 0x40, 0x38, 0x40, 0x3f] // 57 W
,[0x63, 0x14, 0x08, 0x14, 0x63] // 58 X
,[0x07, 0x08, 0x70, 0x08, 0x07] // 59 Y
,[0x61, 0x51, 0x49, 0x45, 0x43] // 5a Z
,[0x00, 0x7f, 0x41, 0x41, 0x00] // 5b [
,[0x02, 0x04, 0x08, 0x10, 0x20] // 5c ¥
,[0x00, 0x41, 0x41, 0x7f, 0x00] // 5d ]
,[0x04, 0x02, 0x01, 0x02, 0x04] // 5e ^
,[0x40, 0x40, 0x40, 0x40, 0x40] // 5f _
,[0x00, 0x01, 0x02, 0x04, 0x00] // 60 `
,[0x20, 0x54, 0x54, 0x54, 0x78] // 61 a
,[0x7f, 0x48, 0x44, 0x44, 0x38] // 62 b
,[0x38, 0x44, 0x44, 0x44, 0x20] // 63 c
,[0x38, 0x44, 0x44, 0x48, 0x7f] // 64 d
,[0x38, 0x54, 0x54, 0x54, 0x18] // 65 e
,[0x08, 0x7e, 0x09, 0x01, 0x02] // 66 f
,[0x0c, 0x52, 0x52, 0x52, 0x3e] // 67 g
,[0x7f, 0x08, 0x04, 0x04, 0x78] // 68 h
,[0x00, 0x44, 0x7d, 0x40, 0x00] // 69 i
,[0x20, 0x40, 0x44, 0x3d, 0x00] // 6a j
,[0x7f, 0x10, 0x28, 0x44, 0x00] // 6b k
,[0x00, 0x41, 0x7f, 0x40, 0x00] // 6c l
,[0x7c, 0x04, 0x18, 0x04, 0x78] // 6d m
,[0x7c, 0x08, 0x04, 0x04, 0x78] // 6e n
,[0x38, 0x44, 0x44, 0x44, 0x38] // 6f o
,[0x7c, 0x14, 0x14, 0x14, 0x08] // 70 p
,[0x08, 0x14, 0x14, 0x18, 0x7c] // 71 q
,[0x7c, 0x08, 0x04, 0x04, 0x08] // 72 r
,[0x48, 0x54, 0x54, 0x54, 0x20] // 73 s
,[0x04, 0x3f, 0x44, 0x40, 0x20] // 74 t
,[0x3c, 0x40, 0x40, 0x20, 0x7c] // 75 u
,[0x1c, 0x20, 0x40, 0x20, 0x1c] // 76 v
,[0x3c, 0x40, 0x30, 0x40, 0x3c] // 77 w
,[0x44, 0x28, 0x10, 0x28, 0x44] // 78 x
,[0x0c, 0x50, 0x50, 0x50, 0x3c] // 79 y
,[0x44, 0x64, 0x54, 0x4c, 0x44] // 7a z
,[0x00, 0x08, 0x36, 0x41, 0x00] // 7b [
,[0x00, 0x00, 0x7f, 0x00, 0x00] // 7c |
,[0x00, 0x41, 0x36, 0x08, 0x00] // 7d ]
,[0x10, 0x08, 0x08, 0x10, 0x08] // 7e ~
,[0x78, 0x46, 0x41, 0x46, 0x78] // 7f
];
TEXT.draw = function(text_obj, scale_) {
var scalex = text_obj.scale / 5;
for (var i = 0; i < text_obj.characters.length; i++) {
for (var u = 0; u < text_obj.characters[i].length; u++) {
for (var t = 0; t < text_obj.characters[i][u].length; t++) {
var ax = text_obj.characters[i][u][t][0].x;
var ay = -text_obj.characters[i][u][t][0].y;
var bx = text_obj.characters[i][u][t][1].x;
var by = -text_obj.characters[i][u][t][1].y;
DISPLAY._draw_fill_shape(
[
{x:bx-(scalex/2),y:by},
{x:bx+(scalex/2),y:by},
{x:ax+(scalex/2),y:ay},
{x:ax-(scalex/2),y:ay},
{x:bx-(scalex/2),y:by}
],
text_obj.color.r, text_obj.color.g, text_obj.color.b,
scale_
);
}
}
}
}
TEXT.update = function(text_obj) {
var text = text_obj.value;
var x = text_obj.x;
var y = text_obj.y;
var scalex = text_obj.scale / 5;
var scaley = text_obj.scale / 6;
var x_ = 0;
var length = text.length;
if (text_obj.type == 1) {
var io = text.indexOf(':');
length = io;
var key_code = parseInt(text.substring(io+1));
if (text_obj.waiting_new_key) {
text = text.substring(0, io) + ' ' + text.substring(io+1);
} else {
text = text.substring(0, io) + ' ' + KEY_CHECK.key_state[key_code].code;
}
x -= (text_obj.scale + text_obj.spacing) / 2;
}
if (text_obj.type == 2) {
var sel_arr = text.split(">");
text = sel_arr[text_obj.current_selection];
length = sel_arr[text_obj.current_selection].length;
}
if (text_obj.type == 3) {
var io = text.indexOf(':');
length = io;
var key_code = parseInt(text.substring(io+1));
text = text.substring(0, io) + ' ' + text.substring(io+1);
x -= (text_obj.scale + text_obj.spacing) / 2;
}
if (text_obj.center == 0) {
x -= (length * (text_obj.scale + text_obj.spacing)) / 2;
}
if (text_obj.center == -1) {
x -= (length * (text_obj.scale + text_obj.spacing));
}
y -= (text_obj.scale / 2) + (scalex / 2);
text_obj.characters = [];
for (var i = 0; i < text.length; i++) {
x_ = i * (text_obj.scale + text_obj.spacing);
x_ += text_obj.spacing;
character = [];
var ascii_bits = this.ascii[text[i].charCodeAt(0)-32];
for (var u = 0; u < ascii_bits.length; u++) {
var on_line = false;
var char_line = [[]];
var bit_binary = (ascii_bits[u] >>> 0).toString(2);
while (bit_binary.length != 7) {
bit_binary = '0' + bit_binary;
}
for (t = 0; t < bit_binary.length; t++) {
if (bit_binary[t] == '1' && !on_line) {
on_line = true;
char_line[char_line.length-1].push({x:x+(scalex*u)+x_,y:y+scaley*t});
}
if (bit_binary[t] == '0' && on_line) {
on_line = false;
char_line[char_line.length-1].push({x:x+(scalex*u)+x_,y:y+scaley*t});
var rhs = bit_binary.substring(t, bit_binary.length);
if (parseInt(rhs, 2) > 0) {
char_line.push([]);
continue;
}
break;
}
if (t == bit_binary.length-1) {
if (!on_line) {
break;
}
char_line[char_line.length-1].push({x:x+(scalex*u)+x_,y:y+scaley*(t+1)});
}
}
for (var t = 0; t < char_line.length; t++) {
if (char_line[t].length == 0) {
continue;
}
character.push(char_line);
}
}
text_obj.characters.push(character);
}
}
var rx_ = 0;
var ry_ = 0;
var gx_ = 0;
var gy_ = 0;
var bx_ = 0;
var by_ = 0;
var r_ = 0;
var g_ = 0;
var b_ = 0;
var r_count = 0;
var r_count_new = 1;
var g_count = 0;
var g_count_new = 1;
var b_count = 0;
var b_count_new = 1;
var color_flickering = 70;
GAME.line_distortion = 2;
GAME.target_scale = 1;
GAME.scale = 0;
GAME.lja = GAME.line_distortion/GAME.scale;
GAME.hud = {};
GAME.hud.line_distortion = 2;
GAME.hud.target_scale = 1;
GAME.hud.scale = 0;
GAME.hud.lja = GAME.hud.line_distortion/GAME.hud.scale;
GAME.living_stars = [];
GAME.init = function() {
TEXT.update(this.screen_text);
this.game_over = false;
this.game_pause = false;
this.started_once = true;
this.game_mode = MENU.selected_game_mode;
this.living_stars = [];
this.hud.scale = 0;
this.hud.lja = this.hud.line_distortion/this.hud.scale;
GAME.scale = 0;
GAME.lja = GAME.line_distortion/GAME.scale;
r_count = 0;
g_count = 0;
b_count = 0;
this.goto_map_animation_stages[0].switch = true;
this.goto_map_animation_stages[1].switch = false;
this.goto_map_animation_stages[2].switch = false;
this.goto_map_animation_stages[0].accu = 0;
this.goto_map_animation_stages[1].player_speed = 0;
this.goto_map_animation_stages[1].cam_speed = 0;
this.goto_map_animation_stages[2].accu = 0;
this.cam.x = 0;
this.cam.y = 0;
this.cam.z = -12;
this.cam.ah = 0;
this.cam.av = Math.PI/2;
this.enems = [];
this.items = [];
this.player.x = 40;
this.player.score.value = 0;
this.player.base_score = 0;
this.player.bullet_count.value = 120;
this.player.big_bullet_count.value = 8;
this.player.is_alive = true;
this.player.lifes.value = 3;
this.player.revive_anim_stages[0].accu = 0;
this.player.revive_anim_stages[1].accu = 0;
this.player.revive_anim_stages[0].switch = true;
this.player.revive_anim_stages[1].switch = false;
this.player.is_reviving = false;
this.player.color = {r:255,g:255,b:255};
this.map.level_start_timer.accu = 0;
this.player.current_rail = this.map.levels[this.map.current_level].starting_rail;
this.update_rail_position(this.player);
for (var i = 0; i < this.map.levels[this.map.current_level].item_probability.length; i++) {
var freq = this.map.levels[this.map.current_level].item_probability[i].spawn_freq;
var margin = this.map.levels[this.map.current_level].item_probability[i].freq_margin;
var rand_ = Math.round(Math.random() * margin);
this.item[i].spawn_freq_ = freq + ((margin/2)-rand_);
this.item[i].spawn_freq_accu = 0;
}
for (var i = 0; i < this.map.levels[this.map.current_level].enem_probability.length; i++) {
var freq = this.map.levels[this.map.current_level].enem_probability[i].spawn_freq;
var margin = this.map.levels[this.map.current_level].enem_probability[i].freq_margin;
var rand_ = Math.round(Math.random() * margin);
this.enem[i].spawn_freq_ = freq + ((margin/2)-rand_);
this.enem[i].spawn_freq_accu = 0;
}
for (var i = 0; i < this.map.levels[this.map.current_level].rails.length; i++) {
this.map.levels[this.map.current_level].rails[i].item_bullets = [];
this.map.levels[this.map.current_level].rails[i].player_bullets = [];
this.map.levels[this.map.current_level].rails[i].enem_bullets = [];
this.map.levels[this.map.current_level].rails[i].big_bullets = [];
this.map.levels[this.map.current_level].rails[i].spike = 0;
}
this.effect_lines = [];
if (this.map.levels[this.map.current_level].allow_spikes) {
var freq = this.map.levels[this.map.current_level].spikes_probability.spawn_freq;
var margin = this.map.levels[this.map.current_level].spikes_probability.freq_margin;
var rand_ = Math.round(Math.random() * margin);
this.spawn_spike_freq = freq + ((margin/2)-rand_);
this.spawn_spike_accu = 0;
}
this.stars_add_speed = 0;
}
GAME.goto_map = function(map_level) {
this.scale = 0;
this.lja = this.line_distortion/this.scale;
r_count = 0;
g_count = 0;
b_count = 0;
this.goto_map_animation_stages[0].switch = true;
this.goto_map_animation_stages[1].switch = false;
this.goto_map_animation_stages[2].switch = false;
this.goto_map_animation_stages[0].accu = 0;
this.goto_map_animation_stages[1].player_speed = 0;
this.goto_map_animation_stages[1].cam_speed = 0;
this.goto_map_animation_stages[2].accu = 0;
this.cam.x = 0;
this.cam.y = 0;
this.cam.z = -12;
this.cam.ah = 0;
this.cam.av = Math.PI/2;
this.enems = [];
this.items = [];
this.player.x = 40;
this.player.base_score = this.player.score.value;
this.player.current_level.value = map_level+1;
this.player.revive_anim_stages[0].accu = 0;
this.player.revive_anim_stages[1].accu = 0;
this.player.revive_anim_stages[0].switch = true;
this.player.revive_anim_stages[1].switch = false;
this.player.is_reviving = false;
this.player.color = {r:255,g:255,b:255};
this.map.current_level = map_level;
this.map.level_start_timer.accu = 0;
this.player.current_rail = this.map.levels[this.map.current_level].starting_rail;
this.update_rail_position(this.player);
for (var i = 0; i < this.map.levels[this.map.current_level].item_probability.length; i++) {
var freq = this.map.levels[this.map.current_level].item_probability[i].spawn_freq;
var margin = this.map.levels[this.map.current_level].item_probability[i].freq_margin;
var rand_ = Math.round(Math.random() * margin);
this.item[i].spawn_freq_ = freq + ((margin/2)-rand_);
this.item[i].spawn_freq_accu = 0;
}
for (var i = 0; i < this.map.levels[this.map.current_level].enem_probability.length; i++) {
var freq = this.map.levels[this.map.current_level].enem_probability[i].spawn_freq;
var margin = this.map.levels[this.map.current_level].enem_probability[i].freq_margin;
var rand_ = Math.round(Math.random() * margin);
this.enem[i].spawn_freq_ = freq + ((margin/2)-rand_);
this.enem[i].spawn_freq_accu = 0;
}
for (var i = 0; i < this.map.levels[this.map.current_level].rails.length; i++) {
this.map.levels[this.map.current_level].rails[i].item_bullets = [];
this.map.levels[this.map.current_level].rails[i].player_bullets = [];
this.map.levels[this.map.current_level].rails[i].enem_bullets = [];
this.map.levels[this.map.current_level].rails[i].big_bullets = [];
this.map.levels[this.map.current_level].rails[i].spike = 0;
}
this.effect_lines = [];
if (this.map.levels[this.map.current_level].allow_spikes) {
var freq = this.map.levels[this.map.current_level].spikes_probability.spawn_freq;
var margin = this.map.levels[this.map.current_level].spikes_probability.freq_margin;
var rand_ = Math.round(Math.random() * margin);
this.spawn_spike_freq = freq + ((margin/2)-rand_);
this.spawn_spike_accu = 0;
}
}
GAME.update_rail_position = function(object_) {
object_.z = this.map.z + this.map.levels[this.map.current_level].rails[Math.round(object_.current_rail)].z;
object_.y = this.map.y + this.map.levels[this.map.current_level].rails[Math.round(object_.current_rail)].y;
}
GAME.update_rail_position(GAME.player);
GAME.spawn_new_enem = function(new_enem_index) {
var enem_types = this.map.levels[this.map.current_level].enem_types;
var new_enem = JSON.stringify(this.enem[enem_types[new_enem_index]]);
new_enem = JSON.parse(new_enem);
new_enem.current_rail = Math.floor(Math.random() * this.map.levels[this.map.current_level].rails.length);
new_enem.speed = Math.floor(Math.random() * (new_enem.max_speed - new_enem.min_speed) + new_enem.min_speed);
new_enem.frame_switch_accu = Math.round(Math.random() * new_enem.frame_switch_speed);
var rail_switch_speed = this.map.levels[this.map.current_level].enem_probability[new_enem_index].rail_switch_speed;
var rail_switch_speed_margin = this.map.levels[this.map.current_level].enem_probability[new_enem_index].rail_switch_speed_margin;
if (rail_switch_speed != -1) {
var rand_ = Math.round(Math.random() * rail_switch_speed_margin);
new_enem.rail_switch_speed = rail_switch_speed + ((rail_switch_speed_margin/2)-rand_);
new_enem.rail_switch_accu = Math.round(Math.random() * rail_switch_speed);
} else {
new_enem.rail_switch_speed = rail_switch_speed;
}
if (new_enem.fire_type != -1) {
var fire_rate = this.map.levels[this.map.current_level].enem_probability[new_enem_index].fire_rate;
var fire_rate_margin = this.map.levels[this.map.current_level].enem_probability[new_enem_index].fire_rate_margin;
var rand_ = Math.round(Math.random() * fire_rate_margin);
new_enem.fire_rate = fire_rate + ((fire_rate_margin/2)-rand_);
}
if (new_enem.big_bullet_type != -1) {
var big_bullet_fire_rate = this.map.levels[this.map.current_level].enem_probability[new_enem_index].big_bullet_fire_rate;
var big_bullet_fire_rate_margin = this.map.levels[this.map.current_level].enem_probability[new_enem_index].big_bullet_fire_rate_margin;
var rand_ = Math.round(Math.random() * big_bullet_fire_rate_margin);
new_enem.big_bullet_fire_rate = big_bullet_fire_rate + ((big_bullet_fire_rate_margin/2)-rand_);
}
if (this.map.allow_rotate[this.map.current_level]) {
new_enem.direction = this.map.levels[this.map.current_level].direction;
} else {
new_enem.direction = (Math.round(Math.random()))?true:false;
}
new_enem.x = this.level_depth;
this.enems.push(new_enem);
}
GAME.spawn_new_item = function(new_item_index) {
var item_types = this.map.levels[this.map.current_level].item_types;
var new_item = JSON.stringify(this.item[item_types[new_item_index]]);
new_item = JSON.parse(new_item);
new_item.current_rail = Math.floor(Math.random() * this.map.levels[this.map.current_level].rails.length);
var speed = this.map.levels[this.map.current_level].item_probability[new_item_index].speed;
var margin = this.map.levels[this.map.current_level].item_probability[new_item_index].speed_margin;
var rand_ = Math.round(Math.random() * margin);
new_item.speed = speed + ((margin/2)-rand_);
new_item.frame_switch_accu = Math.round(Math.random() * new_item.frame_switch_speed);
var rail_switch_speed = this.map.levels[this.map.current_level].item_probability[new_item_index].rail_switch_speed;
var rail_switch_speed_margin = this.map.levels[this.map.current_level].item_probability[new_item_index].rail_switch_speed_margin;
if (rail_switch_speed != -1) {
var rand_ = Math.round(Math.random() * rail_switch_speed_margin);
new_item.rail_switch_speed = rail_switch_speed + ((rail_switch_speed_margin/2)-rand_);
new_item.rail_switch_accu = Math.round(Math.random() * rail_switch_speed);
} else {
new_item.rail_switch_speed = rail_switch_speed;
}
new_item.x = this.level_depth;
this.items.push(new_item);
}
GAME.get_line_middle = function(x, y, z, x0, y0, z0, x1, y1, z1) {
var new_point = {};
var a = get_angle(x0, y0, x1, y1);
var d = get_distance(x0, y0, x1, y1)/2;
new_point.x = x + x0 + Math.cos(a) * d;
new_point.y = y + y0 + Math.sin(a) * d;
var a = get_angle(z0, y0, z1, y1);
var d = get_distance(z0, y0, z1, y1)/2;
new_point.z = z + z0 + Math.cos(a) * d;
new_point.y = y + y0 + Math.sin(a) * d;
return new_point;
}
GAME.convert_line_to_explosion = function(x, y, z, x0, y0, z0, x1, y1, z1, speed, color, fadeout_speed, duration) {
var new_point = this.get_line_middle(x, y, z, x0, y0, z0, x1, y1, z1);
x0 = new_point.x - x - x0;
y0 = new_point.y - y - y0;
z0 = new_point.z - z - z0;
x1 = new_point.x - x - x1;
y1 = new_point.y - y - y1;
z1 = new_point.z - z - z1;
var rotation_speed_ah = (Math.random() * 0.03) * ((Math.random()>0.5)?1:-1);
var rotation_speed_av = (Math.random() * 0.03) * ((Math.random()>0.5)?1:-1);
var direction_ah = Math.random() * (Math.PI*2);
var direction_av = Math.random() * (Math.PI*2);
var direction_speed = Math.random() * 0.1;
var new_line_data = {
x: new_point.x,
y: new_point.y,
z: new_point.z,
speed: speed,
duration: duration,
color: color,
fadeout_speed: fadeout_speed,
line: [{x:x0,y:y0,z:z0},{x:x1,y:y1,z:z1}],
accu: 0,
rotation_ah: Math.PI/2,
rotation_av: Math.PI/2,
rotation_speed_ah: rotation_speed_ah,
rotation_speed_av: rotation_speed_av,
direction_ah: direction_ah,
direction_av: direction_av,
direction_speed: direction_speed,
};
return new_line_data;
}
GAME.add_end_animation = function(obj, current_bullet = null) {
for (var i = 0; i < obj.lines[obj.current_frame].length; i++) {
var x0 = obj.lines[obj.current_frame][i][0].x;
var y0 = obj.lines[obj.current_frame][i][0].y;
var z0 = obj.lines[obj.current_frame][i][0].z;
var x1 = obj.lines[obj.current_frame][i][1].x;
var y1 = obj.lines[obj.current_frame][i][1].y;
var z1 = obj.lines[obj.current_frame][i][1].z;
x0 /= 2;
y0 /= 2;
z0 /= 2;
x1 /= 2;
y1 /= 2;
z1 /= 2;
var rotated_line = this.rotate_line(
this.map.levels[this.map.current_level].rails[Math.round(obj.current_rail)].a,
y0, z0, y1, z1
);
y0 = rotated_line.x0;
z0 = rotated_line.y0;
y1 = rotated_line.x1;
z1 = rotated_line.y1;
var new_line_data = this.convert_line_to_explosion(
obj.x,
obj.y,
obj.z,
x0, y0, z0, x1, y1, z1,
obj.speed,
obj.color,
0.3,
80
);
this.effect_lines.push(new_line_data);
}
if (current_bullet === null) {
return;
}
for (var i = 0; i < current_bullet.lines.length; i++) {
var x0 = current_bullet.lines[i][0].x;
var y0 = current_bullet.lines[i][0].y;
var z0 = current_bullet.lines[i][0].z;
var x1 = current_bullet.lines[i][1].x;
var y1 = current_bullet.lines[i][1].y;
var z1 = current_bullet.lines[i][1].z;
x0 /= 2;
y0 /= 2;
z0 /= 2;
x1 /= 2;
y1 /= 2;
z1 /= 2;
var rotated_line = this.rotate_line(
this.map.levels[this.map.current_level].rails[Math.round(obj.current_rail)].a,
y0, z0, y1, z1
);
y0 = rotated_line.x0;
z0 = rotated_line.y0;
y1 = rotated_line.x1;
z1 = rotated_line.y1;
var new_line_data = this.convert_line_to_explosion(
obj.x,
obj.y,
obj.z,
x0, y0, z0, x1, y1, z1,
obj.speed,
obj.color,
0.3,
80
);
this.effect_lines.push(new_line_data);
}
}
GAME.spawn_player_bullet = function() {
var new_bullet = JSON.stringify(this.bullet[this.player.bullet_type]);
new_bullet = JSON.parse(new_bullet);
new_bullet.x = this.player.x + 8;
new_bullet.y = this.player.y;
new_bullet.z = this.player.z;
new_bullet.speed += this.goto_map_animation_stages[1].player_speed;
this.map.levels[this.map.current_level].rails[Math.round(this.player.current_rail)].player_bullets.push(new_bullet);
}
GAME.spawn_spike = function(rail) {
var new_spike = JSON.stringify(this.spike);
new_spike = JSON.parse(new_spike);
new_spike.x = this.map.levels[this.map.current_level].rails[rail].x + this.level_depth;
new_spike.y = this.map.levels[this.map.current_level].rails[rail].y;
new_spike.z = this.map.levels[this.map.current_level].rails[rail].z;
var speed = this.map.levels[this.map.current_level].spikes_probability.speed;
var speed_margin = this.map.levels[this.map.current_level].spikes_probability.speed_margin;
var rand_ = Math.round(Math.random() * speed_margin);
new_spike.speed = speed + ((speed_margin/2)-rand_);
var stop_position = this.map.levels[this.map.current_level].spikes_probability.stop_position;
var stop_position_margin = this.map.levels[this.map.current_level].spikes_probability.stop_position_margin;
var rand_ = Math.round(Math.random() * stop_position_margin);
new_spike.stop_position = stop_position + ((stop_position_margin/2)-rand_);
this.map.levels[this.map.current_level].rails[rail].spike = new_spike;
}
GAME.spawn_enem_bullet = function(enem) {
var new_bullet = JSON.stringify(this.bullet[enem.bullet_type]);
new_bullet = JSON.parse(new_bullet);
new_bullet.x = enem.x;
new_bullet.y = enem.y;
new_bullet.z = enem.z;
this.map.levels[this.map.current_level].rails[Math.round(enem.current_rail)].enem_bullets.push(new_bullet);
}
GAME.spawn_player_big_bullet = function(big_bullet_type) {
var new_bullet = JSON.stringify(this.big_bullet[big_bullet_type]);
new_bullet = JSON.parse(new_bullet);
new_bullet.current_rail = Math.round(this.player.current_rail);
new_bullet.is_enem_bullet = false;
this.map.levels[this.map.current_level].rails[Math.round(this.player.current_rail)].big_bullets.push(new_bullet);
}
GAME.spawn_enem_big_bullet = function(obj, big_bullet_type) {
var new_bullet = JSON.stringify(this.big_bullet[big_bullet_type]);
new_bullet = JSON.parse(new_bullet);
new_bullet.current_rail = obj.current_rail;
new_bullet.is_enem_bullet = true;
this.map.levels[this.map.current_level].rails[Math.round(obj.current_rail)].big_bullets.push(new_bullet);
}
GAME.update_player_movement = function() {
if (KEY_CHECK.key(KEY_CHECK.LEFT)) {
KEY_CHECK.frame_count0++;
if (KEY_CHECK.frame_count0 >= 10) {
KEY_CHECK.frame_count1++;
if (KEY_CHECK.frame_count1 == KEY_CHECK.fast_repeate) {
this.player.current_rail = Math.round(this.player.current_rail)-1;
KEY_CHECK.frame_count1 = 0;
}
KEY_CHECK.frame_count0 = 10;
}
if (KEY_CHECK.one) {
this.player.current_rail = Math.round(this.player.current_rail)-1;
KEY_CHECK.one = false;
}
this.player.current_rail -= 0.1;
if (Math.round(this.player.current_rail) < 0) {
if (this.map.allow_rotate[this.map.current_level]) {
this.player.current_rail = this.map.levels[this.map.current_level].lines.length-1;
} else {
this.player.current_rail = 0;
}
}
this.update_rail_position(this.player);
} else if (KEY_CHECK.key(KEY_CHECK.RIGHT)) {
KEY_CHECK.frame_count0++;
if (KEY_CHECK.frame_count0 >= 10) {
KEY_CHECK.frame_count1++;
if (KEY_CHECK.frame_count1 == KEY_CHECK.fast_repeate) {
this.player.current_rail = Math.round(this.player.current_rail)+1;
KEY_CHECK.frame_count1 = 0;
}
KEY_CHECK.frame_count0 = 10;
}
if (KEY_CHECK.one) {
this.player.current_rail = Math.round(this.player.current_rail)+1;
KEY_CHECK.one = false;
}
this.player.current_rail += 0.1;
if (Math.round(this.player.current_rail) > this.map.levels[this.map.current_level].lines.length-1) {
if (this.map.allow_rotate[this.map.current_level]) {
this.player.current_rail = 0;
} else {
this.player.current_rail = this.map.levels[this.map.current_level].lines.length-1;
}
}
this.update_rail_position(this.player);
} else if (KEY_CHECK.frame_count0 != 0 || KEY_CHECK.frame_count1 != 0 || KEY_CHECK.one != true) {
KEY_CHECK.frame_count0 = 0;
KEY_CHECK.frame_count1 = 0;
KEY_CHECK.one = true;
}
if (this.player.bullet_count.value > 0 && KEY_CHECK.key(KEY_CHECK.FIRE)) {
if (this.player.rapidfire_accu++ >= this.player.rapidfire_speed) {
this.spawn_player_bullet();
this.player.rapidfire_accu = 0;
if (!this.player.is_unlimited_ammo) {
this.player.bullet_count.value--;
}
}
} else {
this.player.rapidfire_accu = this.player.rapidfire_speed;
}
if (this.player.big_bullet_count.value > 0 && KEY_CHECK.key(KEY_CHECK.SEC_FIRE, false)) {
this.spawn_player_big_bullet(this.player.big_bullet_type);
if (!this.player.is_unlimited_ammo) {
this.player.big_bullet_count.value--;
}
}
}
GAME.goto_next_level_animation = function() {
if (!this.player.is_alive) {
return;
}
if (this.goto_map_animation_stages[0].switch) {
if (this.goto_map_animation_stages[0].accu ++ > this.goto_map_animation_stages[0].count) {
this.goto_map_animation_stages[0].switch = false;
this.goto_map_animation_stages[1].switch = true;
}
this.update_player_movement();
}
if (this.goto_map_animation_stages[1].switch) {
if (this.goto_map_animation_stages[1].player_speed < this.goto_map_animation_stages[1].player_max_speed) {
this.goto_map_animation_stages[1].player_speed += this.goto_map_animation_stages[1].player_speed_increment;
}
if (this.goto_map_animation_stages[1].cam_speed < this.goto_map_animation_stages[1].cam_max_speed) {
this.goto_map_animation_stages[1].cam_speed += this.goto_map_animation_stages[1].cam_speed_increment;
}
if (this.player.x < this.level_depth) {
this.update_player_movement();
} else {
this.goto_map_animation_stages[2].switch = true;
for (var i = 0; i < this.enems.length; i++) {
this.add_end_animation(this.enems[i]);
this.enems.splice(i, 1);
i--;
}
for (var i = 0; i < this.items.length; i++) {
this.add_end_animation(this.items[i]);
this.items.splice(i, 1);
i--;
}
}
if (this.player.x < 5000) {
this.player.x += this.goto_map_animation_stages[1].player_speed;
}
if (this.cam.x < 4900) {
this.cam.x += this.goto_map_animation_stages[1].cam_speed;
}
this.stars_add_speed += this.goto_map_animation_stages[1].stars_increase_speed;
}
if (this.goto_map_animation_stages[2].switch) {
if (this.player.color.r > 0) {
this.player.color.r -= this.goto_map_animation_stages[2].fadeout_speed;
this.player.color.g -= this.goto_map_animation_stages[2].fadeout_speed;
this.player.color.b -= this.goto_map_animation_stages[2].fadeout_speed;
}
if (this.goto_map_animation_stages[2].accu++ > this.goto_map_animation_stages[2].count) {
this.goto_map(this.map.current_level+1);
}
}
}
GAME.update_debug_mode_controls = function() {
if (KEY_CHECK.key(KEY_CHECK.CAMERA_MOVE_UP)) {
var ch = Math.cos(this.debug_cam.ah);
var sh = Math.sin(this.debug_cam.ah);
var cv = Math.cos(this.debug_cam.av);
this.debug_cam.x = this.debug_cam.x + ch * 2;
this.debug_cam.y = this.debug_cam.y + sh * 2;
this.debug_cam.z = this.debug_cam.z + cv * 2;
} else if (KEY_CHECK.key(KEY_CHECK.CAMERA_MOVE_DOWN)) {
var ch = Math.cos(this.debug_cam.ah);
var sh = Math.sin(this.debug_cam.ah);
var cv = Math.cos(this.debug_cam.av);
this.debug_cam.x = this.debug_cam.x - ch * 2;
this.debug_cam.y = this.debug_cam.y - sh * 2;
this.debug_cam.z = this.debug_cam.z - cv * 2;
}
if (KEY_CHECK.key(KEY_CHECK.STRAFING_LEFT)) {
this.debug_cam.x = this.debug_cam.x - Math.cos(this.debug_cam.ah+(Math.PI/2)) * 2;
this.debug_cam.y = this.debug_cam.y - Math.sin(this.debug_cam.ah+(Math.PI/2)) * 2;
} else if (KEY_CHECK.key(KEY_CHECK.STRAFING_RIGHT)) {
this.debug_cam.x = this.debug_cam.x - Math.cos(this.debug_cam.ah-(Math.PI/2)) * 2;
this.debug_cam.y = this.debug_cam.y - Math.sin(this.debug_cam.ah-(Math.PI/2)) * 2;
}
if (KEY_CHECK.key(KEY_CHECK.CAMERA_MOVE_LEFT)) {
this.debug_cam.ah -= 0.02;
} else if (KEY_CHECK.key(KEY_CHECK.CAMERA_MOVE_RIGHT)) {
this.debug_cam.ah += 0.02;
}
if (KEY_CHECK.key(KEY_CHECK.UP)) {
this.debug_cam.av -= 0.02;
} else if (KEY_CHECK.key(KEY_CHECK.DOWN)) {
this.debug_cam.av += 0.02;
}
if (KEY_CHECK.key(KEY_CHECK.STRAFING_UP)) {
this.debug_cam.z += 2;
} else if (KEY_CHECK.key(KEY_CHECK.STRAFING_DOWN)) {
this.debug_cam.z -= 2;
}
}
GAME.bullet_hit_detection_player_to_enem = function(bullet, enemy) {
if (enemy.x == bullet.x) {
return false;
}
if (enemy.x <= bullet.x && enemy.x >= bullet.x - bullet.speed) {
return false;
}
return true;
}
GAME.bullet_hit_detection_enem_to_player = function(player, bullet) {
if (player.x == bullet.x) {
return false;
}
if (player.x + player.width == bullet.x) {
return false;
}
if (player.x <= bullet.x && player.x >= bullet.x - bullet.speed) {
return false;
}
if (bullet.x <= player.x + player.width && bullet.x >= player.x) {
return false;
}
return true;
}
GAME.body_hit_detection_player_to_enem = function(player, enemy) {
if (enemy.x == player.x) {
return false;
}
if (enemy.x == player.x + player.width) {
return false;
}
if (enemy.x <= player.x && enemy.x >= player.x - player.speed) {
return false;
}
if (enemy.x <= player.x + player.width && enemy.x >= player.x) {
return false;
}
return true;
}
GAME.revive_player = function() {
this.player.is_reviving = true;
if (this.player.revive_anim_stages[0].switch) {
if (this.player.revive_anim_stages[0].accu++ > this.player.revive_anim_stages[0].count) {
this.player.is_alive = true;
this.player.revive_anim_stages[0].accu = 0;
this.player.revive_anim_stages[0].switch = false;
this.player.revive_anim_stages[1].switch = true;
if (this.stars_add_speed_ > 0) {
this.stars_add_speed = this.stars_add_speed_;
this.stars_add_speed_ = 0;
}
}
}
if (this.player.revive_anim_stages[1].switch) {
if (this.player.revive_anim_stages[1].accu++ > this.player.after_revive_god_time) {
this.player.color = {r:255,g:255,b:255};
this.player.is_reviving = false;
this.player.revive_anim_stages[1].accu = 0;
this.player.revive_anim_stages[1].switch = false;
this.player.revive_anim_stages[0].switch = true;
}
}
}
GAME.update = function() {
r_count++;
g_count++;
b_count++;
if (!this.menu_pause && this.player.is_debug_mode) {
this.update_debug_mode_controls();
}
if (!this.menu_pause && KEY_CHECK.key(KEY_CHECK.DEBUG_MODE, false)) {
this.player.is_debug_mode = !this.player.is_debug_mode;
if (this.player.is_debug_mode) {
this.debug_cam.x = this.cam.x;
this.debug_cam.y = this.cam.y;
this.debug_cam.z = this.cam.z;
this.debug_cam.ah = this.cam.ah;
this.debug_cam.av = this.cam.av;
}
}
if (!this.menu_pause && KEY_CHECK.key(KEY_CHECK.PAUSE, false)) {
this.game_pause = !this.game_pause;
}
if (!this.menu_pause && KEY_CHECK.key(KEY_CHECK.ENTER, false)) {
GSM.change_scene_to(2);
}
if (this.menu_pause || this.game_pause) {
return;
}
if (this.scale < this.target_scale) {
this.scale += (this.target_scale - this.scale) / 100;
if (this.target_scale - this.scale < 0.001) {
this.scale = this.target_scale;
}
this.lja = this.line_distortion*this.scale;
}
if (this.hud.scale < this.hud.target_scale) {
this.hud.scale += (this.hud.target_scale - this.hud.scale) / 100;
if (this.hud.target_scale - this.hud.scale < 0.001) {
this.hud.scale = this.hud.target_scale;
}
this.hud.lja = this.hud.line_distortion*this.hud.scale;
}
STARS.update(this.living_stars);
if (this.player.is_reviving) {
this.revive_player();
}
if (!this.player.is_debug_mode) {
// Update camera following player movements.
var cam_z = this.map.levels[this.map.current_level].cam_positions[Math.round(this.player.current_rail)].z;
var cam_y = this.map.levels[this.map.current_level].cam_positions[Math.round(this.player.current_rail)].y;
if (this.cam.y < cam_y-0.5 || this.cam.y > cam_y+0.5
|| this.cam.z < cam_z-0.5 || this.cam.z > cam_z+0.5)
{
var a = get_angle(this.cam.z, this.cam.y, cam_z, cam_y);
var d = get_distance(this.cam.z, this.cam.y, cam_z, cam_y);
this.cam.y = this.cam.y + Math.sin(a) * (d / this.cam.speed);
this.cam.z = this.cam.z + Math.cos(a) * (d / this.cam.speed);
}
}
var player_score = this.player.score.value;
var next_map_score = this.player.base_score + this.map.levels[this.map.current_level].goto_next_level_score;
var goto_next_level = this.game_mode == 0 && this.player.is_alive && next_map_score != this.player.base_score && player_score >= next_map_score;
if (goto_next_level) {
this.goto_next_level_animation();
}
if (!goto_next_level && this.stars_add_speed > 0) {
this.stars_add_speed -= this.goto_map_animation_stages[1].stars_decrease_speed;
if (this.stars_add_speed < 0.1) {
this.stars_add_speed = 0;
}
}
if (this.map.level_start_timer.accu < this.map.level_start_timer.count) {
this.map.level_start_timer.accu++;
}
var level_is_started = this.map.level_start_timer.accu == this.map.level_start_timer.count;
if (!goto_next_level && this.player.is_alive) {
this.update_player_movement();
}
if (level_is_started) {
// Spawn new enems.
var enem_types = this.map.levels[this.map.current_level].enem_types;
var new_enem_index = Math.floor(Math.random() * enem_types.length);
if (!goto_next_level && this.enem[enem_types[new_enem_index]].spawn_freq_accu++ >= this.enem[enem_types[new_enem_index]].spawn_freq_) {
this.enem[enem_types[new_enem_index]].spawn_freq_accu = 0;
var freq = this.map.levels[this.map.current_level].enem_probability[new_enem_index].spawn_freq;
var margin = this.map.levels[this.map.current_level].enem_probability[new_enem_index].freq_margin;
var rand_ = Math.round(Math.random() * margin);
this.enem[enem_types[new_enem_index]].spawn_freq_ = freq + ((margin/2)-rand_);
if (this.enems.length < this.map.levels[this.map.current_level].enem_limit) {
this.spawn_new_enem(new_enem_index);
}
}
// Spawn new items.
var item_types = this.map.levels[this.map.current_level].item_types;
var new_item_index = Math.floor(Math.random() * item_types.length);
if (!goto_next_level && this.item[item_types[new_item_index]].spawn_freq_accu++ >= this.item[item_types[new_item_index]].spawn_freq_) {
this.item[item_types[new_item_index]].spawn_freq_accu = 0;
var freq = this.map.levels[this.map.current_level].item_probability[new_item_index].spawn_freq;
var margin = this.map.levels[this.map.current_level].item_probability[new_item_index].freq_margin;
var rand_ = Math.round(Math.random() * margin);
this.item[item_types[new_item_index]].spawn_freq_ = freq + ((margin/2)-rand_);
if (this.items.length < this.map.levels[this.map.current_level].item_limit) {
this.spawn_new_item(new_item_index);
}
}
// Spawn spikes.
if (!goto_next_level && this.map.levels[this.map.current_level].allow_spikes) {
if (this.spawn_spike_accu++ > this.spawn_spike_freq) {
this.spawn_spike_accu = 0;
var freq = this.map.levels[this.map.current_level].spikes_probability.spawn_freq;
var margin = this.map.levels[this.map.current_level].spikes_probability.freq_margin;
var rand_ = Math.round(Math.random() * margin);
this.spawn_spike_freq = freq + ((margin/2)-rand_);
var rail = Math.floor(Math.random() * this.map.levels[this.map.current_level].rails.length);
if (this.map.levels[this.map.current_level].rails[rail].spike === 0) {
this.spawn_spike(rail);
}
}
}
}
for (var i = 0; i < this.items.length; i++) {
if (!goto_next_level) {
this.update_rail_position(this.items[i]);
this.items[i].x -= this.items[i].speed;
}
if (!goto_next_level && this.items[i].frame_switch_speed != -1) {
this.items[i].frame_switch_accu++;
if (this.items[i].frame_switch_accu >= this.items[i].frame_switch_speed) {
this.items[i].current_frame = (this.items[i].current_frame+1 < this.items[i].lines.length)?this.items[i].current_frame+1:0;
this.items[i].frame_switch_accu = 0;
}
}
if (!goto_next_level && this.items[i].rail_switch_speed != -1) {
this.items[i].rail_switch_accu++;
if (this.items[i].rail_switch_accu >= this.items[i].rail_switch_speed) {
if (this.map.levels[this.map.current_level].direction) {
this.items[i].current_rail = (this.items[i].current_rail > 0)?this.items[i].current_rail-1:this.map.levels[this.map.current_level].rails.length-1;
} else {
this.items[i].current_rail = (this.items[i].current_rail+1 < this.map.levels[this.map.current_level].rails.length)?this.items[i].current_rail+1:0;
}
this.items[i].rail_switch_accu = 0;
}
}
// Remove item when too close.
if (this.items[i].x <= 40) {
this.items.splice(i, 1);
i--;
continue;
}
// Remove item and add amount.
if (this.player.is_alive && this.items[i].current_rail == Math.round(this.player.current_rail)) {
if (this.items[i].x <= this.player.x + this.player.width) {
this.player.bullet_count.value += this.items[i].bullet_amount;
this.player.big_bullet_count.value += this.items[i].big_bullet_amount;
this.items.splice(i, 1);
i--;
continue;
}
}
}
if (this.map.levels[this.map.current_level].allow_spikes) {
for (var u = 0; u < this.map.levels[this.map.current_level].rails.length; u++) {
if (this.map.levels[this.map.current_level].rails[u].spike === 0) {
continue;
}
var spike = this.map.levels[this.map.current_level].rails[u].spike;
if (this.player.is_god && this.player.x > spike.x) {
this.map.levels[this.map.current_level].rails[u].spike = 0;
this.player.score.value += spike.add_score;
this.player.bullet_count.value += spike.add_bullets;
continue;
}
var player_bullets = this.map.levels[this.map.current_level].rails[u].player_bullets;
if (player_bullets.length != 0) {
var bullet = this.map.levels[this.map.current_level].rails[u].player_bullets[0];
if (bullet.x > spike.x) {
this.map.levels[this.map.current_level].rails[u].player_bullets.splice(0, 1);
spike.is_alive = false;
spike.x += spike.cut_amount;
this.player.score.value += spike.add_score;
this.player.bullet_count.value += spike.add_bullets;
if (spike.x > this.level_depth - 10) {
this.map.levels[this.map.current_level].rails[u].spike = 0;
continue;
}
}
}
for (var t = 0; t < this.map.levels[this.map.current_level].rails[u].big_bullets.length; t++) {
var big_bullet = this.map.levels[this.map.current_level].rails[u].big_bullets[t];
if (big_bullet.detonated) {
if (!big_bullet.is_enem_bullet) {
this.player.score.value += spike.add_score;
this.player.bullet_count.value += spike.add_bullets;
}
this.map.levels[this.map.current_level].rails[u].spike = 0;
break;
}
}
}
if (this.player.x < this.level_depth && !this.player.is_reviving && !this.player.is_god && this.player.is_alive) {
var spike = this.map.levels[this.map.current_level].rails[Math.round(this.player.current_rail)].spike;
if (spike !== 0 && this.player.x > spike.x) {
this.stars_add_speed = 0;
this.player.lifes.value = 0;
this.player.is_alive = false;
this.add_end_animation(this.player);
}
}
}
for (var i = 0; i < this.enems.length; i++) {
if (!goto_next_level) {
this.update_rail_position(this.enems[i]);
this.enems[i].x -= this.enems[i].speed;
}
if (!goto_next_level && this.enems[i].frame_switch_speed != -1) {
this.enems[i].frame_switch_accu++;
if (this.enems[i].frame_switch_accu >= this.enems[i].frame_switch_speed) {
this.enems[i].current_frame = (this.enems[i].current_frame+1 < this.enems[i].lines.length)?this.enems[i].current_frame+1:0;
this.enems[i].frame_switch_accu = 0;
}
}
if (!goto_next_level && this.enems[i].rail_switch_speed != -1) {
this.enems[i].rail_switch_accu++;
if (this.enems[i].rail_switch_accu >= this.enems[i].rail_switch_speed) {
if (this.map.allow_rotate[this.map.current_level]) {
if (this.enems[i].direction) {
this.enems[i].current_rail = (this.enems[i].current_rail > 0)?this.enems[i].current_rail-1:this.map.levels[this.map.current_level].rails.length-1;
} else {
this.enems[i].current_rail = (this.enems[i].current_rail+1 < this.map.levels[this.map.current_level].rails.length)?this.enems[i].current_rail+1:0;
}
} else {
if (this.enems[i].direction) {
this.enems[i].current_rail--;
} else {
this.enems[i].current_rail++;
}
if (this.enems[i].current_rail > this.map.levels[this.map.current_level].rails.length-1) {
this.enems[i].direction = !this.enems[i].direction;
this.enems[i].current_rail = this.map.levels[this.map.current_level].rails.length-1;
} else if (this.enems[i].current_rail < 0){
this.enems[i].direction = !this.enems[i].direction;
this.enems[i].current_rail = 0;
}
}
this.enems[i].rail_switch_accu = 0;
}
}
if (!goto_next_level && this.enems[i].fire_rate != -1) {
this.enems[i].fire_rate_accu++;
if (this.enems[i].fire_rate_accu >= this.enems[i].fire_rate) {
this.spawn_enem_bullet(this.enems[i]);
this.enems[i].fire_rate_accu = 0;
}
}
if (!goto_next_level && this.enems[i].big_bullet_type != -1) {
this.enems[i].big_bullet_rate_accu++;
if (this.enems[i].big_bullet_rate_accu >= this.enems[i].big_bullet_fire_rate) {
this.spawn_enem_big_bullet(this.enems[i], this.enems[i].big_bullet_type);
if (this.map.allow_rotate[this.map.current_level]) {
if (this.enems[i].direction) {
this.enems[i].current_rail = (this.enems[i].current_rail > 0)?this.enems[i].current_rail-1:this.map.levels[this.map.current_level].rails.length-1;
} else {
this.enems[i].current_rail = (this.enems[i].current_rail+1 < this.map.levels[this.map.current_level].rails.length)?this.enems[i].current_rail+1:0;
}
} else {
var old_rail = this.enems[i].current_rail;
if (this.enems[i].direction) {
this.enems[i].current_rail--;
} else {
this.enems[i].current_rail++;
}
if (this.enems[i].current_rail > this.map.levels[this.map.current_level].rails.length-1) {
this.enems[i].direction = !this.enems[i].direction;
this.enems[i].current_rail = this.map.levels[this.map.current_level].rails.length-1;
} else if (this.enems[i].current_rail < 0){
this.enems[i].direction = !this.enems[i].direction;
this.enems[i].current_rail = 0;
}
if (this.enems[i].current_rail == old_rail) {
if (this.enems[i].direction) {
this.enems[i].current_rail--;
} else {
this.enems[i].current_rail++;
}
if (this.enems[i].current_rail > this.map.levels[this.map.current_level].rails.length-1) {
this.enems[i].direction = !this.enems[i].direction;
this.enems[i].current_rail = this.map.levels[this.map.current_level].rails.length-1;
} else if (this.enems[i].current_rail < 0){
this.enems[i].direction = !this.enems[i].direction;
this.enems[i].current_rail = 0;
}
}
}
this.enems[i].big_bullet_rate_accu = 0;
this.enems[i].rail_switch_accu = 0;
}
}
// Remove enem when too close.
if (this.enems[i].x <= 40) {
this.enems.splice(i, 1);
i--;
continue;
}
// Remove enem and player when too close.
if (this.player.is_alive && this.enems[i].current_rail == Math.round(this.player.current_rail)) {
if (!this.body_hit_detection_player_to_enem(this.player, this.enems[i])) {
if (this.player.is_reviving || this.player.is_god) {
this.player.score.value += this.enems[i].add_score;
this.player.bullet_count.value += this.enems[i].add_bullets;
}
this.add_end_animation(this.enems[i]);
this.enems.splice(i, 1);
i--;
if (this.player.is_reviving || this.player.is_god) {
continue;
}
if (this.stars_add_speed > 0) {
this.stars_add_speed_ = this.stars_add_speed;
}
this.stars_add_speed = 0;
this.player.is_alive = false;
this.add_end_animation(this.player);
this.player.lifes.value -= 1;
if (this.player.lifes.value == 0) {
this.game_over = true;
continue;
}
this.revive_player();
continue;
}
}
// Bullet hit detection. Player to enem.
if (this.map.levels[this.map.current_level].rails[this.enems[i].current_rail].player_bullets.length > 0) {
var g = i;
for (var u = 0; u < this.map.levels[this.map.current_level].rails[this.enems[i].current_rail].player_bullets.length; u++) {
var current_bullet = this.map.levels[this.map.current_level].rails[this.enems[i].current_rail].player_bullets[u];
if (this.bullet_hit_detection_player_to_enem(current_bullet, this.enems[i])) {
continue;
}
this.enems[i].lifes -= 1;
if (this.enems[i].lifes < 1) {
this.player.score.value += this.enems[i].add_score;
this.player.bullet_count.value += this.enems[i].add_bullets;
this.add_end_animation(this.enems[i], current_bullet);
this.map.levels[this.map.current_level].rails[this.enems[i].current_rail].player_bullets.splice(u, 1);
this.enems.splice(i, 1);
i--;
break;
}
this.map.levels[this.map.current_level].rails[this.enems[i].current_rail].player_bullets.splice(u, 1);
u--;
continue;
}
if (i != g) {
continue;
}
}
for (var u = 0; u < this.map.levels[this.map.current_level].rails[this.enems[i].current_rail].big_bullets.length; u++) {
var big_bullet = this.map.levels[this.map.current_level].rails[this.enems[i].current_rail].big_bullets[u];
var detonated = big_bullet.detonated;
if (detonated === true) {
if (!big_bullet.is_enem_bullet) {
this.player.score.value += this.enems[i].add_score;
this.player.bullet_count.value += this.enems[i].add_bullets;
}
this.add_end_animation(this.enems[i]);
this.enems.splice(i, 1);
i--;
break;
}
}
}
// Bullet hit detection. enem to player.
for (var i = 0; i < this.map.levels[this.map.current_level].rails[Math.round(this.player.current_rail)].enem_bullets.length; i++) {
if (!this.player.is_alive || this.player.is_god || this.player.is_reviving) {
break;
}
var current_bullet = this.map.levels[this.map.current_level].rails[Math.round(this.player.current_rail)].enem_bullets[i];
if (this.bullet_hit_detection_enem_to_player(this.player, current_bullet)) {
continue;
}
if (this.stars_add_speed > 0) {
this.stars_add_speed_ = this.stars_add_speed;
}
this.stars_add_speed = 0;
this.player.is_alive = false;
this.add_end_animation(this.player, current_bullet);
this.map.levels[this.map.current_level].rails[Math.round(this.player.current_rail)].enem_bullets.splice(i, 1);
this.player.lifes.value -= 1;
if (this.player.lifes.value == 0) {
this.game_over = true;
break;
}
this.revive_player();
break;
}
for (var u = 0; u < this.map.levels[this.map.current_level].rails[Math.round(this.player.current_rail)].big_bullets.length; u++) {
if (!this.player.is_alive || this.player.is_god || this.player.is_reviving) {
break;
}
var detonated = this.map.levels[this.map.current_level].rails[Math.round(this.player.current_rail)].big_bullets[u].detonated;
if (detonated) {
this.player.is_alive = false;
if (this.stars_add_speed > 0) {
this.stars_add_speed_ = this.stars_add_speed;
}
this.stars_add_speed = 0;
this.add_end_animation(this.player);
this.player.lifes.value -= 1;
if (this.player.lifes.value == 0) {
this.game_over = true;
break;
}
this.revive_player();
break;
}
}
for (var i = 0; i < this.map.levels[this.map.current_level].rails.length; i++) {
if (!goto_next_level && this.map.levels[this.map.current_level].rails[i].spike !== 0) {
var stop_position = this.map.levels[this.map.current_level].rails[i].spike.stop_position;
var is_alive = this.map.levels[this.map.current_level].rails[i].spike.is_alive;
if (is_alive && this.map.levels[this.map.current_level].rails[i].spike.x > stop_position) {
var speed = this.map.levels[this.map.current_level].rails[i].spike.speed;
this.map.levels[this.map.current_level].rails[i].spike.x -= speed;
}
}
for (var u = 0; u < this.map.levels[this.map.current_level].rails[i].player_bullets.length; u++) {
this.map.levels[this.map.current_level].rails[i].player_bullets[u].x += this.map.levels[this.map.current_level].rails[i].player_bullets[u].speed;
if (this.map.levels[this.map.current_level].rails[i].player_bullets[u].x >= this.level_depth) {
this.map.levels[this.map.current_level].rails[i].player_bullets.splice(u, 1);
u--;
}
}
for (var u = 0; u < this.map.levels[this.map.current_level].rails[i].enem_bullets.length; u++) {
var speed = this.map.levels[this.map.current_level].rails[i].enem_bullets[u].speed;
this.map.levels[this.map.current_level].rails[i].enem_bullets[u].x -= speed;
if (this.map.levels[this.map.current_level].rails[i].enem_bullets[u].x <= 40) {
this.map.levels[this.map.current_level].rails[i].enem_bullets.splice(u, 1);
u--;
}
}
for (var u = 0; u < this.map.levels[this.map.current_level].rails[i].enem_bullets.length; u++) {
if (!goto_next_level) {
var speed = this.map.levels[this.map.current_level].rails[i].enem_bullets[u].speed;
this.map.levels[this.map.current_level].rails[i].enem_bullets[u].x -= speed;
}
if (this.map.levels[this.map.current_level].rails[i].enem_bullets[u].x <= 40) {
this.map.levels[this.map.current_level].rails[i].enem_bullets.splice(u, 1);
u--;
}
}
for (var u = 0; u < this.map.levels[this.map.current_level].rails[i].big_bullets.length; u++) {
var duration = this.map.levels[this.map.current_level].rails[i].big_bullets[u].duration;
var duration_accu = this.map.levels[this.map.current_level].rails[i].big_bullets[u].duration_accu++;
var detonate_time = this.map.levels[this.map.current_level].rails[i].big_bullets[u].detonate_time;
if (duration_accu >= duration) {
this.map.levels[this.map.current_level].rails[i].big_bullets.splice(u, 1);
u--;
continue;
}
if (duration_accu >= duration * detonate_time) {
this.map.levels[this.map.current_level].rails[i].big_bullets[u].detonated = true;
}
var new_r = Math.round(Math.random() * 255);
var new_g = Math.round(Math.random() * 255);
var new_b = Math.round(Math.random() * 255);
this.map.levels[this.map.current_level].rails[i].big_bullets[u].color.r = new_r;
this.map.levels[this.map.current_level].rails[i].big_bullets[u].color.g = new_g;
this.map.levels[this.map.current_level].rails[i].big_bullets[u].color.b = new_b;
}
}
for (var i = 0; i < this.effect_lines.length; i++) {
if (this.effect_lines[i].accu++ >= this.effect_lines[i].duration) {
this.effect_lines.splice(i, 1);
i--;
continue;
}
this.effect_lines[i].x -= this.effect_lines[i].speed;
this.effect_lines[i].rotation_ah += this.effect_lines[i].rotation_speed_ah;
this.effect_lines[i].rotation_av += this.effect_lines[i].rotation_speed_av