Main Menu

Game - Click the Circle

Started by kevin, July 22, 2005, 03:02:51 PM

Previous topic - Next topic

kevin

PlayBASIC Code: [Select]
; *=---------------------------------------------------------------=*
; Example Name: 'Click The Circle'
; *=---------------------------------------------------------------=*
;
; Level: Beginner
;
; By Kevin Picone
;
; 22,July,2005
;
; *=---------------------------------------------------------------=*
; (c) Copyright 2005 Kevin Picone, All Rights Reserved
; *=---------------------------------------------------------------=*
;
; This example/basic tutorial aims to show programmers some basic
; interaction between a computer controlled character, in this case
; a circle and a single player.
;
; The code set out in three main parts. The Main Loop (which keeps
; it all running), The Intro and the Game.
;
; In this game, the character does not move, it simply waits for the
; player to click on top of it. Once clicked it the character reposition
; it self and waits again. The player has a limited amount of time
; to click the character before the player will loose a life.
;
; So the focus here is to get a some understanding of how to use Variables
; to control the circle character and how to make the player interact with it.
;
; *=---------------------------------------------------------------=*



; Set the GAME to run at a maximum of 60 Frames Per Second.
Setfps 60


; Set the Title of the Play Basic screen to the title of our game
TitleScreen "Click The Circle Game"


; ================================
; Our Programs MAIN LOOP
; ================================

; The main loop, keeps the program running the various parts (into/game)
; of our game.


;Start a DO/LOOP
Do

; ========================================
; Call the Games Title Screen
; ========================================
; The title screen will be displayed until the user
; presses the mouse button to start
; ========================================
Game_Title_Screen()


; ========================================
; Play Game
; ========================================
Play_Game()

; Tell PB to LOOP back to the previous DO Statement above
; to keep the game running,
loop





; *=---------------------------------------------------------------=*
; >> Game TITLE SCreen <<
; *=---------------------------------------------------------------=*
; This section of code displays a simple Title screen.

Function Game_Title_Screen()

; STart a Repeat/Until Loop. This Loop will continue
; executing until the user pressed the LEFT MOUSE Button
Repeat

; Clear the Screen to a purple/redy colour.
Cls rgb(20,30,40)


; Get the Width of the Screen in Dots (PIxels) and store
; value in the Variable 'WIDTH'
Width=GetScreenWidth()

; Get the Height of the Screen in Dots (PIxels) and store
; this value in the Variable 'HEIGHT'
Height=GetScreenHeight()


; Draw a Big Circle as the Title Screen Backdrop
Circlec Width/2,Height/2,Width/3,1,rgb(80,20,80)


; Draws the Games TITLE message, 50 pixels above the center
; of the screen. We calculate the center cordinate from the
; screens Width & Height. So the center point will be half way
; across and down the screen.

; Calc the X positon of the title message (divide width by 2).
x=Width/2

; Calc the Y position of the title message (divide height by 2)
y=(Height/2)-50

; Draw the Games Title to the screen
CenterText x,y,"<<---- Click The Cirle ---->>"


; Add 100 to the previous Y position. We do this so we can print the
; PRESS LEFT MOUSE BUTTON Message 100 pixels bellow the Title message.
; otherwise, the we'd be drawing this message over the title message
y=y+100

; Draw the press mouse button message to the screen.
CenterText x,y,"Press Left Mouse Button To Start"

; Display the Screen to the user
Sync

; Repeat/Until then Left Mouse Button is pressed (='s TRUE)
until LeftMouseButton()=True


; End This function and return to where it was called from.
EndFunction





; *=---------------------------------------------------------------=*
; *=---------------------------------------------------------------=*
; *=---------------------------------------------------------------=*
; *=---------------------------------------------------------------=*
; >> PLay Game <<
; *=---------------------------------------------------------------=*
; *=---------------------------------------------------------------=*
; *=---------------------------------------------------------------=*
; *=---------------------------------------------------------------=*
Login required to view complete source code