Maze /Forms/Play.Graphics.cs

Language C# Lines 228
MD5 Hash 41012b550e3760d4957973937029f2ca Estimated Cost $3,918 (why?)
Repository git://github.com/Concliff/Maze.git View Raw File View Project SPDX
  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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
using Maze.Classes;
using System.Windows.Forms;
using System.Drawing;
using System.Collections.Generic;

namespace Maze.Forms
{
    partial class Play
    {
        void RightPanelPB_Paint(object sender, PaintEventArgs e)
        {
            if (!this.playStarted)
                return;
            // Total game time
            e.Graphics.DrawString("Time: " + (this.gameTime.ElapsedMilliseconds / 1000).ToString(), new Font("Arial", 14), new SolidBrush(Color.White), 10, 30);
            // Ooze drops count to collect.
            e.Graphics.DrawString("Drops x " + Map.Instance.DropsRemain.ToString(),
                new Font("Arial", 14), new SolidBrush(Color.White), 10, 50);
            // Game Scores.
            e.Graphics.DrawString("Total scores: " + Player.Score, new Font("Arial", 12), new SolidBrush(Color.White), 10, 70);
        }

        void LeftPanelPB_Paint(object sender, PaintEventArgs e)
        {
            if (!this.playStarted)
                return;

            // Calcs Ooze energy percentage
            int playerOozePercent = Player.OozeEnergy * 100 / Slug.MaxOozeEnergy;
            Brush emptyBrush = new SolidBrush(Color.Black);
            Brush filledBrush = new SolidBrush(Color.Green);
            Rectangle oozeBar = new Rectangle(20, 100, 100, 30);
            Rectangle oozeAmount = new Rectangle(20, 100, 100 * playerOozePercent / 100, 30);

            // Draw green and black rectanges to show current Energy level.
            e.Graphics.FillRectangle(emptyBrush, oozeBar);
            e.Graphics.FillRectangle(filledBrush, oozeAmount);
            e.Graphics.DrawString(Player.OozeEnergy.ToString(), new Font("Arial", 14), new SolidBrush(Color.White), 50, 105);
        }

        void CellPB_Paint(object sender, PaintEventArgs e)
        {
            // Only when game is started
            if (this.playStarted)
                RebuildGraphMap(e.Graphics);
        }

        private void pbAuraIcons_Paint(object sender, PaintEventArgs e)
        {
            EffectHolder holder = (EffectHolder)((PictureBox)sender).Tag;
            int durationInSeconds = holder.Duration / 1000;

            // Draw Aura Timer
            // Skip if duration == -1 (One-tact effect)
            if (holder.EffectInfo.Duration == -1)
                return;
            // Alignment centre
            int x;
            if ((durationInSeconds) / 10 > 0)
                x = 9;
            else
                x = 15;

            e.Graphics.DrawString(durationInSeconds.ToString(), new Font("Arial", 16), new SolidBrush(Color.White), x, 50); 
        }

        private void SpellBarPB_Paint(object sender, PaintEventArgs e)
        {
            SpellBarPictureBox paintedSpellPB = (SpellBarPictureBox)sender;
            // Draw spell keyboard digits
            // Draw bigger white digits and smaller red one simulating text shadow effect.
            e.Graphics.DrawString(paintedSpellPB.SpellNumber.ToString(), new Font("Arial", 14, FontStyle.Bold), new SolidBrush(Color.White), 35, -2);
            e.Graphics.DrawString(paintedSpellPB.SpellNumber.ToString(), new Font("Arial", 12, FontStyle.Bold), new SolidBrush(Color.Red), 36, 0);
        }

        private void Play_Paint(object sender, PaintEventArgs e)
        {
            //RebuildGraphMap();
        }

        private void pbMenuItems_MouseEnter(object sender, System.EventArgs e)
        {
            PictureBox SenderPB = (PictureBox)sender;
            Graphics g;
            g = SenderPB.CreateGraphics();
            g.DrawString(SenderPB.Name, this.fontMenu, this.brushMenuSelected, 0, 0);
        }

        private void pbMenuItems_MouseLeave(object sender, System.EventArgs e)
        {
            PictureBox SenderPB = (PictureBox)sender;
            Graphics g;
            g = SenderPB.CreateGraphics();
            g.DrawString(SenderPB.Name, this.fontMenu, this.brushMenuUnselected, 0, 0);
        }

        private void pbMenuItems_Paint(object sender, PaintEventArgs e)
        {
            PictureBox senderPB = (PictureBox)sender;
            e.Graphics.DrawString(senderPB.Name, this.fontMenu, this.brushMenuUnselected, 0, 0);
        }

