2023-08-31 09:58:35 +02:00
|
|
|
#include "../config.h"
|
2023-08-14 14:22:53 +02:00
|
|
|
|
2023-01-21 22:45:10 +01:00
|
|
|
#include "player.h"
|
|
|
|
#include "bullet.h"
|
2023-01-22 13:39:43 +01:00
|
|
|
#include "enemy.h"
|
2023-01-21 22:45:10 +01:00
|
|
|
#include <num/num.h>
|
|
|
|
#include <gint/rtc.h>
|
2023-08-31 09:58:35 +02:00
|
|
|
#include "../utilities/fast_trig.h"
|
2023-01-31 23:07:32 +01:00
|
|
|
#include "background.h"
|
2023-01-21 22:45:10 +01:00
|
|
|
|
2023-02-05 10:05:05 +01:00
|
|
|
|
|
|
|
extern bopti_image_t img_Lifebar;
|
2023-08-30 10:01:20 +02:00
|
|
|
extern bopti_image_t *img_mainship1;
|
|
|
|
|
|
|
|
extern bopti_image_t img_player_ship1;
|
|
|
|
extern bopti_image_t img_player_ship2;
|
|
|
|
extern bopti_image_t img_player_ship3;
|
|
|
|
extern bopti_image_t img_player_ship4;
|
|
|
|
extern bopti_image_t img_player_ship5;
|
|
|
|
extern bopti_image_t img_player_ship6;
|
|
|
|
extern bopti_image_t img_player_ship7;
|
|
|
|
extern bopti_image_t img_player_ship8;
|
|
|
|
|
2023-01-21 22:45:10 +01:00
|
|
|
extern bopti_image_t img_Satellite_Lvl1;
|
2023-01-31 23:07:32 +01:00
|
|
|
extern Background MyBackground;
|
|
|
|
|
2023-01-21 22:45:10 +01:00
|
|
|
Player::Player( int16_t _x, int16_t _y, uint8_t _id )
|
|
|
|
{
|
2023-08-30 10:01:20 +02:00
|
|
|
img_mainship1 = &img_player_ship7;
|
|
|
|
|
2023-01-22 23:20:16 +01:00
|
|
|
x = libnum::num(_x);
|
|
|
|
y = libnum::num(_y);
|
2023-01-21 22:45:10 +01:00
|
|
|
|
|
|
|
ID = _id;
|
|
|
|
|
2023-08-30 10:01:20 +02:00
|
|
|
width = img_mainship1->width/2;
|
|
|
|
height = img_mainship1->height/2;
|
2023-01-29 22:39:30 +01:00
|
|
|
speed = 10;
|
2023-01-21 22:45:10 +01:00
|
|
|
|
|
|
|
xmin = (int) x - width;
|
|
|
|
xmax = (int) x + width;
|
|
|
|
ymin = (int) y - height;
|
|
|
|
ymax = (int) y + height;
|
|
|
|
|
|
|
|
if (ID==0) life = 1000;
|
|
|
|
|
2023-01-22 11:07:36 +01:00
|
|
|
lastshoot0 = rtc_ticks();
|
2023-01-21 22:45:10 +01:00
|
|
|
lastshoot1 = rtc_ticks();
|
|
|
|
lastshoot2 = rtc_ticks();
|
|
|
|
|
|
|
|
satellites = true;
|
|
|
|
satLevel = 1;
|
2023-02-05 16:49:56 +01:00
|
|
|
satNumber = 3;
|
2023-01-21 22:45:10 +01:00
|
|
|
satAngle = 0;
|
|
|
|
satRadius = 50;
|
|
|
|
satSpeed = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player::~Player()
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::Update( float dt )
|
|
|
|
{
|
|
|
|
xmin = (int) x - width;
|
|
|
|
xmax = (int) x + width;
|
|
|
|
ymin = (int) y - height;
|
|
|
|
ymax = (int) y + height;
|
|
|
|
|
|
|
|
if(satellites)
|
|
|
|
{
|
|
|
|
satAngle += satSpeed * dt / 25000.0f;
|
|
|
|
if (satAngle>360.0f) satAngle-=360.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::Render( void )
|
|
|
|
{
|
2023-02-05 10:05:05 +01:00
|
|
|
azrp_subimage_p8_effect( (int) x - img_Lifebar.width/2, ymin - 10, &img_Lifebar, 0, 0, img_Lifebar.width, 7, DIMAGE_NONE );
|
|
|
|
|
2023-08-30 10:01:20 +02:00
|
|
|
if (ID==0) azrp_image_p8_effect(xmin, ymin, img_mainship1, DIMAGE_NONE);
|
2023-01-21 22:45:10 +01:00
|
|
|
|
|
|
|
int w = img_Satellite_Lvl1.width/2;
|
|
|
|
int h = img_Satellite_Lvl1.height/2;
|
|
|
|
|
|
|
|
if(satellites)
|
|
|
|
{
|
|
|
|
int incangle = 360/satNumber;
|
|
|
|
|
|
|
|
for(int u=0; u<satNumber; u++)
|
|
|
|
{
|
|
|
|
int angle = (int) satAngle + u*incangle;
|
|
|
|
angle = angle % 360;
|
2023-02-05 13:53:42 +01:00
|
|
|
int xsat = (int) (x + FastCosInt( angle ) * libnum::num( satRadius) );
|
|
|
|
int ysat = (int) (y + FastSinInt( angle ) * libnum::num( satRadius) );
|
2023-01-21 22:45:10 +01:00
|
|
|
azrp_image_p8_effect(xsat-w, ysat-h, &img_Satellite_Lvl1, DIMAGE_NONE);
|
|
|
|
}
|
|
|
|
}
|
2023-02-05 10:05:05 +01:00
|
|
|
|
|
|
|
int16_t life0=1000;
|
|
|
|
|
|
|
|
if (life>life0*2/3) azrp_subimage_p8_effect((int) x - img_Lifebar.width/2, ymin - 9, &img_Lifebar, 0, 7, (img_Lifebar.width*life)/life0, 5, DIMAGE_NONE );
|
|
|
|
else if (life>life0/3) azrp_subimage_p8_effect((int) x - img_Lifebar.width/2, ymin - 9, &img_Lifebar, 0, 12, (img_Lifebar.width*life)/life0, 5, DIMAGE_NONE );
|
|
|
|
else azrp_subimage_p8_effect((int) x - img_Lifebar.width/2, ymin - 9, &img_Lifebar, 0, 17, (img_Lifebar.width*life)/life0, 5, DIMAGE_NONE );
|
|
|
|
|
2023-01-21 22:45:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Player::Test_Impact( Bullet *projectile )
|
|
|
|
{
|
|
|
|
if (projectile->x >= xmin && projectile->x <= xmax && projectile->y >= ymin && projectile->y <= ymax )
|
|
|
|
{
|
|
|
|
life -= projectile->strength;
|
|
|
|
projectile->toberemoved = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
2023-02-05 16:49:56 +01:00
|
|
|
bool Player::Test_Impact( Bonus *bonus )
|
|
|
|
{
|
|
|
|
if (bonus->x >= xmin && bonus->x <= xmax && bonus->y >= ymin && bonus->y <= ymax )
|
|
|
|
{
|
|
|
|
if (bonus->ID==0) life = 1000;
|
|
|
|
else if (bonus->ID==1) satNumber++;
|
|
|
|
|
|
|
|
bonus->toberemoved = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
2023-02-05 10:05:05 +01:00
|
|
|
bool Player::Test_Collision( Enemy *adverseship )
|
2023-01-21 22:45:10 +01:00
|
|
|
{
|
|
|
|
if (adverseship->xmax >= xmin && adverseship->xmin <= xmax && adverseship->ymax >= ymin && adverseship->ymin <= ymax )
|
|
|
|
{
|
|
|
|
life -= 50;
|
|
|
|
adverseship->life -= 25;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::Set_Speed( uint8_t _sp )
|
|
|
|
{
|
|
|
|
speed = _sp;
|
|
|
|
}
|
|
|
|
|
2023-01-22 11:07:36 +01:00
|
|
|
bool Player::Shoot_OK( uint32_t tempshoot, uint8_t shootID )
|
|
|
|
{
|
2023-02-05 10:05:05 +01:00
|
|
|
if (shootID==BULLET_NORMAL)
|
2023-01-22 11:07:36 +01:00
|
|
|
{
|
|
|
|
if(tempshoot-lastshoot0>8)
|
|
|
|
{
|
|
|
|
lastshoot0=tempshoot;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
2023-02-05 10:05:05 +01:00
|
|
|
else if (shootID==BULLET_BLUE)
|
2023-01-22 11:07:36 +01:00
|
|
|
{
|
|
|
|
if(tempshoot-lastshoot1>15)
|
|
|
|
{
|
|
|
|
lastshoot1=tempshoot;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
2023-02-05 10:05:05 +01:00
|
|
|
else if (shootID==BULLET_LASER)
|
2023-01-22 11:07:36 +01:00
|
|
|
{
|
|
|
|
if(tempshoot-lastshoot2>2)
|
|
|
|
{
|
|
|
|
lastshoot2=tempshoot;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
2023-01-21 22:45:10 +01:00
|
|
|
|
2023-01-22 23:20:16 +01:00
|
|
|
void Player::Go_Left( float dt )
|
2023-01-21 22:45:10 +01:00
|
|
|
{
|
|
|
|
if( x > width/2+speed )
|
|
|
|
{
|
2023-01-22 23:20:16 +01:00
|
|
|
libnum::num a = libnum::num( dt / 60000.0f );
|
|
|
|
x -= a * libnum::num( speed );
|
2023-01-21 22:45:10 +01:00
|
|
|
this->Update( 0.0f );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-22 23:20:16 +01:00
|
|
|
void Player::Go_Right( float dt )
|
2023-01-21 22:45:10 +01:00
|
|
|
{
|
|
|
|
if(x < azrp_width-width/2-speed)
|
|
|
|
{
|
2023-01-22 23:20:16 +01:00
|
|
|
libnum::num a = libnum::num( dt / 60000.0f );
|
|
|
|
x += a * libnum::num( speed );
|
2023-01-21 22:45:10 +01:00
|
|
|
this->Update( 0.0f );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-22 23:20:16 +01:00
|
|
|
void Player::Go_Up( float dt )
|
2023-01-21 22:45:10 +01:00
|
|
|
{
|
|
|
|
if(y > height/2+speed)
|
|
|
|
{
|
2023-01-22 23:20:16 +01:00
|
|
|
libnum::num a = libnum::num( dt / 60000.0f );
|
|
|
|
y -= a * libnum::num( speed );
|
2023-01-21 22:45:10 +01:00
|
|
|
this->Update( 0.0f );
|
|
|
|
}
|
2023-01-31 23:07:32 +01:00
|
|
|
|
|
|
|
if (y<azrp_height/4)
|
|
|
|
{
|
|
|
|
libnum::num a = libnum::num( -1.0f * dt / 90000.0f );
|
|
|
|
MyBackground.IncYCoordinate( a );
|
|
|
|
}
|
2023-01-21 22:45:10 +01:00
|
|
|
}
|
|
|
|
|
2023-01-22 23:20:16 +01:00
|
|
|
void Player::Go_Down( float dt )
|
2023-01-21 22:45:10 +01:00
|
|
|
{
|
|
|
|
if(y < azrp_height -height/2 -speed)
|
|
|
|
{
|
2023-01-22 23:20:16 +01:00
|
|
|
libnum::num a = libnum::num( dt / 60000.0f );
|
|
|
|
y += a * libnum::num( speed );
|
2023-01-31 23:07:32 +01:00
|
|
|
this->Update( 0.0f );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y>3*azrp_height/4)
|
|
|
|
{
|
|
|
|
libnum::num a = libnum::num( dt / 90000.0f );
|
|
|
|
MyBackground.IncYCoordinate( a );
|
2023-01-21 22:45:10 +01:00
|
|
|
}
|
|
|
|
}
|