Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / - DBPro Coding Challenges -

Author
Message
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 20th Feb 2006 23:57
Once you've registered your original, you can install your own copy onto other pc's of your own without needing to connect to their website. Means we can have something useful to do at work.

On a completely unrelated topic - for those that don't check the code-snippets forum that often, take a look at what EVOLUTION has come up with - he's written an open source lightmapping function which is just truly amazing. I toyed with very basic lightmapping myself in previous challenges, and quickly realising how near to impossible the task was. He seems to have pulled it off brilliantly, though.

Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 21st Feb 2006 00:07
I saw that, too. It looks great!

formerly xMik
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 21st Feb 2006 00:23
cool!

On an on-topic... er.. topic(?) here is my latest code...


Updates:
1) Moved the "point in asteroid" function into its own.. err. function! This means i can easily reuse it
2) Modified it so you it can now easily detect a collision on a polygon with the mouse. Move the mouse around and you'll see. There are states.
a) Point nowhere near!!
b) Point within the bounding box
c) Point inside the polygon. The polygon check is more expensive so its only worth doing once you know the point in question is inside the box.

Next steps:
1) re-Introduce the rotation... SHOULDN'T be too hard. Would be easier if I didn't have to faff about moving the center point for rotating, but still...
2) Create exploding asteroids
3) Create some kind of player interaction

What do people get with this? I'm getting 372 fps on my machine with the above code. (I have a 4400+ Athlon X2 and a 7800GTX 256Mb)

Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 21st Feb 2006 00:52
works pretty good, but only 25 fps



pwnage!

(hey, if i wasn't such a cheapskate, i'de get something better )

formerly xMik
BillR
21
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 21st Feb 2006 02:10 Edited at: 21st Feb 2006 02:11
@xMilk - Time to get a new system son, you have waited FAR TOO LONG!

There is one place spending money is MORE IMPORTANT, than even buying food...........getting a new computer that can run DBPro and it's programs like they deserve to be run!

Now starve just a little bit, and go out and get yourself a screaming system.....sell anything you have to.......and in your dazed state of hunger you can program with a smile on your face, knowing that your sacrifice was well worth it!
BillR
21
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 21st Feb 2006 11:27 Edited at: 21st Feb 2006 11:49
Well, FINALLY have something working.

I struggled with so many things, even autocam on as the default, can't believe I didn't know about that one.

Anyway, give it a try and let me know what works and doesn't work.
top of source has keys to use, plus other info.

z and x to rotate ship
, and . to fire and move
space to hyperspace
b to self destruct



DBPro's built in collision doesn't work too well sometimes in the game.

I kind of like the way the asteroids came out!
Image All
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 21st Feb 2006 16:20 Edited at: 21st Feb 2006 16:20
@Nicholas Thompson: your pixel-perfect collision doesn't work o.O they go through eachother b][/b]P

FunkyStickmen: Battle of the Races (1%)
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 21st Feb 2006 19:31 Edited at: 21st Feb 2006 19:40
Lol - I haven't quite got that far yet! It only applied to the mouse position...

EDIT: Just installed DBP on my wortk machine before heading home and tried my code given above. I get 31 fps steady... which aint bad considering my work machine is designed to run Office!!! Its a 2.8Ghz Dell with onboard Intel "graphics accelerator". I wonder how much quicker it'd run if I just let the P4 take over!

btw: xMilk - you DEFINATELY need to upgrade if your system is being beaten by an onboard Intel setup! Starvation is definately an option!

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 22nd Feb 2006 00:19 Edited at: 22nd Feb 2006 00:20
Updated my code - collision now "works" between asteroids even when rotating!!!! Although nothing happens yet...




I have hit a wall though. Due to the way I make and store my asteroid data, I cant think of a neat way to delete an individual asteroid and make 2 new ones. The biggest issue is that I have made the psuedoLines array 2D. This makes it harder to remove stuff. If it was a normal 1D array I could easily play with the queue/stack commands

