First Question

BlitzPlus Forums/BlitzPlus Beginners Area/First Question

Kirkkaf(Posted 2011) [#1]
Hi everyone,

This is my first question I have, although not really BlitzPlus related it's more how I should go about doing certain things.

For my first game I thought I would keep it simple and have a ball bounce around of the sides of the screen and when you click the ball you gain points and the ball randomly repositions and increases in speed.

I want to create a border around the edge of the screen, what is the best way to do this?

1. Draw one image the size of my screen with a border and check whether or not the ball has reached the coordinates of the border.

2. Draw rectangles using Blitz command and check the same way.

3. Draw rectangles and check for image collide (not sure if this works with blitzs commands or just images loaded into memory.)

Or is there a better way?

Thanks in advance.


xlsior(Posted 2011) [#2]
I'd go with #1 myself.


Andy_A(Posted 2011) [#3]
Welcome to the forums!

I would suggest you play with all of the things you mentioned but, if you just want to get started, I would suggest plan (1).

(pseudo-code follows:)

Set Graphics mode

Load the 'main' image with the border same size as your screen

Set the color in the middle of the image as transparent.

Load the 'ball' image and set the color of the corners to transparent.

Set up a loop to:
....Clear the screen
....draw the border image
....draw the ball image
....check for mouse click on ball
....update score
....check for ball hitting border using 'ImagesCollide()'
....update ball movement
....Flip (make the buffered screen visible)
....check for game exit
continue loop

release image resources
end

If you get stuck, post your code, and I'm sure we'll be able to help you.

Good luck!


Kirkkaf(Posted 2011) [#4]
Thanks for the help guys.

I am following your instructions Andy_A and am having trouble I have loaded my resouces (images) within a function and used the mask function. I think because I loaded the images using a function to keep things tidy in my opinion they arn't global handles and can't seem to draw them.

Do all resouces have to be loaded out of functions? Sorry if this is suck a noobish question, I am completely new to game programming.

Thanks for your patients.


xlsior(Posted 2011) [#5]
If you declare the image handling variables as global before you call your image loading function, it should work.

You can also load your assets in the main program before you enter any functions, but if you happen to do your drawing in a function somewhere (which you probably would), then you'd still either need to make sure that the images were globals, or pass all the references to them when you call your drawing function.

It's probably the easiest to just make them global.


Kirkkaf(Posted 2011) [#6]
@xlsior - I actually tried to make a global handle within a function but It said I can't declare handles within functions. So it's best to load images from the main program then?

What if my program had ALOT of images would it matter loading them from the main program? As long as I just load the images when needed and release images that are no longer used?

Thanks.


Andy_A(Posted 2011) [#7]
One to get around not being able to declare image handles in a function is to declare the variable names of the handles as 'global' in you main program and load the images in the function.

If you have lots of images to load in the main program, then you will probably want to use an integer array to load all of the images.