02-18-2005, 08:37 PM
Finally got directional movement nailed down.
Here is a simple SCREEN with DRAW image demo.
Here is a simple SCREEN with DRAW image demo.
Code:
' directional movement test
' using simple screen/draw graphics for demo
option explicit
'$include: "win/gdi32.bi"
#define SC_ESCAPE &h01
#define SC_SPACE &h39
#define SC_UP &h48
#define SC_LEFT &h4B
#define SC_RIGHT &h4D
#define SC_DOWN &h50
#define PI 3.141592
sub sprite.moveforward(currentX as long, currentY as long, currentAngle as long, currentSpeed as long)
dim radians as double
' calculate radians from current angle (direction object is facing)
radians = (currentAngle - 90) * (pi / 180)
' calcualte new x/y positions dependant upon the current speed of movement
currentX = currentX + currentSpeed * COS(radians)
currentY = currentY + currentSpeed * SIN(radians)
end sub
type sprite
xpos as long
ypos as long
length as long
facing as long
speed as long
end type
dim s1 as sprite
s1.xpos = 200
s1.ypos = 200
s1.length = 20
s1.facing = 0
s1.speed = 0
dim moveX as double
dim moveY as double
dim done as long
screen 12
done = FALSE
do
' DRAW sprite with color 0 to "erase"
DRAW "S4"
DRAW "BM" + str$(s1.xpos) + "," + str$(s1.ypos)
DRAW "C0"
DRAW "TA" + str$(-s1.facing) + "BD5L10E10F10L10BU5"
' process user commands to move sprite
if multikey(SC_LEFT) then
s1.facing = s1.facing - 1
end if
if multikey(SC_RIGHT) then
s1.facing = s1.facing + 1
end if
if multikey(SC_UP) then
s1.speed = 2
end if
if multikey(SC_DOWN) then
s1.speed = -2
end if
' adjust for sprite movement
sprite.moveforward(s1.xpos, s1.ypos, s1.facing, s1.speed)
' keep image on screen
if s1.xpos < 1 then s1.xpos = 639
if s1.xpos > 639 then s1.xpos = 1
if s1.ypos < 1 then s1.ypos = 479
if s1.ypos > 470 then s1.ypos = 1
' draw image on screen
DRAW "S4"
DRAW "BM" + str$(s1.xpos) + "," + str$(s1.ypos)
DRAW "C15"
DRAW "TA" + str$(-s1.facing) + "BD5L10E10F10L10BU5"
' check for user quit
if multikey(SC_ESCAPE) then
done = TRUE
end if
sleep 1
s1.speed = 0
loop until done
ature has its way of warning a person away from danger: The distinct black and white coloration on a skunk, the chilling buzz of a rattlesanke, a redneck handing you his beer and saying "Watch this!"