Help for a beginner

Previous topic - Next topic

Havard

Hi

Having frequented retroremakes for a number of years there are a number of familiar names on this site. - so hello old friends!  Having been a Blitz devotee for a number of years, I took up Gernots's offer of an education licence for my school and have been experimenting with GL basic.  I converted one of my games over without too much trouble and now am reviving an old project - Target Renegade Remix - by starting from scratch and rewriting/reusing old code.  I have hit two problems and both of them are quite major and probably linked to my understanding of GL basic.

1. Fullscreen - I can't run at fullscreen or expand teh window to fullscreen at a resolution of 320x200.  Can go fullscreen at 320x240?  This works in blitz.  Any ideas?

2. I am trying to detect simultaneous button presses for cntrl and an arrow key to produce a back kick but I just can't get it to work.  The code is included below - any suggestions, please let me know (I tried a different key instead of cntrl as I wondered if it was a hardware problem with the keyboard but this made no difference).

Code (glbasic) Select
// --------------------------------- //
// Project: TR Remix
// Start: Monday, July 27, 2009
// IDE Version: 6.164

SETSCREEN 640,480,TRUE

//LOADFONT "fonts/zx32colour.png",1
//LOADFONT "fonts/zx16colour.png",1

//load graphics
LOADSPRITE "backgrounds/level01.png",0
LOADSPRITE "backgrounds/bottombar2.png",1

//player1
LOADANIM "graphics/p1.png",100,32,42 //walking
LOADSPRITE "graphics/shadow1.png",101 //shadow
LOADANIM "graphics/p1hit.png",102,56,15 //p1 hit to floor
LOADANIM "graphics/p1flyingkick.png",103,40,46 //flying kick
LOADANIM "graphics/p1punch.png",104,40,45 //p1punch
LOADANIM "graphics/p1floorpunch.png",105,28,30 //p1 floor punch
LOADANIM "graphics/p1knee.png",106,32,42 //p1 knee
LOADANIM "graphics/p1bk.png",107,40,45 //p1 back kick
LOADSPRITE "graphics/head.png",99

//Set up variables
GLOBAL p1x=100,p1y=60,p1f=0,p1dir=1,p1state=0
GLOBAL scroll=0,lives=3

//main loop
WHILE KEY(57)=0

//draw background
DRAWSPRITE 0,n,0
DRAWSPRITE 1,0,141
FOR n=1 TO lives; DRAWSPRITE 99,n*20,170; NEXT
//PRINT "P1",0, 150
//a$=Str(p1score): ss=LEN(a$): a$="":FOR n=0 TO 5-ss: a$=a$+"0":NEXT: a$=a$+Str(p1score)
//jf_text (fntzx16, 25, 150, a$)
//jf_text (fntzx16, 205, 150, "P1")

keypress()
drawsprites()
SHOWSCREEN

WEND

FUNCTION keypress:

right1=0; left1=0; up1=0; down1=0;

IF KEY(205) THEN right1=1
IF KEY(203) THEN left1=1
IF KEY(200) THEN up1=1
IF KEY(208) THEN down1=1


//code to make player release punch key
IF KEY(29) THEN b1=1
IF KEY(29)=0 THEN b1=0
IF b1=1 AND bd=0 THEN punch1=1
bd=b1

PRINT "punch="+punch1,100,150
PRINT "right="+right1,100,160
PRINT "left="+left1,100,170
PRINT "up="+up1,100,180
PRINT "p1state="+p1state,100,190
PRINT "p1dir="+p1dir, 20,150
PRINT "bd="+bd, 20,160
PRINT "b1="+b1, 20,170

IF p1state<>0 THEN GOTO jump2

//check for back kick
IF punch1 AND right1 //AND p1dir=-1
p1state=2
p1f=0
delay=0
ENDIF

IF punch1 AND left1 //AND p1dir=1
p1state=2
p1f=0
ENDIF


//check for just a punch
IF punch1=1 AND p1state=0
p1state=1
p1f=0
ENDIF

IF right1=1
p1x=p1x+1
p1dir=1
p1f=p1f+.3
ENDIF

IF left1=1
p1x=p1x-1
p1dir=-1
p1f=p1f-.3
ENDIF

