1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#include "..\\include\\SWEngine.h"
#pragma comment (lib,"..\\lib\\SWUtil.lib")
#pragma comment (lib,"..\\lib\\SWTypes.lib")
#pragma comment (lib,"..\\lib\\SWCore.lib")
#pragma comment (lib,"..\\lib\\SWEngine.lib")
#include ".\\Objects\\Creature.h"
#include ".\\Objects\\PhysObj.h"
#include <list>
#include <iterator>
using namespace std;
#define WDTH 1280
#define HGHT 960
void drawWorld();
void renderLoop();
swApplication CreatureApp;
std::list<int> obj;
obj.push_back(5);
Creature crocy(300.0f,300.0f,128,128,".\\crocy\\\0",60,50,40);
Creature monster(5.0f,5.0f,128,128,".\\GreenEye\\\0",70,60,70);
int indexc=0;
int indexm=0;
int world,fontID;
//SW Setting
swKeyboardState state;
//-------------------------------------------------------------------------------------------
void GameLoop(){
swInputListenKeyboard(&state);
if(state.keyESCAPE){
swEngineExit();
}
//crocy
if(crocy.velY==0)
crocy.velY=1;
if(crocy.drawTarget.y+crocy.drawTarget.h>=HGHT)
crocy.velY=-1;
if(crocy.drawTarget.y<=0)
crocy.velY=1;
if(crocy.velX==0)
crocy.velX=1;
if(crocy.drawTarget.x+crocy.drawTarget.w>=WDTH)
crocy.velX=-1;
if(crocy.drawTarget.x<=0)
crocy.velX=1;
crocy.updatePos();
//monster
monster.stop();
if(monster.health>0)
{
if(state.keyUP){
monster.velY+=1;
}
if(state.keyLEFT){
monster.velX-=1;
}
if(state.keyDOWN){
monster.velY-=1;
}
if(state.keyRIGHT){
monster.velX+=1;
}
}
monster.updatePos();
renderLoop();
}
//-------------------------------------------------------------------------------------------
void renderLoop()
{
swGraphicsBeginScene();
//Background
swGraphicsSetBgColor0(0.0f,0.0f,0.6f);
//BlendingMode
swGraphicsSetBlendingMode(SW_BLENDING_MODE_SOLID);
//Draw Image
swGraphicsSetColor0(1,1,1,1);
drawWorld();
//update image index
indexc=(indexc+1)%(swGraphicsGetCountOfImgInSprite(crocy.pic[crocy.getAction()][crocy.getDir()])*3);
if(monster.health>0)
indexm=(indexm+1)%(swGraphicsGetCountOfImgInSprite(monster.pic[monster.getAction()][monster.getDir()])*3);
else
indexm=(indexm+1)>=(swGraphicsGetCountOfImgInSprite(monster.pic[monster.getAction()][monster.getDir()])*3)?indexm:indexm+1;
swGraphicsRenderSprite0(crocy.pic[crocy.getAction()][crocy.getDir()],(int)indexc/3,&(crocy.drawTarget));
if(monster.health>0)
{
if(crocy.drawTarget.x>monster.drawTarget.x&&crocy.drawTarget.x<(monster.drawTarget.x+monster.drawTarget.w))
if(crocy.drawTarget.y>monster.drawTarget.y&&crocy.drawTarget.y<(monster.drawTarget.y+monster.drawTarget.h))
monster.health--;
}
swGraphicsRenderSprite0(monster.pic[monster.getAction()][monster.getDir()],(int)indexm/3,&(monster.drawTarget));
swGraphicsRenderText(fontID,1,20,WDTH-50,HGHT-50,0,crocy.getHealth());
swGraphicsRenderText(fontID,1,20,10,HGHT-50,0,monster.getHealth());
swGraphicsEndScene();
};
//-------------------------------------------------------------------------------------------
void drawWorld()
{
int tileSz=2;
//draw dirt
for(int i=0;i<tileSz+1;i++)
for(int j=0;j<tileSz;j++)
{
swRect tilePos={(float)(0+512*i),(float)(0+512*j),512,512};
swGraphicsRenderSprite0(world,0,&tilePos);
}
}
//-------------------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
//Application Settings
CreatureApp.hInstance=hInstance;
CreatureApp.fullScreen=false;
CreatureApp.cursor=true;
CreatureApp.width=WDTH;
CreatureApp.height=HGHT;
CreatureApp.title="Creatures";
CreatureApp.path=".\\rsc\\";
CreatureApp.appRun=GameLoop;
//Application Execution
if(swEngineInit(&CreatureApp))
{
//Init My Application
crocy.init();
monster.init();
world=swGraphicsCreateSprite(".\\world\\");
fontID=swGraphicsCreateFont(".\\Font.tga");
swEngineRun();
swEngineExit();
}
return 0;
}
| |