การสร้างเกมแนว Shooting

Post on 12-Feb-2016

368 views 0 download

description

การสร้างเกมแนว Shooting. การสร้างเกมแนว Shooting. เกมแนว Shooting เกิดขึ้นมานานแล้วก่อนเกม Pong เสียอีก ซึ่งได้มีการพัฒนาวีการเล่นเรื่อยมาจนมาถึงปัจจุบัน เกมแนวนี้ยังคงได้รับความนิยมอยู่เนื่องจากสามารถเล่นได้เรื่อยๆ และท้าทายความสามารถซึ่งต้องอาศัยทักษะการบังคับหลบหลีกเป็นหลัก. - PowerPoint PPT Presentation

Transcript of การสร้างเกมแนว Shooting

การสรางเกมแนว Shooting

การสรางเกมแนว Shooting

เกมแนว Shooting เกดขนมานานแลวกอนเกม Pong เสยอก ซงไดมการพฒนาวการเลนเรอยมาจนมาถงปจจบน เกมแนวนยงคงไดรบความนยมอยเนองจากสามารถเลนไดเรอยๆ และทาทายความสามารถซงตองอาศยทกษะการบงคบหลบหลกเปน

หลก

การสรางเกมแนว Shooting

ในป1943 ขณะทเครองเลน Famicom โดงดงสดขด บรษท Capcom จงไดสรางเกมชอ 1943 ขนมา ซงพฒนามาจากภาคกอนๆ โดยเปนเกมทจำาลองเหตการณสงครามโลก ผเลนจะตองบงคบเครองบนเพอทำาลายศตรใหหมด นบวาเปนเกมทไดรบความนยมมากอกเกมหนง

สราง Room

เรมจากการสราง room โดยตงคาตอไปน

โหลดภาพ Sprite

นำาภาพ sprite เขามาเกบไวพรอมทง ภาพพนหลงดวยสงเกตชอไฟลจะตรงกบ ชอ sprite หลงจาก “sp_”

การทำาใหพนหลงเคลอนท

การตงคาพนหลงท Room Properties ใหความเรวแนวตงของพนหลงเปน 1 เพอใหดเหมอนเครองบนกำาลงบนขนเรอยๆ ดงตอไป

การทำาใหเครองบนดนจอไปทางซายและขวา

สำาหรบมมมองนนถาสงเกตในเกมจะเหนวา เมอเครองบนของผเลนบนไปสดจอดานขวาและซาย มมมองจะเลอนตามผเลนไป สามารถตงคาไดตอไปน สงเกตทชอง Object following ซงขณะนเรายงไดสรางวตถแทนตวผเลนซงจะปรากฏใ นขนตอนตอไป

สรางออบเจกต

ลำาดบตอไปใหสรางออบเจกตในเกมซงจะมคอนขางมาก สามารถแบงออกเปนหมวดหมไดดงน

กลม Player

ออบเจกตภายในกลมนจะเกยวกบตวทผเลนตองควบคมอาวธของผเลน รวมถงการแสดงสถานะของผเลนดวย

กลม Enemy

ออบเจกตภายในกลมนจะเกยวของกบศตร อาวธศตรและการควบคมสรางศตร

กลม Island

ออบเจกตภายในกลมนจะไมเกยวของกบการเลนเกมแตจะสรางขนมาประกอบฉากเพอความสวยงาม

รายละเอยดของออบเจกตในแตละกลมมดงตอไปน กลม Player

Information about object: player เปน parent ของเครองบนทกลำา Sprite: <no sprite> Solid: false Visible: true Depth: -10 Persistent: false Parent: <no parent> Mask: <same as sprite>

กลม Player

Create Event: COMMENT: ตงตวแปรเพอถวงเวลาการยง ถาคา

เปน 0 คอยงได ถาคาเปน 1 คอนยงไมได Set variable shot to 0

กลม Player

Alarm Event for alarm 0: COMMENT: คนคา 0 ทำาใหยงไดอกครง Set variable shot to 0

Player

Step Event: COMMENT: ทำาใหเครองบนไมออกนอกจอ If bbox_right is lager than room_width Set variable x to room_width- (sprite_width/2) If bbox_left is smaller than 0 Set variable x to sprite_width/2 If bbox_bottom is larger than room_height Set variable y to room_height-(sprite_height/2) If bbox_top is smaller than 0 Set variable y to sprite_height/2

Player