IF up1=1
p1y=p1y-1
p1f=p1f+(p1dir*.3)
ENDIF

IF down1=1
p1y=p1y+1
p1f=p1f+(p1dir*.3)
ENDIF

IF p1f>11 THEN p1f=0
IF p1f<0 THEN p1f=10
//limits fo x AND y movement FOR player
IF p1x<8 THEN p1x=8
IF p1x>300 THEN p1x=300
IF p1y>92 THEN p1y=92
IF p1y<42 THEN p1y=42

//scroll screen if all baddies beaten in section
IF p1x>200 AND scroll=1
p1x=200
n=n-1
ENDIF

jump2:

ENDFUNCTION

// 0rder sprites from top to bottoom
FUNCTION drawsprites:
FOR n=42 TO 92
IF p1state<>0 THEN GOTO JUMP1

IF p1dir=1 AND p1y=n
DRAWSPRITE 101,p1x,p1y+35
DRAWANIM 100,p1f,p1x,p1y
ENDIF

IF p1dir=-1 AND p1y=n
DRAWSPRITE 101,p1x+6,p1y+35
DRAWANIM 100,p1f+12,p1x,p1y
ENDIF


JUMP1:
//punch
IF p1state=1 AND p1dir=1 AND p1y=n
DRAWSPRITE 101,p1x,p1y+35
DRAWANIM 104,p1f,p1x-6,p1y-3
p1f=p1f+.1

IF p1f>3
p1state=0
p1f=0
punch1=0
ENDIF

ENDIF

IF p1state=1 AND p1dir=-1 AND p1y=n
DRAWSPRITE 101,p1x+6,p1y+35
DRAWANIM 104,p1f+7,p1x-4,p1y-3
p1f=p1f+.1

IF p1f>3
p1state=0
p1f=0
punch1=0
ENDIF
ENDIF

//back kick
IF p1state=2 AND p1dir=1 AND p1y=n
DRAWSPRITE 101,p1x,p1y+35
DRAWANIM 107,p1f+2,p1x-12,p1y-3
p1f=p1f+.1; IF p1f>1 THEN p1f=1
INC delay, 1

IF p1f=1 AND delay=50
p1state=0
p1f=0
punch1=0
delay=0
ENDIF

ENDIF

IF p1state=2 AND p1dir=-1 AND p1y=n
DRAWSPRITE 101,p1x+4,p1y+35
DRAWANIM 107,p1f,p1x+6,p1y-3
p1f=p1f+.1; IF p1f>2 THEN p1f=2

IF p1f=2 AND delay=50
p1state=0
p1f=0
punch1=0
delay=0
ENDIF

ENDIF
NEXT


ENDFUNCTION


If you want to check the old blitz version then click below:

http://www.havsoft.co.uk/Target%20Renegade.htm

Thanks.

MrTAToad

#1
For point 1, I believe you've found a bug - 320x200 resolution wont go to full screen.  The lowest resolution it does is 640x480.  This is on a Windows machine, by the way.

For point 2, the problem seems to be IF p1state<>0 THEN GOTO jump2 - its blocking the check for the flips.  I would avoid all use of GOTO if I were you...

Hemlos

GOTO...definetly get rid of it.

Offtopic: optimizing your code a little bit:

IF KEY(29) THEN b1=1
IF KEY(29)=0 THEN b1=0

can be written like this:
b1=KEY(29)
Bing ChatGpt is pretty smart :O

Havard

