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.

Newcomers DBPro Corner / Problem with coding game in DB

Author
Message
Joshg345
13
Years of Service
User Offline
Joined: 15th Jun 2011
Location:
Posted: 15th Jun 2011 14:57
Hey, I've been trying to code a dodgeball game in Dark Basic but I've got some problems. There's 4 sprites that I want to move using the up, down, left and right keys but I want the 4 sprites to move together. I have a problem with the sprites not moving at all. I also have a ball that I want to move in random directions by bouncing off collisions with the walls but the ball isn't moving. Plus now I've tried to code the ball, the ball has disappeared. And also there's a problem with sprite 4, which is one of my players, and sprite 4 has disappeared and I don't know why. Could you please tell a look at my code and tell me why it's not working the way I want? And what I can do to get it to work? Thanks!
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 15th Jun 2011 21:05
Hi Josh

I've had a look through your code, there are a number of issue.

1: Use the "randomize" and "timer()" commands at the start of your code to get randomize values when using the "rnd" command, else you'll get the same set of numbers each time the program runs. (have a look at the example given in the help file for "rnd", run it a couple of times then take out the line "randomize timer()" run that a couple of times and see what happens).

This effects the starting position and speed of the ball.

2: You put "sync on" a the start of the program but then did not put a "sync command at the end of the main loop to refresh the screen. This meant that the screen was black.

3: You weren't calling the "sprite" command once the positions had been changed so the sprites will not move on the screen. All the times you were using the "sprite" command before the main loop were unnecessary.

4: The y coordinate system when in 2D is that zero on the Y axis is at the top of the screen and larger values of Y will be toward the bottom of the screen. So to get the ball to drop from the top of the screen to the bottom of the screen, the starting coordinate should be zero or less (a negative value will mean the sprite is off the top of the screen) and the spreed should be a positive number so in the loop the code would be:

(y position) = (y position) + (speed in y direction)


I tend to print position and speed to the screen when I'm developing a program to give me an idea of what's going on, it can give a hint if things are moving in the wrong direction or if they've left the screen.

Another tip is to the use the "screen widht()" and "screen height()" commands to get the size of the screen.

5: The other thing, that I've only just discover" is that even with the sprite hidden, it will still register a hit when the hidden sprite hits another sprite.

6: Another thing I noticed was that you had different images for each player sprite but then only used the one image for all four sprites. Without seeing the files, I don't know if the players were all meant to be different or the same.

I've gone through the code and edited it to get something to work. It's not perfect but you can control the players, the balls drops, hits are registered and when the ball goes off the bottom of the screen it will be positioned at the top, at a random x coordinate with a random speed. I've not used any external media but programmed some simple sprite into the code so you can run it as is.



The main issue is that when the player's hit the boundary, you're only restricting the first sprite inside the boundary but not the other three so they will move off the screen. There are some other things that could be done better but I'll give you a chance to work these things out for yourself.

Anyway, I hope this gets you some of the way to sorting out your game.

Login to post a reply

Server time is: 2024-11-27 21:32:05
Your offset time is: 2024-11-27 21:32:05