thank you for code J_milton :)
So far I put timer in my game
I have notice that freebasic allergo dont notice this one when i convert from C++ Allergo to freebasic allergo as I am making sure that my game run 60FPS on every pc :)
install_int_ex(increment_speed_counter, BPS_TO_TIMER(60))
freebasic allergo doesnt know this one above code :(
Code: Select all
#include "allegro.bi"
Option Explicit
#define WHITE makecol(255,255,255)
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define Depth 32
#define Speed 3
Type Daft_Dog
X AS integer
Y as integer
end type
Type Stick
X2 as integer
Y2 as integer
end type
'Now we can have variables like Doggy.X, Doggy.Y
'------------------------------------------------------------------------------
Dim shared Doggy As Daft_Dog
Dim shared Sticky As Stick
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
Dim shared Buffer As bitmap ptr
Dim shared Background AS Bitmap ptr
Dim shared Dog As Bitmap Ptr
Dim shared Stick As Bitmap Ptr
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' You must Declare the function without you will get error when you run it!
'------------------------------------------------------------------------------
Declare Function Allergo_Setup
Declare Function Load_Images
Declare Function Move_Player
Declare Function Render_Sprites
Declare Function Shut_down
'------------------------------------------------------------------------------
Common Shared speed_counter As Long
speed_counter = 0
Allergo_Setup
Load_Images
' Varibles
Doggy.x = SCREEN_W/2 - Dog->w/2 : Doggy.y = SCREEN_H/2 - Dog->h/2
Sticky.x2 = 200 : Sticky.y2 = 200
' Timer
LOCK_VARIABLE(speed_counter) ' Used to set the timer - which regulates the game's
LOCK_FUNCTION(increment_speed_counter)' speed.
install_int_ex(increment_speed_counter, BPS_TO_TIMER(60))' Set our BPS
' main loop
while (not key(KEY_ESC))
while(speed_counter > 0)
Move_Player ' Move the Daft Dog..heh heh
Render_Sprites ' Draw everythings
speed_counter +1
wend
wend
Shut_down
'------------------------------------------------------------------------------
' All the functions blow on what I have made!
'------------------------------------------------------------------------------
function Allergo_Setup
allegro_init
install_keyboard
install_timer
set_color_depth Depth
set_gfx_mode GFX_AUTODETECT_WINDOWED, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0
end function
function Load_Images
Background = load_bitmap("GFX\grass.bmp", NULL)
Dog = load_bitmap("GFX\Dog.bmp" , NULL)
Stick = load_bitmap("GFX\Stick.bmp" , NULL)
buffer = create_bitmap(640,480)
end function
function Move_Player
if (key(KEY_UP)) then
Doggy.Y=Doggy.Y-speed
endif
if (key(KEY_Down)) then
Doggy.Y=Doggy.Y+speed
endif
if (key(KEY_LEFT)) then
Doggy.X=Doggy.X-speed
endif
if (key(KEY_RIGHT)) then
Doggy.X=Doggy.X+speed
endif
' To stop the doggy moving off the player area
IF Doggy.X<0 Then Doggy.X=0
IF Doggy.X>=610 Then Doggy.X=610
IF DOGGY.Y<0 Then Doggy.Y=0
IF DOGGY.Y>=450 Then Doggy.Y=450
end function
Function Render_Sprites
' draw the sprite
clear_bitmap(buffer)
draw_sprite(buffer, Background, 0,0)
draw_sprite(buffer, Dog, Doggy.x, Doggy.y)
draw_sprite(buffer, Stick, Sticky.x2, Sticky.y2)
vsync '<- I added this
blit(buffer, Screen, 0,0,0,0,640,480)
End Function
'-------------------------------------------------------------------------------
' Timer
'-------------------------------------------------------------------------------
Sub incRement_speed_counter
speed_counter += 1
end Sub
function Shut_down
' delete the bitmap
destroy_bitmap(buffer)
destroy_bitmap(Background)
destroy_bitmap(dog)
destroy_bitmap(Stick)
remove_keyboard
allegro_exit
end function
'------------------------------------------------------------------------------
' THE END
'------------------------------------------------------------------------------