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.

Author
Message
Mokraton
13
Years of Service
User Offline
Joined: 4th Dec 2011
Location:
Posted: 4th Dec 2011 23:14
I am in the early stages of creating a game based around Geometry Wars. I am making my own sprites, textures, and bitmaps, and source code. I am having trouble writing the source code thus far, I am in the early stages of a the game and fairly new to programming with DarkBASIC Pro. I load my bitmap and my sprite on the screen, but I have trouble moving my sprite properly. I can move him Up, Down, Left, and Right, and have him rotate, but when he rotates the up arrow key is still based on the y axis and he move directly up. I would like to program it so that when the avatar is angled 90 degrees, the up arrow key will instead more the sprite foward instead of directly up. Same deal with the Left, Right, and Down Arrow Keys. Any Suggestion? I am fairly new to programming so be as clear as possible with your answer.

Beginning Programmer
Professional Nerd

Attachments

Login to view attachments
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 5th Dec 2011 13:41

Will always move the sprite "forward" or "backward" if you use a negative number.

My signature is NOT a moderator plaything! Stop changing it!
noobnerd
14
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 5th Dec 2011 22:25
yeah you can use the move sprite command like mobiius said, or you can do it better ( more precise ) by using newxvalue and newzvalue respectively.

like this :



the advantage of this is that you will always know precisely where your sprite is. the commands sprite x() and sprite y() only return integers.

so if you want to move a sprite by increments of like 0.01 you are in some trouble. ( unless you use the above method )
Mokraton
13
Years of Service
User Offline
Joined: 4th Dec 2011
Location:
Posted: 6th Dec 2011 00:14
I tried using the

Move Sprite

command, and it worked, but it would jump my sprite foward so many paces, and then back to the original position. Is there a command that will consistently move my sprite foward like in Mario.

I am still working my way around noobnerd's example. Right now, my code for moving my sprite looks like this:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

x as integer
y as integer

player.x = screen width()/2
player.y = screen height()/2

Load Image "media\Avatar.png", player.id
Sprite player.id, player.x, player.y, player.id

TheGrid:
Do

Play Music Music

Sprite background.id, 0, 0, background.id
Sprite player.id, player.x, player.y, player.id

`Function Move Avatar
Move_Avatar()

Sync
Loop

Function
`If WASD is clicked, move player
If keystate(17) = 1 Then dec player.y
If keystate(30) = 1 Then dec player.x
If keystate(31) = 1 Then inc player.y
If keystate(32) = 1 Then inc player.x
EndFunction
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Note: This isn't my entire source code, just the avatar movement sections

Beginning Programmer
Professional Nerd

Attachments

Login to view attachments
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 6th Dec 2011 06:31
Hi, have a look at my project (attached). You'll have to compile it yourself but I think it's what you're after. It uses basic trig to move a spaceship in the desired direction. If you don't understand anything, just ask.

Attachments

Login to view attachments
Mokraton
13
Years of Service
User Offline
Joined: 4th Dec 2011
Location:
Posted: 6th Dec 2011 23:26
Thanks, Hodgey! That solved my problem. I rewrote it in my code and it works perfectly. Thank you everyone for you help! I'm sure I'll be back again with more questions.

Beginning Programmer
Professional Nerd
Mokraton
13
Years of Service
User Offline
Joined: 4th Dec 2011
Location:
Posted: 7th Dec 2011 02:06
I do have another question though, If I want my character to rotate,rather than hitting the left and right arrowkeys, have him rotate so that he faces my mouse cursor? So if I am point my mouse to the right of him, my avatar will be facing 90 degrees and if I push the up arrowkey and will be heading right, and if I hit the down arrowkey he will be heading left.

Basically, I would like my charcter to be facing my mouse, wherever it may be positioned.

Beginning Programmer
Professional Nerd

Attachments

Login to view attachments
chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 7th Dec 2011 11:45
Hi there.
@Mokraton to make your character point to mouse , use something like this:



Cheers.

I'm not a grumpy grandpa
Mokraton
13
Years of Service
User Offline
Joined: 4th Dec 2011
Location:
Posted: 8th Dec 2011 00:14
Thank You chafari! This helped me very much, keep the answers comeing plz as I have many more questions.

I started a Function for my avatar shooting Bullets

I'm trying my best to get the bullet to shoot where my avatar is pointed(which is now where my cursor is pointed)

This Function is my attempt to shoot a bullet from my avatar

Function Shoot_Bullet(s, X, Y)
angle = MouseP
speed = 5

If Spacekey()=1
Show Sprite bullet.id

moveX = sin(angle)*speed
moveY = (cos(angle)*-1)*speed

Move Sprite s, speed
Endif
EndFunction

For my entire source code, download the file, I have attached

Thank you all for your help!

Beginning Programmer
Professional Nerd

Attachments

Login to view attachments
chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 8th Dec 2011 12:24
Hi again Mocraton.
I couldn't see your example code as you sent the Dbpro instead of your dba file. Here's an example of how you can shoot bullets. I hope it can help.



Cheers.

I'm not a grumpy grandpa
Mokraton
13
Years of Service
User Offline
Joined: 4th Dec 2011
Location:
Posted: 9th Dec 2011 00:18
Thank you chafari for your help.

I am trying my best to incorporate your source code into my program and it works, but I have a slight glitch(which is most likely my fault).

When my avatar shoots the bullet, the bullet follows my mouse and I would like the bullet to just go directly foward. Once the bullet will travel straight foward, I also would like to write a loop so it will continously shoot bullets repetitivly because my game doesn't even have enemies yet and I already find it annoying just having to click the mouse button to shoot bullets.

I will do my best to figure it out on my own because I am doing this program as a learning experience. If you read this post before I post another message stating that I figured it out, please have a look at my code.

I appreciate all the help you have given me so far and do not want to annoy you with a constant barrage of nit-picky questions, but I am a new progammer and need a lot of help(especially with the seemingly easy problems).

If I accidently posted my DBPro File again and not my DBA file then I will upload the source code into another post (because its not a super long source code yet).

Thank you!

Beginning Programmer
Professional Nerd

Attachments

Login to view attachments
Mokraton
13
Years of Service
User Offline
Joined: 4th Dec 2011
Location:
Posted: 9th Dec 2011 00:25
5 minutes after that last post, I found my mistake.

I fixed the bullet following my mouse problem, but I saw a new problem.

If I click the space button very quickly, my bullets will disappear before I want them to. I am looking for a way to have as many bullets on the screen as I can.

I am re-posting my code again, anyone who would like to help, you are welcome to. (for an addition error with my code, read the post above)

Beginning Programmer
Professional Nerd

Attachments

Login to view attachments
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 9th Dec 2011 09:08 Edited at: 9th Dec 2011 09:10
Hi Mokratron, I'm glad you found my snippet helpful.

Quote: "If I click the space button very quickly, my bullets will disappear before I want them to. I am looking for a way to have as many bullets on the screen as I can. "

I've currently got something like this except it is written in AppGameKit which is very similar to DBP. Basically it is a dynamic array (an array that changes in size) of bullets. Here's the AppGameKit code (I'm too lazy to convert it to DBP right now but you should be able to translate it without too much trouble):


Login to post a reply

Server time is: 2025-05-18 20:59:10
Your offset time is: 2025-05-18 20:59:10