Labels

Learn the powerful enterprise adaptable database:

Getting Started With ADABAS & Natural

Friday, December 2, 2016

201-Construct2 Game Stage Objects


.
201-Construct2 Game Stage Objects

Objective

1) Create Game Stage Objects consists of:
1.1) TextScore
1.2) TextTime
1.3) TextWellDone
1.4) TextTimeIsUp
1.5) ButtonRestart
2) Create Dummy Game Play Objects consists of:
2.1) PlayTarget Object
2.2) PlayDrag Object

1) Create New Project

Template: New empty SD portrait 4:3 project
Name: GameStage
Layout: LayoutHome
Event: EventHome
Object Types: ObjectPlay and ObjectStage

2) Add Stage Objects

-ButtonRestart
-TextGameOver
-TextInstructions
-TextScores
-TextTime
-TextWellDone
Name
TextScores
Position
10,10
Size
200,30
Text
SCORES:----
Font
Lucida Console (12pt)
Horizontal Alignment
Left
Vertical Alignment
Center
Hotspot
Top-Left
Name
TextTime
Position
470,10
Size
200,30
Text
TIME:----
Font
Lucida Console (12pt)
Horizontal Alignment
Right
Vertical Alignment
Center
Hotspot
Top-Right
Name
TextInstructions
Position
10,40
Size
460,30
Text
Drag and drop Game Object to Game Target
Color
Blue
Font
Lucida Console (12pt)
Horizontal Alignment
Center
Vertical Alignment
Center
Hotspot
Top-Left
Name
TextGameOver
Position
240, 200
Size
200, 50
Text
Game Over!
Color
Red
Font
Lucida Console (24pt)
Horizontal Alignment
Center
Vertical Alignment
Center
Hotspot
Center
Name
TextWellDone
Position
240, 230
Size
200, 50
Text
Well Done!
Color
Green
Font
Lucida Console (24pt)
Horizontal Alignment
Center
Vertical Alignment
Center
Hotspot
Center
Name
ButtonRestart
Position
160, 350
Size
160, 24
Text
RESTART

3) Add Blink Action

No
Event
Action
GroupBlinkTexts
1
System/every-0.5-seconds
GroupBlinkTextGameOver
2
TextGameOver/opacity=0
TextGameOver/set-opacity-to 100
3
System/else
TextGameOver/set-opacity-to 0
GroupBlinkTextWellDone
4
TextWellDone/opacity=0
TextWellDone/set-opacity-to 100
5
System/else
TextWellDone/set-opacity-to 0
gamestage-201a.gif
DOWNLOAD: GameStage201A.capx

4) Add Dummy Play Objects

-SpritePlaySpot
-TextDrag
-TextTarget
Name
SpritePlaySpot
Position
100,325
Size
10,10
Behavior
Pin
Color
Yellow
Name
TextDrag
Position
100,325
Size
50, 50
Behavior
DragDrop
Flash
Container
This Object
Member=SpritePlaySpot
Text
A
Color
Black
Font
Arial(24pt)
Horizontal Alignment
Center
Vertical Alignment
Center
Hotspot
Center
Name
TextTarget
Position
100,150
Size
50, 50
Text
A
Color
Orange
Font
Arial(24pt)
Horizontal Alignment
Center
Vertical Alignment
Center
Hotspot
Center
Change the text of TextInstructions to the following:
Drag Black Letter to Orange Letter
Insert Actions for Dummy ObjectPlay items.
No
Event
Action
GroupObjectPlayActions
1
System/on-start-of-layout
SpritePlaySpot/Pin-to-TextDrag(Position & angle)
2
TextDrag/on-DragDrop-drag-start
TextDrag/Move-to-top-of-layer
SpritePlaySpot/Move-to-bottom-of-layer
3
TextDrag/on-DragDrop-drop
[and]
SpritePlaySpot/Is-overlapping-TextTarget
TextDrag/Flash

5) Add Scoring Logic

Insert variable globalScores and initialize it to 0.
Insert variable globalMaxScores and initialize it to 1.
When the Letters matched, Add 1 to globalScore after TextDrag flashes and Update TextScores.
No
Event
Action
GroupStageActions
1
TextScores/set-text-to "SCORES:"&zeropad(globalScores,4)
gamestage-overlaps.gif

6) Add the Winning Logic

During the start of layout, set the visibility of TextGameOver and TextWellDone to Not Visible.
At every ticks, detect winning condition ie globalScores=globalMaxScores. If True, set the visibility of TextGameOver and TextWellDone to Visible.
No
Event
Action
GroupGameOverCondition
1
System/everytick
2
[sub]System/globalScores=globalMaxScores
TextGameOver/set-visible
TextWellDone/set-visible
3
gamestage-winning-condition.gif
DOWNLOAD: GameStage201B.capx

7) Add The Time Controller

The game ends when the user scores the maximum point or the time is over.
Add a global variable, globalTimer=5.
Take the GroupStageActions out of the System/on-start-of-layout event.
That is, if your GroupStageActions is as follows ...
...then make it look like this
Add a event/actions
No
Event
Action
GroupStageActions
1
System/globalTimer>0
TextTime/set-text-to "TIME:" & zeropad(ceil(globalTimer),4)
2
System/set-variable-to max(0,globalTimer-dt)
3
System/Else
TextTime/set-text-to "TIME:" & zeropad(0,4)
No
Event
Action
GroupGameOverCondition
1
System/everytick
2
[sub]System/globalScores=globalMaxScores
TextGameOver/set-visible
TextWellDone/set-visible
System/set-globalTimer-to 0
3
[sub]System/Else
[and]globalTimer=0
TextGameOver/set-visible
Finally, provide action for the ButtonRestart/on-clicked event to reset global variable and restart layout.

DOWNLOAD: GameStage201C.capx

.

No comments:

Post a Comment