forums

TNT Basic Forums > Bugs!
Window graphics
< Last Thread     Next Thread >
Author
Thread        Post A Reply

12-02-2007 17:07

Posted by:
Maxime

Location:
Paris France

Find more posts by Maxime

Hello, new to TNT. I programmed Think C times ago, but new implemented in Mac languages are too difficult to begin with... So, congratulations.
I made some tries to see if I could build a card game with TNT, with card moved by the mouse, in a window (window mode, hardware or not). I can move the cards the way I want, but the window itself is strange. When you click in the upper band (AFTER having acted inside the window), the whole window jumps to another place ! You can recover control by clicking outside, and then back in the band, which works correctly now. Except you are in Paused mode, even if you click in the window.
Else, the 3 balls do not function correctly. The first one is blank, but on clic, it makes an image (number 0) appear somewhere inside the window ! Second (parking window) is OK. Third is blank and inactive.

This is not much of a problem, but perhaps I have made something wrong I could change ?
Here is my program's text, with just 2 sprites for the time now :

'_________________ Inits ________
fade down
window mode 640,480 ' switch to window mode
fade up

load images 128 ' load images de la bank 128
draw picture 2000 ' draw back ground
'_________________ Variables ________
int k
int xpos[],ypos[]
int xm,ym,xmm,ymm
Global int non=1000, saisi=1000, clique=0, nc=52, ic
int xpos[53],ypos[53]
'__________________ PROG _____________
for k=1 to 2 ' init sprites
xpos[k]=200+2*k
ypos[k]=300+50*k
Set Sprite Priority k,k
sprite k,xpos[k],ypos[k],k
'pr= get sprite Priority k
next k
repeat ' ______game loop

if clique=0 and Mouse Button 'teste si on clique sur une nouvelle carte (pas si elle est déjà saisie)
for k=0 to nc
if Point In Rect (mouse x, mouse y, xpos[k]-25,ypos[k]-37 to xpos[k]+25,ypos[k]+37) 'on vient de cliquer dans une carte
' add conditions : cartes apparentes, etc.
saisi=k
break
end if
next k
end if
if Mouse Button=false 'mouse released
saisi=non
clique=0
end if
if saisi<>non 'holding a card, move it
xpos[saisi]=xpos[saisi]+mouse x-xmm
ypos[saisi]=ypos[saisi]+mouse y-ymm
if saisi=1
xpos[saisi+1]=xpos[saisi+1]+mouse x-xmm ' moves a second card sticked to the 1
ypos[saisi+1]=ypos[saisi+1]+mouse y-ymm
end if
'PutUp(saisi)
sprite saisi,xpos[saisi],ypos[saisi],saisi
if saisi=1
sprite saisi+1,xpos[saisi+1],ypos[saisi+1],saisi+1
end if
end if
if Mouse Button ' if mouse maintained down
clique=1
end if
xmm=mouse x 'to mesure (mouse x - xmm) to move the card
ymm=mouse y
draw frame

until pressed (0) and pressed (55) ' _______ end of game (Apple Q)
fade down
text mode
fade up
show mouse

procedure PutUp(int u) '_____ Puts u card on top
int k
for k=0 to u-1
Set Sprite Priority k,k
next k
Set Sprite Priority u,nc
for k=u+1 to nc
Set Sprite Priority k,k-1
next k
end proc '______

end

12-04-2007 22:25

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Hi Maxime (again...)

OK, first off, have just read this post and the answer to your priority question has to be Y coordinate related if you are doing a stack of cards...

Second, window mode was a bit of an after thought and uses a dodgy set of API calls which are not really up to the challenge these days. It is not a proper GUI application and doesn't really act like one, so I'm afraid that this is a fundamental problem in TNT and not your code.

The good news is that I'm re-writing TNT as we speak, it's not a patch up job or a slight revision, but a total re-write from the ground up. This new version, TNT2, will fix (hopefully!) many of the issues which bug the current one. More information on this newer version can be found over at the BLOG thread in the Open Source forum.

You picked a good time to discover TNT as there are some exciting things planned for the coming months. Please stick with it and if there is anything else you need just drop us a line...

Danny (nod the mod)

12-05-2007 07:17

Posted by:
Maxime

Location:
Paris France

Find more posts by Maxime

Priority, window

Thanks allnods
Window malfunction is not a great problem, I just wanted to tell.

