1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.Linq; |
---|
4 | using Microsoft.Xna.Framework; |
---|
5 | using Microsoft.Xna.Framework.Content; |
---|
6 | using Microsoft.Xna.Framework.Graphics; |
---|
7 | |
---|
8 | namespace WindowsGame1 |
---|
9 | { |
---|
10 | public class RendererBase |
---|
11 | {//sisältää kaikkea jännää yksittäisten asioiden renderöintiin. |
---|
12 | public SpriteBatch spriteBatch; |
---|
13 | public RendererBase(SpriteBatch spriteBatch) { |
---|
14 | this.spriteBatch = spriteBatch; |
---|
15 | } |
---|
16 | public void renderGroundTile(Texture2D texture, int x, int y) |
---|
17 | {//renderöi maata |
---|
18 | //maatilen koko on 64x64. |
---|
19 | spriteBatch.Draw(texture, new Rectangle(x * 64, y * 64, texture.Width, texture.Height), null, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0.01f); |
---|
20 | } |
---|
21 | public void renderGroundObject(Texture2D texture, int x, int y, Vector2 size, Matrix matrix, Camera camera) |
---|
22 | {//renderöi maassa olevan asian (ei liiku) |
---|
23 | Vector2 position = Vector2.Transform(new Vector2((x + 0.5f) * 64, (y + 0.5f) * 64), matrix) - new Vector2(size.X / 2, size.Y); |
---|
24 | spriteBatch.Draw(texture, new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y), null, Color.White, 0, Vector2.Zero, SpriteEffects.None, (position.Y + size.Y) / (camera.size.Y + 256*camera.zoomFactor/*128 on suurimman objektin korkeus*/)); |
---|
25 | } |
---|
26 | public void renderDistantSprite(Texture2D texture, Vector3 position, Vector2 size, Matrix matrix) |
---|
27 | {//Renderöi kaukaisia juttuja kuten auringon ja tähdet |
---|
28 | Vector3 calcPosition = Vector3.Transform(position * 64.0f, matrix); |
---|
29 | spriteBatch.Draw(texture, new Rectangle((int)(calcPosition.X), (int)(calcPosition.Y), (int)size.X, (int)size.Y), null, Color.White, 0f, new Vector2(texture.Width / 2, texture.Height / 2), SpriteEffects.None, 1f); |
---|
30 | } |
---|
31 | public void renderBackground(Texture2D texture, Vector2 size) |
---|
32 | { |
---|
33 | spriteBatch.Draw(texture, new Rectangle(0, 0, (int)size.X, (int)size.Y), Color.White); |
---|
34 | } |
---|
35 | } |
---|
36 | } |
---|