Talking about Ononmin game, Actionscript 3, Flash and Game development.
I want you to play a bit Ononmin.
It’s a simple and addictive game that does not require any physics or 3D library to work.
So it’s the best candidate to be prototyped.
In this first part we’ll create the “mushroom” you control. In the original game, you can’t move the mushroom, allowing the player to just move the launchable ball.
To change the game a bit, in this version you can move the “mushroom” along the x axis with the mouse, and the launchable ball will move from left to right just like in Create a Flash game like Gold Miner.
So at the moment I created these two objects:
The “mushroom” and the ball.
The main file, called onon.as
, simply creates the player:
package {
import flash.display.Sprite;
public class onon extends Sprite {
public var player:mushroom = new mushroom();
public function onon():void {
addChild(player);
}
}
}
As you can see at line 4, I’m calling mushroom.as
that just make the mushroom follow the mouse along the x axis at line 12 and creates the ball at line 5
package {
import flash.display.Sprite;
import flash.events.Event;
public class mushroom extends Sprite {
public var bullet:ball=new ball();
public function mushroom():void {
y=100;
addChild(bullet)
addEventListener(Event.ENTER_FRAME, on_enter_frame);
}
public function on_enter_frame(e:Event) {
x=stage.mouseX;
}
}
}
And finally ball.as
manages the ball. This is a little more “complex” so I commented all lines
package {
import flash.display.Sprite;
import flash.events.Event;
public class ball extends Sprite {
// starting degrees value
public var degrees:int=0;
// value to transform degrees to radians
public var deg_to_rad=0.0174532925;
// rotation speed
public var speed:int=2;
public function ball():void {
addEventListener(Event.ENTER_FRAME, on_enter_frame);
}
public function on_enter_frame(e:Event) {
// updating the degrees
degrees+=speed;
// inverting the speed if degrees are > 80 or < -80
if (Math.abs(degrees)>80) {
speed*=-1;
}
// placing and rotating the ball along the mushroom circumference
// using a bit of trigonometry
y=-20-30*Math.cos(degrees*deg_to_rad);
x=30*Math.sin(degrees*deg_to_rad);
rotation=degrees;
}
}
}
And this is the result:
Use the mouse to move the mushroom along the x axis
Download the source code.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.