About Priority, the problem is : if you have a pile of cards and click on it, instead of selecting the top one (the one with the highest priority), it selects the one with the lowest (or highest, I don't remember) sprite number ! I have not solved the problem yet, but, I will be obliged to create a special pointer and manage so that it reflects priorities, which means I will be obliged to change these (all !) and the pointer at each move...

Apart, if somebody is interested in card games, I have built a set of 52 cards which can spare time to volunteers...

12-05-2007 18:37

Posted by:
swagIT

Location:
Great Wet North (Vancouver)

Find more posts by swagIT

Hi Maxime - oddly enough I was working on the same issue recently.

I used arrays for each row or 'stack' of selectable cards in my solitaire game.

http://www.frankenspud.com/downloads/eots.zip

Basically say a stack can hold up to 12 cards:
I have an array 'stackone[13]' this lets me hold 0 to 12 items

I numbered my sprites 1 to 52 for the 52 cards in the deck.

eg: if a card is on the bottom of the stack it would be stackone[1]=1
'(ace of clubs)
an empty (no card) stackone[1] would have a value of '0'

When a stack is selected by the 'mouse button' collision event you can scroll through a stack like this:

================
x=14
pickcard=0

repeat
x=x-1
pickcard = stackone[x]
until pickcard <>0

Stackone[x]=0 'this sets the chosen card's place in the stack to off
================

This will select the topmost card and pass the value to 'pickcard'

Something like that - does that make any sense

Let me know if you would like me to email the source from my solitaire game... I'm no pro but it might give some ideas

cheers

barry

swagitdev at frankenspud dot com

12-06-2007 07:26

Posted by:
Maxime

Location:
Paris France

Find more posts by Maxime

Stacks

Thanks stagIT
Your mechanism seems good and physically correct, I will have to build something like this. Perhaps a little more intricate, because I would like to be able to move sets of several cards at the same time. But I will do !
I would appreciate if you could send me your code at maxime.nul at wanadoo.fr.
Merci beaucoup

12-07-2007 05:55

Posted by:
Maxime

Location:
Paris France

Find more posts by Maxime

For loop is always run once !

Hello
I discovered that a "for k =1 to n" is run once if n=1, which is normal. But it's also run once, if n=0 ! I consider it a bug, what do you think ?
I can manage through writing :

if n>0
for k=1 to n
...
next k
end if

But it complicates the coding and it is a great source of veiled errors that will happen only in certain configurations of data...
Yours

12-07-2007 19:04

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Yes, it will always run once, but no, it's not a bug...

The 'For' loop is a variation on 'Repeat... Until' / 'Do... While' constructs, which are also 'do once' loops. You need 'While', where the condition precedes the body of the code.

The reason why it works if n=0 is that the 'For' loop checks the condition at the the end of the loop, in the 'next' statement, so first time through it has no idea whether it is doing the right thing or not...

It has been this way since the dawn of programming and is definitely not a bug, so sorry Maxime, you're just using the wrong loop.

Danny (nod the mod)

12-09-2007 22:12

Posted by:
Maxime

Location:
Paris France

Find more posts by Maxime

FOR loop is always run once !

OK, allnods, I know. It is like this and you find it perfect.
It was like that on my TRS 80, I just hoped it would have changed since, like in other languages...

12-10-2007 08:53

Posted by:
Maxime

Location:
Paris France

Find more posts by Maxime

For loop II

Hello
I was a bit hard, yesterday, following your answer, and I apologize. I recognize your great efforts and competence and I thank you for it. But...

In my idea, if "for k=1 to 1" and "for k=1 to 0" give the same result, it can be considered a bug, or at least an error generator. I know that the simplest way to implement "for...next" is : reading the "for k", executing what follows, read the next and stop or not if the next value is > or not to the current one. But if you could make it a little more complicated (not so much I think) so it would work as awaited, and as some other languages do, it would be great.

Thank again you for your job

12-10-2007 23:54

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

No worries Maxime...

You were not harsh, but the reason why the 'For' loop is as it is, is because of speed. You obviously have a bit of experience behind you, so I'll explain. The loop equates to an equivalent machine code call (in my day it was 'DBRA', 'Debra' to the geeks or 'Decrement and BRAnch' to those of us who just read the manuals...). As it is a single machine code call it is stupidly quick, the quickest loop variant there is in fact (which is why it is used so often). The only way to slow down a 'for' loop is to add the word 'step'... which brings me nicely to the other reason why it is as it is... For a=1 To 0 Step -1 is valid and often useful syntax. Repeat... Until was added to the general BASIC syntax to provide a little more flexibility, and the While... Wend / End While type was added for the reasons you are experiencing. I have said this in these forums before and will doubtless say it again, but BASIC is about as close as most people will ever get to writing down and dirty assembler (it may sound strange but trust me it's true, I've been doing this for nearly twenty years now). You get a limited syntax and have to do the best you can with it, it may not look pretty but god it's quick. The more 'Programmer Friendly' stuff you bolt on, the slower it gets... Objects, Inheritance... they may all look lovely but they chew up clock cycles.

I apologise for rambling on, but this is something I've spent years working around, it's sort of an occupational hazard. The loop you need is the 'While' loop as it was made for just your situation. I have never seen another language pre-flight a For loop, and off of the top of my head I can't see a reason to do so.

If you are interested in speed over 'code readability' (what ever that means these days), or just don't want to use a 'While', you could try losing loops all together and control your iterations with a conditional GOTO... It's even faster than a For and you can do what you like with it!

Happy Coding...

Danny (nod the mod)

12-11-2007 08:51

Posted by:
Maxime

Location:
Paris France

Find more posts by Maxime

Thanks for your explanation
The reason (speed) you give is a good one, I'm afraid.
By the way I already changed my for loops to whiles...
I solved all problems as far though not very "beautifully" some times. Only the priority question is a bit tricky, but I will succeed... with time

12-11-2007 09:13

Posted by:
Maxime

Location:
Paris France

Find more posts by Maxime

'Slowly thinking...;=)
I suggest you add some advice in the Help : "For" loops execute at least once, whatever are the limits"
Same for window mode : "Does not work correctly in all window functions (moving window, etc) now"

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.