Showing posts with label game. Show all posts
Showing posts with label game. Show all posts
Wednesday, February 18, 2015
Enter the Matrix PC game Full version

God loves, hype kills. Marketing departments everywhere are doing such a thorough job that it seems every other day, a new entertainment property emerges that is heralded as the be-all, end-all experience ever to grace a movieplex, television screen or concert stage. Usually, the "new best thing" cannot stand up under the weight of expectation.
If the universal hype machine had never been fired up, perhaps folks would just sit back and enjoy their movies, games and music. But as it stands, everyone is expecting the most mind-blowing, orgasmic experience of their lives every time they sit in a theater or pop a game in their console or PC. The second Matrix film, The Matrix Reloaded has been playing to mixed reviews, partially due to the rampant hype that has been unleashed by the creators, media and fans. As the tagline states, no matter where you are "The Matrix Has You."
Enter Enter the Matrix. Developed by Shiny and published by Atari, its the first game ever to exploit the uber-lucrative Matrix license. Its impossible to know what kind of game would have to be shipped in order to avoid disappointment, but its easy to see that Enter the Matrix is not that game.
Hype aside, what it is, is an above-average action game that incorporates cool elements of the film with a decent engine to provide an experience that is similar to Dead to Rights and Max Payne. Whats more, the movies creators went the extra mile to ensure that the game isnt a rehash of what played out onscreen in The Matrix Reloaded. Instead, the movie follows the side-story of Niobe and Ghost, and their missions within the Matrix to help the A Team (Neo, Morpheus and Trinity) succeed. There is tons of exclusive content that was shot at the same time as the film that is inter-cut with the story. That alone is probably worth at least a rental from hardcore Matrix fans, and there are a lot of them in the world. Read more
System requirements:
Windows 98/ME/2000/XP
MINIMUM
Pentium II or AMD Duron 800MHz Processor
128MB RAM
4.3GB Hard Disk Space
nVidia GeForce 256 or ATI Radeon 8500 Video Card
Windows Compatible Sound Card
4X CD-ROM Drive
DirectX 9.0
RECOMMENDED
Pentium III or AMD Athlon 1.2GHz Processor
256MB RAM
7200RPM Hard Disk Speed
Sound Blaster Audigy 2 Sound Card
Screen Shots: Click on the image to view large screen
![]() | ![]() | ![]() |
Download
click to begin
180 MB
I hope you like it......!
Saturday, February 14, 2015
Pepsi man direct play game for PC full version

Pepsiman is a game that is very hard to describe.You take control of Pepsiman and collect Pepsi cans while running through hazardous levels dodging obstacles all the way. The game is somewhat rare and hard to find, so consider yourself lucky if you have it.
Gameplay (8/10)
A lot of people are probably asking themselves Who is Pepsiman?. Well, if you dont know who Pepsiman is then why are you reading this? Pepsiman is the spokesman for Pepsi in Japan. You also may remember his cameo in Fighting Vipers for Sega Saturn. Too bad they removed him from the U.S. version. He has starred in many commercials, so why not his own game? The difficulty in this game is average. It shouldnt take too long to beat. The objective is to collect Pepsi cans on the way to the end of the level. You are racing against the clock so be careful not to get hit by a car. There are many obstacles stopping you from getting to your goal. Like cars, people, boxes and many more. There are a total of 4 stages with 3 levels each. Which makes 12 levels in all. Doesnt sound like much does it? You have to remember this game was released in Japan for a somewhat cheap price. The first 2 levels in each stage are played from a 3rd person perspective.
It automatically runs forward for you all you have to do is move Pepsiman left and right and jump over or slide under obstacles. The 3rd level in each stage is played out like the scene in Indiana Jones where that boulder is chasing after him. In these levels Pepsiman is running towards you. The main goal is to collect 100 pepsi cans that are scattered throughout the level. It is not an easy task. While you dont have to get all 100 to beat the game it will be over way too quick if you dont. Read more
System requirements:
No special requirements
Screen Shots: Click on the image to view large
![]() | ![]() | ![]() |
How to Download
File Size: 10 MB
Pepsi man for PC: Download
I hope you like it....!
Tuesday, February 10, 2015
Farm Frenzy 3 Ice Age PC Game Full version

