Descolado Posted May 30, 2021 Share Posted May 30, 2021 I'm trying to slow down a MOB at certain points in its movement (when it reaches the top or the bottom of the screen). I'm using the code below and it works for a few seconds. When FRAME reaches a value of 1500 the Enemy MOB simply STOPS on the screen. Does anyone know why this happens? I remember reading here on the forum once (I didn't find it anymore) something about "moving half a pixel". I've seen in some posts / examples something like "Speed = $ 20" but I don't understand how it works. Does anyone have another suggestion to change the speed of this enemy (making it slower at certain times)? DIM speedX1: speedX1 = 1 DIM speedY1: speedY1 = 1 DIM delta: delta = 4 Enemy: PROCEDURE SPRITE 2, X1 + HIT + VISIBLE, Y1 + ZOOMY2, CS_RED + SPR02 print at screenpos(5,5), <5>frame IF (FRAME % delta) THEN X1 = X1 + speedX1 Y1 = Y1 + speedY1 END IF IF X1 >= 160 THEN speedX1 = -1 IF X1 <= 8 THEN speedX1 = 1 IF Y1 >= 80 THEN speedY1 = -1: changed = 1 IF Y1 <= 8 THEN speedY1 = 1 : changed = 0 IF changed = 0 THEN delta = 4 ELSE delta = 2 END Quote Link to comment Share on other sites More sharing options...
+nanochess Posted May 30, 2021 Share Posted May 30, 2021 (edited) You should use "AND delta" and assign values 3 and 1 to 'delta' variable. The reason for this is because the division operation is done with successive subtraction, and once FRAME reachs 1500 it takes more than one frame of video to do a "big" division. The idiom SPEED = $20 could be interpreted like this: you are assigning the speed 32 to a "thing", let us say for #x and #y (we need 16 bits for big values, also put the statement SIGNED SPEED at the start of your code) Let us say that in each frame you add SPEED to #X and #Y, also let us say that you want to move #x and #y for a pixel each frame. So 32 is equal to one pixel per frame. We need to convert this #X and #Y variables to the real pixel coordinates, so we use this code: x = #x / 32 y = #y / 32 And then we can use the result values for positioning the sprite on screen. The beauty of this is that now we can modify SPEED to be anywhere from $01 to $40 and it will move in different speeds very smoothly! And also can be a negative value to move in reverse. Edited May 30, 2021 by nanochess Quote Link to comment Share on other sites More sharing options...
Descolado Posted May 31, 2021 Author Share Posted May 31, 2021 Thanks, Oscar. I am using his first book to continue the programming process on Intellivision, but I am very rusty, I have not been working with code for 3 years, it is helping a lot. The second book is already in my plans. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.