Will have to think about this tomorrow! Would appreciate anyone's idea's on this. If this was done in Java, it'd be so easy!! Lol!! I miss Object Oriented Programming

I'm pleased I got the collision working though!

Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 22nd Feb 2006 01:42
I'm barely managing to get my head around your types within types within arrays method of programming. Looks like very nice, organised code, though.

BillR
21
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 22nd Feb 2006 02:30 Edited at: 22nd Feb 2006 02:31
@Nicholas - Your math is impressive, but it makes my head hurt.

I also store all my asteroid data in 2D arrays.
Why don't you add an active status value in your array for each asteroid.
If the value is 1, then process the data for that asteroid, if it's 0, then skip that one.

Make the asteroid array big, and just add new asteroids to the end as you need them, activating new entries, and de-activating them as they are destroyed.

My asteroid array is set to 100, even though I start level 1 with only 8 asteroids. Scanning through a larger array say 100 entries, processing the active asteroids is very fast.


Hey, did anyone try my entry?
Did it work OK on your system?
Image All
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 22nd Feb 2006 04:00 Edited at: 22nd Feb 2006 04:02
Quote: "I'm barely managing to get my head around your types within types within arrays method of programming."


Easy



FunkyStickmen: Battle of the Races (1%)
Segan
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location: Canada
Posted: 22nd Feb 2006 06:01 Edited at: 22nd Feb 2006 06:05
@Nick: I didn't look at your code in depth, but it appears that your variable (Asteroids) is still a one dimension variable, and you should be able to "Add to queue" and delete elements like normal.

ex: (Pulled from my recent entry)



Although I may be missing the point and giving you something that doesn't work in your case. If you are working with multi-dimensional arrays later on (and that was your actual problem), you can try using memblocks/"make memory" techniques to store the info, rather than arrays (store the location in the array however). This method works, but will make you rewrite a bunch of your code I'm afraid.

ex:


This way, you can use the above method, and still use the variable "bombs" (or whatever) to provide data such as xpos, ypos etc. You just have the extra hassle of putting your entire two-dimensional array into a memblock...


Edit: I reread your message, and looked at the "psudolines" part of your code, and realised that the first part of this post is probably not very useful... Oh, well... I'll leave it on here anyways.
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 22nd Feb 2006 08:15 Edited at: 22nd Feb 2006 09:54
@BillR - I might have to resolve to doing that... Cheers

@Segan - You're right, the Asteroids array is 1D and would give me no problem at all. The issue is with the PsuedoLines array which is 2D. One dimension for the asteroids and the other is an index of each vertex for the polygon. Unfortunately, you can use the add to queue commands with 2D arrays.. However, if I have never heard of the make memory commands. This looks VERY interesting to me.

See, during my sleep my brain seems to program... Not sure why, but I dont complain when it comes up with 'solution'. My theory was that I could live and sleep at night with having a fixed number of points in the polygon. This means I could attach ANOTHER type to my Asteroid like this:


and then have a function to get them like an array... Thing is, I dont think functions can return types can they?


Segan - your make memory idea could be a VERY elegant solution to this problem. By creating a "pointer ID" in the asteroid type, part of the creation could be to make a block of memory. This block needs to house '2 * number_of_points * size_of_a_float' which would means every even float could be x# and every odd float could be y#. One or two functions could make that very neat...

Segan - how do you retrieve data from a memory block like that? I haven't played with them but you have got my attention and programming spidy-senses tingling!!

EDIT: Just got to work and tried out my above code. Pleased to see it still running at 30fps even with the newly added asteroid collision detection. You know whats wierd - it seems that no matter what DBP app I run on this intel chipset, I always get 30fps!! Whether there are 6 rotating sprites or a fulling normal mapped sphere with a 30Mb texture on it! I dont quite understand this setup... Lol!

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 22nd Feb 2006 13:11
Nic, see if this is usefull.

http://forum.thegamecreators.com/?m=forum_view&t=72176&b=1


