Author Topic: Sprites in freebasic ?  (Read 6011 times)

0 Members and 1 Guest are viewing this topic.

Offline Panther

  • ZX 81
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Sprites in freebasic ?
« on: July 15, 2009 »
I'm pretty new to the world of Freebasic, and thanks to lots and lots of help from Drewpee  :clap: I'm slowly coming to terms with it's use and also tinyptc, seeing some other things that have been programmed in FB, alot seem to use Sprites, generated from Sprite boards/sheets.

Is there an easy way to use these, and how do you achieve collision detection between sprites ?

I might just stick to simple graphics for now  :P

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: Sprites in freebasic ?
« Reply #1 on: July 15, 2009 »
There is no built-in sprite support in FB so you'll have to create your own routines. You should take a look at the Bload, ImageCreate, Put/Get functions in the [/url=http://www.freebasic.net/wiki/wikka.php?wakka=FBWiki]FBWiki[/url] as they contains some samples programs on how to create and load bitmap images and use them in FB.

Collision can be a somewhat complicated subject, depending on what sort of sprites you are using, but a quick answer would be that each sprite has a bounding box around it and you "simply" check the boundaries of one box against another box. It is not quite so simple, but that is the main idea.

You should probably focus on getting some sprites loaded and moving around and then you can worry about collisions and such when you get that going. I'll try and work up a simple example on creating a sprite and getting it to move around on the screen.

Offline Panther

  • ZX 81
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Re: Sprites in freebasic ?
« Reply #2 on: July 15, 2009 »
Cheers for the tips, and any code when you get chance would be wicked !  :kewl:

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: Sprites in freebasic ?
« Reply #3 on: July 15, 2009 »
Here is a little example for you. It loads a sprite and you can move it around on the screen using the arrows keys. Escape exits the program. It shows the basics and some simple collision detection. I'll try and throw a better explanation into the FreeBasic tutorials section.


Online Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Sprites in freebasic ?
« Reply #4 on: July 15, 2009 »
Hi Panther,

first of all welcome to the forum, I briefly saw your learnings over on RCM, unfortunately I couldn't reply there as I don't have time to moderate that forum too, but I did have a glance through the code that had been left for you.

While I won't say it was wrong (any learning is good learning I guess if it got you interested), the techniques you were being shown (like reading the image data each frame) were poor programming practice and very inefficient.

You would do a lot worse than take the advice that RDC offered you here, but since I know that you use tinyptc, we can get you up to speed using one thing I made earlier :D

I created an image drawing library, it loads a screen and allows you to draw sections of that image anywhere you want, here's a link to the thread (which also contains a little tutorial), I really encourage you to look at this thread, it will help you.

http://www.dbfinteractive.com/forum/index.php/topic,3788.0.html

You may or may not need some other help in getting tinyptc properly installed, please post as many questions as you have and we'll get you all the help you need.

There is also another library I made which is in the resources part of this site.

http://www.dbfinteractive.com/downloadmenu.php

It's called "freebasic framework" and it contains simple commands for drawing things like circles, lines, triangles, rectangles, text etc, they are all pretty optimised and you've seen it used before (Andy has based quite a lot of his programs on this framework).

The main thing is to just post whatever questions you need to and also show us how you are getting along :)
« Last Edit: July 15, 2009 by Shockwave »
Shockwave ^ Codigos
Challenge Trophies Won:

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Sprites in freebasic ?
« Reply #5 on: July 16, 2009 »
Panther,
Shockwave's framework has been invaluable to me, the text, lines routines etc. are used in nearly everything I code to some extent.
Look forward to seeing some of your code.

DrewPee (AndyRCM)
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline Panther

  • ZX 81
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Re: Sprites in freebasic ?
« Reply #6 on: July 16, 2009 »
Cheers for the tips Shockwave, I'll try them out when I have time  :)

I'm slowly working my way through the FreeBasic Tutorials section  ;D