]> git.r.bdr.sh - rbdr/super-polarity/blob - SuperPolarity/Actors/GameActor.cs
Update project to work on VS Code mac
[rbdr/super-polarity] / SuperPolarity / Actors / GameActor.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
8
9 namespace SuperPolarity
10 {
11 public class GameActor : Actor
12 {
13 // Graphics / In-Game
14 protected Texture2D Texture;
15 protected Vector2 Origin;
16
17 // Constraints / Behavior
18 public int HP;
19 protected bool Immortal;
20 public int Value;
21
22 public override int Width
23 {
24 get { return Texture.Width; }
25 }
26
27 public override int Height
28 {
29 get { return Texture.Height; }
30 }
31
32 public GameActor(SuperPolarity newGame)
33 : base(newGame)
34 {
35 }
36
37 public virtual void Initialize(Texture2D texture, Vector2 position)
38 {
39 base.Initialize (position);
40
41 Texture = texture;
42
43 Collides = true;
44
45 Origin = new Vector2(Texture.Width / 2, Texture.Height / 2);
46
47 HP = 1;
48 Immortal = false;
49
50 Value = 1;
51 InitBox ();
52 }
53
54 public override void Draw(SpriteBatch spriteBatch)
55 {
56 base.Draw(spriteBatch);
57
58 try {
59 spriteBatch.Draw(Texture, Position, null, Color, Angle, Origin, 1f, SpriteEffects.None, 0f);
60 } catch (ArgumentNullException) {
61 Console.WriteLine ("Where'd the texture go?.");
62 }
63 }
64
65 public override void CleanUp()
66 {
67 base.CleanUp ();
68 Texture = null;
69 }
70
71
72 public void TakeDamage(int amount)
73 {
74 if (!Immortal)
75 {
76 HP = HP - amount;
77 if (HP < 0)
78 {
79 Die();
80 }
81 }
82 }
83 }
84 }