Discuss Scratch
- Discussion Forums
- » Things I'm Making and Creating
- » need help with python the script won't work
- ThatCat2000
-
Scratcher
45 posts
need help with python the script won't work
from settings import *
import pygame as pg
import math
class Player:
def __init__(self, game):
self.game = game
self.x, self.y = PLAYER_POS
self.angle = PLAYER_ANGLE
def movement(self):
sin_a = math.sin(self.angle)
cos_a = math.cos(self.angle)
dx, dy = 0, 0
speed = PLAYER_SPEED * self.game.delta_time
speed_sin = speed * sin_a
speed_cos = speed * cos_a
keys = pg.key.get_pressed()
if keys:
dx += speed_cos
dy += speed_sin
if keys:
dx += -speed_cos
dy += -speed_sin
if keys:
dx += speed_sin
dy += -speed_cos
if keys:
dx += -speed_sin
dy += speed_cos
self.x += dx
self.y += dy
if keys:
self.angle -= PLAYER_ROT_SPEED * self.game.delta_time
if keys:
self.angle += PLAYER_ROT_SPEED * self.game.delta_time
self.angle %= math.tau
def draw(self):
pg.draw.line(self.game.screen, ‘yellow’, (self.x * 100, self.y * 100),
(self.x * 100 + WIDTH * math.cos(self.angle),
self.y * 100 + WIDTH * math. sin(self.angle)), 2)
pg.draw.circle(self.game.screen, ‘green’, (self.x * 100, self.y * 100), 15)
def update(self):
self.movement()
@property
def pos(self):
return self.x, self.y
@property
def map_pos(self):
return int(self.x), int(self.y)
import pygame as pg
import math
class Player:
def __init__(self, game):
self.game = game
self.x, self.y = PLAYER_POS
self.angle = PLAYER_ANGLE
def movement(self):
sin_a = math.sin(self.angle)
cos_a = math.cos(self.angle)
dx, dy = 0, 0
speed = PLAYER_SPEED * self.game.delta_time
speed_sin = speed * sin_a
speed_cos = speed * cos_a
keys = pg.key.get_pressed()
if keys:
dx += speed_cos
dy += speed_sin
if keys:
dx += -speed_cos
dy += -speed_sin
if keys:
dx += speed_sin
dy += -speed_cos
if keys:
dx += -speed_sin
dy += speed_cos
self.x += dx
self.y += dy
if keys:
self.angle -= PLAYER_ROT_SPEED * self.game.delta_time
if keys:
self.angle += PLAYER_ROT_SPEED * self.game.delta_time
self.angle %= math.tau
def draw(self):
pg.draw.line(self.game.screen, ‘yellow’, (self.x * 100, self.y * 100),
(self.x * 100 + WIDTH * math.cos(self.angle),
self.y * 100 + WIDTH * math. sin(self.angle)), 2)
pg.draw.circle(self.game.screen, ‘green’, (self.x * 100, self.y * 100), 15)
def update(self):
self.movement()
@property
def pos(self):
return self.x, self.y
@property
def map_pos(self):
return int(self.x), int(self.y)
- crunchycowL
-
Scratcher
15 posts
need help with python the script won't work
I’m not sure what the problem is but I don’t think u can start a line with @
- DifferentDance8
-
Scratcher
1000+ posts
need help with python the script won't work
I’m not sure what the problem is but I don’t think u can start a line with @some modules actually allow you to do that. I think it modifies the below line of code in a way
- Discussion Forums
- » Things I'm Making and Creating
-
» need help with python the script won't work