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 / Problems With My First Game...

Author
Message
TheRobot452
13
Years of Service
User Offline
Joined: 5th Apr 2011
Location:
Posted: 6th Apr 2011 05:40
Ok, so I was attempting to make my first game when I ran into a few problems. I have made 2 versions of the game and both I have had both technical problems and problems stemming from my limited knowledege base. The game I am attempting to recreate is an extremely simple version of brick breaker. I will first show the code, and then explain my problems.



trampolineX = 300
trampolineXY = 500

box trampolineX, 600, trampolineXY, 700

Enter Code For Bricks (ie. box 121, 245, 356, 467)

Do

if leftkey()=1
trampolineX - 3
trampolineXY - 3
Endif

if rightkey()=1
trampolineX + 3
trampolineXY + 3
endif

loop

The problems with this code are that A: When you press an arrow key nothing happens and B: I wouldn't know how to code the collisions.

Thank you very much to any who help. It is much appreciated.
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 6th Apr 2011 14:11
Ok, first of all it is a good idea to turn the sync on and set a sync rate. I generally use a sync rate of 60. So put this at the top of your program.

and then put 'sync' just above the 'loop' bit in your program. So you have something like this


The next thing you need to do is to draw the sprites inside your loop, like this


Note: you only have to call the sync command once in your loop.

Try this and see if it helps

A clever person solves a problem, a wise person avoids it - Albert Einstein
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 8th Apr 2011 15:20
Your code may be hard to check, simply because nobody else will have your graphics.

Having said that, a quick look at your code snippet reveals that both the left key and the right key are doing the same thing, which is moving sprite 1 400 pixels forward. The MOVE SPRITE command moves a sprite in the direction it is facing.

You could rotate the sprite 90 degrees, so that it is facing towards the right side of the screen. Then MOVE SPRITE would work, although moving it 400 pixels is too far.

Or, you could just position the sprite with the SPRITE command, which accepts new x and y coordinates. Your second code snippet would work well if you added the SPRITE command.

Except that, in order to change a variable (like trampolineX) you have to assign the new value.

This might help you...



Note: This is just an example. I used WAIT 1 to slow down the sprite so you could see how it moves. WAIT is not the best way to do this.

Login to post a reply

Server time is: 2024-09-29 02:23:45
Your offset time is: 2024-09-29 02:23:45