Qbasicnews.com
April 03, 2020, 08:14:30 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: light cycle game  (Read 2429 times)
computerkid14
Forum Regular
**
Posts: 143



« on: October 24, 2004, 04:46:42 PM »

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?
Logged
Rokkuman
Na_th_an
*****
Posts: 1973



« Reply #1 on: October 24, 2004, 06:30:26 PM »

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.
Logged
computerkid14
Forum Regular
**
Posts: 143



« Reply #2 on: October 24, 2004, 06:36:27 PM »

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
Logged
Rokkuman
Na_th_an
*****
Posts: 1973



« Reply #3 on: October 24, 2004, 06:40:31 PM »

....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.
Logged
computerkid14
Forum Regular
**
Posts: 143



« Reply #4 on: October 24, 2004, 06:44:28 PM »

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.
Logged
Rokkuman
Na_th_an
*****
Posts: 1973



« Reply #5 on: October 24, 2004, 06:52:31 PM »

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). Smiley
Logged
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #6 on: October 24, 2004, 07:08:29 PM »

It would be:

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

something like that ><
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
computerkid14
Forum Regular
**
Posts: 143



« Reply #7 on: October 24, 2004, 09:23:07 PM »

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
Logged
computerkid14
Forum Regular
**
Posts: 143



« Reply #8 on: October 25, 2004, 09:09:07 AM »

im still trying to figure this out. for some reason when i try and use it, it messes with my clipping.
Logged
Rokkuman
Na_th_an
*****
Posts: 1973



« Reply #9 on: October 27, 2004, 08:32:03 AM »

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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!