Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
light cycle game
#1
im making a light cycle game. I have a pixel and you control it and as it goes it doesnt clear the screen so you get a long line after it. I need to know how to program it so if it hits it's own line it crashes. a la snake. can someone help me out. do i have to store all the positions the pixel was in some type of varible so if the new x1 and y1 = any of those it prints you crashed?
Reply
#2
Well, if you're not going for backgrounds or anything, then you can use POINT(X,Y) to retreive the color of a pixel. For instance:

[syntax="qbasic"]
if point(15, 23) = 15 then
OWNED
end if
[/syntax]

If you're going for something with backgrounds, however, then this isn't the way to go whatsoever. Just let me know if you are.
Reply
#3
i mean
________________________ there is a line. there is just black BG.
i want to have it so if that line were to loop around and hit itself it would goto crash

crash:
cls
print "you suck because you just crashed."

how would i use point in that context
Reply
#4
....then use the code I just gave you? Test to see if the pixel is any color other than black, and if it is, it's probably not where the pixel should be.
Reply
#5
OHHH the 15 is the color?
so like:


if point (y1,x1) = 4 then goto crash


like that?

but how about when it starts out it'll always say your crashed? because if i pset it at y1,x1 at color 4 it will be color 4 therefore printing you crashed.
Reply
#6
Test before the pixel is drawn, or test the pixel a step ahead, based on it's direction. For instance, if it's going right, then you'd test POINT(X - 1, Y). Smile
Reply
#7
It would be:

do
input move
test new pos for crash
-if no crash then move
-if crash then boom
loop

something like that >^-^<
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#8
thanks or the algorithem im still i bit cconfussed as to where it goes i posted the code without the point thing,

if you could tell em where it could go.

white tiger are you saying on every line of the movment satment, put the point thing?

Code:
SCREEN 13
CLS
game:
CLS
x1 = 60
y1 = 50
x2 = 100
y2 = 150
xadj = 1
yadj = 1
LINE (x2, y2)-(x2 + 10, y2 + 10), 2, B
delay = 1
DO
LINE (19, 19)-(299, 19)
LINE (299, 19)-(299, 179)
LINE (299, 179)-(19, 179)
LINE (19, 179)-(19, 19)

a$ = INKEY$

PSET (x1, y1), 5

IF y1 > 20 THEN IF a$ = "w" THEN y1 = y1 - 1
IF y1 < 180 THEN IF a$ = "s" THEN y1 = y1 + 1
IF x1 < 300 THEN IF a$ = "d" THEN x1 = x1 + 1
IF x1 > 20 THEN IF a$ = "a" THEN x1 = x1 - 1

IF x1 = 20 THEN GOTO crash                   'collision and
IF x1 = 300 THEN GOTO crash
IF y1 = 180 THEN GOTO crash
IF y1 = 20 THEN GOTO crash

IF x1 > x2 AND x1 < x2 + 10 AND y1 > y2 AND y1 < y2 + 10 THEN
PRINT " you won!!"
END
END IF
LOOP UNTIL a$ = "q"
IF a$ = "q" THEN GOTO last

crash:

COLOR 5
PRINT "YOU CRASHED!!!"
INPUT "would you like to play again "; play$
IF play$ = "yes" THEN GOTO game

last:
CLS
COLOR 5
PRINT "goodbye"
END
Reply
#9
im still trying to figure this out. for some reason when i try and use it, it messes with my clipping.
Reply
#10
It would go where it's making the dot move. First, move the dot, dont' DRAW it, but move it. Use POINT to see if that pixel is anything other than black, if it's black, it's the ground, if it's not, it's something that will kill him, and make your programming go accordingly.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)