Shmup/src/bullet.cpp

90 lines
1.8 KiB
C++
Raw Normal View History

2023-01-20 21:11:57 +01:00
#include "bullet.h"
#include <azur/azur.h>
#include <azur/gint/render.h>
#include <cstdint>
#include <stdlib.h>
#include <num/num.h>
extern bopti_image_t img_bullet_normal;
extern bopti_image_t img_bullet_blue;
2023-01-22 11:07:36 +01:00
extern bopti_image_t img_bullet_laser;
2023-02-05 10:05:05 +01:00
extern bopti_image_t img_bullet_enemy_blue;
2023-01-20 21:11:57 +01:00
2023-02-05 10:05:05 +01:00
Bullet::Bullet( uint16_t lx, uint16_t ly, int16_t dx, int16_t dy, uint8_t id )
2023-01-20 21:11:57 +01:00
{
x = libnum::num( lx );
y = libnum::num( ly );
2023-02-05 10:05:05 +01:00
sx = libnum::num( dx );
sy = libnum::num( dy );
2023-01-20 21:11:57 +01:00
ID=id;
2023-02-05 10:05:05 +01:00
if (ID==BULLET_NORMAL)
2023-01-20 21:11:57 +01:00
{
2023-01-21 14:04:58 +01:00
strength = 5;
2023-01-20 21:11:57 +01:00
}
2023-02-05 10:05:05 +01:00
else if (ID==BULLET_BLUE)
2023-01-20 21:11:57 +01:00
{
2023-01-21 14:04:58 +01:00
strength = 2;
2023-01-20 21:11:57 +01:00
}
2023-02-05 10:05:05 +01:00
else if (ID==BULLET_LASER)
2023-01-22 11:07:36 +01:00
{
strength = 1;
}
2023-02-05 10:05:05 +01:00
else if (ID==BULLET_ENEMY_BLUE)
{
strength = 2;
}
2023-01-20 21:11:57 +01:00
toberemoved = false;
}
Bullet::~Bullet()
{
}
void Bullet::Update( float dt )
{
libnum::num a = libnum::num( dt / 12000.0f );
x += sx * a;
y += sy * a;
if (x<-10 || x>azrp_width+10 || y<-10 || y>azrp_height+10) toberemoved=true;
2023-01-20 21:11:57 +01:00
}
void Bullet::Render( )
{
2023-02-05 10:05:05 +01:00
int16_t px = (int) x;
int16_t py = (int) y;
2023-01-20 21:11:57 +01:00
2023-02-05 10:05:05 +01:00
if (ID==BULLET_NORMAL)
2023-01-20 21:11:57 +01:00
{
azrp_image_p8( px-img_bullet_normal.width/2, py-img_bullet_normal.height/2, &img_bullet_normal, DIMAGE_NONE );
2023-01-20 21:11:57 +01:00
return;
}
2023-02-05 10:05:05 +01:00
else if (ID==BULLET_BLUE)
2023-01-20 21:11:57 +01:00
{
azrp_image_p8( px-img_bullet_blue.width/2, py-img_bullet_blue.height/2, &img_bullet_blue, DIMAGE_NONE );
2023-01-20 21:11:57 +01:00
return;
}
2023-02-05 10:05:05 +01:00
else if (ID==BULLET_LASER)
2023-01-22 11:07:36 +01:00
{
azrp_image_p8( px-img_bullet_laser.width/2, py-img_bullet_laser.height/2, &img_bullet_laser, DIMAGE_NONE );
2023-01-22 11:07:36 +01:00
return;
}
2023-02-05 10:05:05 +01:00
else if (ID==BULLET_ENEMY_BLUE)
{
azrp_image_p8( px-img_bullet_enemy_blue.width/2, py-img_bullet_enemy_blue.height/2, &img_bullet_enemy_blue, DIMAGE_NONE );
return;
}
2023-01-20 21:11:57 +01:00
}