Thanks for the replies - I have discoverd that I can only go fullscreen at 640x480 which is a bit of a pain if you are writing retroremakes/games.  I suppose the obvious solution is to double the graphics size (shame you can't resize teh window as this would have the desired effect).

As to my code - you are nearly right as about the jump but I use teh variable p1state to define whether the player has started a move and jumps the control input until this is finished.  So I don't think this is the problem.  I am pretty sure that if p1state=0 the program will continue to move to the check for both key presses and back kick should be started but for some reason it is not registering the key presses but just the punch and then p1state is set.  I cna get it to work by holding both arrow keys first and the hitting cntrl but I don't understand why it doesn't work unless I have got my logic wrong. (I am sure this is how it works in my original blitz version)?

Finally, if you suggest I don't use jumps - what would you suggest I do?  I come from a background of basic with line numbers and got/gosubs were staple program control.  I try to be  abit more modula but struggle!!!

MrTAToad

The idea is to put things in seperate functions and perhaps setup a WHILE loop to control the main function.

Havard

Here is the code without jumps but still not working -help!!!!!!!!!!!!!!

Code (glbasic) Select
// --------------------------------- //
// Project: TR Remix
// Start: Monday, July 27, 2009
// IDE Version: 6.164

SETSCREEN 640,480,TRUE

//LOADFONT "fonts/zx32colour.png",1
//LOADFONT "fonts/zx16colour.png",1

//load graphics
LOADSPRITE "backgrounds/level01.png",0
LOADSPRITE "backgrounds/bottombar2.png",1

//player1
LOADANIM "graphics/p1.png",100,32,42 //walking
LOADSPRITE "graphics/shadow1.png",101 //shadow
LOADANIM "graphics/p1hit.png",102,56,15 //p1 hit to floor
LOADANIM "graphics/p1flyingkick.png",103,40,46 //flying kick
LOADANIM "graphics/p1punch.png",104,40,45 //p1punch
LOADANIM "graphics/p1floorpunch.png",105,28,30 //p1 floor punch
LOADANIM "graphics/p1knee.png",106,32,42 //p1 knee
LOADANIM "graphics/p1bk.png",107,40,45 //p1 back kick
LOADSPRITE "graphics/head.png",99




//Set up variables
GLOBAL p1x=100,p1y=60,p1f=0,p1dir=1
GLOBAL p1state=0,punch1=0,b1=0,bd=0,delay=0
GLOBAL right1=0,left1=0,up1=0,down1=0
GLOBAL scroll=0,lives=3

//main loop
WHILE KEY(57)=0

//draw background
DRAWSPRITE 0,n,0
DRAWSPRITE 1,0,141
FOR n=1 TO lives; DRAWSPRITE 99,n*20,170; NEXT
//PRINT "P1",0, 150
//a$=Str(p1score): ss=LEN(a$): a$="":FOR n=0 TO 5-ss: a$=a$+"0":NEXT: a$=a$+Str(p1score)
//jf_text (fntzx16, 25, 150, a$)
//jf_text (fntzx16, 205, 150, "P1")

keypress()
drawsprites()
IF p1state=0 THEN controlp1()
SHOWSCREEN


WEND



FUNCTION keypress:

right1=0; left1=0; up1=0; down1=0;

IF KEY(205) THEN right1=1
IF KEY(203) THEN left1=1
IF KEY(200) THEN up1=1
IF KEY(208) THEN down1=1


//code to make player release punch key

b1=KEY(29)
IF b1=1 AND bd=0 THEN punch1=1
bd=b1


PRINT "punch="+punch1,100,150
PRINT "right="+right1,100,160
PRINT "left="+left1,100,170
PRINT "up="+up1,100,180
PRINT "p1state="+p1state,100,190
PRINT "p1dir="+p1dir, 20,150
PRINT "bd="+bd, 20,160
PRINT "b1="+b1, 20,170

ENDFUNCTION

FUNCTION controlp1:

//check for back kick
IF punch1 AND right1 AND p1dir=-1
p1state=2
p1f=0
delay=50
ENDIF

IF punch1 AND left1 AND p1dir=1
p1state=2
p1f=0
ENDIF

//check for just a punch
IF punch1=1 AND p1state=0
p1state=1
p1f=0
ENDIF

IF right1=1
p1x=p1x+1
p1dir=1
p1f=p1f+.3
ENDIF

IF left1=1
p1x=p1x-1
p1dir=-1
p1f=p1f-.3
ENDIF

IF up1=1
p1y=p1y-1
p1f=p1f+(p1dir*.3)
ENDIF

IF down1=1
p1y=p1y+1
p1f=p1f+(p1dir*.3)
ENDIF

IF p1f>11 THEN p1f=0
IF p1f<0 THEN p1f=10

//limits fo x AND y movement FOR player
IF p1x<8 THEN p1x=8
IF p1x>300 THEN p1x=300
IF p1y>92 THEN p1y=92
IF p1y<42 THEN p1y=42

//scroll screen if all baddies beaten in section
IF p1x>200 AND scroll=1
p1x=200
n=n-1
ENDIF

ENDFUNCTION

// 0rder sprites from top to bottoom
FUNCTION drawsprites:
FOR n=42 TO 92



IF p1state=0

IF p1dir=1 AND p1y=n
DRAWSPRITE 101,p1x,p1y+35
DRAWANIM 100,p1f,p1x,p1y
ENDIF

IF p1dir=-1 AND p1y=n
DRAWSPRITE 101,p1x+6,p1y+35
DRAWANIM 100,p1f+12,p1x,p1y
ENDIF

ENDIF


//punch
IF p1state=1 AND p1dir=1 AND p1y=n
DRAWSPRITE 101,p1x,p1y+35
DRAWANIM 104,p1f,p1x-6,p1y-3
p1f=p1f+.1

IF p1f>3
p1state=0
p1f=0
punch1=0
ENDIF

ENDIF

IF p1state=1 AND p1dir=-1 AND p1y=n
DRAWSPRITE 101,p1x+6,p1y+35
DRAWANIM 104,p1f+7,p1x-4,p1y-3
p1f=p1f+.1

IF p1f>3
p1state=0
p1f=0
punch1=0
ENDIF
ENDIF

//back kick
IF p1state=2 AND p1dir=1 AND p1y=n
DRAWSPRITE 101,p1x,p1y+35
DRAWANIM 107,p1f+2,p1x-12,p1y-3
p1f=p1f+.1; IF p1f>1 THEN p1f=1
INC delay, 1

IF p1f=1 AND delay=50
p1state=0
p1f=0
punch1=0
delay=0
ENDIF

ENDIF

IF p1state=2 AND p1dir=-1 AND p1y=n
DRAWSPRITE 101,p1x+4,p1y+35
DRAWANIM 107,p1f,p1x+6,p1y-3
p1f=p1f+.1; IF p1f>2 THEN p1f=2

IF p1f=2 AND delay=50
p1state=0
p1f=0
punch1=0
delay=0
ENDIF

ENDIF
NEXT


ENDFUNCTION







Hemlos

Hi again,


Have no fear....me and MrTAT arent the only ones here that can help you, theres a good dozen people on these forums that will jump into this thread when they see an opportunity to help!


First...dont panic, youre in good hands! You may need to wait an hour, or sometimes a few days...depends on who is around the forums.

Second, I know exactly how you feel about the logic of the code here...I come from BASIC on a commodore 128 :)
I had to learn a few things, and from there everything is pretty smooth.

