180 lines
3.7 KiB
C
180 lines
3.7 KiB
C
/*
|
|
* Metro Siberia 4 - A sequel to Dark Storm's Metro Siberia 3 for CASIO calculators.
|
|
* Copyright (C) 2015 Dark Storm
|
|
* Copyright (C) 2022 Mibi88
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* 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, see https://www.gnu.org/licenses/.
|
|
*/
|
|
|
|
#include "includes.h"
|
|
|
|
Ship ship;
|
|
static Vector smoke_cubes[5];
|
|
|
|
extern bopti_image_t map_1;
|
|
extern bopti_image_t timer_3;
|
|
extern bopti_image_t timer_2;
|
|
extern bopti_image_t timer_1;
|
|
extern bopti_image_t score_bar;
|
|
|
|
int score_delay;
|
|
|
|
int play_game(void)
|
|
{
|
|
int collision = 0, timer = 3, ticks = 0;
|
|
ship.score = 0;
|
|
init_ship();
|
|
ship.scrolling.x = 0;
|
|
ship.scrolling.y = 0;
|
|
for(int i = 0; i < 5; i++)
|
|
{
|
|
smoke_cubes[i].x = 0;
|
|
smoke_cubes[i].y = 0;
|
|
}
|
|
while(timer != 0){
|
|
dclear(C_WHITE);
|
|
calculate_tops();
|
|
dimage(-ship.scrolling.x, 0, &map_1);
|
|
draw();
|
|
if(timer == 3){
|
|
dimage(59, 25, &timer_3);
|
|
}else if(timer == 2){
|
|
dimage(59, 25, &timer_2);
|
|
}else if(timer == 1){
|
|
dimage(59, 25, &timer_1);
|
|
}
|
|
dupdate();
|
|
sleep_ms(1000);
|
|
timer--;
|
|
}
|
|
|
|
score_delay = 0;
|
|
ship.score = 0;
|
|
|
|
while(1)
|
|
{
|
|
clearevents();
|
|
if(keydown(KEY_SHIFT) || keydown(KEY_EXE)){ // Go up
|
|
ship.thrust = false;
|
|
}
|
|
if(keydown(KEY_EXIT)){
|
|
return 2;
|
|
}
|
|
sleep_ms(20);
|
|
calculate_tops();
|
|
dclear(C_WHITE);
|
|
collision = move();
|
|
if(ship.scrolling.x >= 3328){
|
|
return 1;
|
|
}
|
|
if(collision == 1){
|
|
return 0;
|
|
}
|
|
draw();
|
|
dupdate();
|
|
ship.thrust = true;
|
|
clearevents();
|
|
ticks++;
|
|
score_delay++;
|
|
if(ticks>=SMOKE_CUBES_SPACING)
|
|
{
|
|
for(int i=0;i<4;i++)
|
|
{
|
|
smoke_cubes[i].x = smoke_cubes[i+1].x;
|
|
smoke_cubes[i].y = smoke_cubes[i+1].y;
|
|
}
|
|
smoke_cubes[4].x = ship.scrolling.x + MARGIN;
|
|
smoke_cubes[4].y = ship.position.y;
|
|
ticks = 0;
|
|
}
|
|
|
|
if(score_delay>=SCORE_DELAY)
|
|
{
|
|
ship.score++;
|
|
score_delay=0;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void draw(void)
|
|
{
|
|
int i;
|
|
|
|
for(i = 0; i < 3; i++)
|
|
{
|
|
dline(ship.tops[i].x, ship.tops[i].y, ship.tops[(i + 1) % 3].x, ship.tops[(i + 1) % 3].y, C_BLACK);
|
|
}
|
|
|
|
for(i = 0; i < 5; i++)
|
|
{
|
|
drect_border(smoke_cubes[i].x-1 - ship.scrolling.x, smoke_cubes[i].y-1, smoke_cubes[i].x+1 - ship.scrolling.x, smoke_cubes[i].y+1, C_WHITE, 1, C_BLACK);
|
|
}
|
|
dimage(0, 0, &score_bar);
|
|
dprint_opt(1, 1, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "Score : %d", ship.score);
|
|
}
|
|
|
|
int move(void)
|
|
{
|
|
int i;
|
|
ship.acceleration.y = - GRAVITY * (float)(TIMER_PHYSIC) / 1000;
|
|
if(ship.thrust) ship.acceleration.y += THRUST * (float)(TIMER_PHYSIC) / 1000;
|
|
|
|
ship.speed.x += ship.acceleration.x;
|
|
ship.speed.y += ship.acceleration.y;
|
|
|
|
ship.position.x += ship.speed.x;
|
|
ship.position.y += ship.speed.y;
|
|
|
|
ship.scrolling.x = ship.position.x;
|
|
|
|
dimage(-ship.scrolling.x, 0, &map_1);
|
|
|
|
// collision
|
|
for(i=0;i<3;i++)
|
|
{
|
|
if(dgetpixel(ship.tops[i].x, ship.tops[i].y) == C_BLACK){
|
|
return 1;
|
|
}
|
|
if(ship.tops[i].y<0 || ship.tops[i].y>64){
|
|
return 1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
void calculate_tops(void)
|
|
{
|
|
Vector tmp;
|
|
float angle = 15.0;
|
|
int i;
|
|
|
|
angle = _atan(ship.speed.y / ship.speed.x);
|
|
|
|
init_tops();
|
|
|
|
for(i = 0; i < 3; i++)
|
|
{
|
|
tmp.x = ship.tops[i].x;
|
|
tmp.y = ship.tops[i].y;
|
|
|
|
ship.tops[i].x = tmp.x * cos(angle) + tmp.y * sin(angle);
|
|
ship.tops[i].y = tmp.y * cos(angle) - tmp.x * sin(angle);
|
|
|
|
ship.tops[i].x += MARGIN;
|
|
ship.tops[i].y += ship.position.y;
|
|
}
|
|
}
|