forums

TNT Basic Forums > Programming Q&A
Newbie questions. Backgrounds, obstacles, location.
< Last Thread     Next Thread >
Author
Thread        Post A Reply

11-10-2004 16:47

Posted by:
DaveyJJ

Location:
Waterloo, ON

Find more posts by DaveyJJ

First off, very nice basic (pardon the pun) development environment. I was able to easily decipher many of the example projects code (except for the math parts, high school trig was 25 years ago now :-)). This is certainly something I will show to my (gifted) seven year old whose already got the computer programming bug.

I will certainly purchase a copy when window mode can be set (a pet peeve of mine).

That being said, here a couple of newbie questions I have, mostly revolving around the "Ball Collisions" example code.

1. How would you set a background image to appear?

2. How could you set up an object (obstacle, assume a square) that the balls would also bounce off of? Copy and modify the "bounce off walls" part of the code so it defined an object?

3. How would you make the balls disappear when they were at a location or struck an object? I assume it would be simple to, in this instance, to add a point to a counter and reset the balls?

My goal is to modify the code so that my son and I can make a simple marble-"sumo" game where two balls exist, controlled by the arrows and WASD keys, where the object is to knock the other ball/player either out of the arena or into a "hole" on the play surface.

Thanks.

11-10-2004 17:31

Posted by:
DaveyJJ

Location:
Waterloo, ON

Find more posts by DaveyJJ

Additionally ...

I've managed to make a button that has three states (and associated graphics) appear using the following code, but to over and down states don't work. I put this up in the setup part of the code in the "Ball Collision" code ...

Load Images 128
New Button 1,800,7,000,001,002

Any reason why the over and down states don't fire?

11-10-2004 17:34

Posted by:
JW

Location:
Netherlands

Click Here to Email JW   Find more posts by JW

QUESTION 1:-----------

load map 128
open canvas 2,640,480
open map viewport 2,0,0,0 to 640,48

(2 is the canvas ID)
set viewport offset 2,x,y (for a scrolling)
--------------------------
QUESTION 2:-----------
I think it's best to just make a sprite out of it ? And then check for a
sprite collision...

QUESTION 3:------------

stop sprite if you use the way described in question 2.



JW

11-10-2004 19:34

Posted by:
DaveyJJ

Location:
Waterloo, ON

Find more posts by DaveyJJ

I probably didn't frame question 1 correctly.

I have a single 1024x768 image that I want to appear as the background of my 1024x768 window. How do I get that image to appear in the background?

11-10-2004 19:57

Posted by:
DaveyJJ

Location:
Waterloo, ON

Find more posts by DaveyJJ

Thank you, Philipp (Switzerland)

I managed to get the picture to draw in the background using Philipp's suggestion ...

Draw Picture 131,1

I just imported it into the graphics section and call it onto canvas 1 using it's ID.

Thanks!

11-10-2004 21:13

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

If you want to put other objects inside, the method will vary depending on the shape of the object. If all you want is a square, you can just make the sides of the square like walls, except they will be restricted. Anything else would require using some math.

11-10-2004 21:39

Posted by:
DaveyJJ

Location:
Waterloo, ON

Find more posts by DaveyJJ

I'm actually making quite a bit of progress, Eric. How do I add carriage returns in the following line of code you made (I've changed the coordinates)?

draw text 800,20,"Total Energy: "+as str(totalEnergyInt)+" Total X Momentum: "+as str(totalMomentumXint)+" Total Y Momentum: "+as str(totalMomentumYint)

I'd like it to do this ...

'draw text 800,20,"Total Energy: "+as str(totalEnergyInt)+"<CR here>Total X Momentum: "+as str(totalMomentumXint)+"<CR here>Total Y Momentum: "+as str(totalMomentumYint)

Many thanks! next onto making the balls not leave a white path behind them.

11-10-2004 22:15

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

I don't think the draw text command can use carriage returns. You would have to make multiple draw text commands, one for each line.

Right now I tried to make a rectangular object, but I ran into some difficulty. It would be straightforward if not for the corners; hitting the corners means the ball should bounce as if hitting a diagonal surface. I'll try to figure out how to fix it...but now that I noticed that problem, I think circular objects would be simpler to implement.

About those white circles...the program might become slower now that the background is a picture instead of a solid color. Before, the blue circles could be erased by drawing a white circle where the blue one used to be, but now that the background isn't uniform you will have to redraw the entire background. That will be much slower. The other option would be to draw the balls as sprites instead of just drawing blue circles, which would make the game much faster.

11-10-2004 23:08

Posted by:
DaveyJJ

Location:
Waterloo, ON

Find more posts by DaveyJJ

It's still very, very fast with the background image so I will experiment with the sprites, but I don't need any more speed. How to turn off the white trails?

Also, when I try this, it doesn't work.

Do I need a set pen color black in front of each?

draw text 800,20,"Total Energy: "+as str(totalEnergyInt)+"

draw text 800,40,"Total X Momentum: "+as str(totalMomentumXint)+"

draw text 800,60,"Total Y Momentum: "+as str(totalMomentumYint)+"

11-10-2004 23:10

Posted by:
DaveyJJ

Location:
Waterloo, ON

Find more posts by DaveyJJ

Actually, yes it does. Sorry. I'd left out something. How to make the balls not leave the white? Thanks very much, btw.

11-10-2004 23:23

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

No problem.
First thing, take out the lines that draw the white circles. Look at line 137(?), which uses "fill oval" to erase. Then comes the part that will slow the game down: You have to draw the background picture instead.

11-11-2004 15:36

Posted by:
DaveyJJ

Location:
Waterloo, ON

Find more posts by DaveyJJ

More progress

OK, I've managed to get a couple of sprites loaded (images of marbles) that are the exact same size as the balls are. They are, of course, static and on a layer above the background and the moving balls. You're original balls are now not controllable; i.e., only ball [0] is controllable, I commented out the line that read ...

if key=49 then control=wrap(control+1,0,numOfBalls-1) 'spacebar changes control ball index

I'm going to assume that it's not easy to change the code to make this now all work like it needs to ... load the sprite images into the "ball definitions", make the background a sprite, etc.

Where should I begin, do you think? By wiping out the background and turning it into a sprite? Then come the tough part, right? Making the sprites have the same behaviour as the balls do. Will it be somewhat easy to modify your moving code to move sprites instead of drawn objects?

11-11-2004 15:38

Posted by:
DaveyJJ

Location:
Waterloo, ON

Find more posts by DaveyJJ

And if I make the "background" image a sprite, then the current balls and text showing momentum appear hidden/below the sprite, unless you can layer a sprite behind another layer?

11-11-2004 16:47

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

You can layer the sprites using "set sprite priority", but you don't need to; as long as the balls are sprites, the background doesn't need to be a sprite. Just draw the background once in the beginning.

11-11-2004 18:04

Posted by:
DaveyJJ

Location:
Waterloo, ON

Find more posts by DaveyJJ

I see what you mean about a slow re-draw when you comment out the filling white oval and have to redraw the background on every frame reset. Yikes.

So I guess then, I'm going to have to make the movement and collision code apply to the sprites that are on screen. Which involves a re-write of the hard part of your code. I'll have a go at it on a backup of what I have currently.

As a last, desperate question before having to attempt to make the ball code apply to sprites ... Can the balls in your code have an image applied to them?

No? darn ... ;-)

11-11-2004 18:48

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Sorry. :)

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.