You playing a red cube. User the mouse to eat other cubes. Have fun :)
Code: Select all
const level_incraser = .75
const beginnlevel = 1
type cube_2d
x as double
y as double
c as integer
size as double
declare sub draw
declare function is_hit(cube as cube_2d) as integer
end type
'draws our cube
sub cube_2d.draw
line(x,y)-(x+size,y+size),c,bf
end sub
'checks if cube colodies with another cube
function cube_2d.is_hit(cube as cube_2d) as integer
if x+size >= cube.x and x <= cube.x+cube.size and y+size >= cube.y and y <= cube.y+cube.size then
return 1
else
return 0
end if
end function
'example
sub add_cube(cubetable() as cube_2d,create as integer = 1)
if create = 1 then
redim preserve cubetable(ubound(cubetable)+1)
end if
with cubetable(ubound(cubetable))
.x= int(rnd*640)+1
.y= int(rnd*480)+1
.c= int(rnd*15)+1
.size = int(rnd*64)
end with
end sub
sub game(level as integer)
dim as double ki_speed = level * level_incraser
'setup screen
sleep
print "INIT"
'setup cubes
dim as cube_2d cubes(any),user
'setup for mouseparameter
dim as integer mx,my
setmouse 320,240,0
'setup for screenpage parameter
dim as integer scr0 = 0,scr1 = 1
'setup for cubes
'user cube
user.size = 16
user.c = 4
'create testcube
for i as integer = 0 to 20
add_cube(cubes())
next
static as integer drawn
dim as integer cubes_to_kill = ubound(cubes) + 1, killed_cubes
dim as integer oldkilledcubes
do
getmouse mx,my
'out of map detectection
with user
if .x + .size > 640 then setmouse mx-.size,my
if .y + .size > 480 then setmouse mx,my-.size
.x = mx - (user.size / 2)
.y = my - (user.size / 2)
end with
'draws the user(red)
'simple object handling with colision detection
Print "Cubekiller 0.1"
Print "Kill all Cubes - Level : ";Level; "(";killed_cubes;"/";cubes_to_kill;"Cubes killed) "
if killed_cubes = cubes_to_kill then
PRINT "YOU WON"
exit do
end if
killed_cubes = 0
for i as integer = lbound(cubes) to ubound(cubes)
if cubes(i).size > 0 then
'superb ki
if user.x+user.size >= cubes(i).x and user.x < cubes(i).x+cubes(i).size then
cubes(i).x-=ki_speed
else
if user.x+user.size <= cubes(i).x and user.x > cubes(i).x+cubes(i).size then
cubes(i).x+=ki_speed
else
cubes(i).x-=ki_speed
end if
end if
if user.y+user.size <= cubes(i).y and user.y > cubes(i).x+cubes(i).size then
cubes(i).y+=ki_speed
else
if user.y+user.size >= cubes(i).y and user.y < cubes(i).x+cubes(i).size then
cubes(i).y-=ki_speed
else
cubes(i).y+=ki_speed
end if
end if
if cubes(i).x+cubes(i).size > 640 then cubes(i).x= 1
if cubes(i).y+cubes(i).size > 480 then cubes(i).y= 1
if cubes(i).y <= 1 then cubes(i).y = 480-cubes(i).size
if cubes(i).x <= 1 then cubes(i).x = 640-cubes(i).size
cubes(i).draw
if cubes(i).is_hit(user) = 1 then
cubes(i).size-=1
user.size+=.25
end if
else
killed_cubes+=1
end if
next
user.draw
screensync
drawn = 0
cls
loop until inkey = chr(27)
end sub
screenres 640,480
game beginnlevel
dim as integer level
level = beginnlevel
do
if level = 0 then
level = beginnlevel
else
level += 1
end if
game level
loop