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 Discussion / Error with pong

Author
Message
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 19th Dec 2008 22:56

Why is it not working?

~QJ
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 20th Dec 2008 00:05
If your refering to the Losing on start problem then your problem is here



Spesificly

if ballx > 640
goto you_lose
endif

i have no idea why that would be in there lol but your ball collision isn't working. you would do better with sprites its really easy. with my pong game i just made a box at 0,0,10,40 or something around there and used get image and Sprite commands so then you can use sprite collision for your ball.

so then you can just use the sprite command in your main loop like this

Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 20th Dec 2008 00:10
see what's happening is that the ballx is getting set to 645 (???)
to see, use the ctl or watever once it runs and

where in the setup it clearly says:


~QJ
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 20th Dec 2008 00:24
thats odd i took out the if ballX>640 part and it works fine
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 20th Dec 2008 00:29
When i run it the X just keeps going up (i printed it) cuz nothing hapens when it goes past the player haha
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 20th Dec 2008 01:06
@quirkyjim

Since you have set sync on in setup, put a Sync in your main do loop:



Enjoy your day.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 20th Dec 2008 01:41
oh i'm dumb i put that in there when i copied it into my computer

sorry! haha
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 20th Dec 2008 03:05
I'm having some trouble with sprites: they're not showing up!


~QJ
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 20th Dec 2008 06:34
your gunna need the sprite command in the loop. that should fix it. if not your lline since its on 0 you might not be able to see it when its on the edges of the screen. try moving it over a little if putting it in the loop doesn't work
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 22nd Dec 2008 16:40
Get rid of the "start" label, that's a bad habit you've picked up.
You've got quite a nice structure there, clear subroutines and indented too . You should make it a bit clearer where subroutines end and stuff like that, it just makes it easier to read that's all.



I'll go through your code a bit more just posting now in case someone else is reading your code.


Goke of the day: I coded an AI replica of Steve Irwin. It crashed because of a string array.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 22nd Dec 2008 16:55 Edited at: 22nd Dec 2008 16:57
Your "draw first" sub can be done much easier, you don't need separate bitmaps for each image, bitmaps are like pages you can draw on a page and then cut out an image and keep using the same page to draw and grab another image...


running out of time!
Since player and enemy look the same we can use the same image.
you don't have to draw the sprites before you enter the look although they will have to exist before you check them i.e. SPRITEX(#)


Goke of the day: I coded an AI replica of Steve Irwin. It crashed because of a string array.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Dec 2008 03:35
Sorry about the triple posting I was in the library and running out of time

Ok now before I start tearing into your code it is worth mentioning that you're displaying a lot of good traits; I've mentioned before about your good indenting and structure (excluding the odd jumpy bits), I also like how you made "playerx" and "enemyx" variables even though they never change, this has two benefits 1. you only have to change the initial value and every instance is changed without having to manually edit, also if you decided you wanted a special powerup or what-have-you that changed the size of the bat you could simply do so without having to re-write your whole program. 2. It makes everything much easier to follow i.e. "if ballx > 640 then ..." is more ambiguous than "if ballx > playerx". I would try to keep your variable name short and to the point though because long calculations involving "ballmomentumx", for instance, could have things running off the page.

Unfortunately i havent been able to test why your sprites aren't working as I've been away from DB all day. But I figure that if we sort some other things out, they might decide they want to work too ; as often is the case.

The main problem I see is the transition from "menu" to game. As I learnt from the wise grand master TDK, the best way to make this transition is for the program to flow into the game loop and call up the menu (from a sub) when it is required; just think about the trouble you ran into: the user finishes a game and wants to try again (he hasn't read your code and doesn't realise it is impossible!) but the "menu" (start) is out of reach at the top of the program! All you can do is kick him out of the loop and back up to the top! How very undignified
But it doesn't have to be like that, we can let the user come and go as he pleases, like this...

Hope that works. Either way you can see how it works, try editing your game so it has similar structure.


Goke of the day: I coded an AI replica of Steve Irwin. It crashed because of a string array.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 24th Dec 2008 07:34
hey just wondering is there a better way to do the sprites other then in the main loop cuz thats how i have it and it makes it verydiffucult because i can't delete the images :/
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Dec 2008 14:06
That's because of the way sprites work; the image is constantly updated to the screen so you don't have to worry about clearing up where the image was before.
However you can HIDE or DELETE sprites to stop them being drawn to screen. Check the help file.


Goke of the day: [Q]What's a coders' favourite part of an orchestra?
[A]The strings.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 24th Dec 2008 17:44
ok just wondering thanks
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 25th Dec 2008 13:46
@Quirky Jim
You don't seem to have created bitmaps 1,2 and 3. You need to CREATE BITMAP #,width,height before you can use it.
However seeing as you don't really need extra bitmaps you can just delete the lines that set bitmap and draw to the screen (bitmap 0). That might be why nothing was happening.
Is your game working now?


Goke of the day: [Q]What's a coders' favourite part of an orchestra?
[A]The strings.

Login to post a reply

Server time is: 2025-06-07 20:59:56
Your offset time is: 2025-06-07 20:59:56