Whether you prefer the sunny beaches of Tropical Farm, or the icy landscapes of Farm Frenzy: Ice Age, one thing is certain - farming fans have no shortage of time management games to choose from. Farm Frenzy 3: Ice Age is the third frantic game with the title "Farm Frenzy 3" to be released by Alawar in recent months, and it delivers much of what youd expect from the series.
The original Farm Frenzy 3 had you traveling across the globe, while Farm Frenzy 3: American Pie had you farming in the USA with robots. You may be wondering to yourself, "Why is each game is being called Farm Frenzy 3 instead of Farm Frenzy 4 or 5?" The answer becomes apparent if youve played more than one game in the series. Each Farm Frenzy 3 game is a variant of the original, with the same game play mechanics and feel, yet a slightly different theme.
As you might have guessed by the name, Farm Frenzy: Ice Age follows Scarlet as she runs a frosty farm way up in the North Pole. Theres a surprise guest, but his jolly identity should be a no-brainer given the location. Like always, the story is light and doesnt offer much in the way of details or explanations.
The game play follows the same familiar format as the other Farm Frenzy 3 games. You need to keep your well full in order to provide food for your animals to stay alive. Animals drop produce, like eggs and feathers, and these can be gathered and sold.
The graphics have undergone a complete overhaul to fit with the chilly theme, so you farm over a frozen pond instead of a green pasture. All of the animals are animated, so its fun to watch them waddle around the screen eating fish and amusing themselves. Since everything is Arctic-themed, you get to raise penguins, royal (colorful) penguins, walruses, and wooly mammoth. As usual, you can also buy cats to help gather produce, and dogs to chase away predators. Dogs dont explode in this version, by the way...they just roll off the screen.
Polar bears pose a problem and will randomly attack and steal your livestock, but these can be captured with rapid mouse clicks and then sold for a profit. They can even be dressed up in funny snowsuits for extra cash later in the game. For another cute surprise, pause your game and leave it running for a while, and see what happens.
You can use produce youve gathered to produce processed goods like cookies and cakes once youve bought the right upgrades, and additional goodies can be paid for and airlifted into the playing field to help you meet your targets. Most of these processed goods are the same as in Farm Frenzy 3, and include cookies, cakes, fancy feathers, clothing, and of course ice cream.
Like in previous games, sometimes processed goods are required to make other processed goods, leading to complex chains. For example, feathers can be made into decorative feathers, which can then be made into fabric, which can then be sewn into clothes, which can then finally be used to dress bears. Dont worry about having to remember all of that, since everything is introduced very slowly and becomes second nature with repetition. Read more
System Requirements:
OS: Windows XP/Vista/7/8
CPU: 800 Mhz
RAM: 1024 MB
DirectX: 9.0
Hard Drive: 95 MB
Screen Shots: Click on the image to view large screen
![]() | ![]() | ![]() |
Download
click to begin
95 MB
Note: you must follow these steps after click on Download Button
Thursday, February 5, 2015
Creating a Pentomino game using AS3 Part 17
Today well add the ability to draw holes and cells on the grid.
First of all well declare 3 new variables, 2 of which are booleans set to false by default, and third is a Point variable with default coordinates -1;-1.
In the constructor, add 3 new event listeners for MOUSE_DOWN, MOUSE_UP and ENTER_FRAME events:
The canDraw value will be off when the canvas size window is open, and on when the window is closed. Thats why we can set canDraw to false in the beginning of newLevel() and to true in the end of its editContinue() function:
The mouseDown value is set to true in onMouseDown() and to false in onMouseUp(). Moreover, we set currentCell to -1;-1 point in onMouseUp():
Were using the currentCell variable because our drawing tool will be similar to a brush, but it also has to toggle cells (from a hole to a cell, and from a cell to a hole). If the user once clicked on a cell, it toggles its value. But since we are going to have our drawing code written in an ENTER_FRAME event handler, we need to make sure the same cell doesnt get toggled more than once.
In the onEnterFrame() function, we check if we are allowed to draw and if the mouse is held down. Then we check if the users mouse is rolled over a cell. If it is, we check if that cell does not have the coordinates of currentCell. And if so, we toggle the value, set currentCells coordinates to currently selected cells coordinates and call drawGrid():
Full code so far:
Thanks for reading!
The results:
Read more »
First of all well declare 3 new variables, 2 of which are booleans set to false by default, and third is a Point variable with default coordinates -1;-1.
private var canDraw:Boolean = false;
private var mouseDown:Boolean = false;
private var currentCell:Point = new Point(-1, -1);
In the constructor, add 3 new event listeners for MOUSE_DOWN, MOUSE_UP and ENTER_FRAME events:
addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
The canDraw value will be off when the canvas size window is open, and on when the window is closed. Thats why we can set canDraw to false in the beginning of newLevel() and to true in the end of its editContinue() function:
private function newLevel():void {
canDraw = false;
var newScreen:MovieClip = new new_edit_screen();
addChild(newScreen);
newScreen.tWidth.restrict = "0-9";
newScreen.tHeight.restrict = "0-9";
newScreen.tWidth.text = 10;
newScreen.tHeight.text = 6;
newScreen.incorrect.alpha = 0;
newScreen.btn_continue.addEventListener(MouseEvent.CLICK, editContinue);
function editContinue(evt:MouseEvent):void {
if (newScreen.tWidth.text == "" || newScreen.tHeight.text == "" || newScreen.tWidth.text == "0" || newScreen.tHeight.text == "0") {
newScreen.incorrect.alpha = 1;
return;
}
newScreen.parent.removeChild(newScreen);
mapGrid = [];
var width:int = newScreen.tWidth.text;
var height:int = newScreen.tHeight.text;
for (var i:int = 0; i < height; i++) {
mapGrid[i] = [];
for (var u:int = 0; u < width; u++) {
mapGrid[i][u] = 1;
}
}
// grid settings
calculateGrid();
gridShape.x = gridStartX;
gridShape.y = gridStartY;
// draw tiles
drawGrid();
// canPutShape settings
canPutShape.graphics.clear();
canPutShape.graphics.lineStyle(2, 0xff0000);
canPutShape.graphics.drawRect(0, 0, gridCellWidth, gridCellWidth);
canPutShape.alpha = 0;
canDraw = true;
}
}
The mouseDown value is set to true in onMouseDown() and to false in onMouseUp(). Moreover, we set currentCell to -1;-1 point in onMouseUp():
private function onMouseDown(evt:MouseEvent):void {
mouseDown = true;
}
private function onMouseUp(evt:MouseEvent):void {
mouseDown = false;
currentCell = new Point(-1, -1)
}
Were using the currentCell variable because our drawing tool will be similar to a brush, but it also has to toggle cells (from a hole to a cell, and from a cell to a hole). If the user once clicked on a cell, it toggles its value. But since we are going to have our drawing code written in an ENTER_FRAME event handler, we need to make sure the same cell doesnt get toggled more than once.
In the onEnterFrame() function, we check if we are allowed to draw and if the mouse is held down. Then we check if the users mouse is rolled over a cell. If it is, we check if that cell does not have the coordinates of currentCell. And if so, we toggle the value, set currentCells coordinates to currently selected cells coordinates and call drawGrid():
private function onEnterFrame(evt:Event):void {
// if drawing is allowed and mouse is down
if (canDraw && mouseDown) {
var mousePos:Point = new Point(Math.floor((mouseX - gridStartX) / gridCellWidth), Math.floor((mouseY - gridStartY) / gridCellWidth));
// if valid coordinates
if (mousePos.x < mapGrid[0].length && mousePos.y < mapGrid.length && mousePos.x >= 0 && mousePos.y >= 0) {
// if the cell is not "current cell"
if (mousePos.x != currentCell.x || mousePos.y != currentCell.y) {
currentCell.x = mousePos.x;
currentCell.y = mousePos.y;
if (mapGrid[mousePos.y][mousePos.x] == 1) {
mapGrid[mousePos.y][mousePos.x] = 0;
}else {
mapGrid[mousePos.y][mousePos.x] = 1;
}
drawGrid();
}
}
}
}
Full code so far:
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.sampler.NewObjectSample;
import flash.utils.ByteArray;
/**
* Open-source pentomino game engine
* @author Kirill Poletaev
*/
public class pentomino_editor extends MovieClip
{
private var mapGrid:Array = [];
private var shapeButtons:Array = [];
private var gridShape:Sprite = new Sprite();
private var canPutShape:Sprite = new Sprite();
private var gridStartX:int;
private var gridStartY:int;
private var gridCellWidth:int;
private var canDraw:Boolean = false;
private var mouseDown:Boolean = false;
private var currentCell:Point = new Point(-1, -1);
public function pentomino_editor()
{
addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
// add shape buttons
for (var i:int = 0; i < 4; i++) {
for (var u:int = 0; u < 3; u++) {
var shapeButton:MovieClip = new edit_shape();
shapeButton.x = 528 + u * 62;
shapeButton.y = 15 + i * 84;
addChild(shapeButton);
shapeButton.bg.alpha = 0.3;
shapeButton.shape.gotoAndStop(3 * i + u + 1);
shapeButtons.push(shapeButton);
shapeButton.addEventListener(MouseEvent.ROLL_OVER, buttonOver);
shapeButton.addEventListener(MouseEvent.ROLL_OUT, buttonOut);
}
}
// buttons
btn_mainmenu.addEventListener(MouseEvent.CLICK, doMainmenu);
btn_reset.addEventListener(MouseEvent.CLICK, function():void{newLevel()});
// new level
newLevel();
addChild(gridShape);
addChild(canPutShape);
}
private function onMouseMove(evt:MouseEvent):void {
if(mapGrid.length>0){
var mousePos:Point = new Point(Math.floor((mouseX - gridStartX) / gridCellWidth), Math.floor((mouseY - gridStartY) / gridCellWidth));
canPutShape.x = mousePos.x * gridCellWidth + gridStartX;
canPutShape.y = mousePos.y * gridCellWidth + gridStartY;
if (mousePos.x < mapGrid[0].length && mousePos.y < mapGrid.length && mousePos.x >= 0 && mousePos.y >= 0) {
canPutShape.alpha = 1;
}else {
canPutShape.alpha = 0;
}
}
}
private function newLevel():void {
canDraw = false;
var newScreen:MovieClip = new new_edit_screen();
addChild(newScreen);
newScreen.tWidth.restrict = "0-9";
newScreen.tHeight.restrict = "0-9";
newScreen.tWidth.text = 10;
newScreen.tHeight.text = 6;
newScreen.incorrect.alpha = 0;
newScreen.btn_continue.addEventListener(MouseEvent.CLICK, editContinue);
function editContinue(evt:MouseEvent):void {
if (newScreen.tWidth.text == "" || newScreen.tHeight.text == "" || newScreen.tWidth.text == "0" || newScreen.tHeight.text == "0") {
newScreen.incorrect.alpha = 1;
return;
}
newScreen.parent.removeChild(newScreen);
mapGrid = [];
var width:int = newScreen.tWidth.text;
var height:int = newScreen.tHeight.text;
for (var i:int = 0; i < height; i++) {
mapGrid[i] = [];
for (var u:int = 0; u < width; u++) {
mapGrid[i][u] = 1;
}
}
// grid settings
calculateGrid();
gridShape.x = gridStartX;
gridShape.y = gridStartY;
// draw tiles
drawGrid();
// canPutShape settings
canPutShape.graphics.clear();
canPutShape.graphics.lineStyle(2, 0xff0000);
canPutShape.graphics.drawRect(0, 0, gridCellWidth, gridCellWidth);
canPutShape.alpha = 0;
canDraw = true;
}
}
private function calculateGrid():void {
var columns:int = mapGrid[0].length;
var rows:int = mapGrid.length;
// free size: 520x460
// fit in: 510x450
// calculate width of a cell:
gridCellWidth = Math.round(510 / columns);
var width:int = columns * gridCellWidth;
var height:int = rows * gridCellWidth;
// calculate side margin
gridStartX = (520 - width) / 2;
if (height < 450) {
gridStartY = (450 - height) / 2;
}
if (height >= 450) {
gridCellWidth = Math.round(450 / rows);
height = rows * gridCellWidth;
width = columns * gridCellWidth;
gridStartY = (460 - height) / 2;
gridStartX = (520 - width) / 2;
}
}
private function drawGrid():void {
gridShape.graphics.clear();
var width:int = mapGrid[0].length;
var height:int = mapGrid.length;
var i:int;
var u:int;
// draw background
for (i = 0; i < height; i++) {
for (u = 0; u < width; u++) {
if (mapGrid[i][u] == 1) drawCell(u, i, 0xffffff, 1, 0x999999);
}
}
}
private function drawCell(width:int, height:int, fill:uint, thick:Number, line:uint):void {
gridShape.graphics.beginFill(fill);
gridShape.graphics.lineStyle(thick, line);
gridShape.graphics.drawRect(width * gridCellWidth, height * gridCellWidth, gridCellWidth, gridCellWidth);
}
private function buttonOver(evt:MouseEvent):void {
evt.currentTarget.bg.alpha = 1;
}
private function buttonOut(evt:MouseEvent):void {
evt.currentTarget.bg.alpha = 0.3;
}
private function doMainmenu(evt:MouseEvent):void {
(root as MovieClip).gotoAndStop(1);
}
private function onMouseDown(evt:MouseEvent):void {
mouseDown = true;
}
private function onMouseUp(evt:MouseEvent):void {
mouseDown = false;
currentCell = new Point(-1, -1)
}
private function onEnterFrame(evt:Event):void {
// if drawing is allowed and mouse is down
if (canDraw && mouseDown) {
var mousePos:Point = new Point(Math.floor((mouseX - gridStartX) / gridCellWidth), Math.floor((mouseY - gridStartY) / gridCellWidth));
// if valid coordinates
if (mousePos.x < mapGrid[0].length && mousePos.y < mapGrid.length && mousePos.x >= 0 && mousePos.y >= 0) {
// if the cell is not "current cell"
if (mousePos.x != currentCell.x || mousePos.y != currentCell.y) {
currentCell.x = mousePos.x;
currentCell.y = mousePos.y;
if (mapGrid[mousePos.y][mousePos.x] == 1) {
mapGrid[mousePos.y][mousePos.x] = 0;
}else {
mapGrid[mousePos.y][mousePos.x] = 1;
}
drawGrid();
}
}
}
}
}
}
Thanks for reading!
The results:
Empire Z Android Game free download
Empire Z
Android Game
Manage Your City and Save People from Zombies.
Survive after Zombie Apocalypse
download android games for free

