OK, I've realised that I'm not a good programmer..
Miscellaneous Forums/General Discussion/OK, I've realised that I'm not a good programmer..
I have ideas to make games but can't for the life of me get to grips with coding them. I'm still not grasping how everything works and how to implement ideas and workout solutions.
I have this game I'm making called BubblePop and I've reached the stage where I have to code the engine. I get stuck and don't know how to proceed so I abandon coding and look for other activities to do(getting banned on forums).
I would post on the forum to ask help but then I have doubts because the problem may be simple and I might get laughed at. So I don't post.
I've tried various methods to get motivated when I hit a stumbling block with coding and it works to some extent. The problem is that when I can't figure out how to code what I want to code I lose interest fast. This causes a lot of frustration for me especially when I see other people plodding along just fine and releasing games.
What should i do?
Should i start with just a pong game, then supe it up? Should I then try and do something different like Space Invaders or any other game that doesn't require a lot of skill as a coder?
Any other noobs out there in the same boat as me?
Any other noobs out there in the same boat as me?
Nope, you're all alone. That "Beginner's" section over there? Yep, completely empty.
Dude ... just ask the friggin' questions. I think my first post on here I asked how to position the cursor for text input.
Locate(x,y)
I didn't know that but no one laughed at me (not that I could hear anyway ;) Sometimes the only way to make those new connections is to ask for help. If you're having problems with a game called BubblePop then I doubt Space Invaders or Pong will be any easier for you. Get the questions out of the way so you can make some real progress. Once you get to a certain point you won't be asking technical questions anymore and then you can just focus on game design.
Should i start with just a pong game, then supe it up?
AMON, that philosophy is one of the best to use in my opinion. Start of with something simple first then once the framework is done you can always improve on it.
I would post on the forum to ask help but then I have doubts because the problem may be simple and I might get laughed at. So I don't post.
a) When have you ever seen anyone laugh at beginners for asking a question?
b) You think getting laughed at for being an ass is an improvement?
Should i start with just a pong game, then supe it up? Should I then try and do something different like Space Invaders or any other game that doesn't require a lot of skill as a coder?
Yes.
Amon: You need to be more confident. I'd rather you asked stupid questions than beat yourself up because you're unable to make progress.
Even if you haven't got a natural aptitude for coding, it doesn't mean you can't get good at it. One of the best ways of learning is to really immerse yourself in the subject.
I was a Blitz beginner only a very few months ago and I've learned heaps just by browsing through the code archives and some of the older posts in this forum. I did have a head start though, I used to code on the Amiga (about 10 years ago!).
If you really, truly get stuck on something and you need pointing in the right direction then by all means click on my username and send me an email. I would encourage you to think about posting on the forum though, there are keener minds than my own reading these words :)
*EDIT* I would back your idea of starting simple. You will learn a lot of useful techniques. It's all good having ideas for games, but if you get bogged down writing a menu system you're going to feel very frustrated. If you've already done 3 or 4 really simple games, odds are you've got plenty of framework code which you can use or rewrite in your best-thing-since-sliced-bread game.
You are probably ahead of me as far as development goes. You've already tried out a few things. Me, I've got only 2 projects on the go and one of those isn't even game related. I'm just plodding along (as you put it) at my own pace and learning little things about B3D as I go (learned about banks just recently).
PONG!!!!! do ya know how hard it would be for most of these lunkheads to code a good PONG game... myself included :)
seriously... you can code a game, i know ya can... all it is is getting the game broken down into lil manageable parts...
forget the phrase game engine... it's meaningless right now... think of your game as the engine...
as a matter of fact, forget the code right now, and just jot down in plain English, what you want the game to do...
next, jot down the major components of the game... scenery, creatures/people/actors, guns, etc... then take each component and jot down what it has to do in the game...
the scenery, the camera (view), and the player (not to be confuised with the player character) are your main componenets... also, if it's a fishing game, then the water, the fish, the rod and reel will become the major components...
in plain english, what do you want these things to do...
now, you've got something from which to work from... look at it and see if it sounds reasonable... and doable...
ok... here's where the work is gonna start... we're gonna assume that you have already made the models for the scenery... if not, go do that now, and come back when it's done...
ok, you're back... now put that scenery you just busted your hump doin aside for a second... and lets go back to that phrase you used earlier... the game engine...
what is it... well, in Blitz3D, the only thing you're gonna need for a simple generic game engine is...
1- to initialize the graphics state of the players machine... checking for errors which indicate that the players system may not be able to run your game, in which case it should exit cleanly, and if possible, let the player know what has happened..
2- initialize most of your basic variables,constants, globals, etc... these will be the values that the game overall will need to access...
3- some sorta menu... make it trivial right now...
4- and then a main loop... this is where your game will happen... this is where your actual game code will be placed... this is where those components you jotted down earlier will come to life and do things... usually as the result of user input via the keyboard, mouse, whatever... or a game timer...
and that's basically it... that's your game engine... write that code... and make sure it works...
now you can go back and look at the components you wrote up, and refine them a lil if need be...
next... lets get the simplest functionality coded... the scenery... simple, i say, because the scenery usually doesn't do anything... it just sits there... the only thing you need do is load it...
next you will have to take care of the view (camera)... usually it is connected to the player characters avatar, but right now, lets just put one in there, and since i know that you've written down that the view will have to move and turn around... this is gonna be a two step deal... first initialize the view... then add keyhandlers in the main loop...
everything that you want to have happen once only happens before the main loop... everything that you want to happen 60 times a second, while the game is being played happens in the main loop...
[end of page one of the tutorial]
--Mike
[page two of the tutorial]
oh, and take note... this is where you might wanna use functions, and just call them from inside the main loop...
yes, you are entering the advanced planning stage now... you might consider putting all the functions for a specific component of your game into a *.bb file and loaded by the main game .bb file... the camera and view functions in FishingGameView.bb... the player functions in FishingGamePlayer.bb, and so on... and since you are gonna callto these functions from your main loop, they should be loaded in the initialization part (the beginning) of your code...
you don't have to write em all now, but be ready to...
doing it this way makes things a lil easier to work with... you'll see this later...
ok... back to the mainloop and the view... just enter a call to a function we're gonna call UpdatePlayerView... that's all... just enter a line like that UpdatePlayerView()...
then open the FishingGamePlayerView.bb and create the function UpdatePlayerView... and code in all the keyboard responses you wanna use WASD etc... so that when the user presses the W key, the view (camera) appears to move forward... and so on...
when done, test it... your Fishing Game is on its way...
now just do this for all the components in your game... the view is easy... relatively speaking... but the actual player character and animating it, and coordinating the animations with the key moves are gonna be a lil harder... just take each thing one step at a time...
before you know it... you'll be ready to publish Martian Trout Fishing 1.0...
and i'l still be here telling people what to do, but not not doing any of it myself...
basically... that's all there is to it... the simplefied version of all there is to it...
:)
good luck
oh... yeah, helpful hints...
1 -steal code from the smart people here.. with their permission of course... in spite of their outward appearances, there are some pretty bright nuts on the tree here... check the code archives and use what you can...
2 -ask, but don't be afraid to try something first... you'll be amazed at the insane stuff that wil work...
3- when you make a million dollars... remember, i'm old... now... and donations are tax deductable...
--Mike
advices I can give:
- don't rush things
- try to discover reusable systems, they're everywhere
- try to work modular^2, avoid game/app-only code.. there's a reusable system even there
- spend oodles o' time on those systems.. because there's no pressure of a game lurking behind you, you can spend full time on those stand-alone systems
Note that haven't ever made a game, only apps.. :) (started on a vertical shooter once, stopped because I didn't have explosion-gfx :D)
"Amon" - coding is the least of your worries.
You are also incredibly ugly.
:)
Erm, "ENAY" told me that.
Hey, Thanks for the tips and advice Guys. I guess I'll start off with something simple and work onwards.
"Amon" - coding is the least of your worries.
You are also incredibly ugly.
I know, I tried to enter an Ugly competition but was kicked out because I was a professional. :D
Expect a Pong or Space Invaders game from me soon.
Thanks again guys :)
i always though it was a good idea to start with pong. thats was the first game i made, its good because you can then extend it for some decant AI coding, both cheating AI and real AI (has a personallity).
I have this game I'm making called BubblePop and I've reached the stage where I have to code the engine
There's your problem.
To use an analogy: You have to start the engine before you can drive the car.
I always write the core of the game first, writting it inside out. The last thing to be done is a title screen and options - they're just decoration to slap on the top.
I always write the core of the game first, writting it inside out. The last thing to be done is a title screen and options - they're just decoration to slap on the top.
Hmm!, I've always done it the other way round. I would do the title screen and set up all options menus, structure the main loop in order to incorperate the main engine later on.
Does anybody else work on the engine first? Wouldn't that mean that if you did the engine first you would have to hack your own code to get it into a playable state?
I'll try it your way though Becky. Would it be as simple as coding the engine and the playable part of the game into a function that can be called from the main loop?
Thanks :)
engine... engine... engine... i told ya... forget about the engine... your game is gonna be the engine...
if its a fishing game, the scenery, the fish, and the fisherman... code them....
if it's a race game... the cars the scenery... code them...
if it's a flight sim.. the airplanes the scenery...
the only engine ya gotta think about is the mainloop in blitz... code that once... or steall one from one of the examples you like and use that as a basis...
listen to me... i'm a certafried expoit on dis sh###...
just look at all the AAA titles i've written!!!!!
:)
--Mike
i do it your way amon. I create a load of gamestate consts so that i can quickly try somthing out and then just do a select gamestate.
It doesn't matter how good you are at coding. It's all about your skill in procrastination. Not going into irc EVER EVER EVER really helps.
> Erm, "ENAY" told me that.
Erm, In your wildest fantasies maybe :)
What seems to work best for me, though maybe not for anyone else <g>, is to keep "game" and "Blitz" categories separate (this is kinda what Red Ock/Mike said, but maybe more extreme). That is, when thinking about a game, I should be thinking in terms of game items (for example, if it's a boardgame then something like map, counters, and rules) and not in actual Blitz commands.
Once I've worked out in general, non-Blitz terms how the game will work, I create the game's objects and actions using Blitz commands. Then I create the game itself using only those objects and actions that I've made. For example, when I place a counter on the map, I don't think in terms of "DrawImage" directly, I use something like "Counter.Place(2,3)."
If I ever feel tempted to directly use a Blitz command to manipulate a game object or action, I know that I've failed to fully implement my game objects or actions. So I stop working on the game itself to dip into Blitz to make a game item to do what I need. Then I go back to creating the game itself without using Blitz commands directly.
This involves a bit more work than a more-direct approach, but I personally find it helpful to work as high-level as possible and as close to game-world terms as possible. It also seems to keep things simpler for me, since each "clump" of Blitz code only has to handle one object or action (and even I can manage that... usually <g>).
I LIKE CHIPS TOO!....oh err...wrong thread.
puki, you just had me giggling like a girl for 30 seconds straight.
well here's some more advice (although it seems you've got plenty now :) ) I've been trying to make the same game for about 2 years now, and recently I've been getting on much better with it, using Blitz3d is one reason, but also I have given up over-complicating the game, I wanted to have loads of moddable features, and i spent ages trying to figure out how to mod all this stuff that nobody would ever want to mod anyway... this was a big waste of my time and irritating. and now I actually feel like going back to write the game! This also made coding easier for me (i think some people call it hardcoding) because I know all I have to do is get it working, and I don't have to make it tie in with my "grand -stoopid- scheme" this really made the difference to getting some actual progress with the coding! Another case of K.I.S.S. :)
that's a verrrrrrrry good point you make muk... i must agree... definitely KISS...
--Mike
I would post on the forum to ask help but then I have doubts because the problem may be simple and I might get laughed at. So I don't post.
You get laughed at anyway. You might aswell just post your questions, at least that way you'll get an answer too.
If you want to be a better programmer there are loads of good books to help you (most of them Java ones tho'). Look up Bruce Eckel, Mark Allan Wiess and Martin Fowler for some good ones on programming, Frederick Brooks for ones on the nature of software, Craig Larman for books about software engineering and Kent Beck for books about Agile Development Processes (XP).
Jeez, don't look those guys up. They'll make you learn about factorisation, Fiestel cipher based hashes (OK, just took that from a non-public post--sorry, Mikkel!) and polymorphism.
I'm with 'muk'. I ran into the same problems, trying so hard to do things "right" and modular-ly that I couldn't get anything finished. Just hack that @#!*!
Does anybody else work on the engine first? Wouldn't that mean that if you did the engine first you would have to hack your own code to get it into a playable state?
I do the engine first... If nothing else, the major show-stoppers will be in that area, so if you really run into something that you can't figure out and makes you discontinue the whole thing, at least you didn't also waste a whole bunch of time on the 'easy' things that you could have done later on in the process.
Also, don't worry about OOP or object-based programming or any of the other 'fancy' features of Blitz. For games, you just to know if..else..endif, functions and loops. Everything else is just fancy ways of doing those three things.
For regular readers... yes I know that is an oversimplification, but it's still right ;)
The conventional wisdom is: "build one to throw away."
Prototype separately anything you expect will be hard (e.g. the engine.) After you have determined what all the tricky parts will be, reconsider your architecture and build a better one which will be modular and clean enough to plug into your finished product. I usually cheat and refactor instead of throwing out my code, but that's because I've a fetish for refactoring.
So, to answer your question - does anybody else work on the engine first - yes, I work on it both first and second.
I would post on the forum to ask help but then I have doubts because the problem may be simple and I might get laughed at. So I don't post.
That's pretty much the only thing you could have said that I'd have laughed at. Stupid questions are what the Beginner's forum is for. Try to pose your questions as carefully as possible and people will enjoy helping you.
People wont laugh at noobs, or even those who are here for longer and seem to know little. I mean most of us are grownups pretty much, and i dont see it as very grown up to laugh at someone in the first place.
I think what youre talking about is taking too large a steps in coding. This is when you have a working version now, but in order to get the next working version you need to code the WHOLE feature (ie function) and you cannot test it inbetween. Then what you need to do is find ways of debugging along the way, and in your case more importantly, figuring out what/how to do. Just think proceduraly and take small steps.
The only time I get demotivated is when i take too many big steps without testing/debugging and i run it the next time and i get some totally f-ed up results which are so complicated to understand my head is about to blow up. Then the long process of debugging takes place, often i use RuntimeError to find whats gone wrong and where, or position spheres in the 3d world to see the coordinates or behaviour, you just have to be inovative a little.
Amon, if you are having trouble understanding the basics of programming or how it works I suggest getting into a couple of things first.
This:
http://www.c-jump.com/is a real-world board game that helps you understand the game loop
This:
http://www.squeak.org/this is a very simple OBJECT ORIENTED PROGRAMMING INTERFACE designed for ALL AGES. It seriously will help you understand the mechanics BEHIND OOP and help you memorize, visualize, and comprehend OOP.
Thos:
http://www.gamemaker.nl/Another VERY simple OBJECT ORIENTED PROGRAMMING INTERFACE designed for ALL AGES. I used this program before I got back into programming and it seriously inderectly taught me OOP (before I even knew what OOP was)
My kids will be playing C-Jump when they have learned to read (and after I've actually had some kids).
Amazing idea.
That c-jump game looks funny. I'll have to order that.
-Amon-
What is BubblePop?
What is BubblePop and where can we have a look at the source ? (and steal all your ideas - kidding!).
All your source are belong to us!
What is BubblePop?
It's a little game I'm making where you have to match bubbles to pop them. I'll be spamming the Beginners area soon as I'm stuck with some of the code.
I don't think theres much originality in it but it's something different anyway.
[OT]Did anybody else read the thread where it shows that MAXGUI will cost $25?[/OT]
Amon
What direction do the bubbles travel and how are the matched (vertically, horizontally, diagonally) ? Is it 3D or 2D?
Amon you do know about the commands 'debuglog' and 'runtimeerror' dont you?
Jeez, don't look those guys up. They'll make you learn about factorisation, Fiestel cipher based hashes (OK, just took that from a non-public post--sorry, Mikkel!)
Actually that's from "Network Security Essentials" by Wiliam Stallings, and isn't very relevant to games or games programming, but a good starter if you want to learn about encryption.
and polymorphism.
You use polymorphism too James. Just because you don't know it's called polymorphism, doesn't make it less useful.
Amon,
Do what I do when I get stuck... which is often at times depending on the project.
PSEUDOCODE (however it is spelled)
Organize your thinking about what steps this engine has to accomplish to do what you want it to do.
Write it down or note it somewhere and if you did it in STEP order you really know what each line of code should tell the game to do:
' Check all arrays for matching bubbles
' pop matching bubbles
' move other bubbles down
etc.
Then go for it... you get stuck... ask for help.
RZ
Oh and incidently, having seen some of Amons code, he's actualy a pretty acomplished programmer. I was able to track down his problem in about 15 minutes - so his problem is definately one with game logic, rather than syntax or methods.
I find it helps to draw things out on paper. Visual cues are mucheasier for me to understand. Might not work for you though, but you can do an MI (Multiple Inteligences) test to find out.
An effective wa of programming is probably different things to different people. I like to delve straight into the code and not have anything on paper at all.
At some point I get stuck and the pencil comes out. If I get really stuck I sleep on it :)
At some point I get stuck and the pencil comes out. If I get really stuck I sleep on it :)
I can't do that. If I'm really stuck I lie staring at the cieling, unable to sleep until I've solved it. Once I'm confident I've solved it, I sleep fine tho', even without having to test my theory. When I wake, I've usually forgotten it all. Sigh.
If you have very hairy armpits try spreading them with peanut butter....or alternatively, for that babe-killer smile try gluing peanuts to your teeth.
I can't do that. If I'm really stuck I lie staring at the cieling, unable to sleep until I've solved it
I do that too with really frustrating problems, but I fall asleep eventually and, regardless of whether or not I had any trouble falling asleep, it isn't until the next morning that I realize the solution.
I often solve problems while asleep, anyone else get that?
@Amon, I have code for the type of project you're doing, if you want a peek at the source just give me a shout. (its just a lil thing I've been doing while taking a break from the module player)
Hi, Thanks for the replies. I appreciate it.
Heres an extremely early screenshot of what I'm working on(BubblePop).

