Which demo? I have posted a lot of them.
Once the "game engine" is written the hard part starts and that may involve artists and the construction of worlds. Even the simple platform game needs a world for the character to traverse while it battles enemies and collects rewards. This last part takes 99% of time required to write a game which is why lone coders rarely if ever get beyond the beginnings of such games unless they work on the same game for many years.
The idea should be original enough not to be an obvious clone of another game although all new ideas evolve out of combinations, extensions or inspirations from older ones. Tetris was apparently inspired by pentomino puzzles which in turn is just about fitting together different shaped tiles which go all the way back to tiling floors and walls.
Like badidea that was another demo game where I worked on my own version of controlling a tank in "yet another tank game". But this illustrates a conflict in that many cowboy coders like to write their own code not fit in with other people's coding methods. It would be like two people working on the same painting.
This was an experiment in using the mouse to aim the turret and firing using the left mouse button.
Code: Select all
'some useful defines
Const Pi = 4 * Atn(1)
Dim Shared As Double TwoPi = 8 * Atn(1)
Dim Shared As Double RtoD = 180 / Pi ' radians * RtoD = degrees
Dim Shared As Double DtoR = Pi / 180 ' degrees * DtoR = radians
screenres 640,480,32
color rgb(0,0,0),rgb(255,255,255):cls
dim shared as integer mx,my,mb 'mouse variable
dim shared as any ptr target
target = imagecreate(16,16,rgb(255,0,255))
circle target,(7,7),7,rgb(0,0,0)
line target,(7,0)-(7,15),rgb(0,0,0)
line target,(0,7)-(15,7),rgb(0,0,0)
setmouse ,,0 'turn off mouse cursor
dim shared as any ptr imgExplosion
imgExplosion = imagecreate(300,50)
dim shared as any ptr imgBullet
imgBullet = imagecreate(5,5,rgb(255,0,255))
line imgBullet,(0,0)-(4,4),rgb(255,0,255),bf
circle imgBullet,(2,2),2,rgb(255,255,0),,,,f
dim shared as any ptr imgTank,imgTurret,rotTank,rotTurret
imgTank = imagecreate(49,49,rgb(255,0,255))
'create
line imgTank,(9,11)-(9+29,11+26),rgb(100,100,250),bf
line imgTank,(9,11)-(9+29,11+26),rgb(0,0,0),b
line imgTank,(10,5)-(10+27,5+7),rgb(100,100,250),bf
line imgTank,(10,5)-(10+27,5+7),rgb(0,0,0),b
line imgTank,(10,36)-(10+27,36+7),rgb(100,100,250),bf
line imgTank,(10,36)-(10+27,36+7),rgb(0,0,0),b
line imgTank,(37,15)-(37+4,15+18),rgb(200,100,0),bf
line imgTank,(37,15)-(37+4,15+18),rgb(0,0,0),b
imgTurret = imagecreate(49,49,rgb(255,0,255))
line imgTurret,(18,18)-(18+13,18+12),rgb(100,200,150),bf
line imgTurret,(18,18)-(18+13,18+12),rgb(0,0,0),b
line imgTurret,(1,22)-(1+17,22+4),rgb(100,200,150),bf
line imgTurret,(1,22)-(1+17,22+4),rgb(0,0,0),b
rotTank = imagecreate(49,49) 'rotated version of tank
rotTurret = imagecreate(49,49) 'rotated version of turret
'create explosion graphics
for i as integer = 0 to 5
circle imgExplosion,(i*50+25,25),(i+1)*4,rgb(200,155,0),,,,f
circle imgExplosion,(i*50+25,25),(i+1)*2,rgb(255,255,0),,,,f
next i
type SPRITE
as single x
as single y
as integer w
as integer h
as single dx
as single dy
as integer d 'direct 0=UP, 1=DOWN, 2=LEFT, 3=RIGHT
as single mv 'speed
as single tAngle 'turret angle
as single Angle 'tank direction
as integer alive
end type
function testCollision(s1 as SPRITE,s2 as SPRITE) as boolean
return (s1.y+s1.h) > (s2.y) and (s1.y) < (s2.y+s2.h) and (s1.x) < (s2.x+s2.w) and (s1.x + s1.w) > (s2.x)
end function
dim shared as SPRITE tank
tank.x = 320
tank.y = 240
tank.w = 49
tank.h = 49
tank.mv = 0
tank.Angle = 0
tank.tAngle = 0
dim shared as SPRITE bullet
bullet.x = 0
bullet.y = 0
bullet.w = 5
bullet.h = 5
bullet.mv = 0
bullet.angle = 0
dim shared as SPRITE explosion
explosion.x = 0
explosion.y = 0
explosion.w = 50
explosion.h = 50
explosion.alive = 0
sub rotateImage(img1 as any ptr,img2 as any ptr,ww as double)
dim as double tx,ty,nx,ny,vx,vy,angle
angle = (ww+180)*DtoR
dim as uinteger c
for yp as double = 0 to 48 step .5
for xp as double = 0 to 48 step .5
c = point(xp,yp,img1):'get color
'select centre of image as centre of rotation
vx = xp-(48\2)
vy = yp-(48\2)
'equations to compute new x,y coordinates for rotation of ww degrees
tx = cos(angle) * vx - sin(angle) * vy
ty = cos(angle) * vy + sin(angle) * vx
nx = tx+(48\2)
ny = ty+(48\2)
pset img2,(nx,ny),c
next xp
next yp
end sub
sub update()
screenlock
cls
put (tank.x,tank.y),rotTank,trans
put (tank.x,tank.y),rotTurret,trans
if bullet.alive > 0 then
circle (bullet.x,bullet.y),5,rgb(255,0,0),,,,f
put (bullet.x,bullet.y),imgBullet,trans
end if
dim as integer frame
if explosion.alive > 0 then
frame = int(explosion.alive\10)
frame = 5-(frame-1)
put (explosion.x-25,explosion.y-25),imgExplosion,(frame*50,0)-(frame*50+explosion.w,explosion.h),trans
explosion.alive = explosion.alive - 1
end if
put (mx,my),target,trans 'show target
line ((tank.x+24),(tank.y+24))-((mx+8),(my+8)),rgb(0,0,255)
screenunlock
end sub
sub moveTank()
tank.x = tank.x + tank.dx 'make move
tank.y = tank.y + tank.dy
'boundary check
if tank.x < 0 or tank.y < 0 or tank.x+tank.w > 639 or tank.y + tank.h > 479 then
tank.x = tank.x - tank.dx 'undo move
tank.y = tank.y - tank.dy
tank.dx = 0
tank.dy = 0
tank.mv = 0
end if
end sub
dim as double time1
time1 = timer
update()
do
if timer > time1 + 0.01 then
time1 = timer
getmouse mx,my,,mb
'show rotated version of image
rotateImage(imgTank,rotTank,tank.Angle)
rotateImage(imgTurret,rotTurret,tank.tAngle)
tank.mv = 0
if multikey(&H4D) then 'RIGHT
tank.d = 0
tank.angle = 0
tank.mv = 1
end if
if multikey(&H4B) then 'LEFT
tank.d = 1
tank.Angle = 180
tank.mv = 1
end if
'just rotates turret by itself
if multikey(&H50) then 'DOWN
tank.d = 2
tank.Angle = 90
tank.mv = 1
end if
if multikey(&H48) then 'UP
tank.d = 2
tank.angle = 270
tank.mv = 1
end if
'use mouse to get tAngle
mx = mx + 8
my = my + 8
tank.tAngle = atan2((my+8)-(tank.y+24),(mx+8)-(tank.x+24))*57.2958 'get slope angle from x1,y1
if tank.tAngle < 0 then tank.tAngle = tank.tAngle + 360
tank.dx = cos(tank.angle * DtoR) * tank.mv
tank.dy = sin(tank.angle * DtoR) * tank.mv
if mb=1 and bullet.alive = 0 then
bullet.alive = 100
bullet.x = Cos(tank.tAngle*DtoR)*25 + tank.x+24
bullet.y = Sin(tank.tAngle*DtoR)*25 + tank.y+24
bullet.angle = tank.tAngle
bullet.dx = cos(bullet.angle * DtoR) * 2
bullet.dy = sin(bullet.angle * DtoR) * 2
end if
if bullet.alive > 0 then
bullet.alive = bullet.alive - 1
bullet.x = bullet.x + bullet.dx
bullet.y = bullet.y + bullet.dy
if bullet.alive = 0 then
explosion.x = bullet.x
explosion.y = bullet.y
explosion.alive = 50
end if
end if
moveTank()
update()
end if
loop until multikey(&H01)