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 / Some sprite positioning problems

Author
Message
Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 16th Jul 2011 21:12
Today I'm trying to randomize the X and Y position of the enemy in my Space Invaders-a-like game. Also I'm trying to not allow the player to leave the width of the screen and I've got a little problem with my bullets going straight through the enemy.

Randomizing the enemy position X and Y goes well, but for some reason I can't make the enemy to not spawn in places where the player can't shoot it, "under the player", below the player, or too far to the left or right on the X axis

This is place in the loop




Second problem;

when the Position player X: = 1420 the right key can be pressed and hold, then the Position player X: = 1440 but the player doesn't move at all.

I hope it's a bit understandable! Here's the code ;




Third problem is that for some reason the bullet fired will go through the enemy. At the start the collision hit works perfectly but at any random time when the enemy is randomly re-placed after loosing it's health elsewhere, the bullet will go through them instead of hitting it!
Code here



I'm attaching a *.zip file of the game with source code in case I forgot something to add in the codes.

Attachments

Login to view attachments
Gencheff
14
Years of Service
User Offline
Joined: 12th Jun 2010
Location: UK by way of USSR
Posted: 17th Jul 2011 01:18
I'm a bit lazy at the moment to fix everything,however I did discover the issue behind the non-colliding bullet-enemy sprites.

The bullet sprite size is far too small and for some reason it won't register collision at 7x7px.I scaled it up to 16x16 and it works.

Samotnijat vylk nasred gorata.
-3D,2D Artist,Animator,Web developer and Programmer.
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 17th Jul 2011 02:24
Quote: "The bullet sprite size is far too small and for some reason it won't register collision at 7x7px.I scaled it up to 16x16 and it works."

The problem is he is moving it too far each loop. He has this piece of code:

It moves 40 pixels each time literally jumping over the enemy on occasion. He will have to make this number smaller, or the bullet bigger.

@ Ramon: I made a few changes and I suggest manipulating the x,y values yourself without using the sprite x(), sprite y() commands. I've found that this gives more control. If you have an questions, just ask.



Gencheff
14
Years of Service
User Offline
Joined: 12th Jun 2010
Location: UK by way of USSR
Posted: 17th Jul 2011 02:42 Edited at: 17th Jul 2011 02:42
Touche.Your observation makes perfect sense.I didn't really look at the movement "speed".

To be fair,a bullet of 16x16px looks nice and there would be no need to slow down the sprite movement.

Samotnijat vylk nasred gorata.
-3D,2D Artist,Animator,Web developer and Programmer.
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 17th Jul 2011 02:51
Quote: "Touche.Your observation makes perfect sense.I didn't really look at the movement "speed"."

It's more of a been there done that kind of thing.

Quote: "To be fair,a bullet of 16x16px looks nice and there would be no need to slow down the sprite movement."

I always make my game themes to somehow support lasers. A good laser sprite, unbeatable

Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 17th Jul 2011 17:58
I don't know where to start anymore.
It seems that my desktop width is 1440 + 20invisible pixels wich is a Dell laptop related bug.
The desktop mode is for example 1440x900 but due to this bug or whatever you want to call it, the actual resolution is 1460x900. The pixels between 1440 and 1460 are not visible (outside the screen), it doesnt matter what kind of resolution you use.
I have to fix this by adding -20 to every friggin line of code that uses the desktop or screen width. It's not possible to make a command such as xres = screen width() - 20 it will only scale the screen's width.


Anyway if I start the game and my playerX position is 0, the sprite/image will still move a few pixels to the left if I press the left key, and when I stop pressing the left key it goes back to playerX 0, same for the right side.

Also I can't shoot more than 1 bullet on the screen due to (what I think) an array missing that creates sprites for the bullets. I was wondering if it's better to make a new weapon system(array) and if anyone could point me in the right directions for creating this. I do know how arrays work but I don't know how to actually create a practical idea of the theory I have.
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 17th Jul 2011 19:47
If your sprite is positioned at X 1440, then it will be drawn outside the screen. It draws the first pixel of the sprite at 1440, the second on 1441, the third on 1442 and so on. Dont know how to explain it better, does it help?

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 18th Jul 2011 00:28
@ Ramon:
Quote: "I don't know where to start anymore."

Maybe a project of this calibre is a little too soon. Have a go at creating smaller projects, they don't need to be complete games. Just experiment around with sprites, find out what works and what doesn't and so next time you'll have a far clearer idea of how to accomplish your goals.

Login to post a reply

Server time is: 2024-11-22 19:09:47
Your offset time is: 2024-11-22 19:09:47