Need help with mouse input (VARY NUBE)
Author |
Message |
bookboy15
|
Posted: Fri May 09, 2008 12:26 pm Post subject: Need help with mouse input (VARY NUBE) |
|
|
Need help with turing
VERY NUBE
This was accidentally posted in The wrong place so i reposted it on the advice of Aziz
Thanks also to btiffin for the help on posting
I'm trying to create an interactive game where you shoot targets X's with the mouse (clicking)
but i need a way to allow the mouse to give input for only a couple of seconds
as well does anyone know of a way to turn the cursor into a targeting icon?
here is a copy of the program so far (VERY NUBE)
code: | % Stephen James
% assalt
% mo 4-28
loop
var CComand : string
var x, y, button : int
var column, row, ammo, hits, shots, amamo : int
color (black)
put "objective shoot the taget(X)"
put "enter your starting ammo to continue"
put "game will not end till all ammo is exosted"
get amamo
ammo := amamo
hits := 0
shots := 0
loop
locate (22, 1)
put "amamo :", ammo
put "hits :", hits
put "shots :", shots
% place target
randint (column, 1, 80)
randint (row, 1, 25)
locate (row, column)
color (blue)
put "X"
Mouse.Where (x, y, button)
% for a hit
if x = column and y = row then
locate (12, 40)
color (red)
put "HIT!"
ammo := ammo - 1
hits := hits + 1
shots := shots + 1
locate (row, column)
color (red)
put "*"
delay (1000)
%for a miss
elsif x < column or x > column or y < row or y > row then
locate (12, 40)
color (blue)
put "miss"
ammo := ammo - 1
shots := shots + 1
delay (1000)
end if
exit when ammo = 0
delay (500)
end loop
put "you made ", hits, " hits out of ", shots, " shots"
put "enter any letter to continue"
get CComand
cls
end loop |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
chrisbrown
![](http://compsci.ca/v3/uploads/user_avatars/18814724584bcbb8192aae8.png)
|
Posted: Fri May 09, 2008 2:32 pm Post subject: RE:Need help with mouse input (VARY NUBE) |
|
|
Two things: Mouse.Where gives you the x and y coords of the cursor, NOT the row and column it is in. You need to either figure out a formula to convert coords to rows/cols, or look into using Draw.Text instead of locate to draw your 'X's. The second method is probably a better choice for you at this point.
As well, your program does not respond to mouse clicks. Instead of using delays, try the following:
Turing: |
%...Draw X to screen...
%Wait one second, exiting if a button is pressed
for i : 1.. 200
Mouse.Where (x, y, button )
exit when button = 1
delay(5)
end loop
%Check position of cursor in relation to target X; make sure you check that the button has been pressed, otherwise your program won't behave properly.
|
|
|
|
|
|
![](images/spacer.gif) |
bookboy15
|
Posted: Tue May 13, 2008 1:32 pm Post subject: Re: Need help with mouse input (VARY NUBE) |
|
|
I'm considering a new approach to the game as I now plan to use it for my final project, if i can get it to work, I plan on inputing graphics (ducks) for targets and having the hole thing move up.
ex
code: | loop
randint (column, 1, 80)
locate (25, column)
% "duck" would be replaced with a picture of an actual duck
put "duck"
delay (500)
end loop |
I might have to go about it differently but right now my biggest problem is that i need a way to keep track of the constantly changing location of the targets (ducks)
also how do I insert if possible a graphic (duck) and how do i prevent the info in the bottom left corner of the first program from being moved or replaced by a target
Sorry about spelling and all the questions again VERY NUBE, I really appreciate the help |
|
|
|
|
![](images/spacer.gif) |
Asherel
![](http://compsci.ca/v3/uploads/user_avatars/13469987481b9ee523128.png)
|
Posted: Tue May 13, 2008 2:17 pm Post subject: Re: Need help with mouse input (VARY NUBE) |
|
|
Pictures as in .jpgs and .bmp are done so by this.
Turing: |
var pic1 : int := Pic.New ("PicID.exetension")
|
That creates a variable for the picture, and loads that picture. If you need more information, click F10 when in Turing and Search for Pic |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Wed May 14, 2008 10:32 am Post subject: RE:Need help with mouse input (VARY NUBE) |
|
|
to move the whole thing up, make all the duck's y cordinate the same, and increase it by 1 every time it goes through the loop.
to make them move randomly left/right make use Rand.Int (1,2). If it = 1 then x := x + 1
if it = 2 then x := x - 1. you could change it to
use the y-coordiante as well, but then you would not be able to use the same y for every duck. If youknow how to use a sprite, use them instead of straight pictures. You'll probably get a better mark that way, and you won't have to re-draw all the ducks. |
|
|
|
|
![](images/spacer.gif) |
bookboy15
|
Posted: Wed May 14, 2008 12:46 pm Post subject: Re: Need help with mouse input (VARY NUBE) |
|
|
thanks very much it works much better know and I'll be sure to check out sprite in truing help
I should have thought of moving the ducks that way
what do you think of using an array to keep track of the ducks location? |
|
|
|
|
![](images/spacer.gif) |
StealthArcher
![](http://compsci.ca/v3/uploads/user_avatars/18949255664b176c4f1481b.jpg)
|
Posted: Wed May 14, 2008 4:42 pm Post subject: Re: Need help with mouse input (VARY NUBE) |
|
|
Asherel @ Tue May 13, 2008 1:17 pm wrote: Pictures as in .jpgs and .bmp are done so by this.
Turing: |
var pic1 : int := Pic.New ("PicID.exetension")
|
That creates a variable for the picture, and loads that picture. If you need more information, click F10 when in Turing and Search for Pic
Incorrect, its done like this:
Pic.New creates a photo in memory, of a part of the screen based off of four given coordinates. |
|
|
|
|
![](images/spacer.gif) |
riveryu
![](http://compsci.ca/v3/uploads/user_avatars/196991102647ae2debe0bf0.jpg)
|
Posted: Wed May 14, 2008 4:59 pm Post subject: Re: Need help with mouse input (VARY NUBE) |
|
|
Just a suggestion, the text from put statements dont mix well with any graphics or images, it will create a huge white line arcross the screen. Use Font.Draw etc...
Turing: |
var fontID : int
Draw.FillBox(0, 0, maxx, maxy, blue)
fontID:= Font.New("arial:12:bold")
Font.Draw ("This is Arial bolded size 12 at coords (0,200), u should read f10 Help", 0, 200,fontID, red)
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
bookboy15
|
Posted: Thu May 15, 2008 12:16 pm Post subject: Re: Need help with mouse input (VARY NUBE) |
|
|
Quote: var pic1 : int := Pic.FileNew ("PicID.exetension")
I can't quite get the pics to input properly if I run the Syntax with "PicID.exetension" replaced with the location and name of the file I want nothing happens I don't Evan get an output window if I say "put pic1" after I get a "0"
Sorry about all the questions |
|
|
|
|
![](images/spacer.gif) |
Mackie
![](http://compsci.ca/v3/uploads/user_avatars/217548454cee912ae1202.png)
|
Posted: Thu May 15, 2008 12:22 pm Post subject: RE:Need help with mouse input (VARY NUBE) |
|
|
The picID is just apointer to the file, you actaully need to draw it. Look into Pic.Draw or Draw.Pic, either one works. (F10) |
|
|
|
|
![](images/spacer.gif) |
bookboy15
|
Posted: Thu May 15, 2008 12:26 pm Post subject: Re: Need help with mouse input (VARY NUBE) |
|
|
Ok I get it thanks |
|
|
|
|
![](images/spacer.gif) |
bookboy15
|
Posted: Wed May 21, 2008 12:25 pm Post subject: Re: Need help with mouse input (VARY NUBE) |
|
|
Thanks for the help but I have decided to use visual basic instead of turing for the final project thank you vary kindly to all of the contributers. |
|
|
|
|
![](images/spacer.gif) |
|
|