End Step Event: COMMENT: เมอพลงหมด If health is smaller than 1 Create a medium effect of type ring relative at (0,0) of color 4227327 above objects COMMENT: เมอตายจะหนวงเวลารอกลองขอความขน For all show_status: set Alarm 0 to 120 destroy

the instance

Player

Collision Event with object enemy: COMMENT: ถาชนกบเครองบนศตรเราจะเสยพลง

เทากบตวแปร power ของศตร และใหศตรระเบด Set the health relative to -other.power for other object: destroy the instance

Player

Collision Event with object bullet_enemy: COMMENT: ถาโดนกระสนศตรพลงจะลดเทากบ

power ของกระสนศตร และทำาลายกระสนศตรดวย Set the health relative to-other.power for other object: destroy the instance

Player

Mouse Event for Glob Right Pressed: if global.bomb is larger than 0 for all enemy: destroy the instance for all bullet_enemy: destroy the

instance set variable global.bomb relative to -1

Player

Key Press Event for 1-key Key: COMMENT: เปลยนเครองบน Change the instance into object player 1, yes Performing events Key Press Event for 2-key Key: COMMENT: เปลยนเครองบน Change the instance into object player 2, yes Performing events

Player

Key Press Event for 3-key Key: COMMENT: เปลยนเครองบน Change the instance into object player 3, yes Performing events Key Press Event for 4-key Key: COMMENT: เปลยนเครองบน Change the instance into object player 4, yes Performing events

Player

Key Press Event for 5-key Key: COMMENT: เปลยนเครองบน Change the instance into object player 5, yes Performing events

object: bullet_player

Information about object: bullet_player กระสนทวไปของเครองบนผเลน Sprite: sp_bullet_player Solid: false Visible: true Depth: 0 Persistent: false Parent: <no parent> Mask: <same as sprite>

Create Event: COMMENT: พลงกระสนทจะไปลด hp ศตร Set variable power to 1

Step Event: COMMENT: ทำาใหทศทางของกระสนถกตองและเมอกระสน

ออกนอกจอใหทำาลายทง Scale the sprite with 1 in the xdir, 1 in the ydir, Rotate over direction-90, and no mirroring If expression y > room_heigth + 100 || y <-100 || x<-

100 || x>room_width + 100 is true Destroy the distance

Information about object: player1

เครองบนแบบทหนงของผเลนสามารถยงกระสนไดทละ 2 นด และเคลอนทไดเรว

Sprite: sp_ player1 Solid: false Visible: true Depth: -10 Persistent: false Parent: player Mask: <same as sprite>

player1

Step Event: COMMENT: วงตามเมาสและเรยกเหตการณเหมอนกบ

parent Perform a step towards position (mouse_x,

mouse_y) With speed 3 stop at solid only Call the inherited event of the parent object

player1

Mouse Event for Glob Left Button: COMMENT: ยงกระสนคา shot ตองเปน 0 เทานน if shot is equal to 0 create instance of object bullet_player at relative

position (-5,0) with speed 10 in direction 90 create instance of object bullet_player at relative

position (5,0) with speed 10 in direction 90 set variable shot to 1 set Alarm 0 to 20

Information about object: player2

เครองบนแบบทสองของผเลนสามารถยงกระสนไดเรวตดตอกนแตเคลอนทชา

Sprite: sp_player2 Solid: false Visible: true Depth: -10 Persistent: false Parent: player Mask: <same as sprite>

player2

Step Event: COMMENT: วงตามเมาสและเรยกเหตการณเหมอนกบ

parent perform a step towards position (mouse_x,mouse_y)

with speed 3 stop at solid only call the inherited event of the parent object

player2

Mouse Event for Glob Left Button: COMMENT: ยงกระสน คา shot ตองเปน 0 เทานน if shot is equal to 0 create instance of object bullet_player at

relative position (0,0) with speed 10 in direction 90

set variable shot to 1 set Alarm 0 to 5

Information about object: player3

เครองบนแบบทสามของผเลนสามารถยงกระสนกระจาย 3 ทศทางแตเคลอนทปานกลาง

Sprite: sp_ player3 Solid: false Visible: true Depth: -10 Persistent: false Parent: player Mask: <same as sprite>

player3

Step Event: COMMENT: วงตามเมาสและเรยกเหตการณเหมอนกบ

parent Perform a step towards position (mouse_x,

mouse_y) With speed 2 stop at solid only Call the inherited event of the parent object

player3