Empire Z is strategy game . The game is about the build a strong city hold, make alliance with other online players , train your troops,make farms,roads,resident and kill the zombies to save your peoples.


Game Feature:
Earn prize for your city and your alliance.
Fantastic Graphics
Game Requirements :
OS 2.3 and Above
Version 0.0.6
Download APK from Google PlayStore
Why game mechanics wont save your crappy product
The other day, I was chatting with a LinkedIn product manager about a new app he is working on and I posed a "hard" question: what incentive would users have to use the app initially and on an on-going basis? Before the product manager had a chance to answer, someone nearby chirped in: "you should put in some game mechanics!" Sigh. This is not the first time Ive heard this. "Game mechanics" have been all the rage the last few years. Everywhere you look - from foursquare, to yelp to Xbox - you can find badges, leader boards and reward systems. And while it is sometimes effective, most implementations are either totally useless, or worse yet, counterproductive.
In fact, the very idea that cramming "game-like" elements into a product is enough to attract users is misguided; the proposal of using "game mechanics" as the primary way to drive and maintain user engagement is a short road to failure. I think these misconceptions come from a lack of understanding of two key concepts:
The first reason that game mechanics probably wont work for you is that you dont understand game mechanics. Before you go off and add a leader-board or badging system to your next product, please take the time to go through Sebastian Deterdings superb presentation "Pawned. Gamification and its discontents". Im embedding it within this blog post as the presentation beautifully covers the many mistakes and misconceptions about what gameplay is really all about:
One of the key takeaways from this presentation is that most people dont understand motivation. Think of the most common game mechanics you see in most products today: badges, scores, and progress bars. foursquare has it, so it must work, right? Wrong. These "external rewards" are rarely effective because gamers and humans in general are typically not motivated by external factors, but rather by intrinsic ones. In fact, studies have shown that external rewards and pressures can often act as de-motivators. If youre not convinced, it would be well worth your time to watch Dan Pinks talk on The Surprising Science of Motivation.
The role of game mechanics
If you fail to grasp the key principle of motivation, your game mechanics have no chance of being effective. But even if you do get the mechanics right, there is still no guarantee of success. To understand why, you need to understand that game mechanics are not your core product (unless you are building a game, of course) and have no value in and of themselves. All they can do is act as a "multiplier", encouraging some existing behavior by increasing the behaviors value in the eyes of the user. If that value was originally zero, game mechanics wont help.
To put it another way, if you have a crappy product to begin with, gameplay will not save it. It doesnt matter how many badges, progress bars, leaderboards, achievement scores, or collectibles you add, if the user doesnt see any value in your product, you will not be successful. Moreover, the more obvious the value proposition, the less you need to bother with game dynamics. All of this is best illustrated with a few examples:
cubeduel: a great example of well executed game mechanics - you have to play some number of "duels" before you can see your own score - but absolutely no inherent value to the product itself. Lots of people tried it for a couple minutes, got bored, and never came back.
Pandora: the exact opposite of cubeduel. From the first minute of using Pandora, its value proposition is obvious, and youre hooked. No game mechanics whatsoever are necessary to keep users engaged.
StackExchange: the StackExchange sites are a great example of a strong core value multiplied by effective game mechanics. Most users end up on one of their community sites (StackOverflow is the most popular) by googling a question. The utility of the site becomes obvious immediately: quality answers written and vetted by a community of experts. If your particular question isnt there, you can sign up and ask. At this point, the first game mechanic is revealed: the reputation score. This score starts at zero and as it increases, various "privileges" become available: for example, you cant add comments, create new tags, downvote answers, or offer bounties until your score reaches certain thresholds. To get your score higher, other users need to upvote your questions and answers, which encourages you to actively participate in the site. When you do this, the next game mechanic becomes apparent: your profile. Your questions, answers, reputation score, and tags from any discussions you participated in are all publicly visible. Again, the value is obvious: professional reputation. If you do a good job of participating on the site, you look better in front of employers and colleagues. Strong value * effective game mechanics = 24 million unique visitors per month (and growing).
Stop playing games. Start building awesome products.
Game mechanics can be a powerful tool, but like everything else in your toolbox, its all about knowing when and how to use them. If youre working on some new product, start with the basics and make sure that you have the value proposition nailed down. Only when you have something sufficiently compelling by itself should you start thinking about adding any sort of game mechanics.
Read more »
In fact, the very idea that cramming "game-like" elements into a product is enough to attract users is misguided; the proposal of using "game mechanics" as the primary way to drive and maintain user engagement is a short road to failure. I think these misconceptions come from a lack of understanding of two key concepts:
- Gameplay psychology
- The role of game mechanics
The first reason that game mechanics probably wont work for you is that you dont understand game mechanics. Before you go off and add a leader-board or badging system to your next product, please take the time to go through Sebastian Deterdings superb presentation "Pawned. Gamification and its discontents". Im embedding it within this blog post as the presentation beautifully covers the many mistakes and misconceptions about what gameplay is really all about:
One of the key takeaways from this presentation is that most people dont understand motivation. Think of the most common game mechanics you see in most products today: badges, scores, and progress bars. foursquare has it, so it must work, right? Wrong. These "external rewards" are rarely effective because gamers and humans in general are typically not motivated by external factors, but rather by intrinsic ones. In fact, studies have shown that external rewards and pressures can often act as de-motivators. If youre not convinced, it would be well worth your time to watch Dan Pinks talk on The Surprising Science of Motivation.
The role of game mechanics
If you fail to grasp the key principle of motivation, your game mechanics have no chance of being effective. But even if you do get the mechanics right, there is still no guarantee of success. To understand why, you need to understand that game mechanics are not your core product (unless you are building a game, of course) and have no value in and of themselves. All they can do is act as a "multiplier", encouraging some existing behavior by increasing the behaviors value in the eyes of the user. If that value was originally zero, game mechanics wont help.
To put it another way, if you have a crappy product to begin with, gameplay will not save it. It doesnt matter how many badges, progress bars, leaderboards, achievement scores, or collectibles you add, if the user doesnt see any value in your product, you will not be successful. Moreover, the more obvious the value proposition, the less you need to bother with game dynamics. All of this is best illustrated with a few examples:
| cubeduel: great gameplay, 0 value |
| Pandora: crystal clear value, no games |
| StackExchange: clear value, good game mechanics |
Stop playing games. Start building awesome products.
![]() |
| Kniffel: game mechanics != fun |
Wednesday, February 4, 2015
Creating a Pentomino game using AS3 Part 19
In this tutorial well add a custom alert system to our game.
With this alert system well be able to pop up a window with an error/warning message to the user, with an "OK" button that closes the window.
Start by opening your Flash project and creating a new MovieClip. You can do it by duplicating any of the _screen movieclips you have so far (win_screen or new_edit_screen). Draw a window box, add a button with an id "btn_continue" and a dynamic text field with id "tAlert". Give this MovieClip a class path of alert_screen.
Create the alert_screen.as file. Make the class extend MovieClip, and declare 1 variable - onClose, typed Function.
The constructor shall have two paramaters - one required and one optional. The required one is message:String, which value we apply to tAlerts text property in the constructor. The optional one is closeHandler:Function, set it to null by default. This will be the reference to a function that will be called when the user closes the alert window. In the constructor set onClose to reference this value and also add a CLICK event listener for btn_continue. In the handler function, remove the event listener, remove the movie clip and call onClose function:
Now go to pentomino_editor.as script file. Here we will add 2 new functions - alert() and alertClose(). The first function has 1 parameter message:String, the function simply creates an instance of alertWindow and sets canDraw to false. When creating the alertWindow object, set its message value to the functions parameter, and its closeFunction parameter to alertClose.
The alertClose() function sets canDraw to true:
We can now use alert() instead of trace() in checkSave() function to display errors:
Full pentomino_editor.as code:
Thanks for reading!
Results:
Read more »
With this alert system well be able to pop up a window with an error/warning message to the user, with an "OK" button that closes the window.
Start by opening your Flash project and creating a new MovieClip. You can do it by duplicating any of the _screen movieclips you have so far (win_screen or new_edit_screen). Draw a window box, add a button with an id "btn_continue" and a dynamic text field with id "tAlert". Give this MovieClip a class path of alert_screen.
Create the alert_screen.as file. Make the class extend MovieClip, and declare 1 variable - onClose, typed Function.
The constructor shall have two paramaters - one required and one optional. The required one is message:String, which value we apply to tAlerts text property in the constructor. The optional one is closeHandler:Function, set it to null by default. This will be the reference to a function that will be called when the user closes the alert window. In the constructor set onClose to reference this value and also add a CLICK event listener for btn_continue. In the handler function, remove the event listener, remove the movie clip and call onClose function:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
/**
* Open-source pentomino game engine
* @author Kirill Poletaev
*/
public class alert_screen extends MovieClip
{
var onClose:Function;
public function alert_screen(message:String, closeHandler:Function = null)
{
onClose = closeHandler;
tAlert.text = message;
btn_continue.addEventListener(MouseEvent.CLICK, onContinue);
}
private function onContinue(evt:MouseEvent):void {
btn_continue.removeEventListener(MouseEvent.CLICK, onContinue);
this.parent.removeChild(this);
onClose.call();
}
}
}
Now go to pentomino_editor.as script file. Here we will add 2 new functions - alert() and alertClose(). The first function has 1 parameter message:String, the function simply creates an instance of alertWindow and sets canDraw to false. When creating the alertWindow object, set its message value to the functions parameter, and its closeFunction parameter to alertClose.
The alertClose() function sets canDraw to true:
private function alert(message:String):void {
var alertWindow:MovieClip = new alert_screen(message, alertClose);
addChild(alertWindow);
canDraw = false;
}
private function alertClose():void {
canDraw = true;
}
We can now use alert() instead of trace() in checkSave() function to display errors:
private function checkSave():Boolean {
// count total cells
var totalCells:int = 0;
var i:int;
var u:int;
var width:int = mapGrid[0].length;
var height:int = mapGrid.length;
for (i = 0; i < height; i++) {
for (u = 0; u < width; u++) {
if (mapGrid[i][u] == 1) totalCells++;
}
}
// check if total cells can be divided by 5
if (totalCells / 5 != Math.round(totalCells / 5)) {
alert("Error!
Incorrect cell count: " + totalCells + ", number must be divideable by 5.");
return false;
}
// count total available shape count
var totalShapes:int = 0;
for (i = 0; i < shapeButtons.length; i++) {
totalShapes += shapeButtons[i].count.value;
}
// check if there are enough shapes available
if (totalCells > totalShapes * 5) {
alert("Error!
Not enough shapes available: " + totalShapes + " out of " + totalCells/5);
return false;
}
return true;
}
Full pentomino_editor.as code:
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.sampler.NewObjectSample;
import flash.utils.ByteArray;
/**
* Open-source pentomino game engine
* @author Kirill Poletaev
*/
public class pentomino_editor extends MovieClip
{
private var mapGrid:Array = [];
private var shapeButtons:Array = [];
private var gridShape:Sprite = new Sprite();
private var canPutShape:Sprite = new Sprite();
private var gridStartX:int;
private var gridStartY:int;
private var gridCellWidth:int;
private var canDraw:Boolean = false;
private var mouseDown:Boolean = false;
private var currentCell:Point = new Point(-1, -1);
public function pentomino_editor()
{
addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
// add shape buttons
for (var i:int = 0; i < 4; i++) {
for (var u:int = 0; u < 3; u++) {
var shapeButton:MovieClip = new edit_shape();
shapeButton.x = 528 + u * 62;
shapeButton.y = 15 + i * 84;
addChild(shapeButton);
shapeButton.bg.alpha = 0.3;
shapeButton.shape.gotoAndStop(3 * i + u + 1);
shapeButtons.push(shapeButton);
shapeButton.addEventListener(MouseEvent.ROLL_OVER, buttonOver);
shapeButton.addEventListener(MouseEvent.ROLL_OUT, buttonOut);
}
}
// buttons
btn_mainmenu.addEventListener(MouseEvent.CLICK, doMainmenu);
btn_reset.addEventListener(MouseEvent.CLICK, function():void { newLevel() } );
btn_save.addEventListener(MouseEvent.CLICK, doSave);
// new level
newLevel();
addChild(gridShape);
addChild(canPutShape);
canPutShape.mouseEnabled = false;
canPutShape.mouseChildren = false;
}
private function onMouseMove(evt:MouseEvent):void {
if(mapGrid.length>0){
var mousePos:Point = new Point(Math.floor((mouseX - gridStartX) / gridCellWidth), Math.floor((mouseY - gridStartY) / gridCellWidth));
canPutShape.x = mousePos.x * gridCellWidth + gridStartX;
canPutShape.y = mousePos.y * gridCellWidth + gridStartY;
if (mousePos.x < mapGrid[0].length && mousePos.y < mapGrid.length && mousePos.x >= 0 && mousePos.y >= 0) {
canPutShape.alpha = 1;
}else {
canPutShape.alpha = 0;
}
}
}
private function newLevel():void {
canDraw = false;
var newScreen:MovieClip = new new_edit_screen();
addChild(newScreen);
newScreen.tWidth.restrict = "0-9";
newScreen.tHeight.restrict = "0-9";
newScreen.tWidth.text = 10;
newScreen.tHeight.text = 6;
newScreen.incorrect.alpha = 0;
newScreen.btn_continue.addEventListener(MouseEvent.CLICK, editContinue);
function editContinue(evt:MouseEvent):void {
if (newScreen.tWidth.text == "" || newScreen.tHeight.text == "" || newScreen.tWidth.text == "0" || newScreen.tHeight.text == "0") {
newScreen.incorrect.alpha = 1;
return;
}
newScreen.parent.removeChild(newScreen);
mapGrid = [];
var width:int = newScreen.tWidth.text;
var height:int = newScreen.tHeight.text;
for (var i:int = 0; i < height; i++) {
mapGrid[i] = [];
for (var u:int = 0; u < width; u++) {
mapGrid[i][u] = 1;
}
}
// grid settings
calculateGrid();
gridShape.x = gridStartX;
gridShape.y = gridStartY;
// draw tiles
drawGrid();
// canPutShape settings
canPutShape.graphics.clear();
canPutShape.graphics.lineStyle(2, 0xff0000);
canPutShape.graphics.drawRect(0, 0, gridCellWidth, gridCellWidth);
canPutShape.alpha = 0;
canDraw = true;
}
}
private function calculateGrid():void {
var columns:int = mapGrid[0].length;
var rows:int = mapGrid.length;
// free size: 520x460
// fit in: 510x450
// calculate width of a cell:
gridCellWidth = Math.round(510 / columns);
var width:int = columns * gridCellWidth;
var height:int = rows * gridCellWidth;
// calculate side margin
gridStartX = (520 - width) / 2;
if (height < 450) {
gridStartY = (450 - height) / 2;
}
if (height >= 450) {
gridCellWidth = Math.round(450 / rows);
height = rows * gridCellWidth;
width = columns * gridCellWidth;
gridStartY = (460 - height) / 2;
gridStartX = (520 - width) / 2;
}
}
private function drawGrid():void {
gridShape.graphics.clear();
var width:int = mapGrid[0].length;
var height:int = mapGrid.length;
var i:int;
var u:int;
// draw background
for (i = 0; i < height; i++) {
for (u = 0; u < width; u++) {
if (mapGrid[i][u] == 1) drawCell(u, i, 0xffffff, 1, 0x999999);
}
}
}
private function drawCell(width:int, height:int, fill:uint, thick:Number, line:uint):void {
gridShape.graphics.beginFill(fill);
gridShape.graphics.lineStyle(thick, line);
gridShape.graphics.drawRect(width * gridCellWidth, height * gridCellWidth, gridCellWidth, gridCellWidth);
}
private function buttonOver(evt:MouseEvent):void {
evt.currentTarget.bg.alpha = 1;
}
private function buttonOut(evt:MouseEvent):void {
evt.currentTarget.bg.alpha = 0.3;
}
private function doMainmenu(evt:MouseEvent):void {
(root as MovieClip).gotoAndStop(1);
}
private function onMouseDown(evt:MouseEvent):void {
mouseDown = true;
}
private function onMouseUp(evt:MouseEvent):void {
mouseDown = false;
currentCell = new Point(-1, -1)
}
private function onEnterFrame(evt:Event):void {
// if drawing is allowed and mouse is down
if (canDraw && mouseDown) {
var mousePos:Point = new Point(Math.floor((mouseX - gridStartX) / gridCellWidth), Math.floor((mouseY - gridStartY) / gridCellWidth));
// if valid coordinates
if (mousePos.x < mapGrid[0].length && mousePos.y < mapGrid.length && mousePos.x >= 0 && mousePos.y >= 0) {
// if the cell is not "current cell"
if (mousePos.x != currentCell.x || mousePos.y != currentCell.y) {
currentCell.x = mousePos.x;
currentCell.y = mousePos.y;
if (mapGrid[mousePos.y][mousePos.x] == 1) {
mapGrid[mousePos.y][mousePos.x] = 0;
}else {
mapGrid[mousePos.y][mousePos.x] = 1;
}
drawGrid();
}
}
}
}
private function doSave(evt:MouseEvent):void {
if (checkSave()) {
trace("Save!");
}
}
private function checkSave():Boolean {
// count total cells
var totalCells:int = 0;
var i:int;
var u:int;
var width:int = mapGrid[0].length;
var height:int = mapGrid.length;
for (i = 0; i < height; i++) {
for (u = 0; u < width; u++) {
if (mapGrid[i][u] == 1) totalCells++;
}
}
// check if total cells can be divided by 5
if (totalCells / 5 != Math.round(totalCells / 5)) {
alert("Error!
Incorrect cell count: " + totalCells + ", number must be divideable by 5.");
return false;
}
// count total available shape count
var totalShapes:int = 0;
for (i = 0; i < shapeButtons.length; i++) {
totalShapes += shapeButtons[i].count.value;
}
// check if there are enough shapes available
if (totalCells > totalShapes * 5) {
alert("Error!
Not enough shapes available: " + totalShapes + " out of " + totalCells/5);
return false;
}
return true;
}
private function alert(message:String):void {
var alertWindow:MovieClip = new alert_screen(message, alertClose);
addChild(alertWindow);
canDraw = false;
}
private function alertClose():void {
canDraw = true;
}
}
}
Thanks for reading!
Results:
Tuesday, February 3, 2015
Creating a Pentomino game using AS3 Part 43
Today we continue working on level selection screen.
Firstly, go to level_item.as class and delete all the code from the constructor, move it to a separate public function called setLevel():
Full class:
Now go to level_select.as.
I want my level selection menu to work like a horizontally scrolling line of thumbnails, operated by two arrows that display the next and previous level previews. The thumbnails will smoothly scroll to focus on the selected level.
To achieve this, we need to create a holder of 5 level previews. Why 5? Because at the same time only 3 pictures are visible on screen - 1 fully (the selected level), and surrounding 2 - partially. The 2 remaining level items that are invisible are needed, because they will be partially visible when scrolling animation is occuring. Were not going to create a separate level preview item for all the levels in the database, were just going to reuse these 5.
First thing we need to do in level_select.as is create an array of levels. Right now were only going to store 5 levels, 4 of which are dummy levels (with only difference being the title).
Now declare these 5 variables:
The currentLevel value represents the index of the level in "levels" array thats currently selected.
The distance value is the distance in pixels between each level preview object.
The levelHolder MovieClip is a holder for all 5 level previews.
The levelItems array will hold references to all 5 level preview movie clips.
The goX integer value is the coordinate to which the levelHolder movieclip must smoothly move to. This will be used for the scrolling animation.
Open Flash and go to the sixth frame. Add 2 buttons on the left and on the right - set their ids to btn_next and btn_preview.
In constructor, set levelHolder to a new MovieClip() and add 5 level objects one by one to levelHolder and levelItems array.
Add levelHolder to stage, set its coordinates. When setting the x coordinate, calculate the needed position to display the 3rd (central) level preview in the middle.
Set goX to levelHolders x value (we dont want any animation in the beginning).
Call a function called selectLevel(). Put btn_next and btn_prev buttons on top of all the rest elements using setChildIndex() method. Add an ENTER_FRAME event listener with handler onFrame:
Now add a function called selectLevel(). Well be calling it every time we need to update our level item MovieClips and arrow buttons.
Call a function called setLevelPreview() 5 times - pass 2 values as parameters: index of the level item in levelItems array (from 0 to 4) and the index of level data from levels array.
Then add 2 if...statements that enable/disable arrows when needed:
The setLevelPreview() enables or disables a level item object based on whether the respective level data exists. On success, also call the level items setLevel() function to update it with values:
The onFrame() function modifies levelHolders x value to smoothly move to goX coordinate:
Full code so far:
Well work on arrow buttons and more in the next part.
Thanks for reading!
Read more »
Firstly, go to level_item.as class and delete all the code from the constructor, move it to a separate public function called setLevel():
public function setLevel(mapGrid:Array, shapes:Array, title:String):void {
tTitle.text = title;
levelPreview.mouseEnabled = false;
drawPreview(levelPreview, mapGrid);
btn.addEventListener(MouseEvent.CLICK, function() { (root as MovieClip).playLevel(mapGrid, shapes); } );
}
Full class:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
/**
* Open-source pentomino game engine
* @author Kirill Poletaev
*/
public class level_item extends MovieClip
{
public function level_item()
{
}
public function setLevel(mapGrid:Array, shapes:Array, title:String):void {
tTitle.text = title;
levelPreview.mouseEnabled = false;
drawPreview(levelPreview, mapGrid);
btn.addEventListener(MouseEvent.CLICK, function() { (root as MovieClip).playLevel(mapGrid, shapes); } );
}
private function drawPreview(levelPreview:MovieClip, mapGrid:Array):void {
var columns:int = mapGrid[0].length;
var rows:int = mapGrid.length;
var frameWidth:int = levelPreview.width;
var frameHeight:int = levelPreview.height;
var padding:int = 5;
var fitWidth:int = levelPreview.width - (padding * 2);
var fitHeight:int = levelPreview.height - (padding * 2);
var gridStartX:int;
var gridStartY:int;
// calculate width of a cell:
var gridCellWidth:int = Math.round(fitWidth / columns);
var width:int = columns * gridCellWidth;
var height:int = rows * gridCellWidth;
// calculate side margin
gridStartX = (frameWidth - width) / 2;
if (height < fitHeight) {
gridStartY = (fitHeight - height) / 2;
}
if (height >= fitHeight) {
gridCellWidth = Math.round(fitHeight / rows);
height = rows * gridCellWidth;
width = columns * gridCellWidth;
gridStartY = (frameHeight - height) / 2;
gridStartX = (frameWidth - width) / 2;
}
// draw map
levelPreview.x = gridStartX;
levelPreview.y = gridStartY;
levelPreview.graphics.clear();
var i:int;
var u:int;
for (i = 0; i < rows; i++) {
for (u = 0; u < columns; u++) {
if (mapGrid[i][u] == 1) drawCell(u, i, 0xffffff, 1, 0x999999, gridCellWidth, levelPreview);
}
}
}
private function drawCell(width:int, height:int, fill:uint, thick:Number, line:uint, gridCellWidth:int, gridShape:MovieClip):void {
gridShape.graphics.beginFill(fill);
gridShape.graphics.lineStyle(thick, line);
gridShape.graphics.drawRect(width * gridCellWidth, height * gridCellWidth, gridCellWidth, gridCellWidth);
}
}
}
Now go to level_select.as.
I want my level selection menu to work like a horizontally scrolling line of thumbnails, operated by two arrows that display the next and previous level previews. The thumbnails will smoothly scroll to focus on the selected level.
To achieve this, we need to create a holder of 5 level previews. Why 5? Because at the same time only 3 pictures are visible on screen - 1 fully (the selected level), and surrounding 2 - partially. The 2 remaining level items that are invisible are needed, because they will be partially visible when scrolling animation is occuring. Were not going to create a separate level preview item for all the levels in the database, were just going to reuse these 5.
First thing we need to do in level_select.as is create an array of levels. Right now were only going to store 5 levels, 4 of which are dummy levels (with only difference being the title).
private var levels:Array = [
{grid:
[
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
],
shapes:
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
title:
"Standard 10x6"
},
{grid:
[
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
],
shapes:
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
title:
"Standard 2"
},
{grid:
[
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
],
shapes:
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
title:
"Standard 3"
},
{grid:
[
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
],
shapes:
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
title:
"Standard 4"
},
{grid:
[
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
],
shapes:
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
title:
"Standard 5"
}
];
Now declare these 5 variables:
private var currentLevel:int = 0;
private var distance:int = 100;
private var levelHolder:MovieClip;
private var levelItems:Array = [];
private var goX:int;
The currentLevel value represents the index of the level in "levels" array thats currently selected.
The distance value is the distance in pixels between each level preview object.
The levelHolder MovieClip is a holder for all 5 level previews.
The levelItems array will hold references to all 5 level preview movie clips.
The goX integer value is the coordinate to which the levelHolder movieclip must smoothly move to. This will be used for the scrolling animation.
Open Flash and go to the sixth frame. Add 2 buttons on the left and on the right - set their ids to btn_next and btn_preview.
In constructor, set levelHolder to a new MovieClip() and add 5 level objects one by one to levelHolder and levelItems array.
Add levelHolder to stage, set its coordinates. When setting the x coordinate, calculate the needed position to display the 3rd (central) level preview in the middle.
Set goX to levelHolders x value (we dont want any animation in the beginning).
Call a function called selectLevel(). Put btn_next and btn_prev buttons on top of all the rest elements using setChildIndex() method. Add an ENTER_FRAME event listener with handler onFrame:
public function level_select()
{
(root as MovieClip).stop();
btn_back.addEventListener(MouseEvent.CLICK, doBack);
levelHolder = new MovieClip();
for (var i:int = 0; i < 5; i++) {
var level:MovieClip = new level_item();
levelHolder.addChild(level);
levelItems.push(level);
level.x = (level.width + distance) * i;
}
addChild(levelHolder);
levelHolder.y = 120;
levelHolder.x = -(level.width + distance) * 2 + level.width / 2;
goX = levelHolder.x;
selectLevel();
setChildIndex(btn_next, numChildren - 1);
setChildIndex(btn_prev, numChildren - 1);
addEventListener(Event.ENTER_FRAME, onFrame);
}
Now add a function called selectLevel(). Well be calling it every time we need to update our level item MovieClips and arrow buttons.
Call a function called setLevelPreview() 5 times - pass 2 values as parameters: index of the level item in levelItems array (from 0 to 4) and the index of level data from levels array.
Then add 2 if...statements that enable/disable arrows when needed:
private function selectLevel():void {
setLevelPreview(0, currentLevel - 2);
setLevelPreview(1, currentLevel - 1);
setLevelPreview(2, currentLevel);
setLevelPreview(3, currentLevel + 1);
setLevelPreview(4, currentLevel + 2);
if (currentLevel < levels.length - 1) {
btn_next.alpha = 1;
btn_next.mouseEnabled = true;
}else {
btn_next.alpha = 0;
btn_next.mouseEnabled = false;
}
if (currentLevel > 0) {
btn_prev.alpha = 1;
btn_prev.mouseEnabled = true;
}else {
btn_prev.alpha = 0;
btn_prev.mouseEnabled = false;
}
}
The setLevelPreview() enables or disables a level item object based on whether the respective level data exists. On success, also call the level items setLevel() function to update it with values:
private function setLevelPreview(ind:int, num:int):void {
if (num >= 0 && num < levels.length) {
levelItems[ind].alpha = 1;
levelItems[ind].mouseChildren = true;
levelItems[ind].setLevel(levels[num].grid, levels[num].shapes, levels[num].title);
}else {
levelItems[ind].alpha = 0;
levelItems[ind].mouseChildren = false;
}
}
The onFrame() function modifies levelHolders x value to smoothly move to goX coordinate:
private function onFrame(evt:Event):void {
levelHolder.x += Math.round((goX - levelHolder.x) / 5);
}
Full code so far:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
/**
* Open-source pentomino game engine
* @author Kirill Poletaev
*/
public class level_select extends MovieClip
{
private var levels:Array = [
{grid:
[
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
],
shapes:
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
title:
"Standard 10x6"
},
{grid:
[
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
],
shapes:
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
title:
"Standard 2"
},
{grid:
[
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
],
shapes:
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
title:
"Standard 3"
},
{grid:
[
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
],
shapes:
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
title:
"Standard 4"
},
{grid:
[
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
],
shapes:
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
title:
"Standard 5"
}
];
private var currentLevel:int = 0;
private var distance:int = 100;
private var levelHolder:MovieClip;
private var levelItems:Array = [];
private var goX:int;
public function level_select()
{
(root as MovieClip).stop();
btn_back.addEventListener(MouseEvent.CLICK, doBack);
levelHolder = new MovieClip();
for (var i:int = 0; i < 5; i++) {
var level:MovieClip = new level_item();
levelHolder.addChild(level);
levelItems.push(level);
level.x = (level.width + distance) * i;
}
addChild(levelHolder);
levelHolder.y = 120;
levelHolder.x = -(level.width + distance) * 2 + level.width / 2;
goX = levelHolder.x;
selectLevel();
setChildIndex(btn_next, numChildren - 1);
setChildIndex(btn_prev, numChildren - 1);
addEventListener(Event.ENTER_FRAME, onFrame);
}
private function selectLevel():void {
setLevelPreview(0, currentLevel - 2);
setLevelPreview(1, currentLevel - 1);
setLevelPreview(2, currentLevel);
setLevelPreview(3, currentLevel + 1);
setLevelPreview(4, currentLevel + 2);
if (currentLevel < levels.length - 1) {
btn_next.alpha = 1;
btn_next.mouseEnabled = true;
}else {
btn_next.alpha = 0;
btn_next.mouseEnabled = false;
}
if (currentLevel > 0) {
btn_prev.alpha = 1;
btn_prev.mouseEnabled = true;
}else {
btn_prev.alpha = 0;
btn_prev.mouseEnabled = false;
}
}
private function setLevelPreview(ind:int, num:int):void {
if (num >= 0 && num < levels.length) {
levelItems[ind].alpha = 1;
levelItems[ind].mouseChildren = true;
levelItems[ind].setLevel(levels[num].grid, levels[num].shapes, levels[num].title);
}else {
levelItems[ind].alpha = 0;
levelItems[ind].mouseChildren = false;
}
}
private function onFrame(evt:Event):void {
levelHolder.x += Math.round((goX - levelHolder.x) / 5);
}
private function doBack(evt:MouseEvent):void {
(root as MovieClip).gotoAndStop(1);
}
}
}
Well work on arrow buttons and more in the next part.
Thanks for reading!
Subscribe to:
Posts (Atom)