So....let me just say this....your program looks pretty good so far...
...I am going out on a limb here to say, im pretty sure your logic is the issue...


I will help you get the logic in your program to work out properly.
What i need is for you to pack your game directory into a zip file and attach it to your next message.
I want to see it in action as i smooth out your code.
During this process i will also optimize your code to make things much simpler to read.
When im done, i will repost it back here in this thread for you.

-Hemlos
Bing ChatGpt is pretty smart :O

Hemlos

By the way, if you post it within the next 4 hours...
I do have a few things to do within the next 4 hours, so you will need to check back here by 10pm US-EST to see my progress. I will reply with whether or not i can finish it tonight or not...im pretty sure i can.

Certainly, i will have you sorted out by tommorow, no later than 12 noon US-EST.
Send the zip ASAP, so i can get on it. Really i dont expect it to take more than a few minutes to sort.
Bing ChatGpt is pretty smart :O

Havard

Thanks for your kind words and support!  Is there any easy way of attaching a zip or do I need to link to it via my website?

As I said earlier, this is an old remake that I am revisitng - it basically got put on hold due to the birth of my son (2 year s ago) and a loss of interest.  Now that I ma finally getting some time back in my life and not being completely knackered the whole time, I want to get this done.  In the mean time I have changed my computer and my old blitz stuff wasn't compiling plus blitz can be a bit unstable at times.  I sensed that GLbasic is quite similar and the opportunity to build for different systems is really attractive - plus I hope to use it at school with the computer club!

Havard

I have just found out how to attach a zip!  Ignore my stupidity..

[attachment deleted by admin]

Hemlos

No prob....give me a couple hours...need to take care of some things around the house first.
Bing ChatGpt is pretty smart :O

Ian Price

