Upload
shao-ming-lee
View
211
Download
7
Embed Size (px)
Citation preview
開始
KeyEventArgs
MonsterTimer啟動:1.怪物會移動2.怪物會傷人
switch
↑↓←→
F
R K Esc
開始
PutBomb( 人物位置 x,y)
Move函式1.改變圖檔2.改變位置 If true
If true
1.DrawBomb()
2.啟動D2timer
3.DrawAFire()
3秒後炸彈爆
4.clean()
100 ms後火花消失
GetPower()改變火花大小
判別人死?()
怪物被燒傷?()
令 Stillfring = true
令 Stillfring = false
停止使用鍵盤的移動& 放炸彈
怪物被燒第二次()?
停止怪物動作
怪物怒!
If true
If true
If true
KeyEventArgs e• public void Form1_KeyDown(object sender, KeyEventArgs e)/*按鍵產生的事件
*/
• {
• if(PlayerAction) /* PlayerAction值按下”開始”時會令為true*/
• {
• switch (e.KeyCode)
• {
• case Keys.Up:
• {
• MoveUp();
• break;
• }
•
• }
• }
• }….
• case Keys.Up: ) /*上下左右見移動,呼叫移動的函式*/
• {
• MoveUp();
• break;
• }
• case Keys.Down:
• {
• MoveDown();
• break;
• }
• case Keys.Left:
• {
• MoveLeft();
• break;
• }
• case Keys.Right:
• {
• MoveRight();
• break;
• }
移動的函式• public void MoveUp()
• {
• if (UpGo && UpGo_g) /*布林值由死亡函式決定*/
• {
• picS.Image = Image.FromFile("..\\pic_for_show\\man_up.png");
• picS.Location = new System.Drawing.Point(picS.Location.X, picS.Location.Y - 40);
• }
• }
• public void MoveDown()
• {
• if (DownGo && DownGo_g)
• {
• picS.Location = new System.Drawing.Point(picS.Location.X, picS.Location.Y + 40);
• picS.Image = Image.FromFile("..\\pic_for_show\\man_down.png");
• }
• }
• public void MoveLeft()
• {
• LeftGo = (picS.Location.X > 100);
• //之後要寫判別撞到wall rock bomb都不能移動的部分
• if (LeftGo && LeftGo_g)
• {
• picS.Location = new System.Drawing.Point(picS.Location.X - 40, picS.Location.Y);
• picS.Image = Image.FromFile("..\\pic_for_show\\man_left.png");
• }
• }
• case Keys.F: /*放炸彈*/
• {
• if (bomb_number < Quta)
• {
• Px[bomb_number] = picS.Location.X;
• Py[bomb_number] = picS.Location.Y - 100;
• PutBomb(Px[bomb_number], Py[bomb_number]);
• }
• break;
• }
• case Keys.Q: /*自殺鍵*/
• {
• Dead();
• break;
• }
• case Keys.R: : /*復活鍵*/
• {
• Revive();
• break;
• }
• case Keys.Escape: : /*跳離程式*/
• {
• Close();
• break;
• }
•
• case Keys.K : /*重新招喚怪物*/
• {
• MonsterDieTimer.Enabled = false;
• MM.Visible = true;
• MM.Image = Image.FromFile("..\\pic_for_show\\monster.png");
• MonsterDead = false;
• MonsterTimer.Enabled = true;
• break;
• }
死亡函式
• public void Dead()• {• string fileName2;• fileName2 = "..\\pic_for_show\\die.png";• picS.Image = Image.FromFile(fileName2);• UpGo_g = false; • DownGo_g = false; • LeftGo_g = false; • RightGo_g = false; //死了不能移動• CanPutBomb = false; //死了不能放炸彈• }
判別是否被燒死函式• public void BurningToDead(int Loc_x, int Loc_y)
• {
• if (Stillfiring) //如果火還在燒
• {
• bool h1 = (Loc_x + picS.Size.Width > bomb_loc_X - firelength);
• //火焰的左右手臂內
• bool h2 = (Loc_x < bomb_loc_X + 100 + firelength);
• bool h3 = (Loc_y < bomb_loc_Y + 100);
• bool h4 = (Loc_y + picS.Size.Height > bomb_loc_Y);
• bool v1 = (Loc_x + picS.Size.Width > bomb_loc_X); //火焰的上下手臂內
• bool v2 = (Loc_x < bomb_loc_X + 100);
• bool v3 = (Loc_y < bomb_loc_Y + 100 + firelength);
• bool v4 = (Loc_y + picS.Size.Height > bomb_loc_Y - firelength);
• if ((h1 && h2 && h3 && h4) | (v1 && v2 && v3 && v4))
• { Dead(); }
• }
• }
判別怪獸被燒死也同理
• if ((h1 && h2 && h3 && h4) | (v1 && v2 && v3 && v4))
• {
• MM.Image = Image.FromFile(“..\\pic_for_show\\monster_die.png”);
• //改成死掉的圖
• MonsterDead = true;
• MonsterHurt = false;
• Dtimer2.Enabled = false;
• MonsterDieTimer.Enabled = true;
• RageLabel.Visible = false;
• }
復活函式
• public void Revive()
• {
• picS.Image = Image.FromFile("..\\pic_for_show\\man_down.png");
• UpGo_g = true;
• DownGo_g = true;
• LeftGo_g = true;
• RightGo_g = true; //能移動
• CanPutBomb = true; //能放炸彈• }
PutBomb函式
• public void PutBomb(int bomb_loc_X,int bomb_loc_Y)
• {
• if (bomb_number < Quta && CanPutBomb)
• {
• DrawBomb( bomb_loc_X, bomb_loc_Y);
• /*根據位置畫出炸彈位置*/• B1timer.Enabled = true;
• /*開始計時,3秒後爆炸*/• }
• }
B1timer_Tick()
• private void B1timer_Tick(object sender, EventArgs e)
• {
• DrawAFire(Px[bomb_number], Py[bomb_number]);
• /*畫出十字火花*/
• B1timer.Enabled = false; /*關掉計時器*/
• FireOverTimer.Enabled = true;
• /*火花延遲時間計時器*/
• Stillfiring = true; /*火花延遲中*/
• bomb_number++; //累積下一個炸彈
• }
DrawAFire函式• public void DrawAFire(int bomb_loc_X, int bomb_loc_Y)
• {
• this.bomb_loc_X = bomb_loc_X;
• this.bomb_loc_Y = bomb_loc_Y;
• graphics = CreateGraphics();
• image = Image.FromFile( "..\\pic_for_show\\yellow_c.png");
• graphics.DrawImage(image, bomb_loc_X, bomb_loc_Y, 100, 100);//火焰中央
• image = Image.FromFile("..\\pic_for_show\\yellow_v.png");
• graphics.DrawImage(image, bomb_loc_X, bomb_loc_Y - firelength, 100, firelength); //火焰向上
• graphics.DrawImage(image, bomb_loc_X, bomb_loc_Y + firelength, 100, firelength);//火焰向下
• image = Image.FromFile("..\\pic_for_show\\yellow_h.png");
• graphics.DrawImage(image, bomb_loc_X - firelength, bomb_loc_Y, firelength, 100);//火焰向左
• graphics.DrawImage(image, bomb_loc_X + 100, bomb_loc_Y, firelength, 100);
• //火焰向右
• }
• private void FireOverTimer_Tick(object sender, EventArgs e)• {• CleanFire(); /*洗掉畫面的火花*/• FireOverTimer.Enabled = false;• Stillfiring = false; /*火花不延遲*/• }
• public void CleanFire()• {• Invalidate(); • }
MonsterTimer_Tick()• private void MonsterTimer_Tick(object sender, EventArgs e)
• {
• Random rand = new Random();
• int u;
• int v;
• u = (rand.Next() % 100) - 50; //怪獸隨機的亂跑移動-50~-100間的整數
• v = (rand.Next() % 100) - 50;
if (MM.Location.X + u > 0 && MM.Location.X + u + 100 < 900 && MM.Location.Y + v > 0 && M.Location.Y + v + 100 < 600 && !MonsterDead)
//若沒碰到且怪獸還活著才移動
• {
• MM.Location = new System.Drawing.Point(MM.Location.X + u, MM.Location.Y + v);
• }
MonsterTimer_Tick()續
• MonsterBurningToHalfDead(MM.Location.X, MM.Location.Y); //判別是否被火焰燒到
• if (MonsterHurt) //如果受傷才開啟新的timer
• {
• MonsterTimer.Enabled = false;
• Dtimer2.Enabled = true;
• }
• }
Dtimer2_Tick()• private void Dtimer2_Tick(object sender, EventArgs e)
• {
• Random rand = new Random();
• int u;
• int v;
• u = (rand.Next() % 200) - 100; //數值變動變大,移動變劇
• v = (rand.Next() % 200) - 100;
• if (MM.Location.X + u > 0 && MM.Location.X + u + 100 < 900 && MM.Location.Y + v > 0 && MM.Location.Y + v + 100 < 600 && !MonsterDead)
• {
• MM.Location = new System.Drawing.Point(MM.Location.X + u, MM.Location.Y + v);
• }
• RageLabel.Location = new System.Drawing.Point(MM.Location.X + 20, MM.Location.Y - 80);
• RageLabel.Visible = true; ; //顯示 “怒!!!”的字樣
• MonsterBurningToDead(MM.Location.X, MM.Location.Y); //判別是否被火焰燒死
• } //開啟狂怒狀態!!
超人碰到怪獸死掉函式
• public void TouchMonsterToDead(int Loc_x, int Loc_y)
• {
• bool a1 = (Loc_x + 100 > MM.Location.X);
• bool a2 = (Loc_x < MM.Location.X + 100);
• bool a3 = (Loc_y < MM.Location.Y + 100);
• bool a4 = (Loc_y + 100 > MM.Location.Y);
• if (!MonsterDead && a1 && a2 && a3 && a4)
• { Dead(); }
• } //只要怪獸活著都有效
怪獸死掉一陣子後屍體消失
• private void MonsterDieTimer_Tick(object sender, EventArgs e)
• {
• MM.Visible = false;
• MonsterDieTimer.Enabled = false;
• }
增加火力裝備出現事件
• private void PowerUpShowUpTimer_Tick(object sender, EventArgs e)
• {
• PowerUp.Visible = true;
• CanGetPower=true; //變成看得到也吃得到
• PowerUpShowUpTimer.Enabled = false;
• }
GetPower函式• public void GetPower()
• {
• bool a1 = (picS.Location.X + 100 > PowerUp.Location.X);
• bool a2 = (picS.Location.X < PowerUp.Location.X + 100);
• bool a3 = (picS.Location.Y < PowerUp.Location.Y + 100);
• bool a4 = (picS.Location.Y + 100 > PowerUp.Location.Y);
• if (CanGetPower && a1 && a2 && a3 && a4)
• //位置在裝備上面且允許吃裝備了
• {
• firelength = firelength + 50;
• PowerUp.Visible = false;
• CanGetPower = false;
• }
• }
MenulStrip上的選項
• private void 結束EToolStripMenuItem_Click(object sender, EventArgs e)• {• Close();• }• private void 說明ToolStripMenuItem_Click(object sender, EventArgs e)• {
• MessageBox.Show( "歡迎來玩炸彈超人陽春板呀~\n請按方向鍵移動\n按F鍵放炸彈\n按R鍵重生(密技~)\n按K可以把死掉的怪物叫回來");
• }•
• private void 開始SToolStripMenuItem_Click(object sender, EventArgs e)• {• MonsterTimer.Enabled = true; //怪獸開始動• PlayerAction = true; //允許玩家動作• PowerUpShowUpTimer.Enabled = true;• //開始倒數火力增加裝備出現時間• }