Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Game Coding
MiniBusiness
post Jan 18 2008, 07:51 PM
Post #1


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 5
Joined: 18-January 08
Member No.: 27,717



QUOTE
First of we set up the scene, What you will need is a button, I just made a simple graphic with a gradient, then convert it to a button symbol by right clicking and choose convert to symbol. Give the button an instance name, we will need it when we have to do some action scripting. I called mine "roll".
Then we need a simple text box, place it center on the stage, and change its property to dynamic textbox, so its able to receive information through actionscripting.
Basically this is what we need to make things work, but to make the game a bit more interesting we also need some graphic for visual appeal. I just made 6 different view of a dice, I made it in Photoshop, (I could have done it in any graphic related environment.
Import your images to the stage, File -> Import -> Import to stage and locate your dice image files.
Now separately convert all images to movie clips and give them instance names like this dice_1, dice_2, dice_3, dice_4, dice_5 and dice_6.
I very important thing now is to place all dice movie clips exactly on top of each other, an easy way to do this is to type in the x and y coordinates for all movie clips.
Now to the fun part, the action scripting.



roll.onPress = function () {



_root.result.text = 1 + Math.floor(Math.random()*6); /*numbers between 1 and 6 */



}

This function tells flash that when someone clicks on the button the textbox will show a random number between 1 and 6 using the Math function in flash, a very useful tool.
The next thing is to make a simple function that makes all our dice movie clips invisible, we will do this every time we need a new shuffle, then only show the dice with the same number of eyes as shown in the textbox (eg. random number 1 then dice_1._visible = true).



function invisible () {


_root.dice_1._visible = false
_root.dice_2._visible = false
_root.dice_3._visible = false
_root.dice_4._visible = false
_root.dice_5._visible = false
_root.dice_6._visible = false


}

Now we will need to call this function every time the button is pressed so we have to add to the onpress part of our code.


roll.onPress = function () {



_root.result.text = 1 + Math.floor(Math.random()*6); /*numbers between 1 and 6 */



invisible();

}



We are almost done, this next part is the most annoying part to type, its not that complicated its an if condition with 5 else if's, this will control that if the number 1 comes up, then we will show dice movie clip one, if number 2 comes up, then we will show dice movie clip two and so on. This code also has to be added in the buttons onpress code so the final onpress code will look like this.



roll.onPress = function () {



_root.result.text = 1 + Math.floor(Math.random()*6); /*numbers between 1 and 6 */



invisible();



if (_root.result.text == 1) {
_root.dice_1._visible = true
} else if (_root.result.text == 2) {
_root.dice_2._visible = true
} else if (_root.result.text == 3) {
_root.dice_3._visible = true
} else if (_root.result.text == 4) {
_root.dice_4._visible = true
} else if (_root.result.text == 5) {
_root.dice_5._visible = true
} else if (_root.result.text == 6) {
_root.dice_6._visible = true
}

}

Just to clarify I will try to explain how this if and else if part works.

if number 1 comes up then show dice 1

else if number 2 comes up then show dice 2

else if number 3 comes up then show dice 3

And so on.

Here is the final code.


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



roll.onPress = function () {



_root.result.text = 1 + Math.floor(Math.random()*6); /*numbers between 1 and 6 */



invisible();



if (_root.result.text == 1) {
_root.dice_1._visible = true
} else if (_root.result.text == 2) {
_root.dice_2._visible = true
} else if (_root.result.text == 3) {
_root.dice_3._visible = true
} else if (_root.result.text == 4) {
_root.dice_4._visible = true
} else if (_root.result.text == 5) {
_root.dice_5._visible = true
} else if (_root.result.text == 6) {
_root.dice_6._visible = true
}

}



function invisible () {
_root.dice_1._visible = false
_root.dice_2._visible = false
_root.dice_3._visible = false
_root.dice_4._visible = false
_root.dice_5._visible = false
_root.dice_6._visible = false
}
Go to the top of the page
 
+Quote Post
Jeigh
post Jan 18 2008, 09:00 PM
Post #2


Whitest Black Mage
Group Icon

Group: [MODERATOR]
Posts: 1,323
Joined: 20-May 05
From: NB, Canada
Member No.: 5,281



I'm too lazy to figure out what exactly that code (that you stole *cough*) is supposed to do, but I'm sure its nothing too intense. Games are best made, especially small ones, if its creative and original by the author. I'd suggest anyone that saw this and got excited about making a game take a basic board game like checkers or something and try to recreate it. Thats a good start to programming games wink.gif
Go to the top of the page
 
+Quote Post
toby
post Jan 20 2008, 02:52 PM
Post #3


Premium Member
Group Icon

Group: Members
Posts: 489
Joined: 29-September 06
Member No.: 16,228



What language is that? Doesn't look like C or Actionscript, Java?
Go to the top of the page
 
+Quote Post
bhupinder
post Jan 25 2008, 12:22 AM
Post #4


Member [ Level 1 ]
Group Icon

Group: Members
Posts: 42
Joined: 5-January 08
Member No.: 27,390



Is that even a script lol! What are you using it for?
Go to the top of the page
 
+Quote Post
pyost
post Jan 25 2008, 09:55 AM
Post #5


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,002
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500



It's ActionScript.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. How To Make A Text Based Online Game Script ?(23)
  2. Best Snes Game?(25)
  3. Creating A Game In Rpg Maker 2000/2003(18)
  4. Online Multiplayer Game(16)
  5. Make Your Own FPS Game(32)
  6. The Best Strategy Game(29)
  7. Wuts A Good Game Maker Program?(12)
  8. Freelancer: The Forgotten Game(9)
  9. New Game: Sudoku(17)
  10. Help Me Create A Text-based, Turn-based Game(10)
  11. Need For Speed Most Wanted!(19)
  12. Please Recommend A Decently Priced & Good FPS Game(36)
  13. Entropia Universe(8)
  14. Gba Game Program(5)
  15. Battle Dawn(2)
  1. Slavehack(12)
  2. Torn City(9)
  3. Halo 3(3)
  4. Novalogic Games(1)
  5. Xml Needed?(4)
  6. Game'istaan - Game Development Contest @ Niit(2)
  7. Making Educational Game(3)
  8. What You Need Before You Can Create A Text-based Game..(7)
  9. Free Action Game Online(0)
  10. What Is Your Favorite First Person Shooter Game?(0)
  11. Looking For Coder To My Web Game(0)
  12. Wow Game(1)
  13. Grid-iron - Management Game(0)


 



- Lo-Fi Version Time is now: 7th September 2008 - 10:56 PM