Open MMORPG: It's your game!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 22nd Feb 2006 13:22
I have been keeping an eye in that thread and it does show potential. I'm kind of unsure about it thought because it looks like you're basically exploiting the boundaries of the language and these kinds of things could easily be fixed in later versions thus writing off the code that relies on it...

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 22nd Feb 2006 13:53
Good point and very true. That is what is being done. And, it might be exploiting the IDE, so that may not work in another IDE.

I thought I saw Make Memblock From Array / Make Array From Memblock functions in 5.9? That would work along the same lines. Then the memblock ID could be passed to the function.


Open MMORPG: It's your game!
Segan
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location: Canada
Posted: 23rd Feb 2006 04:23 Edited at: 23rd Feb 2006 04:25
@Nick: Well, as you can see from my edit, I kind of misread your program the first time, and by the time I had realised that, I didn't have time to completely edit my post!

(I think the most clever way to put it is: You should use "make memory" or memblocks to create a psuedo array for your psuedo points )

Anyways, I currently use some very useful "peek/poke" commands found in one of IanM's DLLs for accessing and saving the memory. This is mostly because of the fact that Darkbasic doesn't currently support retrieving floats from memory direclty (some extra unnessesary code is needed).

For the contest, I would use functions similar to these (you can code manually, but writing "readinteger" and "writeinteger" is so much clearer and easier.)



And for your information, here are some functions to return those nasty floats (work so much slower than the DLL though...)



Oh, but if you can use that method that Riidii was hinting to (temp array in function-->memblock for storage --> back to array for use again) it may save a whole lot of code.
Camaro
18
Years of Service
User Offline
Joined: 22nd Feb 2006
Location: Cyberspace
Posted: 23rd Feb 2006 06:16
Has anyone won this & what will they get?
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 23rd Feb 2006 09:57
Thats interesting... Why is a Float different to an Integer? Surely if you do:
local value as integer
value = *pointer

then you can do:
local valye as float
value = *pointer

Why does a float require all the extra bumf?

Cheers for that code the Segan! I think memory "blocks" like these are the way to go.

Segan
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location: Canada
Posted: 23rd Feb 2006 16:20
I think that it is the same reason why you can't have dynamic multi-dimensioned arrays .

Actually, what happens I think is that for some reason, Darkbasic does not differenciate floats from integers when using that command, so everything is outputted as if it were an iteger (which means all the extra 1s and 0s involved in floats are all added to the number, and that means you get a pretty big output using your method.) All of the extra code in there is just converting the integer to a float.

Oh, and just curious, but is "valye" a southern United States spelling? or a UK spelling?
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 23rd Feb 2006 16:43
valye is a southern UK spelling that is commonly associated with pre-coffee and just-got-to-work-and-cant-type-for-peanuts. I'm surprised it hasn't made its way over to Canada yet!

I might just have to have a play with that method.. Thanks for bringing it to my attention, it holds a LOT of potential. I've never quite realised the power pointers could have in this context!

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 23rd Feb 2006 17:31
If you want to get more into memory pointers, you may want to check out DSG's work here.

http://forum.thegamecreators.com/?m=forum_view&t=71343&b=6

By itself, it doesn't do much. But it seems like a fairly safe way to handle large quantities of memory.


Open MMORPG: It's your game!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 23rd Feb 2006 23:36
Segan + Riidii: Thanks VERY much for those resources... I think I have pointers hacked down now. They're not TOO hard.

Segan - I looked through that read float function and have made a few tweaks. It is now purely mathematical rather than using string conversions (Ãœber slow strings!!)



Keep hitting any key (except escape!! ) and it will produce 5 random float and then retrieve them.

Works pretty well I think. Now to put it to the test.

Thanks again guys for your help. I hope this snippet can help others too. Might put it into a seperate thread, see what response it gets...

Segan
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location: Canada
Posted: 24th Feb 2006 03:35
@Nick: Thanks for doing that improvement! It DOES speed it up some!

