public CAsteroid(IGameObjectManager pObjMan, IEngineCore pEngineCore, TPoint2 stPos, float fSize) : base(pObjMan, pEngineCore) { ObjType = EGameObjectType.GotAsteroid; _uiCounter = (uint)Rand.Next(500); RenderLayer = 2; _fSize = fSize; _fColScale = 0.8f; _stPos = stPos; _fAngle = Rand.Next(360); IResourceManager pResMan; IEngineSubSystem pSubSys; pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RESOURCE_MANAGER, out pSubSys); pResMan = (IResourceManager)pSubSys; IEngineBaseObject pBaseObj; pResMan.GetResourceByName(Res.MeshAsteroid, out pBaseObj); _pMesh = (IMesh)pBaseObj; pResMan.GetResourceByName(Res.TexAsteroid, out pBaseObj); _pTex = (ITexture)pBaseObj; }
public override void Draw() { _pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); TPoint2 pos = new TPoint2(_stPos.x - _fSize / 2f, _stPos.y - _fSize / 2f); TPoint2 dim = new TPoint2(_fSize, _fSize); _pRender2D.DrawTextureSprite(pTexExplo, ref pos, ref dim, _uiCounter / 2, _fAngle, E_EFFECT2D_FLAGS.EF_BLEND); }
public void Render() { TPoint2 shd_pos = stZombiePos + new TPoint2(10f, 10f); pRender2D.DrawTextureSprite(tex, ref shd_pos, ref pd, (uint)fZombieAnimFrame, fZombieAngle + 90f, (E_EFFECT2D_FLAGS.EF_COLOR_MIX | E_EFFECT2D_FLAGS.EF_BLEND)); pRender2D.DrawTextureSprite(tex, ref stZombiePos, ref pd, (uint)fZombieAnimFrame, fZombieAngle + 90f); }
public CShot(IGameObjectManager pObjMan, IEngineCore pEngineCore, TPoint2 stPos, float fAngle) : base(pObjMan, pEngineCore) { ObjType = EGameObjectType.GotShot; RenderLayer = 3; _fSize = 64f; _fColScale = 0.5f; this._stPos = stPos; this._fAngle = fAngle; IResourceManager pResMan; IEngineSubSystem pSubSys; pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RESOURCE_MANAGER, out pSubSys); pResMan = (IResourceManager)pSubSys; IEngineBaseObject pBaseObj; pResMan.GetResourceByName(Res.TexSpark, out pBaseObj); pTexSpark = (ITexture)pBaseObj; ISoundSample p_snd; pResMan.GetResourceByName(Res.SndFire, out pBaseObj); p_snd = (ISoundSample)pBaseObj; p_snd.Play(); }
public void Update(TPoint2 stMouseInCamera) { if (bFrameForward) { fZombieAnimFrame += 0.3f; } else { fZombieAnimFrame -= 0.3f; } if (bFrameForward && (int)fZombieAnimFrame == 15) { bFrameForward = false; } else if (!bFrameForward && (int)fZombieAnimFrame == 0) { bFrameForward = true; } fZombieAngle = TO_DEG((float)Math.Atan2(stMouseInCamera.y - (stZombiePos.y + 64f), stMouseInCamera.x - (stZombiePos.x + 64f))); stZombiePos.x += (float)Math.Cos(TO_RAD(fZombieAngle)) * 0.75f; stZombiePos.y += (float)Math.Sin(TO_RAD(fZombieAngle)) * 0.75f; }
public CExplo(IGameObjectManager pObjMan, IEngineCore pEngineCore, TPoint2 stPos, float fSize) : base(pObjMan, pEngineCore) { RenderLayer = 4; this._fSize = fSize; this._stPos = stPos; _fAngle = Rand.Next(360); IResourceManager pResMan; IEngineSubSystem pSubSys; pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RESOURCE_MANAGER, out pSubSys); pResMan = (IResourceManager)pSubSys; IEngineBaseObject pBaseObj; pResMan.GetResourceByName(Res.TexExplo, out pBaseObj); pTexExplo = (ITexture)pBaseObj; ISoundSample p_snd; pResMan.GetResourceByName(Res.SndExplo, out pBaseObj); p_snd = (ISoundSample)pBaseObj; p_snd.Play(); }
public CPlayer(IGameObjectManager pObjMan, IEngineCore pEngineCore) : base(pObjMan, pEngineCore) { _fVelocity = 0f; uiShotPause = 15; ObjType = EGameObjectType.GotPlayer; _stPos = new TPoint2(Res.GameVpWidth / 2f, Res.GameVpHeight / 2f); _fSize = 150f; _fColScale = 0.6f; dimPl = new TPoint3(_fSize, _fSize, _fSize); IResourceManager pResMan; IEngineSubSystem pSubSys; pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_INPUT, out pSubSys); pInput = (IInput)pSubSys; pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RESOURCE_MANAGER, out pSubSys); pResMan = (IResourceManager)pSubSys; IEngineBaseObject pBaseObj; pResMan.GetResourceByName(Res.MeshShip, out pBaseObj); pMesh = (IMesh)pBaseObj; pResMan.GetResourceByName(Res.TexShip, out pBaseObj); pTex = (ITexture)pBaseObj; pResMan.GetResourceByName(Res.TexSpark, out pBaseObj); pTexSpark = (ITexture)pBaseObj; }
void Update(IntPtr pParam) { bool prsd; pInput.GetKey(E_KEYBOARD_KEY_CODES.KEY_ESCAPE, out prsd); if (prsd) { pEngineCore.QuitEngine(); return; } pInput.GetMouseStates(out mouse); stMouseOnScreen = new TPoint2((float)mouse.iX, (float)mouse.iY); // convert our on-screen mouse coordinates to camera space // process zombie movement and its sprite animation zombie.Update(stMouseInCamera); // move copter copter.Update(); // Choper flies on screen between -60 and 856 coords so here's a way to convert its coords to [-100,100] range pSoundChannel.SetPan((int)Math.Round((copter.stCopterPos.x + 60 - 460) * 0.2)); counter++; }
void Render(IntPtr pParam) { pRender2D.Begin2D(); TPoint2 pc; pc = new TPoint2((float)(350 + Math.Cos(counter / 200.0) * 200), (float)(350 + Math.Sin(counter / 200.0) * 80)); TPoint2 ps = new TPoint2(1, 1); // make floating camera pRender2D.SetCamera(ref pc, //camera center (float)Math.Sin(counter / 50.0) * 15, //camera angle ref ps //camera scale ); pRender2D.ProjectScreenToCamera(ref stMouseOnScreen, out stMouseInCamera); pc = new TPoint2(-750f, -750f); ps = new TPoint2(2000f, 2000f); pRender2D.DrawTexture(pTextures[7], ref pc, ref ps, 0f, E_EFFECT2D_FLAGS.EF_TILE_TEXTURE); //draw stone layer with per vertex blending TColor4 white = TColor4.ColorWhite(); TColor4 col = TColor4.ColorWhite(0); TPoint2 p1 = new TPoint2(0f, 225f); uint x, y; pTextures[8].GetDimensions(out x, out y); TPoint2 pdim = new TPoint2((float)x, (float)y); pRender2D.SetVerticesColors(ref col, ref white, ref white, ref col); pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND)); pRender2D.SetVerticesColors(ref white, ref col, ref col, ref white); p1 = new TPoint2(0f + 256f, 225f); pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND)); pRender2D.SetVerticesColors(ref white, ref col, ref col, ref col); p1 = new TPoint2(0f + 256f, 225f + 256f); pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND)); pRender2D.SetVerticesColors(ref col, ref white, ref col, ref col); p1 = new TPoint2(0f, 225f + 256f); pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND)); //// set color mix to semi-transparent black for object shadows col = TColor4.ColorBlack(128); pRender2D.SetColorMix(ref col); for (int i = 0; i < MyMeshes.Length; i++) // all meshes with shadows except copter { MyMeshes[i].Draw(); } zombie.Render(); copter.Render((float)counter); pRender2D.End2D(); }
private void FireEngine(int side) { float multip = Res.Clamp(side, -1, 1); TPoint2 s = new TPoint2((float)(_stPos.x - Math.Cos(Res.ToRad(_fAngle - multip * 20f)) * 75f), (float)(_stPos.y - Math.Sin(Res.ToRad(_fAngle - multip * 20f)) * 75f)); _pObjMan.AddObject(new CSpark(_pObjMan, _pEngineCore, s)); }
public void Draw() { TPoint2 p1 = P2coord - new TPoint2(shift, shift); TPoint2 pdim = new TPoint2(P3Dim.x, P3Dim.y); pRender2D.DrawTexture(ShadowTex, ref p1, ref pdim, Angle, (E_EFFECT2D_FLAGS.EF_FLIP_VERTICALLY | E_EFFECT2D_FLAGS.EF_COLOR_MIX | E_EFFECT2D_FLAGS.EF_BLEND)); pRender2D.DrawMesh(Mesh, Tex, ref P2coord, ref P3Dim, ref P3Axis, Angle, E_EFFECT2D_FLAGS.EF_DEFAULT, true, 90, bClearDepthBuf); }
public Copter(MyMesh copterMesh, ITexture rotorTex, ITexture rotorShadow) { stCopterPos = new TPoint2(400, 200); fCopterAngle = 0f; CopterMesh = copterMesh; RotorTex = rotorTex; RotorShadow = rotorShadow; vint_dim = new TPoint2(400f, 400f); }
public void Update() { fCopterAngle += 0.5f; double DegAng = TO_RAD(fCopterAngle); stCopterPos += new TPoint2((float)Math.Cos(DegAng) * 4, (float)Math.Sin(DegAng) * 6); CopterMesh.P2coord = stCopterPos; CopterMesh.Angle = fCopterAngle; vint_pos = new TPoint2((float)(stCopterPos.x - 200f + Math.Cos(TO_RAD(fCopterAngle)) * 80f), (float)(stCopterPos.y - 200f + Math.Sin(TO_RAD(fCopterAngle)) * 80f)); }
// This function creates texture and renders models shadow to it. void RenderMeshToTexture(out ITexture pTex, IMesh pMesh, ITexture pMeshTex) { pResMan.CreateTexture(out pTex, null, 256, 256, E_TEXTURE_DATA_FORMAT.TDF_RGBA8, E_TEXTURE_CREATION_FLAGS.TCF_DEFAULT, E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_BILINEAR); pRender.SetRenderTarget(pTex); TPoint2 coords = new TPoint2(128f, 128f); TPoint3 dims = new TPoint3(256f, 256f, 1f); TPoint3 axis = new TPoint3(0f, 0f, 1f); pRender2D.DrawMesh(pMesh, pMeshTex, ref coords, ref dims, ref axis); pRender.SetRenderTarget(null); // switch back to on-screen drawing }
public override void Draw() { TColor4 c = TColor4.ColorRed(); _pRender2D.SetColorMix(ref c); TPoint2 pos = new TPoint2(_stPos.x - _fSize / 2f, _stPos.y - _fSize / 2f); TPoint2 dim = new TPoint2(_fSize, _fSize); _pRender2D.DrawTexture(pTexSpark, ref pos, ref dim, _uiCounter * 2f, E_EFFECT2D_FLAGS.EF_COLOR_MIX | E_EFFECT2D_FLAGS.EF_BLEND); base.Draw(); }
public void Render(float counter) { CopterMesh.Draw(); pRender2D.DrawTexture(RotorTex, ref vint_pos, ref vint_dim, counter * 25f); // make blinky rotor shadow TColor4 col = TColor4.ColorBlack((byte)(counter % 3 == 2 ? 64 : 16)); pRender2D.SetColorMix(ref col); TPoint2 p1 = vint_pos + new TPoint2(100f, 100f); pRender2D.DrawTexture(RotorShadow, ref p1, ref vint_dim, 0f, (E_EFFECT2D_FLAGS.EF_COLOR_MIX | E_EFFECT2D_FLAGS.EF_BLEND)); }
public MyMesh(IMesh Amesh, ITexture Atex, ITexture ShadowTex, TPoint2 Acoord, TPoint3 ADim, int shift, float AAngle = 0, bool bClearDepthBuf = false) { Mesh = Amesh; Tex = Atex; this.ShadowTex = ShadowTex; P2coord = Acoord; P3Dim = ADim; P3Axis = new TPoint3(0, 0, 1); Angle = AAngle; this.bClearDepthBuf = bClearDepthBuf; this.shift = shift; }
void Render(IntPtr pParam) { pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); TPoint2 pos = mousePos - new TPoint2(200f, 200f); TPoint2 dim = new TPoint2(400f, 400f); pRender2D.DrawTexture(pTexLight, ref pos, ref dim, 0, E_EFFECT2D_FLAGS.EF_BLEND); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_MASK); pos = new TPoint2(); pRender2D.DrawTexture(pTexTarget[2], ref pos, ref ScreenSize, 0, E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_FLIP_VERTICALLY); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); }
void Update(IntPtr pParam) { bool prsd; pInput.GetKey(E_KEYBOARD_KEY_CODES.KEY_ESCAPE, out prsd); if (prsd) { pEngineCore.QuitEngine(); return; } TMouseStates states; pInput.GetMouseStates(out states); stMousePos = new TPoint2((float)states.iX, (float)states.iY); if (counter % 250 == 0) { ISoundChannel chan; pSndOwl.PlayEx(out chan, E_SOUND_SAMPLE_PARAMS.SSP_NONE); chan.SetPan((int)(owlX - cameraPosition.x)); chan.Unaquire(); } cameraPosition.x = (float)(GAME_VP_WIDTH / 2f + 250f + Math.Cos(counter / 200f) * 225f); cameraPosition.y = GAME_VP_HEIGHT / 2f + 300f; cameraAngle = (float)Math.Sin(counter / 200f) * 5f; cameraScale = (float)(1f + Math.Abs(Math.Sin(counter / 200f) * 0.25f)); lights[0].x = (float)(650f - Math.Cos(counter / 100f) * 100f); lights[0].y = (float)(700f - Math.Sin(counter / 150f) * 50f); if (owlX > 1500f) { owlGoLeft = true; } else if (owlX < 100f) { owlGoLeft = false; } owlX += (owlGoLeft ? -1f : 1f) * 4f; ++counter; }
public override void Draw() { _pRender2D.DrawMesh(pMesh, pTex, ref _stPos, ref dimPl, ref axisPl, _fAngle - 90f, E_EFFECT2D_FLAGS.EF_DEFAULT, false); _pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); _pRender2D.SetColorMix(ref c); float sparkScale = Res.Clamp(uiShotPause / _shootingDelay, 0f, 1f); TPoint2 pos = new TPoint2((float)(_stPos.x - 32f * sparkScale + Math.Cos(Res.ToRad(_fAngle)) * 65f), (float)(_stPos.y - 32f * sparkScale + Math.Sin(Res.ToRad(_fAngle)) * 65f)); TPoint2 dim = new TPoint2(64f * sparkScale, 64f * sparkScale); _pRender2D.DrawTexture(pTexSpark, ref pos, ref dim, _uiCounter / 2f, E_EFFECT2D_FLAGS.EF_COLOR_MIX | E_EFFECT2D_FLAGS.EF_BLEND); base.Draw(); }
void DrawAdvanced(TRectF screen) { pTexBg.Draw2D((int)screen.x, (int)screen.y, (uint)screen.width, (uint)screen.height, 0, 0); TPoint2 pos = new TPoint2(screen.x + screen.width - 160f, screen.y + 20f); TPoint2 dim = new TPoint2(128f, 128f); pRender2D.DrawTexture(pTexPlanetRenderIn, ref pos, ref dim, 0, E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_FLIP_VERTICALLY /* because render targets are flipped */); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); // not to triangulate complex polygon every frame we can batch it this way and triangulation will be done only after update tick pRender2D.BeginBatch(false); pRender2D.DrawPolygon(pTexAnimWater[counter / 5 % 11], ref waterWaves.ToArray()[0], (uint)waterWaves.Count, E_PRIMITIVE2D_FLAGS.PF_FILL); pRender2D.EndBatch(); uint w, h; pTexJellyFish.GetDimensions(out w, out h); float x_offset = (float)(Math.Abs(Math.Cos(counter / 20f)) * 50); float y_offset = (float)(Math.Sin(counter / 10f) * 75); TPoint2 jellyPos = new TPoint2(screen.x + 175f, screen.y + 200f); TPoint2 vert1 = new TPoint2(); TPoint2 vert2 = new TPoint2(); TPoint2 vert3 = new TPoint2(x_offset, -y_offset); TPoint2 vert4 = new TPoint2(-x_offset, -y_offset); pRender2D.SetVerticesOffsets(ref vert1, ref vert2, ref vert3, ref vert4); TColor4 c = TColor4.ColorViolet(); pRender2D.SetColorMix(ref c); dim = new TPoint2(w / 2f, h / 2f); pRender2D.DrawTexture(pTexJellyFish, ref jellyPos, ref dim, -45f, E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_VERTICES_OFFSETS | E_EFFECT2D_FLAGS.EF_COLOR_MIX); pTexLightRound.GetDimensions(out w, out h); pos = jellyPos - new TPoint2(90f, 15f); dim = new TPoint2(w, h); pRender2D.DrawTexture(pTexLightRound, ref pos, ref dim, 0, E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX); }
public CScorePopup(IGameObjectManager pObjMan, IEngineCore pEngineCore, TPoint2 stPos, float fSize, uint uiScore) : base(pObjMan, pEngineCore) { _uiScore = uiScore; pObjMan.IncreaseGameScore(uiScore); RenderLayer = 5; _fSize = Res.Clamp(fSize / 100f, 0.25f, 5f); _stPos = stPos; IResourceManager pResMan; IEngineSubSystem pSubSys; pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RESOURCE_MANAGER, out pSubSys); pResMan = (IResourceManager)pSubSys; IEngineBaseObject pBaseObj; pResMan.GetResourceByName(Res.FntMain, out pBaseObj); _pFnt = (IBitmapFont)pBaseObj; }
public CSpark(IGameObjectManager pObjMan, IEngineCore pEngineCore, TPoint2 stPos) : base(pObjMan, pEngineCore) { RenderLayer = 1; _fSize = 96f; this._stPos = stPos; _fAngle = Rand.Next(360); pos = new TPoint2(stPos.x - _fSize / 2f, stPos.y - _fSize / 2f); dim = new TPoint2(_fSize, _fSize); IResourceManager pResMan; IEngineSubSystem pSubSys; pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RESOURCE_MANAGER, out pSubSys); pResMan = (IResourceManager)pSubSys; IEngineBaseObject pBaseObj; pResMan.GetResourceByName(Res.TexSpark, out pBaseObj); pTexSpark = (ITexture)pBaseObj; }
void Clear() { bugs.Clear(); for (var i = 0; i < 100; i++) { bugs.Add(new TBug(new TPoint2(rand.Next((int)ScreenWidth), rand.Next((int)ScreenHeight)), rand.Next(360))); } // render clear background image to texture for the first time for (uint i = 0; i < 2; i++) { pRender.SetRenderTarget(pTexTarget[i]); TPoint2 pos = new TPoint2(); pRender2D.DrawTexture(pTexBg, ref pos, ref ScreenSize, 0f, E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_TILE_TEXTURE); } pRender.SetRenderTarget(null); }
void DrawSprites(TRectF screen) { pTexGrass.Draw2D((int)screen.x, (int)screen.y, (uint)screen.width, (uint)screen.height, 0, 0); pTexGirl.Draw2DSimple((int)(screen.x + 400), (int)(screen.y + 30), (counter / 5) % 16); // simpliest way to draw animated sprite // draw tank uint width, height; TPoint2 scale = new TPoint2(2f, 2f); // scale X and Y axes by two pRender2D.SetScale(ref scale); pTexTankBody.GetDimensions(out width, out height); TPoint2 pos = new TPoint2(screen.x + 50f, screen.y + 150f); TPoint2 dimension = new TPoint2(width, height); pRender2D.DrawTexture(pTexTankBody, ref pos, ref dimension, 0, E_EFFECT2D_FLAGS.EF_ALPHA_TEST /* better than blending if we want to have sharp edges */ | E_EFFECT2D_FLAGS.EF_SCALE); pTexTankTurret.GetDimensions(out width, out height); TPoint2 rot = new TPoint2(48f, 64f); pRender2D.SetRotationPoint(ref rot); // rotate turret around it's base center, not the center of the image TPoint2 turretCenter = new TPoint2(screen.x + 50f - 10f, screen.y + 150f + 18f); float turretAngle = (float)(-30f + Math.Sin(counter / 15f) * 20f); dimension = new TPoint2(width, height); pRender2D.DrawTexture(pTexTankTurret, ref turretCenter, ref dimension, turretAngle, E_EFFECT2D_FLAGS.EF_ALPHA_TEST | E_EFFECT2D_FLAGS.EF_SCALE | E_EFFECT2D_FLAGS.EF_ROTATION_POINT); // draw light at the end of tank cannon pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); pTexLight.GetFrameSize(out width, out height); dimension = new TPoint2(width, height); pos = turretCenter + new TPoint2((float)Math.Cos(ToRad(turretAngle)) * 165f, (float)(Math.Sin(ToRad(turretAngle - 15f)) * 165f)); pRender2D.DrawTextureSprite(pTexLight, ref pos, ref dimension, (counter / 2) % 14, 0, E_EFFECT2D_FLAGS.EF_BLEND); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); // switch back blending mode to common one }
void RenderPlanetInToTexture() { TColor4 c = TColor4.ColorWhite(0); // set clear color here because SetRenderTarget will clear color buffer for us pRender.SetClearColor(ref c); pRender.SetRenderTarget(pTexPlanetRenderIn); pRender2D.Begin2D(); TPoint2 pos = new TPoint2(); TPoint2 dim = new TPoint2(256f, 256f); pRender2D.DrawTexture(pTexMask, ref pos, ref dim, 0f, E_EFFECT2D_FLAGS.EF_BLEND); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_MASK); float texOffsetX = counter / 200f; // generate two triangles to form a quad and move their texture coordinates horizontally TVertex2[] quad = { new TVertex2(0f, 0f, texOffsetX, 0f, 1f, 1f, 1f, 1f), new TVertex2(256f, 0f, 1f + texOffsetX, 0f, 1f, 1f, 1f, 1f), new TVertex2(256f, 256f, 1f + texOffsetX, 1f, 1f, 1f, 1f, 1f), new TVertex2(0f, 0f, texOffsetX, 0f, 1f, 1f, 1f, 1f), new TVertex2(256f, 256f, 1f + texOffsetX, 1f, 1f, 1f, 1f, 1f), new TVertex2(0f, 256f, 0f + texOffsetX, 1f, 1f, 1f, 1f, 1f) }; pRender2D.DrawTriangles(pTexPlanet, ref quad[0], (uint)quad.Length, E_PRIMITIVE2D_FLAGS.PF_FILL); pRender2D.End2D(); c = TColor4.ColorOfficialBlack(); pRender.SetClearColor(ref c); // set clear color back pRender.SetRenderTarget(null); }
void Render(IntPtr pParam) { if (pRender2D == null) return; pRender2D.Begin2D(); // Draw sky TPoint2 ps = new TPoint2(); TPoint2 pt = new TPoint2(GAME_VP_WIDTH, GAME_VP_HEIGHT); pRender2D.DrawTexture(pSky, ref ps, ref pt, 0, E_EFFECT2D_FLAGS.EF_NONE); // Draw background ps = new TPoint2(cameraPosition.x / 1.5f, cameraPosition.y / 1.5f); pt = new TPoint2(cameraScale, cameraScale); pRender2D.SetCamera(ref ps, cameraAngle, ref pt); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); ps = new TPoint2(-200f, 150f); pt = new TPoint2(1399f, 517f); TRectF rect = new TRectF(0f, 905f, 1399f, 517f); pRender2D.DrawTextureCropped(pBg, ref ps, ref pt, ref rect, 0.0f, E_EFFECT2D_FLAGS.EF_BLEND); // Draw moving fog on background ps = new TPoint2(cameraPosition.x / 1.2f, cameraPosition.y / 1.2f); pt = new TPoint2(cameraScale, cameraScale); pRender2D.SetCamera(ref ps, cameraAngle, ref pt); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); // Sometimes it's better to batch a lot of similar objects. pRender2D.BeginBatch(); TColor4 col = new TColor4(255, 255, 255, 64); pRender2D.SetColorMix(ref col); for (uint i = 0; i < 22; ++i) for (uint j = 0; j < 2; ++j) { ps = new TPoint2((float)(500f + Math.Sin((float)i) * 600f - Math.Cos((float)counter / 50f) * 10f * (i % 4)), (float)(475f + Math.Sin((float)j * 2.5f) * 150f - Math.Sin((float)counter / 50f) * 20f * (i % 3))); pt = new TPoint2(250f, 150f); pRender2D.DrawTexture(pFog, ref ps, ref pt, 0f, (E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX)); } pRender2D.EndBatch(); // Draw foreground scene // Setup camera and blending pt = new TPoint2(cameraScale, cameraScale); pRender2D.SetCamera(ref cameraPosition, cameraAngle, ref pt); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); // Owl col = new TColor4(150, 150, 150, 255); pRender2D.SetColorMix(ref col); // make sprite little darker ps = new TPoint2(owlX, 425f); pt = new TPoint2(48f, 128f); E_EFFECT2D_FLAGS EEF = (E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX | (owlGoLeft ? E_EFFECT2D_FLAGS.EF_FLIP_HORIZONTALLY : E_EFFECT2D_FLAGS.EF_DEFAULT)); pRender2D.DrawTextureSprite(pOwl, ref ps, ref pt, (uint)(counter / 3) % 15, 0f, EEF); // Draw tree ps = new TPoint2(); pt = new TPoint2(1399f, 900f); rect = new TRectF(0f, 0f, 1399f, 900f); pRender2D.DrawTextureCropped(pBg, ref ps, ref pt, ref rect, 0f, E_EFFECT2D_FLAGS.EF_BLEND); // Glowing disc under moving light pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); ps = new TPoint2(-100f, 0f); pt = new TPoint2(); pRender2D.SetVerticesOffsets(ref ps, ref ps, ref pt, ref pt); col = new TColor4(65, 59, 193, 255); pRender2D.SetColorMix(ref col); ps = new TPoint2(lights[0].x - 32f, lights[0].y + 64f); pt = new TPoint2(256f, 256f); pRender2D.DrawTexture(pLightRound, ref ps, ref pt, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_OFFSETS | E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX)); // Girl Shadow pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); ps = new TPoint2(-150f + (float)Math.Cos((float)counter / 100f) * 100f, -55f); pt = new TPoint2(-50f + (float)Math.Cos((float)counter / 100f) * 100f, -55f); TPoint2 pp = new TPoint2(15f, 5f); pRender2D.SetVerticesOffsets(ref ps, ref pt, ref pp, ref pp); col = new TColor4(0, 0, 0, 128); pRender2D.SetColorMix(ref col); ps = new TPoint2(550f, 725f); pt = new TPoint2(60f, 120f); pRender2D.DrawTextureSprite(pTexGirl, ref ps, ref pt, (uint)(counter / 5) % 16, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_OFFSETS | E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX)); // Girl Sprite pRender2D.DrawTextureSprite(pTexGirl, ref ps, ref pt, (uint)(counter / 5) % 16, 0f, E_EFFECT2D_FLAGS.EF_BLEND); // Lights pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); for (uint i = 0; i < 5; ++i) { ps = new TPoint2(lights[i].x, lights[i].y); pt = new TPoint2(64f, 128f); pRender2D.DrawTextureSprite(pLight, ref ps, ref pt, (uint)(counter / 2) % 14, 0f, E_EFFECT2D_FLAGS.EF_BLEND); } pRender2D.ResetCamera(); // We must calculate correct coordinates in game space because game resolution and screen resolution can be different. TPoint2 pos; pRender2D.AbsoluteToResolutionCorrect(ref stMousePos, out pos); ps = new TPoint2(pos.x - 37, pos.y - 37); pt = new TPoint2(75f, 75f); pRender2D.DrawTextureSprite(pVox, ref ps, ref pt, (uint)(counter / 2) % 16, 0f, E_EFFECT2D_FLAGS.EF_BLEND); uint tw, th; pFont.GetTextDimensions(HELP_TEXT, out tw, out th); col = TColor4.White; pFont.Draw2D((float)((GAME_VP_WIDTH - tw) / 2), (float)(GAME_VP_HEIGHT - th), HELP_TEXT, ref col); pRender2D.End2D(); }
void DrawPrimitives(TRectF screen) { TColor4 c; TRectF rect; rect = new TRectF(5f, 5f, 170f, 170f); c = TColor4.ColorBlue(); pRender2D.DrawRectangle(ref rect, ref c, E_PRIMITIVE2D_FLAGS.PF_LINE); rect = new TRectF(10f, 10f, 160f, 160f); c = TColor4.ColorGray(); pRender2D.DrawRectangle(ref rect, ref c, E_PRIMITIVE2D_FLAGS.PF_FILL); pRender2D.DrawTriangles(null, ref triangles[0], (uint)triangles.Length, E_PRIMITIVE2D_FLAGS.PF_FILL); for (int i = 0; i <= 12; i++) { TPoint2 p = new TPoint2(screen.x, screen.y) + new TPoint2(15f + 12 * i, 15f + 12 * i); c = TColor4.ColorTeal(); pRender2D.DrawPoint(ref p, ref c, (uint)(1 + i)); } for (int i = 0; i < 15; i++) { pRender2D.SetLineWidth((uint)(1 + i / 2)); TPoint2 p = new TPoint2(screen.width - i * 20, screen.height); TPoint2 p1 = new TPoint2(screen.width, screen.height - i * 20); c = TColor4.ColorOfficialOrange((byte)(255 - i * 17)); pRender2D.DrawLine(ref p, ref p1, ref c); } pRender2D.SetLineWidth(2); TColor4 c1 = TColor4.ColorAqua(), c2 = TColor4.ColorFuchsia(), c3 = new TColor4(), c4 = new TColor4(); pRender2D.SetVerticesColors(ref c1, ref c2, ref c3, ref c4); // override per vertex color for the line c = new TColor4(); TPoint2 p2 = new TPoint2(screen.width, 75f); TPoint2 p3 = new TPoint2(200f, screen.height); pRender2D.DrawLine(ref p2, ref p3, ref c, E_PRIMITIVE2D_FLAGS.PF_VERTICES_COLORS); pRender2D.SetLineWidth(1); c1 = TColor4.ColorGray(); c2 = TColor4.ColorMagenta(); c3 = TColor4.ColorOrange(); c4 = TColor4.ColorViolet(); pRender2D.SetVerticesColors(ref c1, ref c2, ref c3, ref c4); // override per vertex color for the rectangle rect = new TRectF(250f, 25f, 125f, 125f); pRender2D.DrawRectangle(ref rect, ref c, (E_PRIMITIVE2D_FLAGS.PF_LINE | E_PRIMITIVE2D_FLAGS.PF_VERTICES_COLORS)); c1 = TColor4.ColorBlack(0); c2 = TColor4.ColorGreen(); c3 = TColor4.ColorGreen(); c4 = TColor4.ColorBlack(0); pRender2D.SetVerticesColors(ref c1, ref c2, ref c3, ref c4); rect = new TRectF(260f, 35f, 105f, 105f); pRender2D.DrawRectangle(ref rect, ref c, (E_PRIMITIVE2D_FLAGS.PF_FILL | E_PRIMITIVE2D_FLAGS.PF_VERTICES_COLORS)); p2 = new TPoint2(125f, 50f); c = TColor4.ColorOrange(); pRender2D.DrawCircle(ref p2, 40, 32, ref c, E_PRIMITIVE2D_FLAGS.PF_FILL); c = TColor4.ColorWhite(); for (int i = 0; i < 6; i++) { pRender2D.DrawCircle(ref p2, (uint)(10 + i * 5), (uint)(4 + i * 2), ref c, E_PRIMITIVE2D_FLAGS.PF_LINE); } p2 = new TPoint2(200f, 250f); p3 = new TPoint2(110f, 34f); c = TColor4.ColorViolet(); pRender2D.DrawEllipse(ref p2, ref p3, 64, ref c, E_PRIMITIVE2D_FLAGS.PF_FILL); pRender2D.SetLineWidth(3); p3 = new TPoint2(100f, 30f); c = TColor4.ColorWhite(); pRender2D.DrawEllipse(ref p2, ref p3, 32, ref c, E_PRIMITIVE2D_FLAGS.PF_LINE); p3 = new TPoint2(80f, 24f); c = TColor4.ColorFuchsia(); pRender2D.DrawEllipse(ref p2, ref p3, 8, ref c, E_PRIMITIVE2D_FLAGS.PF_FILL); p3 = new TPoint2(30f, 75f); c = TColor4.ColorOrange(100); pRender2D.DrawEllipse(ref p2, ref p3, 64, ref c, E_PRIMITIVE2D_FLAGS.PF_FILL); pRender2D.DrawPolygon(null, ref star_polygon[0], (uint)triangles.Length, E_PRIMITIVE2D_FLAGS.PF_FILL); }
void Update(IntPtr pParam) { bool prsd; pInput.GetKey(E_KEYBOARD_KEY_CODES.KEY_ESCAPE, out prsd); if (prsd) { pEngineCore.QuitEngine(); return; } TMouseStates states; pInput.GetMouseStates(out states); stMousePos = new TPoint2((float)states.iX, (float)states.iY); if (counter % 250 == 0) { ISoundChannel chan; pSndOwl.PlayEx(out chan, E_SOUND_SAMPLE_PARAMS.SSP_NONE); chan.SetPan((int)(owlX - cameraPosition.x)); chan.Unaquire(); } cameraPosition.x = (float)(GAME_VP_WIDTH / 2f + 250f + Math.Cos(counter / 200f) * 225f); cameraPosition.y = GAME_VP_HEIGHT / 2f + 300f; cameraAngle = (float)Math.Sin(counter / 200f) * 5f; cameraScale = (float)(1f + Math.Abs(Math.Sin(counter / 200f) * 0.25f)); lights[0].x = (float)(650f - Math.Cos(counter / 100f) * 100f); lights[0].y = (float)(700f - Math.Sin(counter / 150f) * 50f); if (owlX > 1500f) owlGoLeft = true; else if (owlX < 100f) owlGoLeft = false; owlX += (owlGoLeft ? -1f : 1f) * 4f; ++counter; }
void Render(IntPtr pParam) { pRender2D.Begin2D(); TPoint2 pc; pc = new TPoint2((float)(350 + Math.Cos(counter / 200.0) * 200), (float)(350 + Math.Sin(counter / 200.0) * 80)); TPoint2 ps = new TPoint2(1, 1); // make floating camera pRender2D.SetCamera(ref pc,//camera center (float)Math.Sin(counter / 50.0) * 15,//camera angle ref ps//camera scale ); pRender2D.ProjectScreenToCamera(ref stMouseOnScreen, out stMouseInCamera); pc = new TPoint2(-750f, -750f); ps = new TPoint2(2000f, 2000f); pRender2D.DrawTexture(pTextures[7], ref pc, ref ps, 0f, E_EFFECT2D_FLAGS.EF_TILE_TEXTURE); //draw stone layer with per vertex blending TColor4 white = TColor4.ColorWhite(); TColor4 col = TColor4.ColorWhite(0); TPoint2 p1 = new TPoint2(0f, 225f); uint x, y; pTextures[8].GetDimensions(out x, out y); TPoint2 pdim = new TPoint2((float)x, (float)y); pRender2D.SetVerticesColors(ref col, ref white, ref white, ref col); pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND)); pRender2D.SetVerticesColors(ref white, ref col, ref col, ref white); p1 = new TPoint2(0f + 256f, 225f); pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND)); pRender2D.SetVerticesColors(ref white, ref col, ref col, ref col); p1 = new TPoint2(0f + 256f, 225f + 256f); pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND)); pRender2D.SetVerticesColors(ref col, ref white, ref col, ref col); p1 = new TPoint2(0f, 225f + 256f); pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND)); //// set color mix to semi-transparent black for object shadows col = TColor4.ColorBlack(128); pRender2D.SetColorMix(ref col); for (int i = 0; i < MyMeshes.Length; i++) // all meshes with shadows except copter { MyMeshes[i].Draw(); } zombie.Render(); copter.Render((float) counter); pRender2D.End2D(); }
public TBug(TPoint2 pos, float ang) { this.pos = pos; lifes = 100; angle = ang; }
void Update(IntPtr pParam) { // We must switch between two textures, because we can't call DrawTexture for texture which is current render target. // Firstly rendering previous background texture with new bugs corpses and trails. TPoint2 pos = new TPoint2(); TPoint2 dim; TColor4 c; uint co = counter % 2; pRender.SetRenderTarget(pTexTarget[co]); pRender2D.DrawTexture(pTexTarget[co == 1 ? 0 : 1], ref pos, ref ScreenSize, 0, E_EFFECT2D_FLAGS.EF_FLIP_VERTICALLY); for (int index = 0; index < bugs.Count; index++) { var bug = bugs[index]; if (bug.lifes < 0) { pSndDeath.Play(); pos = bug.pos + new TPoint2(5f, 0f); dim = new TPoint2(42f, 42f); pRender2D.DrawTexture(pTexBugCorpse, ref pos, ref dim, 90f + bug.angle); bugs.RemoveAt(index); } } // Secondly rendering background texture with moving bugs. pRender.SetRenderTarget(pTexTarget[2]); pos = new TPoint2(); pRender2D.DrawTexture(pTexTarget[counter % 2], ref pos, ref ScreenSize, 0, E_EFFECT2D_FLAGS.EF_FLIP_VERTICALLY); dim = new TPoint2(52f, 42f); foreach (var bug in bugs) { TPoint2 old = bug.pos; bug.pos.x += (float)Math.Cos(bug.angle * Math.PI / 180f) * 0.5f; bug.pos.y += (float)Math.Sin(bug.angle * Math.PI / 180f) * 0.5f; if (bug.pos.x > ScreenWidth || bug.pos.y > ScreenHeight || bug.pos.x < 0f || bug.pos.y < 0f) { bug.pos = old; bug.angle = rand.Next(360); } if (mousePos.DistTo(bug.pos) < 50f) { bug.lifes -= 2; } byte hp = (byte)(bug.lifes > 0 ? (bug.lifes * 2.5 > 256 ? 255: bug.lifes * 2.5) : 0); c = new TColor4(255, hp, hp, 255); pRender2D.SetColorMix(ref c); pRender2D.DrawTextureSprite(pTexBug, ref bug.pos, ref dim, ((uint)(bug.angle + counter / 4) % 8), 90f + bug.angle, E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX); } pRender.SetRenderTarget(null); // process user input here TMouseStates ms; pInput.GetMouseStates(out ms); mousePos = new TPoint2(ms.iX, ms.iY); bool prsd; pInput.GetKey(E_KEYBOARD_KEY_CODES.KEY_ESCAPE, out prsd); if (prsd) { pEngineCore.QuitEngine(); return; } pInput.GetKey(E_KEYBOARD_KEY_CODES.KEY_SPACE, out prsd); if (prsd) { Clear(); counter = 0; return; } ++counter; }
void Init(IntPtr pParam) { // get subsystems pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RESOURCE_MANAGER, out p_sub_sys); pResMan = (IResourceManager)p_sub_sys; pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_INPUT, out p_sub_sys); pInput = (IInput)p_sub_sys; pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RENDER, out p_sub_sys); pRender = (IRender)p_sub_sys; pRender.GetRender2D(out pRender2D); // create arrays IEngineBaseObject pObj = null; pTextures = new ITexture[TexCount]; pShadows = new ITexture[ShadowCount]; pMeshes = new IMesh[MeshCount]; // loading data pResMan.Load(RESOURCE_PATH + "sounds\\helicopter.wav", out pObj, 0); pSound = (ISoundSample)pObj; pSound.PlayEx(out pSoundChannel, E_SOUND_SAMPLE_PARAMS.SSP_LOOPED); for (int i = 0; i < TexCount; i++) { uint flags = TexNames[i].Contains("grass") ? (uint)(E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_BILINEAR | E_TEXTURE_LOAD_FLAGS.TLF_COORDS_REPEAT) : (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_2D; pResMan.Load(RESOURCE_PATH + TexNames[i], out pObj, flags); pTextures[i] = (ITexture)pObj; } pTextures[6].SetFrameSize(256, 256); // zombie sprite splitting for (int i = 0; i < MeshCount; i++) { pResMan.Load(RESOURCE_PATH + MeshNames[i], out pObj, (uint)E_MESH_MODEL_LOAD_FLAGS.MMLF_FORCE_MODEL_TO_MESH); pMeshes[i] = (IMesh)pObj; } // render shadows for (int i = 0; i < MeshCount; i++) { RenderMeshToTexture(out pShadows[i], pMeshes[i], pTextures[i]); } // render rotor shadow pResMan.CreateTexture(out pShadows[5], null, 256, 256, E_TEXTURE_DATA_FORMAT.TDF_RGBA8, E_TEXTURE_CREATE_FLAGS.TCF_DEFAULT, E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_BILINEAR); pRender.SetRenderTarget(pShadows[5]); TPoint2 coords = new TPoint2(128f, 128f); TColor4 col = TColor4.ColorWhite(); pRender2D.DrawCircle(ref coords, 100, 64, ref col, E_PRIMITIVE2D_FLAGS.PF_FILL); pRender.SetRenderTarget(null); // gather, fill and init 3d-objects data MyMeshes = new MyMesh[8] { new MyMesh(pMeshes[0], pTextures[0], pShadows[0], new TPoint2( 900f, 500f), new TPoint3(400f, 400f, 500f), 225), new MyMesh(pMeshes[0], pTextures[0], pShadows[0], new TPoint2(-250f, 300f), new TPoint3(400f, 400f, 500f), 225), new MyMesh(pMeshes[0], pTextures[0], pShadows[0], new TPoint2( 800f, 200f), new TPoint3(400f, 400f, 400f), 225), new MyMesh(pMeshes[1], pTextures[1], pShadows[1], new TPoint2( 0f, 450f), new TPoint3(300f, 300f, 400f), 175), new MyMesh(pMeshes[1], pTextures[1], pShadows[1], new TPoint2( 50f, 750f), new TPoint3(300f, 300f, 300f), 175), new MyMesh(pMeshes[2], pTextures[2], pShadows[2], new TPoint2( 500f, 150f), new TPoint3(400f, 400f, 500f), 225), new MyMesh(pMeshes[3], pTextures[3], pShadows[3], new TPoint2( 180f, 150f), new TPoint3(400f, 400f, 600f), 200), new MyMesh(pMeshes[3], pTextures[3], pShadows[3], new TPoint2( 600f, 550f), new TPoint3(400f, 400f, 600f), 200, 90) }; copter = new Copter(new MyMesh(pMeshes[4], pTextures[4], pShadows[4], new TPoint2(), new TPoint3(600, 600, 600), 200, 0, true), pTextures[5], pShadows[5]); zombie = new Zombie(pTextures[6]); }
// This function creates texture and renders models shadow to it. void RenderMeshToTexture(out ITexture pTex, IMesh pMesh, ITexture pMeshTex) { pResMan.CreateTexture(out pTex, null, 256, 256, E_TEXTURE_DATA_FORMAT.TDF_RGBA8, E_TEXTURE_CREATE_FLAGS.TCF_DEFAULT, E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_BILINEAR); pRender.SetRenderTarget(pTex); TPoint2 coords = new TPoint2(128f, 128f); TPoint3 dims = new TPoint3(256f, 256f, 1f); TPoint3 axis = new TPoint3(0f, 0f, 1f); pRender2D.DrawMesh(pMesh, pMeshTex, ref coords, ref dims, ref axis); pRender.SetRenderTarget(null); // switch back to on-screen drawing }
public void Update(TPoint2 stMouseInCamera) { if (bFrameForward) fZombieAnimFrame += 0.3f; else fZombieAnimFrame -= 0.3f; if (bFrameForward && (int)fZombieAnimFrame == 15) bFrameForward = false; else if (!bFrameForward && (int)fZombieAnimFrame == 0) bFrameForward = true; fZombieAngle = TO_DEG((float)Math.Atan2(stMouseInCamera.y - (stZombiePos.y + 64f), stMouseInCamera.x - (stZombiePos.x + 64f))); stZombiePos.x += (float)Math.Cos(TO_RAD(fZombieAngle)) * 0.75f; stZombiePos.y += (float)Math.Sin(TO_RAD(fZombieAngle)) * 0.75f; }
void Render(IntPtr pParam) { if (pRender2D == null) { return; } pRender2D.Begin2D(); // Draw sky TPoint2 ps = new TPoint2(); TPoint2 pt = new TPoint2(GAME_VP_WIDTH, GAME_VP_HEIGHT); pRender2D.DrawTexture(pSky, ref ps, ref pt, 0, E_EFFECT2D_FLAGS.EF_NONE); // Draw background ps = new TPoint2(cameraPosition.x / 1.5f, cameraPosition.y / 1.5f); pt = new TPoint2(cameraScale, cameraScale); pRender2D.SetCamera(ref ps, cameraAngle, ref pt); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); ps = new TPoint2(-200f, 150f); pt = new TPoint2(1399f, 517f); TRectF rect = new TRectF(0f, 905f, 1399f, 517f); pRender2D.DrawTextureCropped(pBg, ref ps, ref pt, ref rect, 0.0f, E_EFFECT2D_FLAGS.EF_BLEND); // Draw moving fog on background ps = new TPoint2(cameraPosition.x / 1.2f, cameraPosition.y / 1.2f); pt = new TPoint2(cameraScale, cameraScale); pRender2D.SetCamera(ref ps, cameraAngle, ref pt); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); // Sometimes it's better to batch a lot of similar objects. pRender2D.BeginBatch(); TColor4 col = new TColor4(255, 255, 255, 64); pRender2D.SetColorMix(ref col); for (uint i = 0; i < 22; ++i) { for (uint j = 0; j < 2; ++j) { ps = new TPoint2((float)(500f + Math.Sin((float)i) * 600f - Math.Cos((float)counter / 50f) * 10f * (i % 4)), (float)(475f + Math.Sin((float)j * 2.5f) * 150f - Math.Sin((float)counter / 50f) * 20f * (i % 3))); pt = new TPoint2(250f, 150f); pRender2D.DrawTexture(pFog, ref ps, ref pt, 0f, (E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX)); } } pRender2D.EndBatch(); // Draw foreground scene // Setup camera and blending pt = new TPoint2(cameraScale, cameraScale); pRender2D.SetCamera(ref cameraPosition, cameraAngle, ref pt); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); // Owl col = new TColor4(150, 150, 150, 255); pRender2D.SetColorMix(ref col); // make sprite little darker ps = new TPoint2(owlX, 425f); pt = new TPoint2(48f, 128f); E_EFFECT2D_FLAGS EEF = (E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX | (owlGoLeft ? E_EFFECT2D_FLAGS.EF_FLIP_HORIZONTALLY : E_EFFECT2D_FLAGS.EF_DEFAULT)); pRender2D.DrawTextureSprite(pOwl, ref ps, ref pt, (uint)(counter / 3) % 15, 0f, EEF); // Draw tree ps = new TPoint2(); pt = new TPoint2(1399f, 900f); rect = new TRectF(0f, 0f, 1399f, 900f); pRender2D.DrawTextureCropped(pBg, ref ps, ref pt, ref rect, 0f, E_EFFECT2D_FLAGS.EF_BLEND); // Glowing disc under moving light pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); ps = new TPoint2(-100f, 0f); pt = new TPoint2(); pRender2D.SetVerticesOffsets(ref ps, ref ps, ref pt, ref pt); col = new TColor4(65, 59, 193, 255); pRender2D.SetColorMix(ref col); ps = new TPoint2(lights[0].x - 32f, lights[0].y + 64f); pt = new TPoint2(256f, 256f); pRender2D.DrawTexture(pLightRound, ref ps, ref pt, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_OFFSETS | E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX)); // Girl Shadow pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); ps = new TPoint2(-150f + (float)Math.Cos((float)counter / 100f) * 100f, -55f); pt = new TPoint2(-50f + (float)Math.Cos((float)counter / 100f) * 100f, -55f); TPoint2 pp = new TPoint2(15f, 5f); pRender2D.SetVerticesOffsets(ref ps, ref pt, ref pp, ref pp); col = new TColor4(0, 0, 0, 128); pRender2D.SetColorMix(ref col); ps = new TPoint2(550f, 725f); pt = new TPoint2(60f, 120f); pRender2D.DrawTextureSprite(pTexGirl, ref ps, ref pt, (uint)(counter / 5) % 16, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_OFFSETS | E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX)); // Girl Sprite pRender2D.DrawTextureSprite(pTexGirl, ref ps, ref pt, (uint)(counter / 5) % 16, 0f, E_EFFECT2D_FLAGS.EF_BLEND); // Lights pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); for (uint i = 0; i < 5; ++i) { ps = new TPoint2(lights[i].x, lights[i].y); pt = new TPoint2(64f, 128f); pRender2D.DrawTextureSprite(pLight, ref ps, ref pt, (uint)(counter / 2) % 14, 0f, E_EFFECT2D_FLAGS.EF_BLEND); } pRender2D.ResetCamera(); // We must calculate correct coordinates in game space because game resolution and screen resolution can be different. TPoint2 pos; pRender2D.AbsoluteToResolutionCorrect(ref stMousePos, out pos); ps = new TPoint2(pos.x - 37, pos.y - 37); pt = new TPoint2(75f, 75f); pRender2D.DrawTextureSprite(pVox, ref ps, ref pt, (uint)(counter / 2) % 16, 0f, E_EFFECT2D_FLAGS.EF_BLEND); uint tw, th; pFont.GetTextDimensions(HELP_TEXT, out tw, out th); col = TColor4.White; pFont.Draw2D((float)((GAME_VP_WIDTH - tw) / 2), (float)(GAME_VP_HEIGHT - th), HELP_TEXT, ref col); pRender2D.End2D(); }