The aim of the game is to fire bubbles from the center outward to the ring of bubbles. Everytime you match a bubble they pop and the circle of balls gets smaller. There will be variations of the game where you have to make sure that the circle of bubbles doesn't expand or contract beyond a certain point otherwise you lose. Each time you fire a bubble a new one is created untill you either lose or win.
I hope this makes sense.
Now I have one type for the bubbles you shoot from the center and one type for the bubbles that rotate around. I tried using one type for both the bubbles created in the center and the bubbles surrounding those in the center. The problem came when i tried to draw the images to screen.
How would you guys code it?
Sounds interesting, bit like Zuma but you are surrounded. I guess it can't get too small or it would be silly, but when it gets small enough you have completed the level. Nice waterfall by the way, yours or modified Google Image?
Doing better then me, and I know most of the commands and uses. I dunno, some things get to me to. Like Collisions and Networks. But finishing a game is my hardest task so far.
I think using a separate type for the bubbles in the circle is a good idea. This way, you can use Blitz's builtin list to keep track of the order of the bubbles in the circle. When you fire a bubble at the circle, you can Insert the new bubble into the correct location.
Here's a quick hack of the general idea:
const BUBBLE_RADIUS = 20
const POPPING_THRESHOLD = 3
type circle_bubble
field colour_index%
end type
type middle_bubble
field colour_index%
end type
global circle_bubble_count%
global circle_origin_angle_offset#
global middle_bubble.middle_bubble
function create_circle_bubble.circle_bubble(colour_index% = -1)
eb.circle_bubble = new circle_bubble
if colour_index = -1 then colour_index = rand(1, 7)
eb\colour_index = colour_index
circle_bubble_count = circle_bubble_count + 1
return eb
end function
function destroy_circle_bubble(eb.circle_bubble)
delete eb
circle_bubble_count = circle_bubble_count - 1
end function
function find_circle_bubble_at_position.circle_bubble(index%)
this_bubble.circle_bubble = first circle_bubble
for i = 0 to index - 1
this_bubble = after this_bubble
next
return this_bubble
end function
function find_angle_of_bubble(this_bubble.circle_bubble)
ang# = circle_origin_angle_offset
for b.circle_bubble = each circle_bubble
if b = this_bubble then return ang
ang = ang + 360.0 / circle_bubble_count
next
end function
function create_middle_bubble()
middle_bubble = new middle_bubble
middle_bubble\colour_index = rand(1, 7)
end function
function correct_circle_offset(insertion_ang#, bubbles_added%)
; this is all wrong!
;effect# = (constrain_0_to_360(insertion_ang) - 180) / 180
;circle_origin_angle_offset = circle_origin_angle_offset - bubbles_added*BUBBLE_RADIUS/2 * -effect
end function
; init
graphics 800, 600
setbuffer backbuffer()
for i = 1 to 20
create_circle_bubble()
next
create_middle_bubble()
; game loop
while not keyhit(1)
update_game()
draw_world()
wend
end
function update_game()
circle_origin_angle_offset = circle_origin_angle_offset + 1
if mousehit(1) then
mx# = mousex() - graphicswidth() / 2
my# = mousey() - graphicsheight() / 2
local firing_angle#
if my <> 0 then
firing_angle = atan(mx / my)
if my < 0 then firing_angle = firing_angle + 180
else
if mx > 0 then firing_angle = 90 else firing_angle = 270
endif
firing_angle = constrain_0_to_360(firing_angle - circle_origin_angle_offset)
strike_after_index% = floor(firing_angle / (360.0 / circle_bubble_count)) + 1
bubble_before.circle_bubble = find_circle_bubble_at_position(strike_after_index)
correct_circle_offset(find_angle_of_bubble(bubble_before) + 360.0 / circle_bubble_count / 2, 1)
new_bubble.circle_bubble = create_circle_bubble(middle_bubble\colour_index)
if bubble_before <> null then insert new_bubble before bubble_before
delete middle_bubble
create_middle_bubble()
check_for_poppage(new_bubble)
endif
end function
function check_for_poppage(bubble_to_check.circle_bubble)
bubbles_to_pop% = 1
first_bubble_to_pop.circle_bubble = bubble_to_check
last_bubble_to_pop.circle_bubble = bubble_to_check
while true
test_bubble.circle_bubble = before first_bubble_to_pop
if test_bubble = null then test_bubble = last circle_bubble
if test_bubble\colour_index <> first_bubble_to_pop\colour_index then exit
if test_bubble = last_bubble_to_pop then exit
first_bubble_to_pop = test_bubble
bubbles_to_pop = bubbles_to_pop + 1
wend
while true
test_bubble.circle_bubble = after last_bubble_to_pop
if test_bubble = null then test_bubble = first circle_bubble
if test_bubble\colour_index <> last_bubble_to_pop\colour_index then exit
if test_bubble = first_bubble_to_pop then exit
last_bubble_to_pop = test_bubble
bubbles_to_pop = bubbles_to_pop + 1
wend
if bubbles_to_pop >= POPPING_THRESHOLD then
popping_angle# = (find_angle_of_bubble(first_bubble_to_pop) + find_angle_of_bubble(last_bubble_to_pop)) / 2
correct_circle_offset(popping_angle, -bubbles_to_pop)
doomed_bubble.circle_bubble = first_bubble_to_pop
repeat
next_bubble.circle_bubble = after doomed_bubble
if next_bubble = null then next_bubble = first circle_bubble
destroy_circle_bubble(doomed_bubble)
doomed_bubble = next_bubble
until last_bubble_to_pop = null
; check if we just closed a gap on more bubbles to pop
if doomed_bubble <> null then check_for_poppage(doomed_bubble)
endif
end function
function draw_world()
cls
circle_circumference = circle_bubble_count * BUBBLE_RADIUS * 2
circle_radius# = circle_circumference / PI / 2
eb_index% = 0
for eb.circle_bubble = each circle_bubble
ang# = eb_index * 360.0 / circle_bubble_count + circle_origin_angle_offset
x = sin(ang) * circle_radius + graphicswidth() / 2
y = cos(ang) * circle_radius + graphicsheight() / 2
set_colour_by_index(eb\colour_index)
oval(x-BUBBLE_RADIUS, y-BUBBLE_RADIUS, BUBBLE_RADIUS*2, BUBBLE_RADIUS*2)
eb_index = eb_index + 1
next
x = graphicswidth() / 2
y = graphicsheight() / 2
set_colour_by_index(middle_bubble\colour_index)
oval(x-BUBBLE_RADIUS, y-BUBBLE_RADIUS, BUBBLE_RADIUS*2, BUBBLE_RADIUS*2)
flip
end function
function set_colour_by_index(colour_index%)
if colour_index = 1 then color(255, 0, 0)
if colour_index = 2 then color( 0, 255, 0)
if colour_index = 3 then color(255, 255, 0)
if colour_index = 4 then color( 0, 0, 255)
if colour_index = 5 then color(255, 0, 255)
if colour_index = 6 then color( 0, 255, 255)
if colour_index = 7 then color(255, 255, 255)
end function
function constrain_0_to_360#(ang#)
while ang < 0 : ang = ang + 360 : wend
ang = ang mod 360
return ang
end function
I can't figure out the correct math for the correct_circle_offset() routine, which is supposed to be responsible for making the circle expand or contract equally on both sides of an insert or pop, instead of leaving the first bubble always in the same place.
Hopefully this is useful to you.
Ok, here's something I did. press Escape to delete the bubbles one at a time. WHen the number reaches 5 bubbles, the program will end.
Type TBubble
Field BubbleType
End Type
Local NumberBubbles = 20
Local offset = 0
SeedRnd(MilliSecs())
Graphics 1024,768,32,1
For t = 1 To NumberBubbles
Bubble.TBubble = New TBubble
Bubble\BubbleType = Rand(5)
Next
While NumberBubbles > 5
While Not KeyHit(1)
Cls
;the diameter of the circle in bubbles is equal to the number of bubbles divided by Pi
; I then multiply the diameter by 20 which is the radius in pixels of the bubbles to get
; the radius in pixels of the circle.
radius = (Float(NumberBubbles)/Pi)*20.0
;pos is basically where in the circle the bubble is located. So the angle will be pos*AngleStep
pos = 0
AngleStep# = 360.0/Float(NumberBubbles)
For Bubble.TBubble = Each TBubble
; calculate the angle of the bubble and convert to x,y coordinates
Angle = (AngleStep*pos+offset) Mod 360
BubbleX = Cos(Angle)*radius+512
BubbleY = Sin(Angle)*radius+380
;change color based on Bubble Type
Select Bubble\BubbleType
Case 0: Color 255,255,255
Case 1: Color 255,255,0
Case 2: Color 255,0,0
Case 3: Color 0,255,0
Case 4: Color 0,0,255
Case 5: Color 0,255,255
End Select
;draw the bubble
Oval BubbleX-20,BubbleY-20,40,40,True
pos = pos + 1
Next
Flip
;update the angle offset so the bubbles rotate around the center.
offset = offset + 1
If offset >= 360 Then offset = 0
Wend
;decrease the Number of bubbles and delete the last bubble from the type list (Which Bubble still
; points to)
NumberBubbles = NumberBubbles - 1
Delete Bubble
Wend