1 / 37

เกม PONG

เกม PONG. เกม PONG. เกม PONG เกม Pong เป็นเกมคลาสสิกที่โด่งดังมากในอดีต ในครั้งแรกออกมาเป็นเกมตู้ก่อนประมาณ 1972 ต่อมาเมื่อได้รับความนิยมเพิ่มขึ้นในปี 1975 ทางบริษัท Atari จึงนำมาทำเป็นเกมคอนโซลสำหรับเล่นตามบ้านซึ่งทำให้บริษัท Atari ขายเครื่องได้มากกว่า 150,000 เครื่อง.

lilli
Download Presentation

เกม PONG

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. เกม PONG

  2. เกม PONG • เกม PONG • เกม Pong เป็นเกมคลาสสิกที่โด่งดังมากในอดีต ในครั้งแรกออกมาเป็นเกมตู้ก่อนประมาณ 1972 • ต่อมาเมื่อได้รับความนิยมเพิ่มขึ้นในปี 1975 ทางบริษัท Atari จึงนำมาทำเป็นเกมคอนโซลสำหรับเล่นตามบ้านซึ่งทำให้บริษัท Atari ขายเครื่องได้มากกว่า 150,000 เครื่อง

  3. เปิดไฟล์ชื่อ 02-แบบฝึกหัด » 02-pong » Tutorial_pong

  4. สร้าง Room • เริ่มต้นสร้าง room ขนาด 480 x 640 ซึ่งเกมของเราจะเปลี่ยนจากการเล่นในแนวนอนเหมือนอย่างต้นฉบับมาเป็นแนวตั้งบ้าง ส่วน Speed ตั้งไว้ที่ 60 เพื่อให้เกมดู Smooth ขึ้น

  5. โหลดภาพ Sprite • นำภาพ Sprite ที่จะใช้ในเกมเข้ามาจากไฟล์ชื่อ 02-แบบฝึกหัด » 02-pong » sprites ซึ่งจะมีภาพ sp_p1 (ชื่อไฟล์ p1) แทนบาร์ของเรา, sp_p2 (ชื่อไฟล์ p2) แทนบาร์คู่ต่อสู้ และ sp-ball (ชื่อไฟล์ ball) แทนบอลที่ใช้เล่น สำหรับพื้นหลังใช้ background (ชื่อไฟล์ bg)

  6. โหลดภาพ Sprite • สำหรับบาร์ทั้งสองภาพและบอลนั้น จุด origin ต้องตั้งให้อยู่กลางภาพ

  7. สร้างฟอนต์ • สร้างฟอนต์ชื่อ font_score โดยใช้ฟอนต์ Arial • ขนาด 50 ตัวหนา

  8. สร้างออบเจกต์ • หลังจากนั้นสร้างออบเจกต์เพื่อจะนำไปใช้เกมจำนวน 4 ตัว และตั้งค่าต่างๆ โดยเพิ่มออบเจกต์ทั้ง 4 ตัวนี้ลงไป ดังนี้

  9. Object: p1 • Information about object: p1 • ออบเจกต์นี้คือบาร์ที่เราจะต้องบังคับ ซึ่งสามารถใช้เมาท์บังคับบาร์ให้เคลื่อนซ้ายขวาเพื่อไปรับบอลได้

  10. Object: p1 • Sprite: sp_p1 • Solid: false • Visible: true • Depth: 0 • Persistent: false • Parent: <no parent> • Mask: <same as sprite>

  11. Object: p1

  12. Object: p1 • Step Event: • COMMENT: ให้บาร์เคลื่อนที่ตามเมาท์ • Move to position (mouse_x, y) • COMMENT: ทำให้บาร์ไม่ออกนอก room • If bbox_left is smaller than 0 • Set variable x to sprite_width/2 • If bbox_right is lager than room_width • Set variable x to room_width-(sprite_width/2)

  13. Object: p2 • Information about object: p2 • เป็นบาร์ของคู่ต่อสู้ซึ่งจะต้องวิ่งมารับลูกเองตามเงื่อนไข

  14. Object: p2 • Sprite: sp_p2 • Solid: false • Visible: true • Depth: 0 • Persistent: false • Parent: <no parent> • Mask: <same as sprite>

  15. Object: p2

  16. Object: p2 • Step Event: • COMMENT: เมื่อลูกผ่านครึ่ง room ด้านบนมาให้บาร์ฝ่ายตรงข้ามเคลื่อนเข้าหาบอล ถ้าบอลเลยครึ่ง room ด้านล่างก็ให้บาร์มาอยู่ตรงกลาง • If ball.y is smaller than room_height/2 • Perform a step towards position (ball.x, y) with • Speed 10 stop at slid only else • Perform a step towards position (room_width/2, y) with • Speed 3 stop at solid only • COMMENT: ทำให้บาร์ไม่ออกนอก room • If bbox_left is smaller than 0 • Set variable x to sprite_width/2 • If bbox_right is lager than room_width • Set variable x to room_width-(sprite_width/2)

  17. Object: ball • Information about object: ball • บอลในเกมมีรายละเอียดดังต่อไปนี้ • Sprite: sp_ball • Solid: false • Visible: true • Depth: 0 • Persistent: false • Parent: <no parent> • Mask: <same as sprite>

  18. Object: ball

  19. Object: ball • Create Event: • COMMENT: สุ่มทิศทางปล่อยบอล • Start moving in directions 101000101 with speed set to 8

  20. Object: ball

  21. Object: ball • Step Event: • COMMENT: ควบคุมความเร็วไม่ให้เกิน 20 • If speed is larger than 20 • Set variable speed to 20

  22. Object: ball

  23. Object: ball • COMMENT: ทำให้ความเร็วเพิ่มขึ้นทีละ 1 • If vspeed is larger than 0 • Set variable speed relative to 1 • COMMENT: เมื่อบอลกระทบบาร์จะเด้งได้หลายทิศทางตามตำแหน่งที่กระทบ • Set variable direction to (other.x-x)+90

  24. Object: ball

  25. Object: ball • Collision Event with object p2: • COMMENT: ทำให้ความเร็วเพิ่มขึ้นทีละ 1 • If vspeed is smaller than 0 • Set variable speed relative to 1 • COMMENT: สุ่มทิศทางของบอลขณะเด้งกลับ • Set variable direction to - (random (120)+30)

  26. Object: ball

  27. Object: ball • Other Event: outside Room: • COMMENT: ผู้เล่นได้คะแนน • If y is smaller than 0 • Set variable global.score1 relative to 1 • Sleep 0 millisecond; redrawing the screen: true • Display message: you won !!! • COMMENT: ฝ่ายตรงข้ามได้คะแนน • If y is larger than room_height • Set variable global.score2 relative to 1 • Sleep 0 millisecond; redrawing the screen: true • Display message: you lose !!! • Restart the current room with transition effect • <no effect>

  28. Object: ball

  29. Object: ball • Other Event: Intersect Boundary: • COMMENT: เมื่อบอลชนขอบ room ซ้ายและขวาจะเด้งกลับ • If expression bbox_right>room_width && hspeed > 0 is true • Reverse horizontal direction • If expression bbox_left<0 && hspeed< 0 is true • Reverse horizontal direction

  30. Object: show_score • Information about object: show_score • ใช้แสดงคะแนนทั้งสองฝ่าย • Sprite: <no sprite> • Solid: false • Visible: true • Depth: 0 • Persistent: false • Parent: <no parent> • Mask: <same as sprite>

  31. Object: show_score

  32. Object: show_score • Other Event Game Start: • COMMENT: เมื่อเริ่มเกม ให้เซตคะแนนทั้งคู่เป็น 0 • Set variable global.score1 to 0 • Set variable global. score2 to 0

  33. Object: show_score

  34. Object: show_score • Draw Event: • COMMENT: แสดงคะแนนทั้งสองฝ่ายบนจอ • Set the font for drawing text to font_score and align center • Set the drawing color to 16711680 at position (room_width/2,400) draw the value of: global.score1 • Set the font for drawing text to font_score and align center • Set the drawing color to 225 at position (room_width/2,150) draw the value of: global.score2

  35. ที่ room properties กำหนดพื้นหลัง background0 ตามที่กำหนด

  36. วางตำแหน่งออบเจกต์ใน Room • เมื่อสร้างออบเจกต์ทั้งหมดเสร็จเรียบร้อยแล้วจึงนำไปใส่ใน room ตามตำแหน่งที่กำหนด เป็นอันเสร็จเรียบร้อยและลองเล่นเกมดู

  37. THE END

More Related