        /// <summary>
        /// RePaint PlayForm map pictures.
        /// Include images of the player, blocks and objects on a block
        /// </summary>
        private void RebuildGraphMap(Graphics gCellBP)
        {
            GridLocation PBLocation = new GridLocation();
            Cell Block = new Cell();

            List<Maze.Classes.Object> objectsOnMap = new List<Maze.Classes.Object>();

            // CellGraph
            for (int i = 0; i < GlobalConstants.GRIDMAP_WIDTH; ++i)
                for (int j = 0; j < GlobalConstants.GRIDMAP_HEIGHT; ++j)
                {
                    // Calculated location point for every block
                    int x, y;
                    x = /*CellPB.Location.X*/ +(i - 1) * GlobalConstants.CELL_WIDTH - (Player.Position.X - 25);
                    y = /*CellPB.Location.Y*/ +(j - 1) * GlobalConstants.CELL_HEIGHT - (Player.Position.Y - 25);
                    PBLocation.X = Player.Position.Location.X + i - GlobalConstants.GRIDMAP_WIDTH / 2;
                    PBLocation.Y = Player.Position.Location.Y + j - GlobalConstants.GRIDMAP_HEIGHT / 2;
                    PBLocation.Z = Player.Position.Location.Z;
                    PBLocation.Level = Player.Position.Location.Level;
                    Block = Map.Instance.GetCell(PBLocation);

                    // Draw Grid Cell image
                    gCellBP.DrawImage(PictureManager.GetPictureByType(Block.Type), x, y, GlobalConstants.CELL_WIDTH, GlobalConstants.CELL_HEIGHT);


                    // Draw Start Block
                    if (Block.HasAttribute(CellAttributes.IsStart))
                    {
                        gCellBP.DrawImage(PictureManager.StartImage, x + 5, y + 5, 40, 40);
                    }

                    // Draw Finish Block
                    if (Block.HasAttribute(CellAttributes.IsFinish))
                    {
                        gCellBP.DrawImage(PictureManager.FinishImage, x + 5, y + 5, 40, 40);
                    }

                    // Include all objects in this grid
                    objectsOnMap.AddRange(ObjectContainer.Instance.GetObjects(Block.Location));

                }

            /* Draw Visible Objects
             * Order:
             * 1. Slime
             * 2. GridObjects
             * 3. Units
             * 4. Slug
             */
            Image objectImage;

            for (int j = 0; j < 4; ++j)
                for (int i = 0; i < objectsOnMap.Count; ++i)
                {
                    // Default NULL
                    objectImage = null;
                    switch (j)
                    {
                        case 0:
                            // Slime
                            if (objectsOnMap[i].ObjectType == ObjectTypes.GridObject &&
                                ((GridObject)objectsOnMap[i]).GridObjectType == GridObjectTypes.Slime)
                            {
                                objectImage = PictureManager.SlimeImage;
                            }
                            else
                                continue;
                            break;
                        case 1:
                            // GridObjects
                            if (objectsOnMap[i].ObjectType == ObjectTypes.GridObject)
                            {
                                GridObject gridObject = (GridObject)objectsOnMap[i];
                                if (gridObject.GridObjectType == GridObjectTypes.Slime)
                                    continue;

                                objectImage = PictureManager.GetGridObjectImage(gridObject);
                            }
                            else
                                continue;
                            break;
                        case 2:
                            // Units
                            if (objectsOnMap[i].ObjectType == ObjectTypes.Unit)
                            {
                                Unit unit = (Unit)objectsOnMap[i];

                                // Check Smoke Cloud
                                // Draw objects with 'Smoke Cloud' effect if Slug also has it and vice versa
                                if (!(Player.HasEffectType(EffectTypes.SmokeCloud) ^ unit.HasEffectType(EffectTypes.SmokeCloud)))
                                    objectImage = PictureManager.GetUnitImage(unit);
                            }
                            else
                                continue;
                            break;
                        case 3:
                            // Slug
                            if (objectsOnMap[i].ObjectType == ObjectTypes.Slug)
                                objectImage = PictureManager.GetSlugImage((Slug)objectsOnMap[i]);
                            else
                                continue;
                            break;
                    }

                    if (objectImage == null)
                        continue;

                    // Determine object image coords
                    // relative to the object position on Cell and Player (as a center of the GridMap)
                    int xCoord = this.pbGridMap.Size.Width / 2 - ((Player.Position.Location.X - objectsOnMap[i].Position.Location.X) *
                            GlobalConstants.CELL_WIDTH + Player.Position.X - objectsOnMap[i].Position.X) - objectImage.Size.Width / 2;
                    int yCoord = this.pbGridMap.Size.Height / 2 - ((Player.Position.Location.Y - objectsOnMap[i].Position.Location.Y) *
                            GlobalConstants.CELL_HEIGHT + Player.Position.Y - objectsOnMap[i].Position.Y) - objectImage.Size.Height / 2;

                    gCellBP.DrawImage(objectImage, xCoord, yCoord,
                        objectImage.Size.Width, objectImage.Size.Height);
                }
        }

    }
}
Back to Top