I am sure freebasic used
Type Ship
x as integer
y as integer
end type
could anyone care to help over typedef struct?
Code: Select all
#include "allegro.bi"
Option Explicit
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
' create some colors
#define WHITE makecol(255,255,255)
#define BLACK makecol(0,0,0)
#define RED makecol(255,0,0)
#define GREEN makecol(0,255,0)
#define BLUE makecol(0,0,255)
#define SMOKE makecol(140,130,120)
' point structure used to draw lines
typedef struct POINT
x AS INTEGER
y AS INTEGER
end type '}POINT
DIM points AS INTEGER
Dim Pointe as integer
' points array holds do_line points for drawing a line
POINTE points(2000)
DIM curpoint,totalpoints AS INTEGER
' bitmap images
DIM buffer as bitmap ptr
Dim crosshair as bitmap ptr
Dim city as bitmap ptr
dim Bmp as bitmap ptr
' misc variables
dim x1,y1,x2,y2 as integer
Dim done as integer
Dim Destroyed as integer
Dim n as integer
Dim mx,my,mb as integer
Dim Score as integer
Done=0
Destroyed=1
score = -1
Sub updatescore
dim score as integer
' update and display the score
score=score+1
' textprintf_right(buffer,font,SCREEN_W-5,1,WHITE,"SCORE: %d ", score)
end sub
Sub explosion(BMP,x,y,finalcolor)
Dim colour,size as integer
dim n as integer
'dim bmp as bitmap ptr
for n=1 to 20
' generate a random color
colour = makecol(rnd*255,rnd*255,rnd*255)
' random explosion size
size = 20+rnd*20
' draw the random filled circle
circlefill(bmp, x, y, size, colour)
' short pause
rest(2)
next n
' missile tracker looks for this explosion color
circlefill(bmp, x, y, 40, finalcolor)
end sub
Sub doline(BITMAP , x, y, d)
dim totalpoints as integer
' line callback function...fills the points array
points[totalpoints].x = x
points[totalpoints].y = y
totalpoints=totalpoints+1
end sub
Sub firenewmissile()
dim destroyed as integer
Dim totalpoints as integer
dim curpoint as integer
dim x1,y1,x2,y2 as integer
' activate the new missile
destroyed=0
totalpoints = 0
curpoint = 0
' random starting location
x1 = rnd * (SCREEN_W-1)
y1 = 20
' random ending location
x2 = rnd * (SCREEN_W-1)
y2 = SCREEN_H-50
' construct the line point-by-point
do_line(buffer,x1,y1,x2,y2,0,&doline)
end sub
Sub movemissile()
dim Buffer as bitmap ptr
dim x,y,Destroyed,curpoint,totalpoints as integer
' grab a local copy of the current point
x = points[curpoint].x
y = points[curpoint].y
' hide mouse pointer
scare_mouse
' erase missile
rectfill(buffer,x-6,y-3,x+6,y+1,BLACK)
' see if missile was hit by defense weapon
if (getpixel(screen,x,y) = GREEN)then
' missile destroyed! score a point
destroyed=Destroyed+1
updatescore()
else
' no hit, just draw the missile and smoke trail
' draw the smoke trail
putpixel(buffer,x,y-3,SMOKE)
' draw the missile
circlefill(buffer,x,y,2,BLUE)
endif
' show mouse pointer
unscare_mouse()
' did the missile hit a city?
curpoint=curpoint+1
if (curpoint >= totalpoints) then
' destroy the missile
destroyed=destroyed+1
' animate explosion directly on screen
' explosion(screen, x, y, BLACK)
' show the damage on the backbuffer
circlefill(buffer, x, y, 40, BLACK)
endif
end sub
function Allergo_Setup
' initialize program
allegro_init
set_color_depth(16)
set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0)
install_keyboard
install_mouse
install_timer
end function
Allergo_Setup
' create a secondary screen buffer
buffer = create_bitmap(640,480)
' display title
textout(buffer,font,"Strategic Defense (ESC to quit)",0,1,WHITE)
' display score
updatescore()
' draw border around screen
rect(buffer, 0, 12, SCREEN_W-2, SCREEN_H-2, RED)
' load and draw the city images
city = load_bitmap("Media\city.bmp", NULL)
for n=1 to 5
masked_blit(city, buffer, 0, 0, 50+n*120,SCREEN_H-city->h-2, city->w, city->h)
next n
' load the mouse cursor
crosshair = load_bitmap("Media\crosshair.bmp", NULL)
set_mouse_sprite(crosshair)
set_mouse_sprite_focus(15,15)
show_mouse(buffer)
' main loop
while ( not key(KEY_ESC))
' grab the current mouse values
mx = mouse_x
my = mouse_y
mb = (mouse_b & 1)
' fire another missile if needed
if (destroyed) then
firenewmissile()
endif
' left mouse button, fire the defense weapon
if (mb) then
explosion(screen,mx,my,GREEN)
endif
' update enemy missile position
movemissile()
' update screen
blit(buffer,screen,0,0,0,0,640,480)
' pause
rest(10)
wend
set_mouse_sprite(NULL)
destroy_bitmap(city)
destroy_bitmap(crosshair)
allegro_exit