Just to let you know though, I did a stress test on my machine, and the commands that come from IanM's DLL are still about 5-8 times faster, so I will still be using those when there doesn't exist a "no DLLs" limitation.
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 24th Feb 2006 08:07
The DLL is always going to best faster. I wasn't trying to create a replacement function for the DLL - that'd never work! As you say though - this is a good option if you cant/dont want to use DLL's.

Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 24th Feb 2006 16:52
do all projects need to be turned in today, or tomorrow?

formerly xMik
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 24th Feb 2006 18:28
DBPro has a secret built-in Float/DWord/Integer converter . Here...




Open MMORPG: It's your game!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 24th Feb 2006 18:33 Edited at: 24th Feb 2006 18:34
GODDMIT!! Lol!

Might have to do a test on those. Dont know how slow making and deleting memblocks is...

EDIT: Tomorrow is the deadline I think.

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 24th Feb 2006 18:38
You could always have a reserved pre-made memblock hanging around in your code for just such a use. Do the same thing with vectors. If you need a temp vector, set it up at the beginning, that way you aren't defining it a million times throughout the code loops.


Open MMORPG: It's your game!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 24th Feb 2006 18:42
Cunning!!! That HAS to be quicker than my code :-( WHY DID I SPEND 3 HOURS DOING THAT WHEN MEMBLOCKS WOULD HAVE WORKED??? SMEEEEEEEEEG!!!!!

Image All
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 24th Feb 2006 18:49
Deadline is tomorrow? O.o then here's my entry again so that nobody forgets b][/b]P



Quote: "SMEEEEEEEEEG!!!!!"


...okaaay.....

FunkyStickmen: Battle of the Races (1%)
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 24th Feb 2006 19:16 Edited at: 24th Feb 2006 19:17
Why does my monitor spin around everytime I stop playing your game?

Quote: "Cunning!!! That HAS to be quicker than my code"

I think you only added that in so your post wouldn't get blocked by the caps-lock police.


Open MMORPG: It's your game!
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 24th Feb 2006 19:47
Quote: "Has anyone won this & what will they get?"


You win a free trip to Fiji - not a bad prize, eh?
(Flights, accomodation, food and spending money not included.)

Deadline is tomorrow, but as I'm out all day, I'll be judging on Sunday. So you have all of Saturday to complete your entries.

Chris Franklin
19
Years of Service
User Offline
Joined: 2nd Aug 2005
Location: UK
Posted: 25th Feb 2006 00:51
What is the compo? the current one

Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 25th Feb 2006 02:20
an asteroids game

formerly xMik
BillR
21
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 25th Feb 2006 03:01
Sunday - Cool!

Did anyone try my entry (above) yet?

Not finished yet, but it will be by tomorrow.
Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 25th Feb 2006 03:46
@BillR: I get "array does not exist or subscript out of bounds at line 609" as soon as i run it

formerly xMik
Image All
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 25th Feb 2006 07:07
I should change my system's error message sound effect to that Sonic fast-food commercial's punching sound

FunkyStickmen: Battle of the Races (1%)
BillR
21
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 25th Feb 2006 08:52 Edited at: 25th Feb 2006 08:54
@xMilk - Are you running DBPro 5.9?
My game uses vertex commands that are available in DBPro 5.9.

@Ric - Are you able to run my Asteroids game?
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 25th Feb 2006 08:56 Edited at: 25th Feb 2006 08:57
Just playing with an idea here. Check it out.




@Bill, I get the same error. Running 5.8


Open MMORPG: It's your game!
BillR
21
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 25th Feb 2006 09:28 Edited at: 23rd Jul 2006 04:14
@RiiDii - hmm, I guess the vertex commands only work in 5.9.
Shame, My asteroids look REALLY good! I wish you guys could see them.
Thanks for letting me know, I guess I thought most people had upgraded to 5.9 already. I hope Ric has 5.9, otherwise I'm in trouble.
Here is a screen shot.
[img][/img]

Is there a reason some of you haven't upgraded to 5.9?
I probably won't be updating to 6.0, until it comes out of beta.

@RiiDii - Hey your idea looks interesting!
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 25th Feb 2006 10:36 Edited at: 25th Feb 2006 10:39
Thanks Bill. No real reason why I haven't upgraded. I have 5.9 on my laptop. But my main excuse is that I haven't even gotten the hang of all the 5.8 upgrades and then 5.9 comes out. I really wish they would work on documentation before putting a ton of effort into even more commands no one will know how to use.

Edit: I do like the multi-colored asteroids. It reminds me of the old school games when they first tried to put some color into them. They used tinted screens over the monitor - it was a riot!


Open MMORPG: It's your game!
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 25th Feb 2006 11:46
@Bill - yep, your code works fine here. Looking very nice.

@Rii - Looks very interesting - even more interesting will be how you manage to make an asteroids game out of it .... it certainly has potential.

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 25th Feb 2006 21:01
I think what I want to do with this is to make a first person asteroid hunter and an optional overhead view. Anyway, here is an update. Improved graphics. I will probably be able to add in shooting and blowing up asteroids, as well as maybe ship collision before tomorrow.




Open MMORPG: It's your game!
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 26th Feb 2006 01:54
Now you're just trying to make the judging difficult, aren't you!

Looks very nice. I did play around with the graphics a tiny bit - obviously you'll want to get the rest of the gameplay in before you try this, but I did notice that whacking the poly count of the planet sphere, and the atmosphere layer, to 180 rows by 180 colomns had very little imapact on the frame rate (I guess because so little of it is actually in view?), but made the planet look a lot more rounded. Increasing the resolution to 1024 by 768 also improved the look but cut the frame rate a bit more noticably. And blurring the terrain image (blur bitmap 0,4) just before grabbing image 2 added a few seconds to the loading time but made the coastlines a lot less blocky. Perhaps for a different project, I would love to see a sun added, so that you could move from day to night and see sunrise/sunset. Getting carried away now, but if the asteroids' orbital radii were to decrease, you could have a shoot the asteroids before they impact with the Earth type scenareo - would be very cool. Anyway - I'll leave you to it!

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 26th Feb 2006 05:27
Thanks for the feedback Ric. This is something I had bouncing around in my head for a little while and it apparently gained enough momentum to get out. Here's some of the suggested improvements with a few others. I think I could get the sun to be a lot better with more time or able to add media, but it's decent now. Can also shoot and destroy asteroids. Watch out, if you are facing the sun, they can be difficult to see. Not that it matters because there is no 'ship' collision. Enjoy.




Open MMORPG: It's your game!
Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 26th Feb 2006 06:49 Edited at: 26th Feb 2006 06:55
Well, here's my final entry.

===================================================
Controls:

Rotate: 'a'/'d' keys, left/right arrow keys, or mouse left/right
Thrust: 'w' key, up arrow key, or right mouse button
Fire: space bar or left mouse button
===================================================



formerly xMik
BillR
21
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 26th Feb 2006 09:02 Edited at: 26th Feb 2006 09:04
Still working on my entry, but in case something happens, use this as my entry if I don't get to post again, or you are ready to judge.

You can't kill the enemy yet.



Top of source has keys to use.
Use 'Z' and 'X' to rotate ship, leftarrow and rightarrow work too
Use comma ',' to fire, period '.' to thrust
Use 'Space' to Hyperspace to a new position
Use 'Shift' for shields, you have a limited number of shields per level
You only get 5 shots on the screen at a time
BillR
21
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 26th Feb 2006 10:23 Edited at: 26th Feb 2006 10:24
Here is my final entry.


You need DBPro 5.9 to run this code!
Check the post above for the keys to use, or check the top of the source code.

Login to post a reply

Server time is: 2024-11-24 13:44:13
Your offset time is: 2024-11-24 13:44:13