Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / what am I doing wrong here?

Author
Message
pollywog
17
Years of Service
User Offline
Joined: 18th Jan 2007
Location:
Posted: 19th Jan 2007 05:59
Very new to the program but I have a 8x8 sprite sheet with a lion walking in 8 directions. I want the lion to be pointed in the direction I am dragging my mouse, it seems to work sometimes but most of the time the lion is going in all kinds of directions.

Rem Project: lion
Rem Created: 1/18/2007 7:12:40 PM

Rem ***** Main Source File *****
global SPR_LION as word = 1
global IMG_LION as word = 1
global EAST as integer = 1
global WEST as integer = 3
global NORTH as integer = 5
global SOUTH as integer = 9
global NORTHEAST as integer = NORTH + EAST
global NORTHWEST as integer = NORTH + WEST
global SOUTHEAST as integer = SOUTH + EAST
global SOUTHWEST as integer = SOUTH + WEST
`variables
sync on
sync rate 30
hide mouse
`set transparent color to pink
set image colorkey 255,0,255
`load the animated sprite from a single bitmap file
create animated sprite SPR_LION, "lionwalking.bmp",8,8,IMG_LION
`make sure all drawing goes to the screen
set current bitmap 0

do
`update the sprite frame each time thru the game loop
`draw the current sprite frame at x,y
horizontal = EAST
vertical = 0
mx = mousemovex()
my = mousemovey()
if abs(mx) < 1 and abs(my) < 1
set sprite frame SPR_LION,1
else
if mx > 0 then horizontal = EAST
if mx < 0 then horizontal = WEST
if my > 0 then vertical = NORTH
if my < 0 then vertical = SOUTH
play sprite SPR_LION,GetStartFrame(horizontal,vertical),GetEndFrame(horizontal,vertical),40
endif
sprite SPR_LION,mousex(),mousey(),IMG_LION
sleep 20
sync
loop
`*****************Get Start Frame************************************************************
`get the start frame for play sprite
`@parameter horizontal direction
`@parameter veritcal direction
`@ return starting frame
Function GetStartFrame(horizontal as integer, vertical as integer)
direction = horizontal + vertical
select direction
case 1: `EAST
startframe = 1
endcase
case 5: `NORTH
startframe = 8
endcase
case 6: `NORTHEAST
startframe = 17
endcase
case 8: `NORTHWEST
startframe = 24
endcase
case 9: `SOUTH
startframe = 32
endcase
case 10: `SOUTHEAST
startframe = 40
endcase
case 12: `SOUTHWEST
startframe = 48
endcase
case 3: `WEST
startframe = 56
endcase
endselect
endfunction startframe
`***********************Get End Frame******************************************************
`get the start frame for play sprite
`@parameter horizontal direction
`@parameter veritcal direction
`@ return starting frame
Function GetEndFrame(horizontal as integer, vertical as integer)
direction = horizontal + vertical
select direction
case 1: `EAST
endframe = 7
endcase
case 5: `NORTH
endframe = 16
endcase
case 6: `NORTHEAST
endframe = 23
endcase
case 8: `NORTHWEST
endframe = 31
endcase
case 9: `SOUTH
endframe = 39
endcase
case 10: `SOUTHEAST
endframe = 47
endcase
case 12: `SOUTHWEST
endframe = 55
endcase
case 3: `WEST
endframe = 63
endcase
endselect
endfunction endframe
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Jan 2007 14:53 Edited at: 19th Jan 2007 14:53
It could be that the mouse movement is so small that you are getting "jitters". Try using mx and my > 3, for example.

Also, the standard for boolean maths is to use 1,2,4,8,16...as your values, rather than 1,3,5,9...



CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 19th Jan 2007 16:10
and use code boxes, LOL



Login to post a reply

Server time is: 2024-09-25 15:26:24
Your offset time is: 2024-09-25 15:26:24