forums

TNT Basic Forums > Programming Q&A
problem with my program
< Last Thread     Next Thread >
Author
Thread        Post A Reply

05-24-2008 19:09

Posted by:
kastner18

Click Here to Email kastner18   Find more posts by kastner18

I'm writing a game where you are a mouse running around the screen to collect cheese while a cat is trying to catch you.

there are currently two problems with my game and i hope you can help me fix them.

1) you are supposed to have 3 lives and when you get hit by the cat the game calls a procedure that says "life=life-1"
i declared the integer life to =3 at the top of the program but after you get hit once the game ends.

2) the user moves the mouse with the arrow keys, and the cat is supposed to follow you so i said
"move sprite 3,mousex,mousey,speed" but the cat doesn't move to the left or upwards.

please respond if you know how to fix one or both of these problems.

Thank you

05-25-2008 17:36

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Life
Whats happening is that you're continuously colliding with the cat so the lives go 3, 2, 1, 0 in 4 frames, you need to make an invincibility variable that counts down from the hit, or make the mouse get bopped far away. :)

Cat
You gotta move the cat with it's old position, like... (catx-mouse x)/10 or something, I don't know exactly what you want, does the cat come at a constant speed?

And mouse x and mouse y are usually positive since it counts from the top left...

05-29-2008 17:36

Posted by:
kastner18

Click Here to Email kastner18   Find more posts by kastner18

I fixed the problem about the lives but the cat doesn't work properly yet.
here is the relevant code for it:

'Mouse Variables
global int mousex= width/2
global int mousey= height/2
global int mousepic=1
global int mousespeed=10
'Cat Variables
global int catspeed=5

'This makes the cat appear
sprite 3,0,0,3
draw frame

'This makes the mouse appear
sprite 2,mousex,mousey,mousepic
draw frame

'This makes the cat move towards the user's mouse
move sprite 3,mousex,mousey,catspeed

if up
mousey=mousey-mousespeed
else if down
mousey= mousey+mousespeed
else if left
mousex= mousex-mousespeed
mousepic= 2
else if right
mousex= mousex+mousespeed
mousepic= 1
end if

05-30-2008 00:41

Posted by:
kastner18

Click Here to Email kastner18   Find more posts by kastner18

int catx=0
int caty=0
int catspeed=5

sprite 3,catx,caty,3

move sprite 3,mousex,mousey,3


if catx>mousex or caty>mousey
catspeed=-5
else
catspeed=5
end if

do you think that this will fix the problem?

05-30-2008 15:14

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

I think you don't udnerstand what "move sprite" does

the command "move sprite" does NOT mean "move the sprite towards the location i'm telling you", it means "move the sprite by X pixel to the right and Y pixels down".


so

move sprite 3,mouse x, mouse y,2

If the mouse is currently at e.g. (600,350)
The command becomes equivalent to :

move sprite 3,600, 350,2

And means "move the cat 600 pixels to the right and 350 pixels down", and that's not what you want, what you want is to make it move towards pixel 600,350.

There are various ways to do it. I personnaly do not like moan so I will not use the 'move mouse' command, though you could also

if cat_x > mouse x then cat_x = cat_x - 5
if cat_x < mouse x then cat_x = cat_x + 5
if cat_y > mouse y then cat_y = cat_y - 5
if cat_y < mouse y then cat_y = cat_y + 5
sprite 3, cat_x, cat_y,2

this is a very basic example and there's ways to improve it to get smoother movement, but that should get you started

05-31-2008 18:32

Posted by:
swagIT

Location:
Great Wet North (Vancouver)

Find more posts by swagIT

This does what I think you are trying to do:

I tested it with random graphics

=======================

'Mouse Variables
global int width=640
global int height=480
global int mousex= width/2
global int mousey= height/2
global int mousepic=001
global int mousespeed=10
global int cat_x=30
global int cat_y=10
'Cat Variables
global int catspeed=5

window mode 640,480
load images 128
'This makes the cat appear
sprite 3,cat_x,Cat_y,3
'This makes the mouse appear
sprite 2,mousex,mousey,mousepic
draw frame


repeat

wait key press

if up
mousey=mousey-mousespeed
else if down
mousey= mousey+mousespeed
else if left
mousex= mousex-mousespeed
mousepic= 2
else if right
mousex= mousex+mousespeed
mousepic= 1
end if

sprite 2,mousex,mousey,2

if cat_x > mousex then cat_x = cat_x - 5
if cat_x < mousex then cat_x = cat_x + 5
if cat_y > mousey then cat_y = cat_y - 5
if cat_y < mousey then cat_y = cat_y + 5
sprite 3, cat_x, cat_y,3





draw frame

forever

============================

06-01-2008 00:32

Posted by:
kastner18

Click Here to Email kastner18   Find more posts by kastner18

thank you for your help.

06-01-2008 03:18

Posted by:
swagIT

Location:
Great Wet North (Vancouver)

Find more posts by swagIT

no worries

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.