Commit 6532c700 authored by Alexey Hohlov's avatar Alexey Hohlov
Browse files

Базовый класс для транспорта теперь имеет некоторые свойства и методы, общие...

Базовый класс для транспорта теперь имеет некоторые свойства и методы, общие для всех + форматирование.
parent 8063bfac
......@@ -4,8 +4,8 @@
TWeapon::TWeapon()
{
player_id = 0;
_can_shot = false;
_pos.z = 10;
_can_shot = true;
_pos.z = 10.0f;
}
TWeapon::TWeapon(uint8_t pid)
......@@ -22,27 +22,27 @@ void TWeapon::step()
{
switch (_rotation) {
default:
if (rotation_speed > 0.05) rotation_speed -= 0.05;
if (rotation_speed < -0.05) rotation_speed += 0.05;
if (fabs(rotation_speed) < 0.05) rotation_speed = 0;
if (rotation_speed > 0.05f) rotation_speed -= 0.05f;
if (rotation_speed < -0.05f) rotation_speed += 0.05f;
if (fabs(rotation_speed) < 0.05f) rotation_speed = 0.0f;
break;
case rotation_left:
if (rotation_speed < -0.05) rotation_speed += 0.05;
else rotation_speed = min(rotation_speed+0.02,1.0);
if (rotation_speed < -0.05f) rotation_speed += 0.05f;
else rotation_speed = min(rotation_speed+0.02f, 1.0f);
break;
case rotation_right:
if (rotation_speed > 0.05) rotation_speed -= 0.05;
else rotation_speed = max(rotation_speed-0.02,-1.0);
if (rotation_speed > 0.05f) rotation_speed -= 0.05f;
else rotation_speed = max(rotation_speed-0.02f, -1.0f);
break;
}
_angle += rotation_speed;
if (!_can_shot) {
_charge_timer++;
if (_charge_timer >= 200) {
if (_charge_timer > 0) {
_charge_timer--;
if (_charge_timer == 0) {
fprintf(stdout, "armed!\n");
_can_shot = true;
_charge_timer = 0;
}
}
}
......@@ -51,23 +51,25 @@ void TWeapon::shot()
{
if (_can_shot) {
CVector np;
/* np.x = pos.x - 60*Sin(cur_angle) - 30*Cos(cur_angle);
np.y = pos.y + 60*Cos(cur_angle) - 30*Sin(cur_angle);
IProjectile::CreateProjectile("CProjectileFire",np, cur_angle+frand()*10-5, player_id);
np.x = pos.x - 60*Sin(cur_angle) + 30*Cos(cur_angle);
np.y = pos.y + 60*Cos(cur_angle) - 30*Sin(-cur_angle);
IProjectile::CreateProjectile("CProjectileFire",np, cur_angle+frand()*10-5, player_id);
/*np.x = _pos.x - 60*Sin(_angle) - 30*Cos(_angle);
np.y = _pos.y + 60*Cos(_angle) - 30*Sin(_angle);
IProjectile::CreateProjectile("CProjectileFire",np, _angle+frand()*10-5, player_id);
can_shot = false;
shot_timer = 0;*/
np.x = _pos.x - 60*Sin(_angle) + 30*Cos(_angle);
np.y = _pos.y + 60*Cos(_angle) - 30*Sin(-_angle);
IProjectile::CreateProjectile("CProjectileFire",np, _angle+frand()*10-5, player_id);
np.x = _pos.x - 60 * Sin(_angle);
np.y = _pos.y + 60 * Cos(_angle);
_can_shot = false;
_charge_timer = 1;*/
np.x = _pos.x - 60.0f * Sin(_angle);
np.y = _pos.y + 60.0f * Cos(_angle);
//IProjectile::CreateProjectile("CProjectileBullet", np, _angle + frand() * 1 - 0.5, player_id);
IProjectile::CreateProjectile("CProjectileBullet", np, _angle + frand() * 1.0f - 0.5f, player_id);
_can_shot = false;
_charge_timer = 200;
}
}
......@@ -79,7 +81,6 @@ TTank::TTank(uint8_t pid, uint8_t)
player_id = pid;
_pos.z = 4;
_type = "CVehicle";
killtime = 0;
alive = false;
//mass = 2000; //2тонны О.о
......@@ -106,11 +107,12 @@ TTank::TTank(uint8_t pid, uint8_t)
_alpha = 0;
killtime = 1000;
this->solid = true;
solid = true;
}
TTank::~TTank()
{
delete weapon;
//delete(body);
//printf("tank destroyed\r\n");
}
......@@ -296,11 +298,9 @@ void TTank::step()
break;
}
// process();
//перемещаем пушку и крутим ее...
weapon->angle(weapon->angle()+_rot_speed);
weapon->pos(CVector(_pos.x + 10*Sin(_angle), _pos.y - 10*Cos(_angle), 6));
weapon->pos(CVector(_pos.x + 10.0f * Sin(_angle), _pos.y - 10.0f * Cos(_angle), 6.0f));
weapon->step();
/*
......@@ -326,8 +326,7 @@ TODO: переписать на партиклы
void TTank::collide(IObjectStatic* coll)
{
if (!coll->solid)
{
if (!coll->solid) {
return;
}
prev_pos();
......@@ -340,24 +339,24 @@ bool TTank::draw()
CRenderManager& render = CRenderManager::GetInstance();
if (alive) {
render.draw(this->sprite, this->_pos, {128, 128}, this->_angle);
render.draw(this->wpn_sprite, this->weapon->pos(), {128, 128}, this->weapon->angle());
render.draw(this->sprite, this->_pos, {128.0f, 128.0f}, this->_angle);
render.draw(this->wpn_sprite, this->weapon->pos(), {128.0f, 128.0f}, this->weapon->angle());
render.draw_light(this->sprite, this->_pos, {64,64}, this->_angle, color(1.0f, 1.0f, 1.0f, 0.05f));
render.draw_light(this->wpn_sprite, this->weapon->pos(), {64,64}, this->weapon->angle(), color(1.0f,1.0f,1.0f,0.05f));
render.draw_light(this->sprite, this->_pos, {64.0f, 64.0f}, this->_angle, color(1.0f, 1.0f, 1.0f, 0.05f));
render.draw_light(this->wpn_sprite, this->weapon->pos(), {64.0f, 64.0f}, this->weapon->angle(), color(1.0f,1.0f,1.0f,0.05f));
if (_light) {
CPoint left, right;
left = point(this->_pos.x - 30 * Sin(this->_angle) - 16 * Cos(this->_angle),
this->_pos.y + 30 * Cos(this->_angle) - 16 * Sin(this->_angle));
right = point(this->_pos.x - 30 * Sin(this->_angle) + 16 * Cos(this->_angle),
this->_pos.y + 30 * Cos(this->_angle) + 16 * Sin(this->_angle));
left = point(this->_pos.x - 30.0f * Sin(this->_angle) - 16.0f * Cos(this->_angle),
this->_pos.y + 30.0f * Cos(this->_angle) - 16.0f * Sin(this->_angle));
right = point(this->_pos.x - 30.0f * Sin(this->_angle) + 16.0f * Cos(this->_angle),
this->_pos.y + 30.0f * Cos(this->_angle) + 16.0f* Sin(this->_angle));
//render->draw_light(light_spot,left,box(192,256),_angle,color(1.0f,1.0f,1.0f,0.3f));
//render->draw_light(light_spot,right,box(192,256),_angle,color(1.0f,1.0f,1.0f,0.3f));
}
} else if (killtime < 500) {
render.draw(this->sprite, this->_pos, {128, 128}, this->_angle, this->_alpha);
render.draw(this->wpn_sprite, this->weapon->pos(), {128, 128}, this->weapon->angle(), this->_alpha);
render.draw(this->sprite, this->_pos, {128.0f, 128.0f}, this->_angle, this->_alpha);
render.draw(this->wpn_sprite, this->weapon->pos(), {128.0f, 128.0f}, this->weapon->angle(), this->_alpha);
}
return true;
......
#include <game/IBaseVehicle.h>
IBaseVehicle::IBaseVehicle()
{
this->_type = "IBaseVehicle";
this->solid = true;
this->flat = false;
}
void IBaseVehicle::setmov(enum vehicle_moving mov)
{
_moving = mov;
}
void IBaseVehicle::setsteer(enum vehicle_steering steer)
{
_steering = steer;
}
uint8_t IBaseVehicle::pid()
{
return player_id;
}
void IBaseVehicle::pid(uint8_t pid)
{
player_id = pid;
}
......@@ -4,7 +4,7 @@
#include <game/CProjectileFire.h>
#include <game/effects.h>
#include <game/IVehicleBase.h>
#include <game/IBaseVehicle.h>
#include <game/IWeaponBase.h>
//-------------------------------------------------------------------------
......@@ -33,7 +33,6 @@ private:
class TTank : public IBaseVehicle
{
private:
uint8_t player_id;
bool _enabled;
bool alive;
bool killed;
......@@ -67,8 +66,6 @@ public:
bool is_alive(void);
int kill_timer(void) { return killtime; }
uint8_t pid(void) { return player_id; }
void set_light(bool en);
bool light(void) { return _light; }
......
#pragma once
class IBaseVehicle : public IDynamicObject
#include <game/IObjectDynamic.h>
enum vehicle_moving {
moving_none,
moving_forward,
moving_backward,
};
enum vehicle_steering {
steering_none,
steering_left,
steering_right,
};
class IBaseVehicle : public IObjectDynamic
{
}
public:
IBaseVehicle();
void setmov(enum vehicle_moving mov);
void setsteer(enum vehicle_steering steer);
uint8_t pid();
void pid(uint8_t pid);
protected:
enum vehicle_moving _moving;
enum vehicle_steering _steering;
uint8_t player_id;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment