Оператор ЭВМ
Регистрация: 03.09.2014
Сообщений: 20
Написано 2 полезных сообщений (для 2 пользователей)
|
Minecraft на Xors3D C++
Здравствуйте, делал майн на хорсе, компилится, но не запускается.
Вот сбствнн сам код:
![](images/chestnut/misc/code_html.gif)
// include Xors3d Engine header
#include <xors3d.h>
#include <iostream>
int ent; //Unmatched
int kol_blocks; // Количество блоков
int sel_block; // Пикнутый блок
int blck_tp; // Тип
int dist; // Дистанция
int pick; // Луч выделения
int ACube = xCreatePivot(); // x3
void CreateBlockOnPick(float x, float y, float z, int blck_tp);
float CurveValue(float newvalue, float oldvalue, float increments)
{
if (increments > 1.0f) oldvalue = oldvalue - (oldvalue - newvalue) / increments;
if (increments <= 1.0f) oldvalue = newvalue;
return oldvalue;
}
// program entry point
int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR commandLine, int commandShow)
{
// шрифт
int fnt12 = xLoadFont("Arial", 12);
xSetFont(fnt12);
// setup maximum supported AntiAlias Type
xSetAntiAliasType(xGetMaxAntiAlias());
// set application window caption
xAppTitle("Minecraft | by Vovan Kot");
// initialize graphics mode
xGraphics3D(800, 600, 32, false, true);
xSetBuffer(xBackBuffer());
// hide mouse pointer
xHidePointer();
// enable antialiasing
xAntiAlias(true);
// create camera
int camera_piv = xCreatePivot();
int camera = xCreateCamera();
xPositionEntity(camera, 0, 5, -15);
xCameraClsColor(camera, 0, 165, 250);
xCameraRange(camera, 0.5, 50);
// light
int light = xCreateLight();
xRotateEntity(light, 30, 0, 0);
// position camera
xPositionEntity(camera, 0, 2, -10);
// for mouse look
xMoveMouse(xGraphicsWidth() / 2, xGraphicsHeight() / 2);
float mousespeed = 0.5;
float camerasmoothness = 4.5;
float mxs = 0.0f;
float mys = 0.0f;
float camxa = 0.0f;
float camya = 0.0f;
//a-cubes
//Верх
int ACube_top = xCreateCube(ACube);
xPositionEntity(ACube_top, 0, 0.5, 0);
xScaleEntity(ACube_top, 0.48, 0.05, 0.48);
xEntityPickMode(ACube_top, 2);
xNameEntity(ACube_top, "top");
//Низ
int ACube_bottom = xCreateCube(ACube);
xPositionEntity(ACube_bottom, 0, -0.5, 0);
xScaleEntity(ACube_bottom, 0.48, 0.05, 0.48);
xEntityPickMode(ACube_bottom, 2);
xNameEntity(ACube_bottom, "bottom");
//Перед
int ACube_front = xCreateCube(ACube);
xPositionEntity(ACube_front, 0, 0, 0.5);
xScaleEntity(ACube_front, 0.48, 0.48, 0.05);
xEntityPickMode(ACube_front, 2);
xNameEntity(ACube_front, "front");
//Зад
int ACube_back = xCreateCube(ACube);
xPositionEntity(ACube_back, 0, 0, -0.5);
xScaleEntity(ACube_back, 0.48, 0.48, 0.05);
xEntityPickMode(ACube_back, 2);
xNameEntity(ACube_back, "back");
//Левый бок
int ACube_left = xCreateCube(ACube);
xPositionEntity(ACube_left, -0.5, 0, 0);
xScaleEntity(ACube_left, 0.05, 0.48, 0.48);
xEntityPickMode(ACube_left, 2);
xNameEntity(ACube_left, "left");
//Правый бок
int ACube_right = xCreateCube(ACube);
xPositionEntity(ACube_right, 0.5, 0, 0);
xScaleEntity(ACube_right, 0.05, 0.48, 0.48);
xEntityPickMode(ACube_right, 2);
xNameEntity(ACube_right, "right");
xHideEntity(ACube);
//"Выделятор"
int pick_ent_0; //Предыдущий объект
// main program loop
while (!xKeyDown(KEY_ESCAPE))
{
// camera control
if (xKeyDown(KEY_W)) xMoveEntity(camera, 0, 0, 1);
if (xKeyDown(KEY_S)) xMoveEntity(camera, 0, 0, -1);
if (xKeyDown(KEY_A)) xMoveEntity(camera, -1, 0, 0);
if (xKeyDown(KEY_D)) xMoveEntity(camera, 1, 0, 0);
mxs = CurveValue(xMouseXSpeed() * mousespeed, mxs, camerasmoothness);
mys = CurveValue(xMouseYSpeed() * mousespeed, mys, camerasmoothness);
camxa = fmodf(camxa - mxs, 360.0f);
camya = camya + mys;
if (camya < -89.0f) camya = -89.0f;
if (camya > 89.0f) camya = 89.0f;
xRotateEntity(camera, camya, camxa, 0.0);
xMoveMouse(xGraphicsWidth() / 2, xGraphicsHeight() / 2);
if (pick_ent_0 != 0)
{
xEntityColor(pick_ent_0, 255, 255, 255);
}
pick = xCameraPick(camera, xMouseX(), xMouseY());
if (pick != 0) dist = xEntityDistance(camera, pick);
if (pick != 0 && pick != ACube_top && pick != ACube_bottom && pick != ACube_front && pick != ACube_back && pick != ACube_left && pick != ACube_right)
{
sel_block = pick;
pick_ent_0 = sel_block;
xPositionEntity(ACube, xEntityX(pick, true), xEntityY(pick, true), xEntityZ(pick, true));
xShowEntity(ACube);
}
if (dist <= 5 && sel_block != 0) xEntityColor(sel_block, 255, 255, 0);
if (dist <= 5)
{
if (xMouseHit(1) && sel_block != 0 && pick != 0) { /*DeleteBlock(sel_block);*/ xHideEntity(ACube); }
if (xMouseHit(2) && pick != 0) CreateBlockOnPick(xPickedX(), xPickedY(), xPickedZ(), 0);
}
// update animations
xUpdateWorld();
xRenderWorld();
// draw texts
char buffer[128];
sprintf(buffer, "FPS: %i", xGetFPS());
xText(10, 10, buffer);
xText(xGraphicsWidth() / 2, xGraphicsHeight() / 2, "+");
// switch back buffer
xFlip();
}
return 0;
}
void CreateBlock(float x, float y, float z, int blck_tp)
{
switch(blck_tp)
{
case 0:
{
int ent = xCreateCube();
xEntityTexture(ent, xLoadTexture("media/textures/bricks.jpg"));
kol_blocks += 1;
xPositionEntity(ent, x, y, z);
xScaleEntity(ent, 0.5, 0.5, 0.5);
xEntityPickMode(ent, 2);
}
}
}
void CreateBlockOnPick(float x, float y, float z, int blck_tp)
{
int piv = xCreatePivot();
if (xEntityName(pick) == "top") xPositionEntity(piv, xEntityX(ACube), xEntityY(ACube) + 1, xEntityZ(ACube));
else if (xEntityName(pick) == "bottom") xPositionEntity(piv, xEntityX(ACube), xEntityY(ACube) - 1, xEntityZ(ACube));
else if (xEntityName(pick) == "front") xPositionEntity(piv, xEntityX(ACube), xEntityY(ACube), xEntityZ(ACube) + 1);
else if (xEntityName(pick) == "back") xPositionEntity(piv, xEntityX(ACube), xEntityY(ACube), xEntityZ(ACube) - 1);
else if (xEntityName(pick) == "left") xPositionEntity(piv, xEntityX(ACube) - 1, xEntityY(ACube), xEntityZ(ACube));
else if (xEntityName(pick) == "right") xPositionEntity(piv, xEntityX(ACube) + 1, xEntityY(ACube), xEntityZ(ACube));
/*
switch (xEntityName(pick))
{
case 'top': xPositionEntity(piv, xEntityX(ACube), xEntityY(ACube) + 1, xEntityZ(ACube));
case 'bot': xPositionEntity(piv, xEntityX(ACube), xEntityY(ACube) - 1, xEntityZ(ACube));
case 'fron': xPositionEntity(piv, xEntityX(ACube), xEntityY(ACube), xEntityZ(ACube) + 1);
case 'back': xPositionEntity(piv, xEntityX(ACube), xEntityY(ACube), xEntityZ(ACube) - 1);
case 'left': xPositionEntity(piv, xEntityX(ACube) - 1, xEntityY(ACube), xEntityZ(ACube));
case 'righ': xPositionEntity(piv, xEntityX(ACube) + 1, xEntityY(ACube), xEntityZ(ACube));
}
*/
CreateBlock(xEntityX(piv), xEntityY(piv), xEntityZ(piv), blck_tp);
xFreeEntity(piv);
}
|