Mouse Event for Glob Left Button: COMMENT: ยงกระสนคา shot ตองเปน 0 เทานน If shot is equal to 0 Create instance of object bullet_player At relative position (0,0) with speed 10 In direction 115 Create instance of object bullet_player At relative position (0,0) with speed 10 In direction 90 Create instance of object bullet_player At relative position (0,0) with speed 10 In direction 65 Set variable shot to 1 Set alarm 0 to 10

Information about object: bullet_player4

กระสนของเครองบนแบบทสจะแตกตางจากกระสนทวไป

ตรงทเมอสรางขนมาแลวจะตองเซต path ตามทกำาหนดไว โดยให Add path ดงน

bullet_player4

Create Event: Call the inherited event of the parent object COMMENT: เซตกระสนเขา path Set the relative path to path_bullet_palyer4 with Speed 10 and at the end relative

Information about object: player4

เครองบนแบบทสของผเลนสามารถยงกระสนโคงในแนวกวางไปดานหนา

Sprite: sp_ player 4 Solid: false Visible: true Depth: -10 Persistent: false Parent: player Mask: <same as sprite>

player4

Step Event: COMMENT: วงตามเมาสและเรยกเหตการณเหมอนกบ

parent Perform a step toward position (mouse_x, mouse_y) With speed 4 stop at solid only Call the inherited event of the parent object

player4

Mouse Event for Glob Left Button COMMENT: ยงกระสนคา shot ตองเปน 0 เทานน If shot is equal to 0 Create instance of object bullet_player4 at Relative position (0,0) Set variable shot to 1 Set alarm 0 to 10

Information about object: missile

กระสนของเครองบนแบบทหาจะยงเขาหาศตร Sprite: sp_ missile Solid: false Visible: true Depth: 0 Persistent: false Parent: bullet_player Mask: <same as sprite>

missile

Create Event: Call the inherited event of the parent object Set the vertical speed to -5 COMMENT: หนวงเวลา 10 step แลวคอยคลอนทเขาหา

ศตร Set the relative pass to 0 Set alarm 0 to 10

missile

Alarm Event for alarm 0: COMMENT: ใหตวแปรเทากบ 1 เงอนไขใน step

event จะเปนจรงเพอใหเคลอนทเขาหาศตร Set variable pass to 1

missile

Step Event: COMMENT: เมอเงอนไขเปนจรงจะวงเขาหาศตร If pass is equal to 1 COMMENT: ดงตวแปร near เกบคา id ศตรทอยใกลกบตวเองมากทสด Set variable near to instance_nearest (x,y,enemy) COMMENT: ถามศตรใหวงเขาหาศตรตามตวแปร near ถาไมมศตรใหวง

ตรงไปดวยความเรว 10 If number of objects enemy is Larger than 0 Perform a step towards position (near.x,near.y) With speed 10 avoiding solid only Else Set variable speed to 10 COMMENT: เรยกเหตการณของ parent Call the inherited event of the parent object

Information about object: Player5

เครองบนแบบทหาของผเลนสามารถยงจรวด missile เขาหาศตรได

Sprite: sp_ player5 Solid: false Visible: true Depth: -10 Persistent: false Parent: player Mask: <same as sprite>

Player5

Step Event: COMMENT: วงตามเมาสและเรยกเหตการณเหมอนกบ

parent Perform a step towards position (mouse_x,

mouse_y) With speed 3 stop at solid only Call the inherited event of the parent object

Player5

Mouse Event for Glob Left Button: COMMENT: ยงกระสนคา shot ตองเปน 0 เทานนและตองมสตร

ในฉากดวย If number of objects enemy is Larger than 0 If shot is equal to 0 Create instance of object missile at relative Position (-20, 0) Create instance of object missile at relative Position (20, 0) Set variable shot to 1 Set Alarm 0 to 30

Information about object: show_status

แสดงสถานะตางๆ ของผเลนซงจะตอง Add Font กอนดงน

show_status

Sprite: <no sprite> Solid: false Visible: true Depth: -10 Persistent: false Parent: <no parent> Mask: <same as sprite>

show_status

Alarm Event for alarm 0: COMMENT: เมอเราตายชวตจะลดไป 1 Set the number of lives relative to -1 COMMENT: ถายงมชวตเหลอมากกวา 0 ใหเลนตอไป ถานอยกวากแพ If lives are larger than 0 Sleep 0 millisecond; redrawing the Screen: true Display message: try again !!! Set the health to 100 Restart the current room with transition Effect interlaced form left

show_status

