#1✎ 3dcdonHi there.
I do not know how to program but I am trying to learn and improve.
I am trying to create a platform like "Ghost n Goblins" and Super Mario.
I have gathered information on this site and on youtube.
So, right now I think I know how to use buttons, backgrounds and sprite (spset, spofs, spanim).
I can use the right and left buttons to make my sprite walking with an animation.
What i cannot do is shooting, properly shooting in fact.
I can actually shoot but it is not satisfactory at all and I can't figure it out.
Lastly, I use spset and spanim but when I press A the bullet is sent but as soon as I press A again the bullet is erased and a new one is shot.
I have also tried loops (for, while) but the loop works for the shooting but it freezes my hero...
So guys, could you please tell me what I should learn to achieve a right shooting?
#2✎ 278ProKukuQSP Contest 1 Contest ParticipantI participated in the first SmileBASIC Source QSP Contest!shooting mechanics is probably one of the harder things to implement into a game (trajectory, speed, number of bullets on screen), but @randomous' Shooting Tutorial should hopefully give you a better understanding of it.
#4✎ 122seggiepantsThe above linked tutorial looks great, I recommend you read it. If you have questions, feel free to ask. I just want to add a few points to your specific problems.
If I were to guess, I would say that when you shoot a new shot and the previous one disappears, you are reusing the same sprite handle. So setting up the new one just moves the previous one back to the starting point. Instead you need an array (or a bunch of arrays since we don't have classes or user defined types in SmileBasic) to keep track of all the shots the player has fired (remember to clear them when the shot hits something or goes off screen).
When you shoot and the player freezes, I am guessing you go into an entirely different loop to handle the shot being fired. The player isn't updated until you return from the shot fired loop. Instead you need a game loop that goes over everything in the world one by one and updates each one. So if you have an array with shots you do a FOR loop to update each one then update the player. You update just a little bit for everything every time through the loop. One difficulty is of course you are adding and removing things from the game world all the time.
Normally the game loop looks something like:
WHILE game_over == FALSE
Gather user input
Update everything's state/position
Draw Everything to the screen
Unfortunately platform games are fairly involved. I have to recommend you put it on the back burner and do some simpler games to build up your skills first. If I were to guess it sounds like you could probably make Pong but would have trouble with Breakout.
I would recommend working up to a Mario ish game in an order roughly like the following.
1. Guess the number - Basic looping and code constructs
2. Hangman - Data vs code, string manipulation.
3. Simon - Arrays, real time input handling
4. Tic Tac Toe or Connect Four with a computer opponent. AI
5. Text adventure (get lamp type, not just a branching story) Build a virtual world and manipulate it
6. Pong, Beakout or Arkanoid - Realtime graphics, basic physics simulation
7. Tetris or Columns or Puyo Pop. Dynamic world state
8. Space Invaders or Galaga or Galaxian - Multiple enemies
9. Asteroids (use vector graphics for this one, not sprites) - 2d math and geometry
10. Pac Man or top down dungeon crawler like say original Gauntlet - Movement on a 2d grid with tile map and diverse enemy AI
11. Mario-ish side scrolling platformer. Goal!
#5✎ 3dcdonYour advice sounds very reasonable. I will try not to hurry and learn step by step.