Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Move Consecutively
#1
Hey guys, its me again........sum one said to me, to make pacman's movements loop, you need to store it in a a variable, now how would i do this.......i need help........thanx alot........

PS. Example code would help!! :rotfl:
Reply
#2
Quote:Hey guys, its me again........sum one said to me, to make pacman's movements loop, you need to store it in a a variable, now how would i do this.......i need help........thanx alot........

PS. Example code would help!! :rotfl:

start slow...
Code:
SCREEN 11

r = 10
x = 320
y = 240
delta = 10

CLS
PRINT "Wow...I can move a circle...use 2, 4, 6, & 8 on the number pad"
PRINT "(make sure num-lock is on)"

DO

CIRCLE (oldx, oldy), r, 0
CIRCLE (x, y), r, 1

DO
  a$ = INKEY$
LOOP UNTIL a$ <> ""

oldx = x
oldy = y

SELECT CASE a$
  CASE "2"
   y = y + delta
  CASE "4"
   x = x - delta
  CASE "8"
   y = y - delta
  CASE "6"
   x = x + delta
END SELECT

LOOP
Reply
#3
OK, i dunt think u understand...i have sumthing like that in my pacman prog, but it takes it one move at a time....how to i press it once and it moves until pacman hits a wall???
Reply
#4
http://forum.qbasicnews.com/viewtopic.php?t=2915

TIMER
Look at the last post (mine), n00b.

EDIT:

*sigh*
Code:
max.delay# = .5
t1# = TIMER
DO
IF TIMER - t1# > max.delay# THEN EXIT DO
LOOP

Although your evil experience without using GOTOs (Did the teacher just not know about them, or what?) is probably over now.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#5
He refers to continuous movement. That is achieved keeping the direction you're moving in a variable.

Imagine that your pacman is at (x, y) with x% and y% as its location variables. You need two more variables, mx% and my% that will tell him where to move.

If mx%=-1, Mr Pacman will move left. If mx%=1, it will move right. If mx%=0 Mr Pacman will not move horizontally.

The same with my%.

Code:
mx%=0: my%=0

DO   ' Pseudocode, this won't work.

   ' Here check if Mr Pacman is gonna collide. If it is,
   ' make mx%=0, my%=0 to stop it.. Some kind of:
   IF ThereIsAWallAt(x%+mx%, y%) THEN mx%=0
   IF ThereIsAWallAt(x%, y%+mx%) THEN my%=0

   ' Move pacman:
   x% = x% + mx%: y% = y% + my%

   ' Keys
   IF left_cursor THEN mx%=-1: my%=0  ' Move left
   IF right_cursor THEN mx%=1: my%=0  ' Move right
   IF up_cursor THEN my%=-1: mx%=0   ' Move up
   IF down_cursor THEN my%=1: mx%=0  ' Move down

LOOP
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#6
he needs timer for it, too....
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#7
wow, u guys sure know how to confuse me...lol, im so lost its not even funny.......here, ill give you my movement commands......


Code:
DO                                       'Program freezes until user press'
    press$ = INKEY$                         'any key
  LOOP UNTIL press$ <> ""

blah = TIMER + .01
DO
LOOP UNTIL TIMER > blah


    oldrow(5) = row(5)                            'every move is stored into the variable
    oldcol(5) = col(5)

        SELECT CASE press$                  'the following is the conditions for
            CASE CHR$(0) + CHR$(72)             'the key press'
               row(5) = row(5) - 1
            CASE CHR$(0) + CHR$(80)
               row(5) = row(5) + 1
            CASE CHR$(0) + CHR$(75)
               col(5) = col(5) - 1
            CASE CHR$(0) + CHR$(77)
                col(5) = col(5) + 1
        END SELECT

there, now any help???

lol thanx
Reply
#8
just post your whole program, currently, and i'll add what is necessary.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)