implemented shells

This commit is contained in:
devZoGok
2025-05-14 19:34:01 +03:00
parent 6ea9baaed4
commit 94ee446741
13 changed files with 116 additions and 39 deletions
@@ -1,7 +1,21 @@
ProjectileId = {CRUISE_MISSILE = 0, TORPEDO = 1}
ProjectileClass = {CRUISE_MISSILE = 0, TORPEDO = 1}
ProjectileId = {SHELL = 0, CRUISE_MISSILE = 1, TORPEDO = 2}
ProjectileClass = {SHELL = 0, CRUISE_MISSILE = 1, TORPEDO = 2}
G = 9.8
projectiles = {
{
projectileClass = ProjectileClass.SHELL,
size = {x = 1, y = 1, z = 1},
speed = 5,
rotAngle = .1,
explosion = {damage = 100, radius = 20, sfx = PATH .. 'Sounds/SFX/Explosions/explosion02.ogg'},
directHitDamage = 200,
rayLength = 1,
name = "Shell",
basePath = PATH .. "Models/GameObjects/Projectiles/Shells/",
meshPath = "shell.xml",
albedoPath = 'shell.jpg'
},
{
projectileClass = ProjectileClass.CRUISE_MISSILE,
size = {x = 6, y = 13.5, z = 2.54},
+10 -9
View File
@@ -160,11 +160,17 @@ units = {
{
weapons = {
{
type = WeaponClass.HITSCAN,
type = WeaponClass.SHELL,
projectile = {id = ProjectileId.SHELL, pos = {x = 0.06, y = 5.82, z = 11.4}, rot = {w = 1, x = 0, y = 0, z = 0}},
rateOfFire = 1000,
damage = 200,
maxRange = 25,
fireFx = {
{
vfx = false,
duration = 300,
path = PATH .. 'Sounds/Units/Tanks/attack.ogg',
},
{
vfx = true,
duration = 50,
@@ -172,19 +178,14 @@ units = {
path = PATH .. vfxPrefix .. 'muzzleFlash.xml',
color = {x = 1, y = 1, z = 0, a = 1},
},
parent = 'Turret',
parent = 'CannonBarrel',
pos = {x = 0.06, y = 5.82, z = 11.4},
rot = {w = 1, x = 0, y = 0, z = 0},
--scale = .5
},
{
vfx = false,
duration = 300,
path = PATH .. 'Sounds/Units/Tanks/attack.ogg',
}
},
landHitFx = {explosionVfx, explosionSfx},
unitHitFx = {explosionVfx, explosionSfx}
--landHitFx = {explosionVfx, explosionSfx},
--unitHitFx = {explosionVfx, explosionSfx}
}
},
unitClass = UnitClass.TANK,
+3 -2
View File
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.9)
cmake_minimum_required(VERSION 3.5)
set(GAME_NAME battleship)
project(${GAME_NAME})
@@ -10,6 +10,7 @@ else()
endif()
set(CMAKE_CXX_STANDART 17)
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
set(CMAKE_BUILD_TYPE Debug)
set(BUILD_TESTS ON)
set(BUILD_SHARED_LIBS OFF CACHE BOOL FORCED)
@@ -30,7 +31,7 @@ set(UTIL util.cpp binds.h)
set(CONTROLLERS gameObjectFrameController.cpp cameraController.cpp)
set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp addTechnologyCommand.cpp toggleDebugCommand.cpp)
set(CORE gameManager.cpp game.cpp fxManager.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS})
set(PROJECTILES projectile.cpp cruiseMissile.cpp)
set(PROJECTILES projectile.cpp cruiseMissile.cpp shell.cpp)
set(VEHICLES vehicle.cpp engineer.cpp resourceRover.cpp)
set(STRUCTURES structure.cpp factory.cpp pointDefense.cpp extractor.cpp researchStruct.cpp)
set(UNITS gameObjectFactory.cpp unit.cpp ${STRUCTURES} ${VEHICLES})
+1 -1
View File
@@ -204,7 +204,7 @@ namespace battleship{
cursorState = (unloadFlag ? CursorState::UNLOAD : CursorState::LOAD);
}
else if(gameObjUnit && !(ownGameObj || alliedGameObj))
else if(controlPressed || gameObjUnit && !(ownGameObj || alliedGameObj))
cursorState = CursorState::ATTACK;
else
cursorState = CursorState::NORMAL;
+5 -12
View File
@@ -47,19 +47,8 @@ namespace battleship{
flightStage = FlightStage::DESCENT;
}
void CruiseMissile::checkSurfaceCollision(){
Map *map = Map::getSingleton();
int cellId = map->getCellId(pos, false);
if((pos + dirVec * rayLength).y <= map->getCells()[cellId].pos.y){
Game::getSingleton()->explode(pos, explosionDamage, explosionRadius, explosionSfx);
remove = true;
}
}
void CruiseMissile::update(){
GameObject::update();
placeAt(pos + dirVec * speed);
Projectile::update();
switch(flightStage){
case FlightStage::ASCENT:
@@ -73,6 +62,10 @@ namespace battleship{
break;
}
checkCollision();
}
void CruiseMissile::checkCollision(){
if(!remove && flightStage == FlightStage::DESCENT){
checkSurfaceCollision();
if(remove) return;
+1 -1
View File
@@ -15,7 +15,7 @@ namespace battleship{
void pitch(float, vb01::Vector3);
void cruise();
void checkSurfaceCollision();
void checkCollision();
};
}
+4 -1
View File
@@ -45,8 +45,11 @@ namespace battleship{
}
void GameObject::orientAt(Quaternion rotQuat){
model->setOrientation(rotQuat);
rot = rotQuat;
model->setOrientation(rotQuat);
leftVec = model->getGlobalAxis(0);
upVec = model->getGlobalAxis(1);
dirVec = model->getGlobalAxis(2);
}
//TODO remove neccessity to create a material for an invisible mesh
+4 -1
View File
@@ -7,8 +7,9 @@
#include "resourceDeposit.h"
#include "pointDefense.h"
#include "extractor.h"
#include "cruiseMissile.h"
#include "researchStruct.h"
#include "cruiseMissile.h"
#include "shell.h"
#include "defConfigs.h"
#include <solUtil.h>
@@ -52,6 +53,8 @@ namespace battleship{
int projectileClass = SOL_LUA_VIEW["projectiles"][id + 1]["projectileClass"];
switch((ProjectileClass)projectileClass){
case ProjectileClass::SHELL:
return new Shell(unit, id, pos, rot);
case ProjectileClass::CRUISE_MISSILE:
{
Order::Target target = unit->getOrder(0).targets[0];
+11 -7
View File
@@ -73,12 +73,6 @@ namespace battleship{
void Projectile::update() {
GameObject::update();
placeAt(pos + speed * dirVec);
if(!remove){
checkSurfaceCollision();
if(remove) return;
checkUnitCollision();
}
}
void Projectile::checkUnitCollision(){
@@ -112,8 +106,18 @@ namespace battleship{
Map *map = Map::getSingleton();
int cellId = map->getCellId(pos, false);
if(map->getCells()[cellId].type == Map::Cell::LAND)
if((pos + dirVec * rayLength).y <= map->getCells()[cellId].pos.y){
Game::getSingleton()->explode(pos, explosionDamage, explosionRadius, explosionSfx);
remove = true;
}
}
void Projectile::checkCollision(){
if(!remove){
checkSurfaceCollision();
if(remove) return;
checkUnitCollision();
}
}
void Projectile::debug(){
+2 -2
View File
@@ -12,7 +12,7 @@ namespace vb01{
}
namespace battleship {
enum class ProjectileClass{CRUISE_MISSILE, TORPEDO};
enum class ProjectileClass{SHELL, CRUISE_MISSILE, TORPEDO};
class Unit;
class Projectile : public GameObject{
@@ -24,11 +24,11 @@ namespace battleship {
private:
void initProperties();
void initSound();
void checkCollision();
protected:
virtual void reinit();
virtual void checkUnitCollision();
virtual void checkSurfaceCollision();
void checkCollision();
float speed, rayLength, explosionRadius, rotAngle;
int directHitDamage, explosionDamage;
+39
View File
@@ -0,0 +1,39 @@
#include "shell.h"
#include <solUtil.h>
#include <cmath>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace gameBase;
Shell::Shell(Unit *un, int id, Vector3 pos, Quaternion rot) :
Projectile(un, id, pos, rot),
initTime(getTime())
{
initDir = dirVec;
}
void Shell::update(){
float currTime = float(getTime() - initTime) / 1000;
if(currTime == 0) return;
const float G = generateView()["G"];
float angle = initDir.getAngleBetween(Vector3(initDir.x, 0, initDir.z).norm());
dirVec = (
pos +
speed * currTime * cos(angle) * Vector3(initDir.x, 0, initDir.z).norm() +
(currTime * speed * sin(angle) - G * currTime * currTime) * Vector3::VEC_J -
pos
).norm();
upVec = Quaternion(-PI / 2, leftVec) * dirVec;
model->lookAt(dirVec, upVec);
Projectile::update();
checkCollision();
}
}
+19
View File
@@ -0,0 +1,19 @@
#ifndef SHELL_H
#define SHELL_H
#include "projectile.h"
#include <util.h>
namespace battleship{
class Shell : public Projectile{
public:
Shell(Unit*, int, vb01::Vector3, vb01::Quaternion);
void update();
private:
vb01::s64 initTime;
vb01::Vector3 initDir;
};
}
#endif
+1 -1
View File
@@ -279,7 +279,7 @@ namespace battleship{
Vector3 upVec = unit->getUpVec();
Vector3 dirVec = unit->getDirVec();
Vector3 p = unit->getPos() + leftVec * projPos.x + upVec * projPos.y + dirVec * projPos.z;
Quaternion r = unit->getRot() * projRot;
Quaternion r = projRot * unit->getRot();
unit->getPlayer()->addProjectile(GameObjectFactory::createProjectile(unit, projId, p, r));
}