|
|
|
@ -9,19 +9,28 @@ using namespace olc; |
|
|
|
|
|
|
|
|
|
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() { |
|
|
|
|
enemyData[EnemyID::NONE] = { "VOID",BLACK }; |
|
|
|
|
enemyData[EXIT] = { "EXIT",GREEN }; |
|
|
|
|
enemyData[START] = { "SPAWN POSITION",{128,64,0} }; |
|
|
|
|
enemyData[SHOOTME] = { "SHOOTME",YELLOW,1,1,PI / 8,2,1,3 }; |
|
|
|
|
enemyData[COIN] = { "Coin",BLUE }; |
|
|
|
|
enemyData[POWERUP_ARMOR] = { "Armor",{96,0,96} }; |
|
|
|
|
enemyData[POWERUP_SPEED] = { "Speed",{96,0,96} }; |
|
|
|
|
enemyData[POWERUP_SHOT] = { "Shot",{96,0,96} }; |
|
|
|
|
enemyData[SPECIAL_CAMO] = { "Camouflage",DARK_RED }; |
|
|
|
|
enemyData[SPECIAL_STOP] = { "Stop",DARK_RED }; |
|
|
|
|
enemyData[SPECIAL_SHIELD] = { "Shield",DARK_RED }; |
|
|
|
|
enemyData[AREA_MAP] = { "Map",GREEN }; |
|
|
|
|
enemyData[EnemyID::NONE] = { "VOID",undefined,BLACK }; |
|
|
|
|
enemyData[EXIT] = { "EXIT",undefined,GREEN }; |
|
|
|
|
enemyData[START] = { "SPAWN POSITION",undefined,{128,64,0} }; |
|
|
|
|
enemyData[SHOOTME] = { "SHOOTME",enemy_ShootMe,YELLOW,1,1,PI / 8,2,1,3 }; |
|
|
|
|
enemyData[COIN] = { "Coin",undefined,BLUE }; |
|
|
|
|
enemyData[POWERUP_ARMOR] = { "Armor",undefined,{96,0,96} }; |
|
|
|
|
enemyData[POWERUP_SPEED] = { "Speed",undefined,{96,0,96} }; |
|
|
|
|
enemyData[POWERUP_SHOT] = { "Shot",undefined,{96,0,96} }; |
|
|
|
|
enemyData[SPECIAL_CAMO] = { "Camouflage",undefined,DARK_RED }; |
|
|
|
|
enemyData[SPECIAL_STOP] = { "Stop",undefined,DARK_RED }; |
|
|
|
|
enemyData[SPECIAL_SHIELD] = { "Shield",undefined,DARK_RED }; |
|
|
|
|
enemyData[AREA_MAP] = { "Map",undefined,GREEN }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FaceBall::LoadLevel(int level) |
|
|
|
@ -30,14 +39,21 @@ void FaceBall::LoadLevel(int level) |
|
|
|
|
std::vector<std::vector<Tile>>mapData = editor.LoadLevel(level); |
|
|
|
|
MAP_SIZE = { (int)mapData[0].size(),(int)mapData.size() }; |
|
|
|
|
map.clear(); |
|
|
|
|
mapMesh.tris.clear(); |
|
|
|
|
mapWalls.tris.clear(); |
|
|
|
|
mapFloor.tris.clear(); |
|
|
|
|
objects.clear(); |
|
|
|
|
bullets.clear(); |
|
|
|
|
enemies.clear(); |
|
|
|
|
for (int y = 0; y < MAP_SIZE.y; y++) { |
|
|
|
|
std::vector<MapSquare>row; |
|
|
|
|
for (int x = 0; x < MAP_SIZE.x; x++) { |
|
|
|
|
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} }); |
|
|
|
|
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,0,(float)y},{(float)x,0,(float)y + 1},{(float)x + 1,0,(float)y}},{{0,0},{0,1},{1,0}},{WHITE,WHITE,WHITE} }); |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
@ -58,24 +74,25 @@ void FaceBall::LoadLevel(int level) |
|
|
|
|
} |
|
|
|
|
AddWall(wallData, { x,y }); |
|
|
|
|
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} }); |
|
|
|
|
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,1,(float)y},{(float)x,0,(float)y},{(float)x + 1,1,(float)y}},{{0,0},{0,1},{1,0}},{WHITE,WHITE,WHITE} }); |
|
|
|
|
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) { |
|
|
|
|
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} }); |
|
|
|
|
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,0,(float)y + 1},{(float)x,1,(float)y + 1}},{{0,0},{1,1},{1,0}},{WHITE,WHITE,WHITE} }); |
|
|
|
|
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) { |
|
|
|
|
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} }); |
|
|
|
|
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,1,(float)y},{(float)x,1,(float)y + 1}, {(float)x,0,(float)y + 1}},{{1,0},{0,0},{0,1}},{WHITE,WHITE,WHITE} }); |
|
|
|
|
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) { |
|
|
|
|
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} }); |
|
|
|
|
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 + 1},{(float)x + 1,1,(float)y}},{{1,1},{1,0},{0,0}},{WHITE,WHITE,WHITE} }); |
|
|
|
|
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){ |
|
|
|
@ -600,8 +617,8 @@ void FaceBall::RenderWorld() { |
|
|
|
|
//matWorld = Matrix_MultiplyMatrix(matWorld, matTrans);
|
|
|
|
|
|
|
|
|
|
vec3d vUp = { 0,1,0 }; |
|
|
|
|
vec3d vTarget = { 0,sinf(pitch),cosf(pitch) }; |
|
|
|
|
mat4x4 matCameraRot = Matrix_MakeRotationY(fYaw-PI/2); |
|
|
|
|
vec3d vTarget = { 0,sinf(freeRoam?freeRoamCamera_pitch:pitch),cosf(freeRoam ? freeRoamCamera_pitch : pitch) }; |
|
|
|
|
mat4x4 matCameraRot = Matrix_MakeRotationY((freeRoam?freeRoamCamera_yaw:fYaw)-PI/2); |
|
|
|
|
vLookDir = Matrix_MultiplyVector(matCameraRot, vTarget); |
|
|
|
|
vec3d playerCenter = { player.GetPos().x, player.GetPos().y, player.GetPos().z }; |
|
|
|
|
vTarget = Vector_Add(freeRoam ? freeRoamCamera : playerCenter, vLookDir); |
|
|
|
@ -617,6 +634,9 @@ void FaceBall::RenderWorld() { |
|
|
|
|
for (auto& bullet : bullets) { |
|
|
|
|
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;});
|
|
|
|
|
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)); |
|
|
|
|
if (freeRoam) { |
|
|
|
|
if (GetKey(DOWN).bHeld) { |
|
|
|
|
pitch -= 1 * fElapsedTime; |
|
|
|
|
freeRoamCamera_pitch -= 1 * fElapsedTime; |
|
|
|
|
} |
|
|
|
|
if (GetKey(UP).bHeld) { |
|
|
|
|
pitch += 1 * fElapsedTime; |
|
|
|
|
freeRoamCamera_pitch += 1 * fElapsedTime; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
@ -741,10 +761,20 @@ void FaceBall::HandleKeys(float fElapsedTime) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (GetKey(olc::A).bHeld) { |
|
|
|
|
fYaw -= 2 * fElapsedTime; |
|
|
|
|
if (freeRoam) { |
|
|
|
|
freeRoamCamera_yaw -= 2 * fElapsedTime; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
fYaw -= 2 * fElapsedTime; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (GetKey(olc::D).bHeld) { |
|
|
|
|
fYaw += 2 * fElapsedTime; |
|
|
|
|
if (freeRoam) { |
|
|
|
|
freeRoamCamera_yaw += 2 * fElapsedTime; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
fYaw += 2 * fElapsedTime; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (GetKey(olc::F1).bPressed) { |
|
|
|
|
freeRoam = !freeRoam; |
|
|
|
@ -788,13 +818,16 @@ bool FaceBall::OnUserCreate() |
|
|
|
|
arrow = new Decal(new Sprite("assets/arrow.png")); |
|
|
|
|
enemy_ShootMe_tex = new Decal(new Sprite("assets/enemies/ShootMe.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")); |
|
|
|
|
floor_tex = new Decal(new Sprite("assets/floor.png")); |
|
|
|
|
|
|
|
|
|
InitializeEnemyData(); |
|
|
|
|
|
|
|
|
|
Mesh testEnemy("assets/enemies/ShootMe.obj", enemy_ShootMe_tex); |
|
|
|
|
enemy_ShootMe = { "assets/enemies/ShootMe.obj", enemy_ShootMe_tex }; |
|
|
|
|
bullet = { "assets/enemies/bullet.obj",bullet_tex }; |
|
|
|
|
mapMesh.texture = YAZAWA; |
|
|
|
|
mapWalls.texture = wall_tex; |
|
|
|
|
mapFloor.texture = floor_tex; |
|
|
|
|
|
|
|
|
|
InitializeEnemyData(); |
|
|
|
|
|
|
|
|
|
LoadLevel(1); |
|
|
|
|
|
|
|
|
|