#11
Right, I've got a nice solution to keep your graphics at the same resolution and still use a 640x480 screen. I use this in all my GP2X/Wiz/pc games (including B'lox!)

Instead of using SHOWSCREEN, call this function I developed.

What it does is draw your original screen as 320x240 and then grabs it, scales it and redraws it. I like my stuff blocky, hence the SMOOTHSHADING FALSE statement - remove it and see the result. This doesn't have any significant impact even on slower machines like my laptop (which can't display 320x240 anyway, so this is perfect).

Code (glbasic) Select


GLOBAL platform$

platform$=PLATFORMINFO$("device")

IF platform$="DESKTOP" THEN SETSCREEN 640,480,1





// Scale screen
FUNCTION scale:

IF platform$="DESKTOP"
GRABSPRITE 999,0,0,320,240

SMOOTHSHADING FALSE

ZOOMSPRITE 999,160,120,2,2

ENDIF

SHOWSCREEN

ENDFUNCTION



Hope this helps (and nice to see you here) :)

[EDIT] I've just tried the above with your code and it works well.
I came. I saw. I played.

FutureCow

Hi, from a fellow RetroRemaker, an ex-Blitzer, and someone who tries to find time to code with a 2 year old (and a 8 week old :D

I've put my suggestions below. Everyone has their own way of doing things so feel free to disregard anything that doesn't suit you. Here though are some simple suggestions about your coding style (which isn't too bad at all by the way - don't feel I'm saying it's totally crap! :D ) which may help your projects

1) Simple things make your code more readable. This is just my coding style, others might not agree, but I think it makes it a lot more readable both for you, and for anyone trying to help you

* Indent the code inside a function so you can easily spot what code is in that function
ie. change
Code (glbasic) Select

Function DoSomething
A=1
B=2
endfunction

to
Code (glbasic) Select

Function DoSomething
      A=1
      B=2
endfunction

Similarly indent everything after commands like "for","if","while" etc to make it obvious which bits of code relate to those statements

* Don't put multiple commands on a line separated with ";" , put each different command on its own line
Code (glbasic) Select
FOR n=1 TO lives
DRAWSPRITE 99,n*20,170
NEXT


* Even though you can do "if p1 then ..." type commands that are essentially saying "if p1=1 then ...", I would suggest always writing it in the form "if p1=1 then ..." so there's no ambiguity about what values you're testing

* The biggest problem I've had looking at your code in relation to your problem is trying to figure out exactly what your variables are and what they're doing. Eg - What is p1state and what do its values mean? Typically when I'm declaring my variables at the top of my code, this takes up several pages (again, the way I do things, and not the way everyone necessarily would.) The reason for this is that I (usually) create each variable on a separate line, with explainations documented against it where necessary. In this example I would do
Code (glbasic) Select

Global p1state=0                        // What action is player doing?
                                                  // 0=Noting/Walking
                                                  // 1=Punch
                                                  // 2=Backkick

It takes a little longer, but helps as programs (and your use of the variables) have a tendancy to grow. You'll suddenly find that when your p1state now has 8 different player states and can't remember whether it's p1state=5 or p1state=6 when the player is climbing a wall for example

* Make sure all your variable names are obvious as to what they do
It took a bit of reading through your code for me to work out that "p1f" is "p1 animation frame". Using "p1frame" or "p1animframe" would've made it a lot easier. It also helps if you have to come back and edit your code in 3 months time when you've forgotten what all your variables do. Similarly variables like "bd" make no sense to someone without spending ages reading your code to figure out what's going on.

2) Code optimisation
Your drawsprites function has 5 main if statements in it. Each one does a check for "if p1y = n". Make your life easier by putting an "if p1y=n" statement before the 5 if statements already there, that way if p1y != n, you don't have to check all the other conditions.
Similarly you can group the first 3 if statements in the controlp1 function with a single "if punch1=1" command.
It's a lot easier to follow the logic in your code when you have a single conditional statement that effects all the following code. If the condition is false, you know that code will not be called - this way you don't have to check each individual "if" statement to see whether you're checking "p1y" for it each time.

3) Your actual problem that you wanted help with (see, I got there eventually!)
This is a bit tough for me to look at as I'm at work and can't be seen to be playing games while I'm working, hence I'm trying to figure it out from just reading your code.