Else Sleep 0 millisecond; redrawing the Screen: true Show the highscore table Background: <undefined> Show the border New color: 225, other color: 0 Font: “Time New Roman” , 10, 0, 0, 0, 0, 0 If the player does say yes to the Question: Game Over!!! # try again? Restart the game Else End the game

Other Event: Game Start: COMMENT: เมอเรมเกมใหมใหตงคาทกอยางตามน Set the number of lives to 3 Set the health to 100 Set variable global. Bomb to 3 Set the score to 0

Draw Event: COMMENT: แสดงผลตางๆ บนหนาจอ Draw the lives relative at (view_xview [0], view_yview [0]) with sprite life Draw the health bar with relative size (view_xview [0] -15, view_yview [0] – 30, view_xview [0] + 80, view_yview [0]-20) with black Color black and bar color green to red At relative position (view_xview [0] +30, view_yview [0] –50) draw text: ‘bomb: ‘+string (global.bomb) At relative position (view_xview [0] +530, view_yview [0] –10) draw the value Of score with caption score: At relative position (view_xview [0] +300, view_yview [0]) draw text: press <F1> to help

กลม Enemy

Information about object: control_enemy ใชสมเวลาเกดของศตรแตละตว Sprite: <no sprite> Solid: false Visible: true Depth: 0 Persistent: false Parent: <no parent> Mask: <same as sprite>

control_enemy

Create Event: COMMENT: สมเวลาการออกมาของศตร set Alarm 0 to random(180)+60

control_enemy

Alarm Event for alarm 0: With a chance of 1 out of 3 do perform the next Action COMMENT: สมตำาแหนงทจะเกดตามความกวางของ room Create instance of object enemy2_set at position (random (room_width), 0) Else Create instance of object enemy1 at Position (random (room_width), 0) Set Alarm 0 to random (180) +60

control_enemy

Draw Event: COMMENT: แสดง hp หรอพลงของศตรเปนตวเลข Set the font for drawing text to font0 and align Center Set the drawing color to 8454143 For all enemy: at relative position (0, -30) draw Text: ‘HP:’ +string (hp)

enemy

Information about object: enemy เปน parent ของศตรทกตว Sprite: <no sprite> Solid: false Visible: true Depth: 0 Persistent: false Parent: <no parent> Mask: <same as sprite>

enemy

Destroy Event: COMMENT: เมอถกทำาลายจะเลนเอฟเฟกตระเบด Create a small effect of type ring relative at (0,0) of color 255 above object

enemy

Step Event: COMMENT: ปรบทศทางใหถกตองและถาออกนอก room

จะถกทำาลาย Scale the sprite with 1 in the xidir, 1 in the ydir, Rotate over direction+90, and mirroring If expression y>room_height+100 || y<-100 || x<-100 || x>room_width+100 is true Destroy the instance

enemy

Collision Event with object bullet_player: COMMENT: เมอชนกบกระสนของผเลน พลง hp จะลด

เทากบ power ของกระสนผเลน Set variable hp relative to – other. Power COMMENT: ทำาลายกระสนผเลนทงดวย For other objects: destroy the instance COMMENT: ถา hp นอยกวา 1 จะตาย และผเลนไดคะแนน If hp is smaller than 1 Set the score relative to hpfull*100 Destroy the instance

enemy1

Information about object: enemy1 ศตรตวทหนงเคลอนทลงแนวดง สามารถยงกระสนใสผ

เลนได Sprite: sp_enemy1 Solid: false Visible: true Depth: 0 Persistent: false Parent: enemy Mask: <same as sprite>

enemy1

Create Event: COMENT: สม hp หรอพลงของตวเอง (จะไดเลข 1-5) Set variable hp to ceil (random (5)) COMMENT: ตงคา hpfull ไว เมอศตรตายจะใชอางถงตวแปรน ซงคะแนนผ

เลนจะไดเทากบ hpfull x 100 Set variable hpfull to hp COMMENT: power: ซงใชเวลาไปชนกบผเลน ผเลนจะตองถกลบพลงไปเทา

คาของตวแปรน Set variable power to 40 COMMENT: หนวยเวลายงกระสน Set Alarm 0 to 60 COMMENT: ใหเครองบนเคลอนทลง Set the variable vertical speed to 2

enemy1

Alarm Event for alarm 0: COMMENT: ยงกระสนเขาหาผเลน If number of objects player is equal to 1 Create instance of object

bullet_enemy at Relative position (0,0) Set Alarm 0 to 60

bullet_enemy

