Enemies spawn on the map.

linux_template
sigonasr2 2 years ago
parent 53c85209f3
commit fd8cac38af
  1. BIN
      Faceball2030/assets/floor.png
  2. BIN
      Faceball2030/assets/wall.png
  3. 97
      Faceball2030/main.cpp
  4. 20
      Faceball2030/main.h

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

@ -9,19 +9,28 @@ using namespace olc;
FaceBall* game; FaceBall* game;
Enemy::Enemy(EnemyID id,vec3d pos,float rot,float radius)
:id(id), health(game->enemyData[id].health), fireDelay(0),
Object({game->enemyData[id].mesh,pos,rot,radius}) {
EnemyData data = game->enemyData[id];
for (int i = 0; i < data.ammo; i++) {
shots.push_back({ data.reloadTime });
}
}
void FaceBall::InitializeEnemyData() { void FaceBall::InitializeEnemyData() {
enemyData[EnemyID::NONE] = { "VOID",BLACK }; enemyData[EnemyID::NONE] = { "VOID",undefined,BLACK };
enemyData[EXIT] = { "EXIT",GREEN }; enemyData[EXIT] = { "EXIT",undefined,GREEN };
enemyData[START] = { "SPAWN POSITION",{128,64,0} }; enemyData[START] = { "SPAWN POSITION",undefined,{128,64,0} };
enemyData[SHOOTME] = { "SHOOTME",YELLOW,1,1,PI / 8,2,1,3 }; enemyData[SHOOTME] = { "SHOOTME",enemy_ShootMe,YELLOW,1,1,PI / 8,2,1,3 };
enemyData[COIN] = { "Coin",BLUE }; enemyData[COIN] = { "Coin",undefined,BLUE };
enemyData[POWERUP_ARMOR] = { "Armor",{96,0,96} }; enemyData[POWERUP_ARMOR] = { "Armor",undefined,{96,0,96} };
enemyData[POWERUP_SPEED] = { "Speed",{96,0,96} }; enemyData[POWERUP_SPEED] = { "Speed",undefined,{96,0,96} };
enemyData[POWERUP_SHOT] = { "Shot",{96,0,96} }; enemyData[POWERUP_SHOT] = { "Shot",undefined,{96,0,96} };
enemyData[SPECIAL_CAMO] = { "Camouflage",DARK_RED }; enemyData[SPECIAL_CAMO] = { "Camouflage",undefined,DARK_RED };
enemyData[SPECIAL_STOP] = { "Stop",DARK_RED }; enemyData[SPECIAL_STOP] = { "Stop",undefined,DARK_RED };
enemyData[SPECIAL_SHIELD] = { "Shield",DARK_RED }; enemyData[SPECIAL_SHIELD] = { "Shield",undefined,DARK_RED };
enemyData[AREA_MAP] = { "Map",GREEN }; enemyData[AREA_MAP] = { "Map",undefined,GREEN };
} }
void FaceBall::LoadLevel(int level) void FaceBall::LoadLevel(int level)
@ -30,14 +39,21 @@ void FaceBall::LoadLevel(int level)
std::vector<std::vector<Tile>>mapData = editor.LoadLevel(level); std::vector<std::vector<Tile>>mapData = editor.LoadLevel(level);
MAP_SIZE = { (int)mapData[0].size(),(int)mapData.size() }; MAP_SIZE = { (int)mapData[0].size(),(int)mapData.size() };
map.clear(); map.clear();
mapMesh.tris.clear(); mapWalls.tris.clear();
mapFloor.tris.clear();
objects.clear(); objects.clear();
bullets.clear();
enemies.clear();
for (int y = 0; y < MAP_SIZE.y; y++) { for (int y = 0; y < MAP_SIZE.y; y++) {
std::vector<MapSquare>row; std::vector<MapSquare>row;
for (int x = 0; x < MAP_SIZE.x; x++) { for (int x = 0; x < MAP_SIZE.x; x++) {
row.push_back({}); row.push_back({});
mapMesh.tris.push_back({ {{(float)x,0,(float)y},{(float)x,0,(float)y + 1},{(float)x + 1,0,(float)y}},{{0,0},{0,1},{1,0}},{BLUE,BLUE,BLUE} }); mapFloor.tris.push_back({ {{(float)x,0,(float)y},{(float)x,0,(float)y + 1},{(float)x + 1,0,(float)y}},{{0,0},{0,1},{1,0}},{WHITE,WHITE,WHITE} });
mapMesh.tris.push_back({ {{(float)x + 1,0,(float)y},{(float)x,0,(float)y + 1},{(float)x + 1,0,(float)y + 1}},{{1,0},{0,1},{1,1}},{BLUE,BLUE,BLUE} }); mapFloor.tris.push_back({ {{(float)x + 1,0,(float)y},{(float)x,0,(float)y + 1},{(float)x + 1,0,(float)y + 1}},{{1,0},{0,1},{1,1}},{WHITE,WHITE,WHITE} });
EnemyID id = mapData[y][x].enemyId;
if (id>=SHOOTME&& id < COIN) {
enemies.push_back({ id,vec3d{x + 0.5f,0,y + 0.5f},((int)mapData[y][x].facingDir-1)*PI/2,0.2f});
}
} }
map.push_back(row); map.push_back(row);
} }
@ -58,24 +74,25 @@ void FaceBall::LoadLevel(int level)
} }
AddWall(wallData, { x,y }); AddWall(wallData, { x,y });
if (map[y][x].wallN != NULL) { if (map[y][x].wallN != NULL) {
mapMesh.tris.push_back({ {{(float)x,1,(float)y},{(float)x,0,(float)y},{(float)x + 1,1,(float)y}},{{0,0},{0,1},{1,0}},{YELLOW,YELLOW,YELLOW} }); mapWalls.tris.push_back({ {{(float)x,1,(float)y},{(float)x,0,(float)y},{(float)x + 1,1,(float)y}},{{0,0},{0,1},{1,0}},{WHITE,WHITE,WHITE} });
mapMesh.tris.push_back({ {{(float)x,0,(float)y},{(float)x + 1,0,(float)y},{(float)x + 1,1,(float)y}},{{0,1},{1,1},{1,0}},{YELLOW,YELLOW,YELLOW} }); mapWalls.tris.push_back({ {{(float)x,0,(float)y},{(float)x + 1,0,(float)y},{(float)x + 1,1,(float)y}},{{0,1},{1,1},{1,0}},{WHITE,WHITE,WHITE} });
} }
if (map[y][x].wallS != NULL) { if (map[y][x].wallS != NULL) {
mapMesh.tris.push_back({ {{(float)x + 1,1,(float)y + 1},{(float)x,0,(float)y + 1},{(float)x,1,(float)y + 1}},{{0,0},{1,1},{1,0}},{DARK_RED,DARK_RED,DARK_RED} }); mapWalls.tris.push_back({ {{(float)x + 1,1,(float)y + 1},{(float)x,0,(float)y + 1},{(float)x,1,(float)y + 1}},{{0,0},{1,1},{1,0}},{WHITE,WHITE,WHITE} });
mapMesh.tris.push_back({ {{(float)x + 1,1,(float)y + 1},{(float)x + 1,0,(float)y + 1},{(float)x,0,(float)y + 1}},{{0,0},{0,1},{1,1}},{DARK_RED,DARK_RED,DARK_RED} }); mapWalls.tris.push_back({ {{(float)x + 1,1,(float)y + 1},{(float)x + 1,0,(float)y + 1},{(float)x,0,(float)y + 1}},{{0,0},{0,1},{1,1}},{WHITE,WHITE,WHITE} });
} }
if (map[y][x].wallW != NULL) { if (map[y][x].wallW != NULL) {
mapMesh.tris.push_back({ {{(float)x,1,(float)y},{(float)x,1,(float)y + 1}, {(float)x,0,(float)y + 1}},{{1,0},{0,0},{0,1}},{MAGENTA,MAGENTA,MAGENTA} }); mapWalls.tris.push_back({ {{(float)x,1,(float)y},{(float)x,1,(float)y + 1}, {(float)x,0,(float)y + 1}},{{1,0},{0,0},{0,1}},{WHITE,WHITE,WHITE} });
mapMesh.tris.push_back({ {{(float)x,0,(float)y},{(float)x,1,(float)y}, {(float)x,0,(float)y + 1}}, {{1,1},{1,0},{0,1}},{MAGENTA,MAGENTA,MAGENTA} }); mapWalls.tris.push_back({ {{(float)x,0,(float)y},{(float)x,1,(float)y}, {(float)x,0,(float)y + 1}}, {{1,1},{1,0},{0,1}},{WHITE,WHITE,WHITE} });
} }
if (map[y][x].wallE != NULL) { if (map[y][x].wallE != NULL) {
mapMesh.tris.push_back({ {{(float)x + 1,0,(float)y + 1},{(float)x + 1,1,(float)y + 1},{(float)x + 1,1,(float)y}},{{1,1},{1,0},{0,0}},{CYAN,CYAN,CYAN} }); mapWalls.tris.push_back({ {{(float)x + 1,0,(float)y + 1},{(float)x + 1,1,(float)y + 1},{(float)x + 1,1,(float)y}},{{1,1},{1,0},{0,0}},{WHITE,WHITE,WHITE} });
mapMesh.tris.push_back({ {{(float)x + 1,0,(float)y + 1} ,{(float)x + 1,1,(float)y},{(float)x + 1,0,(float)y}},{{1,1},{0,0},{0,1}},{CYAN,CYAN,CYAN} }); mapWalls.tris.push_back({ {{(float)x + 1,0,(float)y + 1} ,{(float)x + 1,1,(float)y},{(float)x + 1,0,(float)y}},{{1,1},{0,0},{0,1}},{WHITE,WHITE,WHITE} });
} }
} }
} }
objects.push_back({ mapMesh,{0,0},0,0 }); objects.push_back({ mapWalls,{0,0},0,0 });
objects.push_back({ mapFloor,{0,0},0,0 });
} }
bool FaceBall::CheckCollision(vec3d movementVector,vf2d pos,float radius){ bool FaceBall::CheckCollision(vec3d movementVector,vf2d pos,float radius){
@ -600,8 +617,8 @@ void FaceBall::RenderWorld() {
//matWorld = Matrix_MultiplyMatrix(matWorld, matTrans); //matWorld = Matrix_MultiplyMatrix(matWorld, matTrans);
vec3d vUp = { 0,1,0 }; vec3d vUp = { 0,1,0 };
vec3d vTarget = { 0,sinf(pitch),cosf(pitch) }; vec3d vTarget = { 0,sinf(freeRoam?freeRoamCamera_pitch:pitch),cosf(freeRoam ? freeRoamCamera_pitch : pitch) };
mat4x4 matCameraRot = Matrix_MakeRotationY(fYaw-PI/2); mat4x4 matCameraRot = Matrix_MakeRotationY((freeRoam?freeRoamCamera_yaw:fYaw)-PI/2);
vLookDir = Matrix_MultiplyVector(matCameraRot, vTarget); vLookDir = Matrix_MultiplyVector(matCameraRot, vTarget);
vec3d playerCenter = { player.GetPos().x, player.GetPos().y, player.GetPos().z }; vec3d playerCenter = { player.GetPos().x, player.GetPos().y, player.GetPos().z };
vTarget = Vector_Add(freeRoam ? freeRoamCamera : playerCenter, vLookDir); vTarget = Vector_Add(freeRoam ? freeRoamCamera : playerCenter, vLookDir);
@ -617,6 +634,9 @@ void FaceBall::RenderWorld() {
for (auto& bullet : bullets) { for (auto& bullet : bullets) {
RenderMesh(matView, vecTrianglesToRaster, bullet); RenderMesh(matView, vecTrianglesToRaster, bullet);
} }
for (auto& enemy : enemies) {
RenderMesh(matView, vecTrianglesToRaster, enemy);
}
//std::sort(vecTrianglesToRaster.begin(),vecTrianglesToRaster.end(),[](triangle&t1,triangle&t2){return (t1.p[0].z+t1.p[1].z+t1.p[2].z)/3.0f>(t2.p[0].z+t2.p[1].z+t2.p[2].z)/3.0f;}); //std::sort(vecTrianglesToRaster.begin(),vecTrianglesToRaster.end(),[](triangle&t1,triangle&t2){return (t1.p[0].z+t1.p[1].z+t1.p[2].z)/3.0f>(t2.p[0].z+t2.p[1].z+t2.p[2].z)/3.0f;});
ClearBuffer(BLACK, true); ClearBuffer(BLACK, true);
@ -697,10 +717,10 @@ void FaceBall::HandleKeys(float fElapsedTime) {
vec3d vForward = Vector_Mul(vLookDir, std::min(player.GetRadius()-0.00001f,moveSpd*fElapsedTime)); vec3d vForward = Vector_Mul(vLookDir, std::min(player.GetRadius()-0.00001f,moveSpd*fElapsedTime));
if (freeRoam) { if (freeRoam) {
if (GetKey(DOWN).bHeld) { if (GetKey(DOWN).bHeld) {
pitch -= 1 * fElapsedTime; freeRoamCamera_pitch -= 1 * fElapsedTime;
} }
if (GetKey(UP).bHeld) { if (GetKey(UP).bHeld) {
pitch += 1 * fElapsedTime; freeRoamCamera_pitch += 1 * fElapsedTime;
} }
} }
else { else {
@ -741,11 +761,21 @@ void FaceBall::HandleKeys(float fElapsedTime) {
} }
} }
if (GetKey(olc::A).bHeld) { if (GetKey(olc::A).bHeld) {
if (freeRoam) {
freeRoamCamera_yaw -= 2 * fElapsedTime;
}
else {
fYaw -= 2 * fElapsedTime; fYaw -= 2 * fElapsedTime;
} }
}
if (GetKey(olc::D).bHeld) { if (GetKey(olc::D).bHeld) {
if (freeRoam) {
freeRoamCamera_yaw += 2 * fElapsedTime;
}
else {
fYaw += 2 * fElapsedTime; fYaw += 2 * fElapsedTime;
} }
}
if (GetKey(olc::F1).bPressed) { if (GetKey(olc::F1).bPressed) {
freeRoam = !freeRoam; freeRoam = !freeRoam;
} }
@ -788,13 +818,16 @@ bool FaceBall::OnUserCreate()
arrow = new Decal(new Sprite("assets/arrow.png")); arrow = new Decal(new Sprite("assets/arrow.png"));
enemy_ShootMe_tex = new Decal(new Sprite("assets/enemies/ShootMe.png")); enemy_ShootMe_tex = new Decal(new Sprite("assets/enemies/ShootMe.png"));
YAZAWA = new Decal(new Sprite("assets/yazawa.png")); YAZAWA = new Decal(new Sprite("assets/yazawa.png"));
wall_tex = new Decal(new Sprite("assets/wall.png"));
bullet_tex = new Decal(new Sprite("assets/enemies/bullet.png")); bullet_tex = new Decal(new Sprite("assets/enemies/bullet.png"));
floor_tex = new Decal(new Sprite("assets/floor.png"));
InitializeEnemyData(); enemy_ShootMe = { "assets/enemies/ShootMe.obj", enemy_ShootMe_tex };
Mesh testEnemy("assets/enemies/ShootMe.obj", enemy_ShootMe_tex);
bullet = { "assets/enemies/bullet.obj",bullet_tex }; bullet = { "assets/enemies/bullet.obj",bullet_tex };
mapMesh.texture = YAZAWA; mapWalls.texture = wall_tex;
mapFloor.texture = floor_tex;
InitializeEnemyData();
LoadLevel(1); LoadLevel(1);

@ -151,6 +151,7 @@ struct Bullet : Object{
struct EnemyData { struct EnemyData {
std::string name; std::string name;
Mesh mesh;
Pixel col=YELLOW; Pixel col=YELLOW;
int health = 1; int health = 1;
float movSpd = 1; float movSpd = 1;
@ -165,6 +166,16 @@ struct mat4x4
float m[4][4] = { 0 }; float m[4][4] = { 0 };
}; };
struct Enemy : Object {
private:
EnemyID id;
int health=1;
std::vector<float> shots;
float fireDelay=0;
public:
Enemy(EnemyID id, vec3d pos, float rot, float radius);
};
class FaceBall : public PixelGameEngine class FaceBall : public PixelGameEngine
{ {
bool freeRoam = false; bool freeRoam = false;
@ -176,15 +187,16 @@ class FaceBall : public PixelGameEngine
EnemyData GetData(EnemyID id); EnemyData GetData(EnemyID id);
Decal* circle,*arrow,*YAZAWA; Decal* circle,*arrow,*YAZAWA;
std::map<EnemyID, EnemyData>enemyData;
private: private:
Mesh mapMesh,enemy_ShootMe,bullet; Mesh mapWalls,mapFloor,enemy_ShootMe,bullet,undefined;
Decal* dot, * enemy_ShootMe_tex,*bullet_tex; Decal* dot, * enemy_ShootMe_tex,*bullet_tex,*wall_tex,*floor_tex;
vi2d MAP_SIZE; vi2d MAP_SIZE;
std::vector<std::vector<MapSquare>>map; std::vector<std::vector<MapSquare>>map;
std::map<EnemyID, EnemyData>enemyData;
std::vector<Object>objects; std::vector<Object>objects;
std::vector<Bullet>bullets; std::vector<Bullet>bullets;
std::vector<Enemy>enemies;
GAMEMODE mode=GAMEMODE::GAME; GAMEMODE mode=GAMEMODE::GAME;
Editor editor; Editor editor;
int level=1; int level=1;
@ -201,6 +213,8 @@ class FaceBall : public PixelGameEngine
Player player = { {3.7,0.3,0.7}, {{0.5,0.5},0.2} }; Player player = { {3.7,0.3,0.7}, {{0.5,0.5},0.2} };
vec3d freeRoamCamera = { 1,0.5,1 }; vec3d freeRoamCamera = { 1,0.5,1 };
float freeRoamCamera_pitch = pitch;
float freeRoamCamera_yaw = fYaw;
float shotSpd = 3.0f; float shotSpd = 3.0f;
float moveSpd = 2.0f; float moveSpd = 2.0f;

Loading…
Cancel
Save