Tracing through your code, I think the problem is simply that your hands wont be quick enough to meet the conditions required by your code. I might have gotten something wrong as I can't run your code at the moment to verify it, but taking a bit of time to run through it manually, here's my conclusion.

Lets say for example you're heading right (p1dir=1) and  you want to do a back kick.
If you press left first, controlp1 immediately sets p1dir=-1. If your ctrl press is registered the next time through the code, you're now no longer pressing the direction opposite the way the character is facing.
Therefore, you'd need to press ctrl first to be able to do a back kick based on your code.

So you press ctrl first.  controlp1 runs through the code that says "if punch1=1". As you haven't pressed a direction key, it runs the code "if p1state=0 ... set p1state=1" - ie. you're now punching.
To process a backkick request, you MUST run the controlp1 code (as that's where it does the opposite keypress + button check). The only time controlp1 is called is when p1state=0 - therefore you have to wait until drawsprites resets p1state at the end of the punch animation which by the look of it is 30 frames.
So 30 frames finishes, p1state=0 again - also, punch is reset to 0.
Lets suppose that sometime in the last 30 frames you pressed left, so now you're facing right, pressing left, and holding down the ctrl key.
Punch must = 1 to register the backkick, but punch CAN'T be set to 1 until you've released it and pressed it again. If you release punch after the 30 frames, then your player changes walking direction and you're not back kicking anymore.

So, you punch, while he's punching you press left and release and repress the control key. If you repress the ctrl key before the 30 frames complete it won't matter as p1state is still not 0. Therefore the only way to make it work is to repress the ctrl key on the 30th frame.

If all that was hard to follow, the end result is that the only way your code lets you back kick is to simultaneously press ctrl and opposite direction in the same frame. If you are more than 1/60th of a second late on either key it won't work.


So, how do we fix it?
Easiest is to make a second button do the backkick.
The only way I see to implement a "press opp direction + fire" is to delay turning the player around. When the player presses the opposite direction set a variable=1
Each loop if playerdir = right, and key = left then variable = variable +1
if Variable > preset amount then playerdir = left
else if player presses fire then backkick

I hope that's helped. I've got to get back to work now but I'll happily help you implement this if you can't figure it out, or if someone else has a better idea.

Here's my slightly modified code where I've changed the indenting and optimised some of the if statements.
Code (glbasic) Select

// --------------------------------- //
// Project: TR Remix
// Start: Monday, July 27, 2009
// IDE Version: 6.164

SETSCREEN 640,480,TRUE

//LOADFONT "fonts/zx32colour.png",1
//LOADFONT "fonts/zx16colour.png",1

//load graphics
LOADSPRITE "backgrounds/level01.png",0
LOADSPRITE "backgrounds/bottombar2.png",1

//player1
LOADANIM "graphics/p1.png",100,32,42 //walking
LOADSPRITE "graphics/shadow1.png",101 //shadow
LOADANIM "graphics/p1hit.png",102,56,15 //p1 hit to floor
LOADANIM "graphics/p1flyingkick.png",103,40,46 //flying kick
LOADANIM "graphics/p1punch.png",104,40,45 //p1punch
LOADANIM "graphics/p1floorpunch.png",105,28,30 //p1 floor punch
LOADANIM "graphics/p1knee.png",106,32,42 //p1 knee
LOADANIM "graphics/p1bk.png",107,40,45 //p1 back kick
LOADSPRITE "graphics/head.png",99




//Set up variables
GLOBAL p1x=100,p1y=60,p1f=0,p1dir=1
GLOBAL p1state=0,punch1=0,b1=0,bd=0,delay=0
GLOBAL right1=0,left1=0,up1=0,down1=0
GLOBAL scroll=0,lives=3

//main loop
WHILE KEY(57)=0

//draw background
DRAWSPRITE 0,n,0
DRAWSPRITE 1,0,141
FOR n=1 TO lives
DRAWSPRITE 99,n*20,170
NEXT

keypress()
drawsprites()
IF p1state=0 THEN controlp1()
SHOWSCREEN


WEND



FUNCTION keypress:

right1=0; left1=0; up1=0; down1=0;

IF KEY(205) THEN right1=1
IF KEY(203) THEN left1=1
IF KEY(200) THEN up1=1
IF KEY(208) THEN down1=1


//code to make player release punch key

b1=KEY(29)
IF b1=1 AND bd=0 THEN punch1=1
bd=b1


PRINT "punch="+punch1,100,150
PRINT "right="+right1,100,160
PRINT "left="+left1,100,170
PRINT "up="+up1,100,180
PRINT "p1state="+p1state,100,190
PRINT "p1dir="+p1dir, 20,150
PRINT "bd="+bd, 20,160
PRINT "b1="+b1, 20,170
ENDFUNCTION

FUNCTION controlp1:
//check for back kick
IF Punch1=1
IF right1=1 AND p1dir=-1
p1state=2
p1f=0
delay=50
ENDIF

IF left1=1 AND p1dir=1
p1state=2
p1f=0
ENDIF

//check for just a punch
IF p1state=0
p1state=1
p1f=0
ENDIF
ENDIF

IF right1=1
p1x=p1x+1
p1dir=1
p1f=p1f+.3
ENDIF

IF left1=1
p1x=p1x-1
p1dir=-1
p1f=p1f-.3
ENDIF

IF up1=1
p1y=p1y-1
p1f=p1f+(p1dir*.3)
ENDIF

IF down1=1
p1y=p1y+1
p1f=p1f+(p1dir*.3)
ENDIF

IF p1f>11 THEN p1f=0
IF p1f<0 THEN p1f=10

//limits fo x AND y movement FOR player
IF p1x<8 THEN p1x=8
IF p1x>300 THEN p1x=300
IF p1y>92 THEN p1y=92
IF p1y<42 THEN p1y=42

//scroll screen if all baddies beaten in section
IF p1x>200 AND scroll=1
p1x=200
n=n-1
ENDIF

ENDFUNCTION

// 0rder sprites from top to bottoom
FUNCTION drawsprites:
FOR n=42 TO 92
IF p1y=n
IF p1state=0
IF p1dir=1
DRAWSPRITE 101,p1x,p1y+35
DRAWANIM 100,p1f,p1x,p1y
ENDIF

IF p1dir=-1
DRAWSPRITE 101,p1x+6,p1y+35
DRAWANIM 100,p1f+12,p1x,p1y
ENDIF
ENDIF

//punch
IF p1state=1
IF p1dir=1
DRAWSPRITE 101,p1x,p1y+35
DRAWANIM 104,p1f,p1x-6,p1y-3
ENDIF
IF p1dir=-1
DRAWSPRITE 101,p1x+6,p1y+35
DRAWANIM 104,p1f+7,p1x-4,p1y-3
ENDIF

p1f=p1f+.1

IF p1f>3
p1state=0
p1f=0
punch1=0
ENDIF
ENDIF

//back kick
IF p1state=2
IF p1dir=1
DRAWSPRITE 101,p1x,p1y+35
DRAWANIM 107,p1f+2,p1x-12,p1y-3
p1f=p1f+.1; IF p1f>1 THEN p1f=1
INC delay, 1

IF p1f=1 AND delay=50
p1state=0
p1f=0
punch1=0
delay=0
ENDIF
ENDIF

IF p1dir=-1
DRAWSPRITE 101,p1x+4,p1y+35
DRAWANIM 107,p1f,p1x+6,p1y-3
p1f=p1f+.1; IF p1f>2 THEN p1f=2

IF p1f=2 AND delay=50
p1state=0
p1f=0
punch1=0
delay=0
ENDIF
ENDIF
ENDIF
ENDIF
NEXT
ENDFUNCTION


FutureCow

I can't test this at work, but see if these changes to your code help. It should compile with any luck :D
The main difference is putting in a delay loop before changing player direction :- ie
Code (glbasic) Select

IF left1=1
IF p1dir = -1
p1x=p1x-1
p1frame=p1frame-.3
ELSE
DirectionChangeCounter = DirectionChangeCounter + 1
IF DirectionChangeCounter > 20
p1dir=-1
DirectionChangeCounter = 0
ENDIF
ENDIF
ENDIF


You may want to change that "20" counter - it's probably way too high.

[attachment deleted by admin]

Hemlos

Havard

As your code is...it does do a back kick already.

hold left and right, and the left ctrl button.

Bing ChatGpt is pretty smart :O