วันพุธที่ 8 มกราคม พ.ศ. 2563

รวมบทความ Workshop Flash Action Script 2.0 3.0 update content

action script 2.0

action script 2.0 ลากๆวางๆ drag and drop 
http://aoodi43.blogspot.com/2013/09/action-script-20-drag-and-drop.html
action script 2.0 บอลเด้งๆ
http://aoodi43.blogspot.com/2013/07/action-script-20.html
action script 2.0 กับ เกมปิงปอง
 http://aoodi43.blogspot.com/2013/07/action-script-20_22.html
action script 2.0 ทำ Web Gallory แบบง่ายๆ 
http://aoodi43.blogspot.com/2013/08/action-script-2-slide-show.html 
action script 2.0 สร้าง presentation slide show
 http://aoodi43.blogspot.com/2013/09/action-script-20-slide-show-presentation.html
action sctipt 2.0 เกมส์เก็บขยะ Junkman 
http://aoodi43.blogspot.com/2013/09/action-sctipt-20-junkman.html
action script 2.0 การเขียน function
http://aoodi43.blogspot.com/2013/09/action-script-20-function.html
action script 2.0 ทำ Quiz Game
http://aoodi43.blogspot.com/2015/05/action-script-20-quiz-game.html
actionscript 2.0 ทำระบบ Physic แบบเกม Mario
http://aoodi43.blogspot.com/2020/01/action-script-20-gravity-physic.html


action script 3.0
action script 3.0 กับ helloworld
http://aoodi43.blogspot.com/2013/07/action-script-30-helloworld.html

action script 3.0 การใช้ keyboard และ Hittest 
http://aoodi43.blogspot.com/2013/07/action-script-30-keyboard-hittest.html 

action script 3.0 ทำโปรแกรมคำนวณหาค่าร้อยละ
http://aoodi43.blogspot.com/2013/07/action-script-30.html 



[Action Script 2.0]สร้าง gravity ระบบ physic เพื่อต้นแบบ platform game แบบ mario

สร้าง Movie Clip มา 2 ตัว ตัวแรกตั้ง instance ว่า ground เป็นพื้น อีกตัวชื่อ sprite เป็นตัวละครของเรา

คลิ๊กขวาที่ movieclip sprite แล้วเลือก action

ฟังก์ชั่น onload เพื่อตั้งค่าเริ่มต้น


onClipEvent(load)
{
 gravity = 0; //แรงโน้มถ่วง

 jumping = false; //ตั้งค่าว่ายังไม่โดด
 jumpheight = 10; //ความสูงตอนกระโดด
}


ใน enterframe ใส่ code เพื่อจัดการแรงโน้มถ่วงดังนี้


onClipEvent(enterFrame)
{

if(!_root.ground.hitTest(_x, _y, true)) //ตัวละครเท้าไม่ติดพื้น
 {
  gravity++; //เกิดแรงโน้มถ่วง
  _y += gravity;//ค่าแกน y เริ่มเยอะขึ้น
 } else //เมื่อเท้าติดพื้นให้ตั้งค่าเป็น 0
 {
  jumping = false;
  gravity = 0;
 }
 //วนลูป set ค่า ตัวละคร อยู่ในตำแหน่ง บนพื้น (ค่าy-ความสูงตนเอง)
 while(_root.ground.hitTest(_x, _y - _height, true))
 {
  jumping = false;
  _y--;
 }

}

ตอนนี้ เราได้ระบบ physic สำหรับทำเกมต่างๆแล้ว
ต่อมาจะทำการเขียน code ส่วนควบคุมตัวละคร
ใส่ keydown เพื่อกระโดดลงไป

if(Key.isDown(Key.UP) && !jumping) // ใส่ เพื่อไม่ให้กด โดดซ้ำได้
 {
  gravity = -jumpheight;
  jumping = true;
 }


 ใส่ code เดินซ้ายขวา

if(Key.isDown(Key.RIGHT))
 {
  _x += 5;
 }

 if(Key.isDown(Key.LEFT))
 {
  _x -= 5;
 }


สรุป code ทั้งหมดด้านล่างนี้

----------------------------------------------------------

onClipEvent(load)
{
 gravity = 0;
 jumping = false;
 jumpheight = 15;
}

onClipEvent(enterFrame)
{
 if(Key.isDown(Key.RIGHT))
 {
  _x += 5;
 }

 if(Key.isDown(Key.LEFT))
 {
  _x -= 5;
 }

 if(Key.isDown(Key.UP) && !jumping)
 {
  gravity = -jumpheight;
  jumping = true;
 }

 if(!_root.ground.hitTest(_x, _y, true))
 {
  gravity++;
  _y += gravity;
 } else
 {
  jumping = false; 
  gravity = 0;
 }

 while(_root.ground.hitTest(_x, _y +_height , true))
 {
  jumping = false;
  _y--;
 }

}