Information about object: bullet_enemy กระสนทวไปของศตรและเปน parent ดวย Sprite: sp_enemy_enemy Solid: false Visible: true Depth: 0 Persistent: false Parent: <no parent> Mask: <same as sprite>

bullet_enemy

Create Event: COMMENT: เมอชนกบผเลน พลงผเลนจะลดลงเทากบ

ตวแปรน Set variable power to 20 COMMENT: เคลอนทเขาหาผเลน Start moving in the direction of position (player.x, player.y) with speed 4

bullet_enemy

Destroy Event: Comment: เมอถกทำาลายจะเลนเอฟเฟกตระเบด For other object: create a small effect of type ring relative at (0,0) of color 4227327 above

object

bullet_enemy

Step Event: COMMENT: เมออกนอก room จะทำาลายตวเอง If expression y>room_height + 100 || y<-100 ||

x< -100|| x>room_width +100 is true

Destroy the instance

enemy2_set

Information about object: enemy2_set ใชสรางศตรแบบทสองออกมาทละ 5 ลำา เมอออกมาครบจะ

ทำาลายตวเอง Sprite: <no sprite> Solid: false Visible: true Depth: 0 Persistent: false Parent: <no parent> Mask: <same as sprite>

enemy2_set

Create Event: COMMENT: ตวแปร 1 ตงขนเพอนบจำานวนเครอง

บนทจะสราง Set variable i to 0 COMMENT: หนวงเวลาการสรางเครองบน Set Alarm 0 to 25

enemy2_set

Alarm Event for alarm 0: COMMENT: ถาเครองบนยงไมถง 5 ลำา ใหสรางตอไป If I is smaller than 5 Create instance of object enemy2 at Relative position (0,0) Set Alarm 0 to 25 Set variable I relative TO 1 Else Destroy the instance

enemy2

Information about object: enemy2 ศตรแบบทสองจะเคลอนทตาม path ทเราได

ตงไวซงจะตอง Add path ดงน

enemy2

Sprite: sp_enemy2 Solid: false Visible: true Depth: 0 Persistent: false Parent: enemy Mask: <same as sprite>

enemy2

enemy2

Create Event: Set variable hp to 2 Set variable hpfull to hp Set variable power to 40 COMMENT: เซตเขา path ทกำาหนดไว Set the relative path to path_enemy2 with

speed 2 And at the end relative

กลม island

Information about object: control_island Sprite: <no sprite> Solid: false Visible: true Depth: 0 Persistent: false Parent: <no parent> Mask: <same as sprite>

control_island

Create Event: COMMENT: หนวงเวลาการสราง island Set Alarm 0 to random (180) +60

control_island

Alarm Event for alarm 0: COMMENT: เมอถงเวลาใหสมสราง island 3 แบบ Create instance of object island, island2, Island3, or <underfined> at position (random (room_width), 0) Set Alarm 0 to random (180) +60

island1

Information about object: island1 เกาะแบบทหนง เคลอนทลงมาเทากบความเรวพนหลง Sprite: sp_island1 Solid: false Visible: true Depth: 100 Persistent: false Parent: <no parent> Mask: <same as sprite>

island1

Create Event: COMMENT: เคลอนทลง Set the vertical speed to 1

island1

Other Event: Outside Room: COMMENT: เมอออกนอก room ใหทำาลาย

ทง Destroy the instance

island2

Information about object: island2 เกาะแบบทสอง เคลอนทตำาลงมาเทากบความเรวพนหลง Sprite: sp_island2 Solid: false Visible: true Depth: 100 Persistent: false Parent: <no parent> Mask: <same as sprite>

island2

Create Event: COMMENT: เคลอนทลง Set the vertical speed to 1

island2

Other Event: Outside Room: COMMENT: เมอออกนอก room ใหทำาลาย

ทง Destroy the instance

island3

Information about object: island3 เกาะแบบทสาม เคลอนทตำาลงมาเทากบความเรวพนหลง Sprite: sp_island3 Solid: false Visible: true Depth: 100 Persistent: false Parent: <no parent> Mask: <same as sprite>

island3

Create Event: COMMENT: เคลอนทลง Set the vertical speed to 1

island3

Other Event: Outside Room: COMMENT: เมอออกนอก room ใหทำาลาย

ทง Destroy the instance

วางตำาแหนงออบเจกตใน Room

เมอสรางวตถทกชนเสรจเรยบรอยแลว วางลงใน room ตามตำาแหนงทกำาหนดเปนอนเสรจเรยบรอย

THE END